【关于web3j对二维结构体数组encode】https://github.com/web3j/web3j/issues/1949 麻烦大佬们有时间看看

i.e: { "components":[ { "internalType":"uint256", "name":"orderIndex", "type":"uint256" }, { "internalType":"uint256", "name":"itemIndex", "type":"uint256" } ], "internalType":"struct FulfillmentComponent[][]", "name":"", "type":"tuple[][]" }

================web3j=================== /*

offerFulfillments = [[{"orderIndex":0,"itemIndex":0}],[{"orderIndex":1,"itemIndex":0}]] */ List encodedParameters = new ArrayList<>(); encodedParameters.add( new DynamicArray( DynamicArray.class, offerFulfillments.stream().map(ov -> new DynamicArray<>( DynamicStruct.class, ov.stream().map(iv -> new DynamicStruct( new Uint256(iv.getOrderIndex()), new Uint256(iv.getItemIndex())) ).collect(Collectors.toList()) ) ).collect(Collectors.toList()) ) ); return FunctionEncoder.encodeConstructor(encodedParameters); the encode data is : 0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000002 0000000000000000000000000000000000000000000000000000000000000001 -- the 1 0000000000000000000000000000000000000000000000000000000000000020 -- 32(dynamicArray + 32) 0000000000000000000000000000000000000000000000000000000000000000 -- 0 0000000000000000000000000000000000000000000000000000000000000000 -- 0 0000000000000000000000000000000000000000000000000000000000000001 -- the 2 0000000000000000000000000000000000000000000000000000000000000020 -- 32(dynamicArray + 32) 0000000000000000000000000000000000000000000000000000000000000001 -- 1 0000000000000000000000000000000000000000000000000000000000000000 -- 0

=============================web3js================ abi = { "components":[ { "internalType":"uint256", "name":"orderIndex", "type":"uint256" }, { "internalType":"uint256", "name":"itemIndex", "type":"uint256" } ], "internalType":"struct FulfillmentComponent[][]", "name":"", "type":"tuple[][]" };

const functionSignature = web3.eth.abi.encodeFunctionCall(abi, [offerFulfillments]);

the i get the encode data is

0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000002 -- total 2 0000000000000000000000000000000000000000000000000000000000000040 -- offset of 1 00000000000000000000000000000000000000000000000000000000000000a0 -- offset of 2 0000000000000000000000000000000000000000000000000000000000000001 -- the 1 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000001 -- the 2 0000000000000000000000000000000000000000000000000000000000000001 0000000000000000000000000000000000000000000000000000000000000000

================================result=============== web3js is right; web3j is wrong

so ,how to get the right data with web3j to encode struct FulfillmentComponent[][]

请先 登录 后评论

1 个回答

Meta - 风是自由的,你也是
请先 登录 后评论
  • 1 关注
  • 0 收藏,1809 浏览
  • 用户_16551 提出于 2023-08-18 22:01