set.py (3069B)
1 """Set identifier value on contract registry 2 3 .. moduleauthor:: Louis Holbrook <dev@holbrook.no> 4 .. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 5 6 """ 7 8 # standard imports 9 import sys 10 import os 11 import logging 12 import hashlib 13 14 # external imports 15 import chainlib.eth.cli 16 from chainlib.chain import ChainSpec 17 from chainlib.eth.connection import EthHTTPConnection 18 from chainlib.eth.tx import receipt 19 from chainlib.eth.constant import ZERO_CONTENT 20 from chainlib.eth.address import to_checksum_address 21 from hexathon import ( 22 add_0x, 23 strip_0x, 24 ) 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 from chainlib.eth.cli.log import process_log 35 from chainlib.eth.settings import process_settings 36 from chainlib.settings import ChainSettings 37 38 # local imports 39 from eth_contract_registry.registry import ContractRegistry 40 41 logging.basicConfig(level=logging.WARNING) 42 logg = logging.getLogger() 43 44 45 def process_config_local(config, arg, args, flags): 46 #hsh = strip_0x(args.chain_hash) 47 #if len(hsh) != 64: 48 # raise ValueError('chain hash must be 32 bytes') 49 #config.add(hsh, '_CHAIN_HASH') 50 if len(config.get('_POSARG')) > 32: 51 raise ValueError('identifier must be max 32 characters') 52 config.add(config.get('_POSARG'), '_IDENTIFIER') 53 return config 54 55 56 arg_flags = ArgFlag() 57 arg = Arg(arg_flags) 58 flags = arg_flags.STD_WRITE | arg_flags.EXEC | arg_flags.WALLET 59 60 argparser = chainlib.eth.cli.ArgumentParser() 61 argparser = process_args(argparser, arg, flags) 62 #argparser.add_argument('--chain-hash', type=str, default=ZERO_CONTENT, help='Chain config hash to use for entry') 63 argparser.add_argument('identifier', type=str, help='Contract identifier to set') 64 args = argparser.parse_args() 65 66 logg = process_log(args, logg) 67 68 config = Config() 69 config = process_config(config, arg, args, flags, positional_name='identifier') 70 config = process_config_local(config, arg, args, flags) 71 logg.debug('config loaded:\n{}'.format(config)) 72 73 settings = ChainSettings() 74 settings = process_settings(settings, config) 75 logg.debug('settings loaded:\n{}'.format(settings)) 76 77 78 def main(): 79 conn = settings.get('CONN') 80 c = ContractRegistry( 81 settings.get('CHAIN_SPEC'), 82 signer=settings.get('SIGNER'), 83 gas_oracle=settings.get('FEE_ORACLE'), 84 nonce_oracle=settings.get('NONCE_ORACLE'), 85 ) 86 87 (tx_hash_hex, o) = c.set( 88 settings.get('EXEC'), 89 settings.get('SENDER_ADDRESS'), 90 config.get('_IDENTIFIER'), 91 settings.get('RECIPIENT'), 92 ) 93 94 if settings.get('RPC_SEND'): 95 conn.do(o) 96 if config.true('_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 102 print(tx_hash_hex) 103 else: 104 print(o) 105 106 107 if __name__ == '__main__': 108 main()