Skip to content

Commit

Permalink
Fix | Correctly parse tuple[] types (#9)
Browse files Browse the repository at this point in the history
* Correctly parse tuple[] types

* modification

* Correct indent lint
  • Loading branch information
alexcampbelling authored Apr 12, 2023
1 parent b8372f8 commit 83f8968
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dist/ethereum-input-decoder.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ function parseCallValue(val, type) {
return val;
if (type.includes('bytes'))
return val;
if (type.includes('tuple['))
return val.map(v => v.toString());
throw Error(`Unknown type ${type}`);
}
catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions dist/ethereum-input-decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ function parseCallValue(val, type) {
return val;
if (type.includes('bytes'))
return val;
if (type.includes('tuple['))
return val.map(v => v.toString());
throw Error(`Unknown type ${type}`);
}
catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethereum-input-decoder",
"version": "0.1.7",
"version": "0.1.8",
"description": "Decodes inputs for a given abi",
"main": "dist/ethereum-input-decoder.js",
"module": "dist/ethereum-input-decoder.esm.js",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function parseCallValue(val: any, type: string): any {
if (type.includes('bytes32[')) return val
if (type.includes('bytes[')) return val
if (type.includes('bytes')) return val
if (type.includes('tuple[')) return val.map(v => v.toString())
throw Error(`Unknown type ${type}`)
} catch (error) {
throw Error(
Expand Down
1 change: 1 addition & 0 deletions test/data/seaport1_4.json

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,42 @@ test('decoder', (t) => {
}
t.deepEquals(result, expectedSetApprovalForAll)
})

t.test('Checking Seaport 1.4 for tuple[] type', (t) => {
t.plan(1)
const decoder = new InputDataDecoder(`${__dirname}/data/seaport1_4.json`)
const data = '0x00000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009e3dcdb2f0d0000000000000000000000000006433ce529c917eaf3cb81cb10dde6dfcbf0cfb2d000000000000000000000000004c00500000ad104d7dbd00e3ae0a5c00560c00000000000000000000000000e7bb385693616c29a9dbc45ab0195d35c8171faa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000642e18f300000000000000000000000000000000000000000000000000000000642f6a730000000000000000000000000000000000000000000000000000000000000000360c6ebe000000000000000000000000000000000000000026dc7c9ed5435f520000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f00000000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000360000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000046545b6bf94000000000000000000000000000000a26b00c1f0df003000390027140000faa7190000000000000000000000000000000000000000000000000003f4bebe12d200000000000000000000000000b3235e9ac33c9fe4341566bee6338287f2dae414000000000000000000000000000000000000000000000000000484c7aa751200000000000000000000000000e5c8a4222012043167be4a7978aee27e2b2dc7180000000000000000000000000000000000000000000000000004b64abbb6d80000000000000000000000000085a3514ff889191fa09b7f7080dc180e676cbc3100000000000000000000000000000000000000000000000000000000000000408fa3b99021e3aaf7804df223ee78d18904d97faf2027e48f794e4d6a0e2ff49131fa0fcd1d4848955878874e12643936ba6e5f12270ce387898d66f9db2dff3500000000360c6ebe'
const result = decoder.decodeData(data)
const expectedFufillBasicOrder = {
"methodName": "fulfillBasicOrder_efficient_6GL6yc",
"params": {
"parameters": {
"considerationToken": "0x0000000000000000000000000000000000000000",
"considerationIdentifier": "0",
"considerationAmount": "44541000000000000",
"offerer": "0x6433cE529C917eaF3cb81CB10ddE6dFCBF0cFB2D",
"zone": "0x004C00500000aD104D7DBd00e3ae0A5C00560C00",
"offerToken": "0xe7bB385693616C29A9dbc45aB0195D35C8171fAA",
"offerIdentifier": "1",
"offerAmount": "1",
"basicOrderType": "5",
"startTime": "1680742643",
"endTime": "1680829043",
"zoneHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"salt": "24446860302761739304752683030156737591518664810215442929803182938525194739538",
"offererConduitKey": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
"fulfillerConduitKey": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
"totalOriginalAdditionalRecipients": "4",
"additionalRecipients": [
"1237250000000000,0x0000a26b00c1F0DF003000390027140000fAa719",
"1113525000000000,0xb3235e9aC33C9fe4341566BeE6338287f2DAe414",
"1271893000000000,0xE5c8a4222012043167Be4A7978Aee27e2b2dC718",
"1326332000000000,0x85a3514Ff889191FA09b7f7080dc180E676CBC31"
],
"signature": "0x8fa3b99021e3aaf7804df223ee78d18904d97faf2027e48f794e4d6a0e2ff49131fa0fcd1d4848955878874e12643936ba6e5f12270ce387898d66f9db2dff35"
}
}
}
t.deepEquals(result, expectedFufillBasicOrder)
})
})

0 comments on commit 83f8968

Please sign in to comment.