Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Blockchain 我可以使用元组作为映射中的键吗?_Blockchain_Ethereum_Solidity - Fatal编程技术网

Blockchain 我可以使用元组作为映射中的键吗?

Blockchain 我可以使用元组作为映射中的键吗?,blockchain,ethereum,solidity,Blockchain,Ethereum,Solidity,我想这样做 struct A { uint x; string str; } mapping ((uint,bytes32,uint)=> structA); 可以将元组用作映射中的键吗?不能,只能将基本类型用作键,请参阅文档: 但是,您可以使用keccak256散列函数将元组转换为bytes32类型,并安全地将该值用作键,如下所示: keccak256(abi.encodePacked(a,b,c)) 其中a、b、c将是元组的值

我想这样做

 struct A
    {
        uint x;
        string str;
    }
 mapping ((uint,bytes32,uint)=> structA);

可以将元组用作映射中的键吗?

不能,只能将基本类型用作键,请参阅文档:

但是,您可以使用
keccak256
散列函数将元组转换为
bytes32
类型,并安全地将该值用作键,如下所示:

keccak256(abi.encodePacked(a,b,c))

其中
a、b、c
将是元组的值