eth-owned

EIP-173 interface and tools for chainlib-eth
git clone git://holbrook.no/eth-owned.git
Info | Log | Files | Refs

owned.py (1620B)


      1 # external imports
      2 from hexathon import (
      3         add_0x,
      4     )
      5 
      6 # local imports
      7 from chainlib.eth.contract import (
      8         ABIContractEncoder,
      9         ABIContractDecoder,
     10         ABIContractType,
     11         abi_decode_single,
     12     )
     13 from chainlib.jsonrpc import JSONRPCRequest
     14 from chainlib.eth.tx import (
     15         TxFactory,
     16         TxFormat,
     17         )
     18 from chainlib.eth.constant import ZERO_ADDRESS
     19 
     20 class ERC173(TxFactory):
     21 
     22     def transfer_ownership(self, contract_address, sender_address, new_owner_address, final=False, tx_format=TxFormat.JSONRPC):
     23         enc = ABIContractEncoder()
     24         if final:
     25             enc.method('transferOwnershipFinal')
     26         else:
     27             enc.method('transferOwnership')
     28         enc.typ(ABIContractType.ADDRESS)
     29         enc.address(new_owner_address)
     30         data = add_0x(enc.get())
     31         tx = self.template(sender_address, contract_address, use_nonce=True)
     32         tx = self.set_code(tx, data)
     33         tx = self.finalize(tx, tx_format)
     34         return tx
     35 
     36 
     37     def owner(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
     38         j = JSONRPCRequest(id_generator)
     39         o = j.template()
     40         o['method'] = 'eth_call'
     41         enc = ABIContractEncoder()
     42         enc.method('owner')
     43         data = add_0x(enc.get())
     44         tx = self.template(sender_address, contract_address)
     45         tx = self.set_code(tx, data)
     46         o['params'].append(self.normalize(tx))
     47         o['params'].append('latest')
     48         o = j.finalize(o)
     49         return o
     50 
     51 
     52     @classmethod
     53     def parse_owner(self, v):
     54         return abi_decode_single(ABIContractType.ADDRESS, v)