eth-erc20

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

minter.py (3431B)


      1 """Add minter to token contact
      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.settings import ChainSettings
     22 from chainlib.eth.cli.log import process_log
     23 from chainlib.eth.settings import process_settings
     24 from chainlib.eth.address import to_checksum_address
     25 from chainlib.eth.cli.arg import (
     26         Arg,
     27         ArgFlag,
     28         process_args,
     29         )
     30 from chainlib.eth.cli.config import (
     31         Config,
     32         process_config,
     33         )
     34 
     35 from hexathon import (
     36         strip_0x,
     37         add_0x,
     38         )
     39 
     40 # local imports
     41 from giftable_erc20_token import GiftableToken
     42 
     43 logg = logging.getLogger()
     44 
     45 
     46 def process_config_local(config, arg, args, flags):
     47     config.add(args.rm, '_RM', False)
     48     config.add(add_0x(args.minter_address[0]), '_MINTER_ADDRESS', False)
     49     return config
     50 
     51 
     52 arg_flags = ArgFlag()
     53 arg = Arg(arg_flags)
     54 flags = arg_flags.STD_WRITE | arg_flags.EXEC | arg_flags.WALLET
     55 
     56 argparser = chainlib.eth.cli.ArgumentParser()
     57 argparser = process_args(argparser, arg, flags)
     58 argparser.add_argument('--rm', action='store_true', help='Remove entry')
     59 argparser.add_argument('minter_address', type=str, help='Address to add or remove as minter')
     60 args = argparser.parse_args()
     61 
     62 logg = process_log(args, logg)
     63 
     64 config = Config()
     65 config = process_config(config, arg, args, flags)
     66 config = process_config_local(config, arg, args, flags)
     67 logg.debug('config loaded:\n{}'.format(config))
     68 
     69 settings = ChainSettings()
     70 settings = process_settings(settings, config)
     71 logg.debug('settings loaded:\n{}'.format(settings))
     72 
     73 
     74 def main():
     75     token_address = settings.get('EXEC')
     76     signer_address = settings.get('SENDER_ADDRESS')
     77     conn = settings.get('CONN')
     78 
     79     recipient_address_input = settings.get('RECIPIENT')
     80     if recipient_address_input == None:
     81         recipient_address_input = signer_address
     82 
     83     recipient_address = add_0x(to_checksum_address(recipient_address_input))
     84     if not config.true('_UNSAFE') and recipient_address != add_0x(recipient_address_input):
     85         raise ValueError('invalid checksum address for recipient')
     86 
     87     minter_address = config.get('_MINTER_ADDRESS')
     88     c = GiftableToken(
     89             settings.get('CHAIN_SPEC'),
     90             signer=settings.get('SIGNER'),
     91             gas_oracle=settings.get('GAS_ORACLE'),
     92             nonce_oracle=settings.get('NONCE_ORACLE'),
     93             )
     94 
     95     if config.get('_RM'):
     96         (tx_hash_hex, o) = c.remove_minter(
     97                 settings.get('EXEC'),
     98                 signer_address,
     99                 minter_address,
    100                 )
    101     else:
    102         (tx_hash_hex, o) = c.add_minter(
    103                 settings.get('EXEC'),
    104                 signer_address,
    105                 minter_address,
    106                 )
    107 
    108     if settings.get('RPC_SEND'):
    109         conn.do(o)
    110         if settings.get('WAIT'):
    111             r = conn.wait(tx_hash_hex)
    112             if r['status'] == 0:
    113                 sys.stderr.write('EVM revert. Wish I had more to tell you')
    114                 sys.exit(1)
    115 
    116         logg.info('add minter {} to {} tx {}'.format(minter_address, token_address, tx_hash_hex))
    117 
    118         print(tx_hash_hex)
    119     else:
    120         print(o)
    121 
    122 
    123 if __name__ == '__main__':
    124     main()