chaind-eth

Queue server for ethereum
Info | Log | Files | Refs | README | LICENSE

erc20.py (1004B)


      1 # external imports
      2 from eth_erc20 import ERC20
      3 from chainlib.eth.tx import TxFormat
      4 
      5 # local imports
      6 from chaind.eth.token import BaseTokenResolver
      7 
      8 
      9 class TokenResolver(BaseTokenResolver):
     10 
     11     def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle):
     12         super(TokenResolver, self).__init__(chain_spec, sender, signer, gas_oracle, nonce_oracle)
     13         self.factory = ERC20(self.chain_spec, signer=self.signer, gas_oracle=self.gas_oracle, nonce_oracle=self.nonce_oracle)
     14 
     15 
     16     def create(self, conn, recipient, gas_value, data=None, token_value=0, executable_address=None, passphrase=None):
     17 
     18         if executable_address == None:
     19             raise ValueError('executable address required')
     20 
     21         (gas_value, token_value, nonce) = self.get_values(gas_value, token_value, executable_address=executable_address)
     22 
     23         tx = self.factory.transfer(executable_address, self.sender, recipient, token_value, tx_format=TxFormat.DICT)
     24         tx['value'] = gas_value
     25 
     26         return tx