eth-erc20

ERC20 interface and example giftable token contract
Info | Log | Files | Refs | LICENSE

factory.py (1476B)


      1 # standard imports
      2 import os
      3 import logging
      4 
      5 # external imports
      6 from chainlib.eth.tx import (
      7         TxFactory,
      8         TxFormat,
      9         )
     10 from chainlib.hash import keccak256_string_to_hex
     11 from chainlib.eth.contract import (
     12         ABIContractEncoder,
     13         ABIContractType,
     14         )
     15 
     16 # local imports
     17 from static_token.data import data_dir
     18 
     19 logg = logging.getLogger(__name__)
     20 
     21 
     22 class StaticToken(TxFactory):
     23 
     24     __abi = None
     25     __bytecode = None
     26 
     27     def constructor(self, sender_address, name, symbol, decimals, supply, tx_format=TxFormat.JSONRPC):
     28         code = StaticToken.bytecode()
     29         enc = ABIContractEncoder()
     30         enc.string(name)
     31         enc.string(symbol)
     32         enc.uint256(decimals)
     33         enc.uint256(supply)
     34         code += enc.get()
     35         tx = self.template(sender_address, None, use_nonce=True)
     36         tx = self.set_code(tx, code)
     37         return self.finalize(tx, tx_format)
     38 
     39 
     40     @staticmethod
     41     def gas(code=None):
     42         return 2000000
     43 
     44 
     45     @staticmethod
     46     def abi():
     47         if StaticToken.__abi == None:
     48             f = open(os.path.join(data_dir, 'StaticToken.json'), 'r')
     49             StaticToken.__abi = json.load(f)
     50             f.close()
     51         return StaticToken.__abi
     52 
     53 
     54     @staticmethod
     55     def bytecode():
     56         if StaticToken.__bytecode == None:
     57             f = open(os.path.join(data_dir, 'StaticToken.bin'))
     58             StaticToken.__bytecode = f.read()
     59             f.close()
     60         return StaticToken.__bytecode