Skip to content

Feature: Add bytes building method #1707

Closed
@SilentCicero

Description

@SilentCicero

Can we have a simple method that nicely and tightly packs things properly like what .call does and returns it in bytes.

A literal copy and past job of what the call method does. Just expose the subroutine for call, that aids in the building of bytes data.

That way I could build transactions by running a sequence like this:

pack here being the bytes packing method.

forward_transaction(destination, value, pack(bytes4(sha3('somemethod(address)'), msg.sender));

The only alternative right now that I can see is doing crazy things like this:

function bytes4and20ToBytes(bytes4 z, bytes32 x) constant returns (bytes) {
        bytes memory bytesString = new bytes(37);
        uint charCount = 0;
        byte char;
        
        for (uint u = 0; u < 4; u++) {
            char = byte(bytes4(uint(z) * 2 ** (8 * u)));
            
            bytesString[charCount] = char;
            charCount++;
        }
        
        for (uint k = 0; k < 1; k++) {
            char = byte(bytes4(uint(0) * 2 ** (8 * k)));

            bytesString[charCount] = char;
            charCount++;
        }
        
        for (uint a = 0; a < 32; a++) {
            char = byte(bytes32(uint(x) * 2 ** (8 * a)));

            bytesString[charCount] = char;
            charCount++;
        }

        return bytesString;
    }

I think the building of bytes data will be critical going forward, and we should have reliable and simple ways to build bytes data for proxy forwarding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions