deploy.py (2578B)
1 """Deploys badge NFT 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 from enum import Enum 18 19 # external imports 20 import chainlib.eth.cli 21 from chainlib.chain import ChainSpec 22 from chainlib.eth.connection import EthHTTPConnection 23 from chainlib.eth.tx import receipt 24 from chainlib.eth.constant import ZERO_ADDRESS 25 26 # local imports 27 from eth_badgetoken import BadgeToken 28 29 logging.basicConfig(level=logging.WARNING) 30 logg = logging.getLogger() 31 32 arg_flags = chainlib.eth.cli.argflag_std_write 33 argparser = chainlib.eth.cli.ArgumentParser(arg_flags) 34 argparser.add_argument('--name', dest='token_name', type=str, help='Token name') 35 argparser.add_argument('--symbol', dest='token_symbol', type=str, help='Token symbol') 36 argparser.add_argument('--declarator', dest='token_declarator', default=ZERO_ADDRESS, type=str, help='Address declarator contract') 37 args = argparser.parse_args() 38 39 extra_args = { 40 'token_name': None, 41 'token_symbol': None, 42 'token_declarator': None, 43 } 44 config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=BadgeToken.gas()) 45 46 wallet = chainlib.eth.cli.Wallet() 47 wallet.from_config(config) 48 49 rpc = chainlib.eth.cli.Rpc(wallet=wallet) 50 conn = rpc.connect_by_config(config) 51 52 chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC')) 53 54 55 def main(): 56 signer = rpc.get_signer() 57 signer_address = rpc.get_sender_address() 58 59 token_name = config.get('_TOKEN_NAME') 60 token_symbol = config.get('_TOKEN_SYMBOL') 61 token_declarator = config.get('_TOKEN_DECLARATOR') 62 63 gas_oracle = rpc.get_gas_oracle() 64 nonce_oracle = rpc.get_nonce_oracle() 65 66 c = BadgeToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) 67 (tx_hash_hex, o) = c.constructor(signer_address, token_name, token_symbol, token_declarator) 68 if config.get('_RPC_SEND'): 69 conn.do(o) 70 if config.get('_WAIT'): 71 r = conn.wait(tx_hash_hex) 72 if r['status'] == 0: 73 sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you') 74 sys.exit(1) 75 # TODO: pass through translator for keys (evm tester uses underscore instead of camelcase) 76 address = r['contractAddress'] 77 78 print(address) 79 else: 80 print(tx_hash_hex) 81 else: 82 print(o) 83 84 if __name__ == '__main__': 85 main()