From 055710763e75e73b7c2dfeb1e61f5b9c35457114 Mon Sep 17 00:00:00 2001 From: nolash Date: Tue, 29 Jun 2021 08:28:42 +0200 Subject: [PATCH] Add allowance handler --- python/eth_erc20/erc20.py | 24 ++++++++++++++++++++++++ python/setup.cfg | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/python/eth_erc20/erc20.py b/python/eth_erc20/erc20.py index 52830dd..5ef5ea2 100644 --- a/python/eth_erc20/erc20.py +++ b/python/eth_erc20/erc20.py @@ -115,6 +115,25 @@ class ERC20(TxFactory): return o + def allowance(self, contract_address, holder_address, spender_address, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('allowance') + enc.typ(ABIContractType.ADDRESS) + enc.typ(ABIContractType.ADDRESS) + enc.address(holder_address) + enc.address(spender_address) + data = add_0x(enc.get()) + tx = self.template(sender_address, contract_address) + tx = self.set_code(tx, data) + o['params'].append(self.normalize(tx)) + o['params'].append('latest') + o = j.finalize(o) + return o + + def transfer(self, contract_address, sender_address, recipient_address, value, tx_format=TxFormat.JSONRPC, id_generator=None): enc = ABIContractEncoder() enc.method('transfer') @@ -184,6 +203,11 @@ class ERC20(TxFactory): return abi_decode_single(ABIContractType.UINT256, v) + @classmethod + def parse_allowance(self, v): + return abi_decode_single(ABIContractType.UINT256, v) + + @classmethod def parse_transfer_request(self, v): v = strip_0x(v) diff --git a/python/setup.cfg b/python/setup.cfg index 3ba2719..01f3f98 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = eth-erc20 -version = 0.0.10a1 +version = 0.0.10a2 description = ERC20 interface and simple contract with deployment script that lets any address mint and gift itself tokens. author = Louis Holbrook author_email = dev@holbrook.no