Ethereum abi.encodePacked() in Rust – 以太坊abi.ENCODE()生锈区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Ethereum abi.encodePacked() in Rust – 以太坊abi.ENCODE()生锈区块链毕设代写 是一篇很好的国外资料

Ethereum abi.encodePacked() in Rust

This project allows data serialization and packing in Rust as it’s being done in Solidity with abi.encodePacked()

Example usage

packing an uint24

let input = vec![     // this is supposed to be uint24 variable in solidity     SolidityDataType::NumberWithShift(U256::from(4001), TakeLastXBytes(24)) ]; let (bytes, hash) = abi::encode_packed(&input); let hash = format!("0x{:}", hash); let expected = "0x000fa1"; assert_eq!(hash, expected);

Packing a lot of data

Solidity

    function packer(         uint24 uint24_data,         uint256 tokenId,         string calldata ipfsURI,         address sample,         uint256 id     ) public pure returns (bytes memory ){         bytes memory res = abi.encodePacked(uint24_data, tokenId, ipfsURI, sample, id);         return res;     }

Rust

let address = hex::decode("d8b934580fcE35a11B58C6D73aDeE468a2833fa8").unwrap(); let address: [u8; 20] = address.try_into().unwrap(); let input = vec![     SolidityDataType::NumberWithShift(U256::from(3838), TakeLastXBytes(24)),     SolidityDataType::Number(U256::from(4001)),     SolidityDataType::String("this-is-a-sample-string"),     SolidityDataType::Address(Address::from(address)),     SolidityDataType::Number(U256::from(1)), ]; let (_bytes, hash) = abi::encode_packed(&input); let hash = format!("0x{:}", hash); let expected = "0x000efe0000000000000000000000000000000000000000000000000000000000000fa1746869732d69732d612d73616d706c652d737472696e67d8b934580fce35a11b58c6d73adee468a2833fa80000000000000000000000000000000000000000000000000000000000000001"; assert_eq!(hash, expected);

style: cargo fmt & cargo fix


Ethereum abi.encodePacked() in Rust

This project allows data serialization and packing in Rust as it’s being done in Solidity with abi.encodePacked()

Example usage

packing an uint24

let input = vec![     // this is supposed to be uint24 variable in solidity     SolidityDataType::NumberWithShift(U256::from(4001), TakeLastXBytes(24)) ]; let (bytes, hash) = abi::encode_packed(&input); let hash = format!("0x{:}", hash); let expected = "0x000fa1"; assert_eq!(hash, expected);

Packing a lot of data

Solidity

    function packer(         uint24 uint24_data,         uint256 tokenId,         string calldata ipfsURI,         address sample,         uint256 id     ) public pure returns (bytes memory ){         bytes memory res = abi.encodePacked(uint24_data, tokenId, ipfsURI, sample, id);         return res;     }

Rust

let address = hex::decode("d8b934580fcE35a11B58C6D73aDeE468a2833fa8").unwrap(); let address: [u8; 20] = address.try_into().unwrap(); let input = vec![     SolidityDataType::NumberWithShift(U256::from(3838), TakeLastXBytes(24)),     SolidityDataType::Number(U256::from(4001)),     SolidityDataType::String("this-is-a-sample-string"),     SolidityDataType::Address(Address::from(address)),     SolidityDataType::Number(U256::from(1)), ]; let (_bytes, hash) = abi::encode_packed(&input); let hash = format!("0x{:}", hash); let expected = "0x000efe0000000000000000000000000000000000000000000000000000000000000fa1746869732d69732d612d73616d706c652d737472696e67d8b934580fce35a11b58c6d73adee468a2833fa80000000000000000000000000000000000000000000000000000000000000001"; assert_eq!(hash, expected);

style: cargo fmt & cargo fix

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/24060.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Ethereum abi.encodePacked() in Rust – 以太坊abi.ENCODE()生锈区块链毕设代写

提供最优质的资源集合

立即查看 了解详情