erc20-demurrage-token

ERC20 token with redistributed continual demurrage
Info | Log | Files | Refs | README

seal.py (1825B)


      1 # standard imports
      2 import enum
      3 
      4 # external imports
      5 from chainlib.eth.constant import ZERO_ADDRESS
      6 from chainlib.jsonrpc import JSONRPCRequest
      7 from chainlib.eth.tx import (
      8         TxFactory,
      9         TxFormat,
     10         )
     11 from chainlib.eth.contract import (
     12         ABIContractEncoder,
     13         ABIContractType,
     14         abi_decode_single,
     15         )
     16 from hexathon import (
     17         add_0x,
     18         )
     19 
     20 class ContractState(enum.IntEnum):
     21     MINTER_STATE = 1
     22     SINK_STATE = 2
     23     EXPIRY_STATE = 4
     24     CAP_STATE = 8
     25 
     26 CONTRACT_SEAL_STATE_MAX = 0
     27 
     28 for v in dir(ContractState):
     29     if len(v) > 6 and v[-6:] == '_STATE':
     30        CONTRACT_SEAL_STATE_MAX += getattr(ContractState, v).value
     31 
     32 
     33 class SealedContract(TxFactory):
     34 
     35     def seal(self, contract_address, sender_address, seal, tx_format=TxFormat.JSONRPC):
     36         enc = ABIContractEncoder()
     37         enc.method('seal')
     38         enc.typ(ABIContractType.UINT256)
     39         enc.uint256(seal)
     40         data = enc.get()
     41         tx = self.template(sender_address, contract_address, use_nonce=True)
     42         tx = self.set_code(tx, data)
     43         tx = self.finalize(tx, tx_format)
     44         return tx
     45 
     46 
     47     def is_sealed(self, contract_address, v, sender_address=ZERO_ADDRESS, id_generator=None):
     48         j = JSONRPCRequest(id_generator)
     49         o = j.template()
     50         o['method'] = 'eth_call'
     51         enc = ABIContractEncoder()
     52         enc.method('isSealed')
     53         enc.typ(ABIContractType.UINT256)
     54         enc.uint256(v)
     55         data = add_0x(enc.get())
     56         tx = self.template(sender_address, contract_address)
     57         tx = self.set_code(tx, data)
     58         o['params'].append(self.normalize(tx))
     59         o['params'].append('latest')
     60         o = j.finalize(o)
     61         return o
     62 
     63 
     64     @classmethod
     65     def parse_is_sealed(self, v):
     66         return abi_decode_single(ABIContractType.BOOLEAN, v)