mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-17 06:02:12 -04:00
add decode_calldata.py
This commit is contained in:
parent
e48efef9dc
commit
33b4422bcc
1 changed files with 43 additions and 0 deletions
43
web3toolkit/scripts/decode_calldata.py
Normal file
43
web3toolkit/scripts/decode_calldata.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- encoding: utf-8 -*-
|
||||
# author: steinkirch
|
||||
|
||||
from utils.strings import pprint
|
||||
from utils.os import load_config
|
||||
from utils.web3_wrapper import Web3Wrapper
|
||||
|
||||
|
||||
def get_data_for_connection() -> dict:
|
||||
"""Prepare a dict of data for connection."""
|
||||
|
||||
data = {}
|
||||
env_keys = ['PROVIDER_URL',
|
||||
'PROVIDER_TYPE',
|
||||
'CONTRACT_ADDRESS',
|
||||
'ABI',
|
||||
'CALLDATA']
|
||||
env_vars = load_config(env_keys)
|
||||
|
||||
data['network'] = env_vars['PROVIDER_URL']
|
||||
data['provider_type'] = env_vars['PROVIDER_URL']
|
||||
data['contract_address'] = env_vars['CONTRACT_ADDRESS']
|
||||
data['calldata'] = env_vars['CALLDATA']
|
||||
data['abi'] = env_vars['ABI']
|
||||
return data
|
||||
|
||||
|
||||
def decode_calldata(data) -> dict:
|
||||
"""Decode raw calldata, given a contract and its ABI."""
|
||||
|
||||
w3 = Web3Wrapper(mode=data['provider_type'],
|
||||
network=data['network'])
|
||||
|
||||
w3.get_pair_contract(address=data['contract_address'), abi=data['abi'))
|
||||
return we.pair_contract.decode_function_input(data['calldata'])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
data = get_data_for_connection()
|
||||
results = decode_calldata(data)
|
||||
pprint(results)
|
Loading…
Add table
Add a link
Reference in a new issue