eth-erc20

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

publish.py (3255B)


      1 #!python3
      2 
      3 """Deploys giftable token
      4 
      5 .. moduleauthor:: Louis Holbrook <dev@holbrook.no>
      6 .. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 
      7 
      8 """
      9 
     10 # SPDX-License-Identifier: GPL-3.0-or-later
     11 
     12 # standard imports
     13 import sys
     14 import os
     15 import json
     16 import argparse
     17 import logging
     18 import time
     19 from enum import Enum
     20 
     21 # external imports
     22 import chainlib.eth.cli
     23 from chainlib.eth.tx import receipt
     24 from chainlib.settings import ChainSettings
     25 from chainlib.eth.cli.log import process_log
     26 from chainlib.eth.settings import process_settings
     27 from chainlib.eth.cli.arg import (
     28         Arg,
     29         ArgFlag,
     30         process_args,
     31         )
     32 from chainlib.eth.cli.config import (
     33         Config,
     34         process_config,
     35         )
     36 
     37 
     38 # local imports
     39 from giftable_erc20_token import GiftableToken
     40 
     41 logg = logging.getLogger()
     42 
     43 
     44 def process_config_local(config, arg, args, flags):
     45     config.add(args.token_name, '_TOKEN_NAME', False)
     46     config.add(args.token_symbol, '_TOKEN_SYMBOL', False)
     47     config.add(args.token_decimals, '_TOKEN_DECIMALS', False)
     48     config.add(args.token_expire, '_TOKEN_EXPIRE', False)
     49     return config
     50 
     51 
     52 arg_flags = ArgFlag()
     53 arg = Arg(arg_flags)
     54 flags = arg_flags.STD_WRITE | arg_flags.WALLET
     55 
     56 argparser = chainlib.eth.cli.ArgumentParser()
     57 argparser = process_args(argparser, arg, flags)
     58 argparser.add_argument('--name', dest='token_name', required=True, type=str, help='Token name')
     59 argparser.add_argument('--symbol', dest='token_symbol', required=True, type=str, help='Token symbol')
     60 argparser.add_argument('--decimals', dest='token_decimals', default=18, type=int, help='Token decimals')
     61 argparser.add_argument('--expire', dest='token_expire', default=0, type=int, help='Token expiry timestamp (after which token cannot be traded)')
     62 args = argparser.parse_args()
     63 
     64 logg = process_log(args, logg)
     65 
     66 config = Config()
     67 config = process_config(config, arg, args, flags)
     68 config = process_config_local(config, arg, args, flags)
     69 logg.debug('config loaded:\n{}'.format(config))
     70 
     71 settings = ChainSettings()
     72 settings = process_settings(settings, config)
     73 logg.debug('settings loaded:\n{}'.format(settings))
     74 
     75 
     76 def main():
     77     signer_address = settings.get('SENDER_ADDRESS')
     78     conn = settings.get('CONN')
     79 
     80     c = GiftableToken(
     81             settings.get('CHAIN_SPEC'),
     82             signer=settings.get('SIGNER'),
     83             gas_oracle=settings.get('GAS_ORACLE'),
     84             nonce_oracle=settings.get('NONCE_ORACLE'),
     85             )
     86 
     87     (tx_hash_hex, o) = c.constructor(
     88             signer_address,
     89             config.get('_TOKEN_NAME'),
     90             config.get('_TOKEN_SYMBOL'),
     91             config.get('_TOKEN_DECIMALS'),
     92             expire=config.get('_TOKEN_EXPIRE'),
     93             )
     94     if settings.get('RPC_SEND'):
     95         conn.do(o)
     96         if settings.get('WAIT'):
     97             r = conn.wait(tx_hash_hex)
     98             if r['status'] == 0:
     99                 sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
    100                 sys.exit(1)
    101             # TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
    102             address = r['contractAddress']
    103 
    104             print(address)
    105         else:
    106             print(tx_hash_hex)
    107     else:
    108         print(o)
    109 
    110 
    111 if __name__ == '__main__':
    112     main()