eth-erc20

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

gift.py (2803B)


      1 """Mints and gifts tokens to a given address
      2 
      3 .. moduleauthor:: Louis Holbrook <dev@holbrook.no>
      4 .. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 
      5 
      6 """
      7 
      8 # SPDX-License-Identifier: GPL-3.0-or-later
      9 
     10 # standard imports
     11 import sys
     12 import os
     13 import json
     14 import argparse
     15 import logging
     16 import time
     17 
     18 # external imports
     19 import chainlib.eth.cli
     20 from chainlib.eth.tx import receipt
     21 from chainlib.chain import ChainSpec
     22 from chainlib.eth.connection import EthHTTPConnection
     23 from chainlib.eth.address import to_checksum_address
     24 from hexathon import (
     25         strip_0x,
     26         add_0x,
     27         )
     28 from chainlib.settings import ChainSettings
     29 from chainlib.eth.cli.log import process_log
     30 from chainlib.eth.settings import process_settings
     31 from chainlib.eth.cli.arg import (
     32         Arg,
     33         ArgFlag,
     34         process_args,
     35         )
     36 from chainlib.eth.cli.config import (
     37         Config,
     38         process_config,
     39         )
     40 
     41 # local imports
     42 from giftable_erc20_token import GiftableToken
     43 
     44 logg = logging.getLogger()
     45 
     46 
     47 def process_config_local(config, arg, args, flags):
     48     config.add(config.get('_POSARG'), '_VALUE', False)
     49     return config
     50 
     51 
     52 arg_flags = ArgFlag()
     53 arg = Arg(arg_flags)
     54 flags = arg_flags.STD_WRITE | arg_flags.WALLET | arg_flags.EXEC
     55 
     56 argparser = chainlib.eth.cli.ArgumentParser()
     57 argparser = process_args(argparser, arg, flags)
     58 argparser.add_argument('value', type=str, help='Token value to send')
     59 args = argparser.parse_args()
     60 
     61 logg = process_log(args, logg)
     62 
     63 config = Config()
     64 config = process_config(config, arg, args, flags, positional_name='value')
     65 config = process_config_local(config, arg, args, flags)
     66 logg.debug('config loaded:\n{}'.format(config))
     67 
     68 settings = ChainSettings()
     69 settings = process_settings(settings, config)
     70 logg.debug('settings loaded:\n{}'.format(settings))
     71 
     72 
     73 def main():
     74     token_address = settings.get('EXEC')
     75     signer_address = settings.get('SENDER_ADDRESS')
     76     recipient = settings.get('RECIPIENT')
     77     value = settings.get('VALUE')
     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.mint_to(
     88             token_address,
     89             signer_address,
     90             recipient,
     91             value,
     92             )
     93     if settings.get('RPC_SEND'):
     94         conn.do(o)
     95         if settings.get('WAIT'):
     96             r = conn.wait(tx_hash_hex)
     97             if r['status'] == 0:
     98                 sys.stderr.write('EVM revert. Wish I had more to tell you')
     99                 sys.exit(1)
    100 
    101         logg.info('mint to {} tx {}'.format(recipient, tx_hash_hex))
    102 
    103         print(tx_hash_hex)
    104     else:
    105         print(o)
    106 
    107 
    108 if __name__ == '__main__':
    109     main()