首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >函数选择器如何处理元组?

函数选择器如何处理元组?
EN

Ethereum用户
提问于 2018-05-30 17:06:56
回答 1查看 2K关注 0票数 7

如何将元组类型编码到函数签名中以生成4字节函数选择器?官方规范没有为元组类型声明任何内容。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2018-10-20 07:16:09

使用(type1,type2,...)表示结构。

例如,fillOrder函数在0x2.0中:

代码语言:javascript
复制
function fillOrder(
    Order memory order,
    uint256 takerAssetFillAmount,
    bytes memory signature
)
    public
    returns (LibFillResults.FillResults memory fillResults);

struct Order {
    address makerAddress;           // Address that created the order.      
    address takerAddress;           // Address that is allowed to fill the order. If set to 0, any address is allowed to fill the order.          
    address feeRecipientAddress;    // Address that will recieve fees when order is filled.      
    address senderAddress;          // Address that is allowed to call Exchange contract methods that affect this order. If set to 0, any address is allowed to call these methods.
    uint256 makerAssetAmount;       // Amount of makerAsset being offered by maker. Must be greater than 0.        
    uint256 takerAssetAmount;       // Amount of takerAsset being bid on by maker. Must be greater than 0.        
    uint256 makerFee;               // Amount of ZRX paid to feeRecipient by maker when order is filled. If set to 0, no transfer of ZRX from maker to feeRecipient will be attempted.
    uint256 takerFee;               // Amount of ZRX paid to feeRecipient by taker when order is filled. If set to 0, no transfer of ZRX from taker to feeRecipient will be attempted.
    uint256 expirationTimeSeconds;  // Timestamp in seconds at which order expires.          
    uint256 salt;                   // Arbitrary number to facilitate uniqueness of the order's hash.     
    bytes makerAssetData;           // Encoded data that can be decoded by a specified proxy contract when transferring makerAsset. The last byte references the id of this proxy.
    bytes takerAssetData;           // Encoded data that can be decoded by a specified proxy contract when transferring takerAsset. The last byte references the id of this proxy.
}

函数选择器使用以下方法计算:

fillOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes),uint256,bytes)

这将产生一个keccak256 of:b4be83d519a652e54a6073d7e55643f575508112b09dcc74264b807477b576c5,前4个字节是:b4be83d5

您可以通过查看这个名为fillOrder:https://etherscan.io/tx/0x4811b7492bd845a46a052b063f943c4760174e932cb171ca25a934de6e7e4da4的tx来确认这一点。

票数 7
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/50010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档