-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from theethernaut/onboarding/util-calldata
Calldata decoding util
- Loading branch information
Showing
5 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,42 @@ | ||
const types = require('ethernaut-common/src/validation/types') | ||
const output = require('ethernaut-common/src/ui/output') | ||
const EthernautCliError = require('ethernaut-common/src/error/error') | ||
const loadAbi = require('../internal/load-abi') | ||
|
||
require('../scopes/interact') | ||
.task('tx', 'Gives information about a mined transaction') | ||
.addPositionalParam( | ||
'transactionId', | ||
'The transaction to lookup', | ||
undefined, | ||
types.bytes32, | ||
) | ||
.addPositionalParam( | ||
'abi', | ||
'The ABI path of the file to decode the tx', | ||
undefined, | ||
types.string, | ||
) | ||
.setAction(async ({ transactionId, abi }, hre) => { | ||
try { | ||
const _abi = loadAbi(abi) | ||
const iface = new hre.ethers.Interface(_abi) | ||
const tx = await hre.ethers.provider.getTransaction(transactionId) | ||
if (!tx) | ||
throw new EthernautCliError('ethernaut-interact', 'No tx found.', false) | ||
const decodedData = iface.parseTransaction({ data: tx.data }) | ||
|
||
// console.log(decodedData) | ||
|
||
const str = ` | ||
functionName: | ||
${decodedData.name}, | ||
args: | ||
(${decodedData.args.join(', ')}) | ||
` | ||
|
||
return output.resultBox(str) | ||
} catch (err) { | ||
return output.errorBox(err) | ||
} | ||
}) |
333 changes: 333 additions & 0 deletions
333
packages/ethernaut-interact/test/fixture-projects/basic-project/abis/dai.json
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,333 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ "internalType": "uint256", "name": "chainId_", "type": "uint256" } | ||
], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "src", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "guy", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "wad", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Approval", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": true, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "bytes4", | ||
"name": "sig", | ||
"type": "bytes4" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "usr", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "bytes32", | ||
"name": "arg1", | ||
"type": "bytes32" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "bytes32", | ||
"name": "arg2", | ||
"type": "bytes32" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "bytes", | ||
"name": "data", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "LogNote", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "src", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "dst", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "wad", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Transfer", | ||
"type": "event" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "DOMAIN_SEPARATOR", | ||
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "PERMIT_TYPEHASH", | ||
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ "internalType": "address", "name": "", "type": "address" }, | ||
{ "internalType": "address", "name": "", "type": "address" } | ||
], | ||
"name": "allowance", | ||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ "internalType": "address", "name": "usr", "type": "address" }, | ||
{ "internalType": "uint256", "name": "wad", "type": "uint256" } | ||
], | ||
"name": "approve", | ||
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [{ "internalType": "address", "name": "", "type": "address" }], | ||
"name": "balanceOf", | ||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ "internalType": "address", "name": "usr", "type": "address" }, | ||
{ "internalType": "uint256", "name": "wad", "type": "uint256" } | ||
], | ||
"name": "burn", | ||
"outputs": [], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "decimals", | ||
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [{ "internalType": "address", "name": "guy", "type": "address" }], | ||
"name": "deny", | ||
"outputs": [], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ "internalType": "address", "name": "usr", "type": "address" }, | ||
{ "internalType": "uint256", "name": "wad", "type": "uint256" } | ||
], | ||
"name": "mint", | ||
"outputs": [], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ "internalType": "address", "name": "src", "type": "address" }, | ||
{ "internalType": "address", "name": "dst", "type": "address" }, | ||
{ "internalType": "uint256", "name": "wad", "type": "uint256" } | ||
], | ||
"name": "move", | ||
"outputs": [], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "name", | ||
"outputs": [{ "internalType": "string", "name": "", "type": "string" }], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [{ "internalType": "address", "name": "", "type": "address" }], | ||
"name": "nonces", | ||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ "internalType": "address", "name": "holder", "type": "address" }, | ||
{ "internalType": "address", "name": "spender", "type": "address" }, | ||
{ "internalType": "uint256", "name": "nonce", "type": "uint256" }, | ||
{ "internalType": "uint256", "name": "expiry", "type": "uint256" }, | ||
{ "internalType": "bool", "name": "allowed", "type": "bool" }, | ||
{ "internalType": "uint8", "name": "v", "type": "uint8" }, | ||
{ "internalType": "bytes32", "name": "r", "type": "bytes32" }, | ||
{ "internalType": "bytes32", "name": "s", "type": "bytes32" } | ||
], | ||
"name": "permit", | ||
"outputs": [], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ "internalType": "address", "name": "usr", "type": "address" }, | ||
{ "internalType": "uint256", "name": "wad", "type": "uint256" } | ||
], | ||
"name": "pull", | ||
"outputs": [], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ "internalType": "address", "name": "usr", "type": "address" }, | ||
{ "internalType": "uint256", "name": "wad", "type": "uint256" } | ||
], | ||
"name": "push", | ||
"outputs": [], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [{ "internalType": "address", "name": "guy", "type": "address" }], | ||
"name": "rely", | ||
"outputs": [], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "symbol", | ||
"outputs": [{ "internalType": "string", "name": "", "type": "string" }], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "totalSupply", | ||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ "internalType": "address", "name": "dst", "type": "address" }, | ||
{ "internalType": "uint256", "name": "wad", "type": "uint256" } | ||
], | ||
"name": "transfer", | ||
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ "internalType": "address", "name": "src", "type": "address" }, | ||
{ "internalType": "address", "name": "dst", "type": "address" }, | ||
{ "internalType": "uint256", "name": "wad", "type": "uint256" } | ||
], | ||
"name": "transferFrom", | ||
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "version", | ||
"outputs": [{ "internalType": "string", "name": "", "type": "string" }], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [{ "internalType": "address", "name": "", "type": "address" }], | ||
"name": "wards", | ||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
Oops, something went wrong.