-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decode WASM ContractEmitted + show tx (#367)
test case: * https://polkaholic.io/tx/0x8a46c728d9d6993a70a08619b2f508d2345e1c686f1e9603d2fc39d4d645591a * https://polkaholic.io/tx/0xac30a28e43b24a89ec211d94e09076e0dce64d0bea4525cfb1e9588e22eb39d4 [psp22 transfer]
- Loading branch information
1 parent
3d38c82
commit 088cf66
Showing
8 changed files
with
171 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2261,4 +2261,4 @@ Promise.all([x]).then(() => { | |
query.autoUpdate() | ||
}).catch(err => { | ||
// handle error here | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const { | ||
ApiPromise, | ||
WsProvider, | ||
Keyring | ||
} = require("@polkadot/api"); | ||
const { | ||
CodePromise, | ||
ContractPromise | ||
} = require('@polkadot/api-contract'); | ||
const { | ||
u8aToU8a, | ||
hexToU8a, | ||
u8aToHex, | ||
compactAddLength | ||
} = require('@polkadot/util'); | ||
|
||
const Query = require("../query"); | ||
|
||
async function main() { | ||
let chainID = 30000; | ||
let endpoint = "wss:https://rpc.shibuya.astar.network"; | ||
|
||
const provider = new WsProvider(endpoint); | ||
provider.on('disconnected', () => { | ||
console.log('CHAIN API DISCONNECTED', chainID); | ||
}); | ||
provider.on('connected', () => console.log('chain API connected', chainID)); | ||
provider.on('error', (error) => console.log('chain API error', chainID, error)); | ||
let api = await ApiPromise.create({ | ||
provider: provider | ||
}); | ||
|
||
let debugLevel = 0 | ||
var query = new Query(debugLevel); | ||
await query.init(); | ||
|
||
console.log(`You are connected to ASTAR/SHIDEN/SHIBUYA chain ${chainID} endpoint=${endpoint} with options`); | ||
|
||
let testcases = [ | ||
// Transfer | ||
{ | ||
"extrinsicHash": "0x8a46c728d9d6993a70a08619b2f508d2345e1c686f1e9603d2fc39d4d645591a", | ||
"address_ss58": "a3kMGnw16gZLbjtKSWrsPJz8BQ2vV5bGfYEVKxowHjiVvbC", | ||
"data": "0x0001d2473025c560e31b005151ebadbc3e1f14a2af8fa60ed87e2b35fa930523cd3c01b5dc1f4c2d5fb2fb14ea92d824f7d440dd1114df1391fff67f1a7f7803c97fc376b20100000000000000000000000000", | ||
"codeHash": "0xa498fd3d0073459ddbed3446dea975f001a3a9669814fae694a2201452952ab4" | ||
} | ||
]; | ||
|
||
|
||
for (const t of testcases) { | ||
let address = t.address_ss58; | ||
let data = t.data; | ||
let wasmContract = await query.getWASMContract(address, chainID); | ||
let metadata = wasmContract.metadata; | ||
try { | ||
const contract = new ContractPromise(api, metadata, address); | ||
const bytes = hexToU8a(data); | ||
let result = contract.abi.decodeEvent(bytes); // compactAddLength(bytes)); | ||
let args = result.args; | ||
let names = result.event.args; | ||
console.log(names); | ||
let out = {}; | ||
args.forEach((a, idx) => { | ||
out[names[idx].name] = a.toHuman(); | ||
}) | ||
let method = result.event.identifier; | ||
console.log(method, out); | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
} | ||
} | ||
|
||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((e) => { | ||
console.error('ERROR', e); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters