eth-interface

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

eip165.py (1060B)


      1 # external imports
      2 from chainlib.eth.constant import ZERO_ADDRESS
      3 from hexathon import (
      4         add_0x,
      5         )
      6 from chainlib.jsonrpc import JSONRPCRequest
      7 from chainlib.eth.contract import (
      8         ABIContractEncoder,
      9         ABIContractDecoder,
     10         ABIContractType,
     11         abi_decode_single,
     12         )
     13 from chainlib.eth.tx import TxFactory
     14 
     15 
     16 class ERC165(TxFactory):
     17 
     18     def supports_interface(self, contract_address, interface_sum, sender_address=ZERO_ADDRESS, id_generator=None):
     19         j = JSONRPCRequest(id_generator)
     20         o = j.template()
     21         o['method'] = 'eth_call'
     22         enc = ABIContractEncoder()
     23         enc.method('supportsInterface')
     24         enc.typ(ABIContractType.BYTES4)
     25         enc.bytes4(interface_sum)
     26         data = add_0x(enc.get())
     27         tx = self.template(sender_address, contract_address)
     28         tx = self.set_code(tx, data)
     29         o['params'].append(self.normalize(tx))
     30         return o
     31 
     32 
     33     @classmethod
     34     def parse_supports_interface(self, v):
     35         return abi_decode_single(ABIContractType.BOOLEAN, v)