erc20-demurrage-token/python/erc20_demurrage_token/expiry.py

37 lines
1.0 KiB
Python
Raw Permalink Normal View History

2023-02-10 14:45:29 +01:00
# external imports
from chainlib.eth.tx import (
TxFactory,
TxFormat,
)
from chainlib.eth.contract import (
ABIContractEncoder,
ABIContractType,
2023-02-10 15:30:25 +01:00
abi_decode_single,
2023-02-10 14:45:29 +01:00
)
2023-02-10 15:30:25 +01:00
from chainlib.eth.constant import ZERO_ADDRESS
2023-02-10 14:45:29 +01:00
class ExpiryContract(TxFactory):
2023-02-10 16:21:37 +01:00
def set_expire_period(self, contract_address, sender_address, expire_timestamp, tx_format=TxFormat.JSONRPC):
2023-02-10 14:45:29 +01:00
enc = ABIContractEncoder()
2023-02-10 15:30:25 +01:00
enc.method('setExpirePeriod')
2023-02-10 14:45:29 +01:00
enc.typ(ABIContractType.UINT256)
enc.uint256(expire_timestamp)
data = enc.get()
tx = self.template(sender_address, contract_address, use_nonce=True)
tx = self.set_code(tx, data)
tx = self.finalize(tx, tx_format)
return tx
2023-02-10 15:30:25 +01:00
def expires(self, contract_address, sender_address=ZERO_ADDRESS):
return self.call_noarg('expires', contract_address, sender_address=sender_address)
@classmethod
def parse_expires(self, v):
return abi_decode_single(ABIContractType.UINT256, v)