add.py (2894B)
1 """Adds a new Address declaration 2 .. moduleauthor:: Louis Holbrook <dev@holbrook.no> 3 .. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 4 5 """ 6 7 # standard imports 8 import os 9 import logging 10 11 # external imports 12 import chainlib.eth.cli 13 from chainlib.chain import ChainSpec 14 from chainlib.eth.connection import EthHTTPConnection 15 from chainlib.eth.tx import receipt 16 from chainlib.eth.address import to_checksum_address 17 from hexathon import ( 18 add_0x, 19 strip_0x, 20 ) 21 from chainlib.eth.cli.arg import ( 22 Arg, 23 ArgFlag, 24 process_args, 25 ) 26 from chainlib.eth.cli.config import ( 27 Config, 28 process_config, 29 ) 30 from chainlib.eth.cli.log import process_log 31 from chainlib.eth.settings import process_settings 32 from chainlib.settings import ChainSettings 33 34 35 # local imports 36 from eth_address_declarator.declarator import AddressDeclarator 37 38 logging.basicConfig(level=logging.WARNING) 39 logg = logging.getLogger() 40 41 42 def process_config_local(config, arg, args, flags): 43 hsh = strip_0x(config.get('_POSARG')) 44 if len(hsh) != 64: 45 raise ValueError('declaration hash must be 32 bytes') 46 config.add(hsh, '_DECLARATION') 47 return config 48 49 50 arg_flags = ArgFlag() 51 arg = Arg(arg_flags) 52 flags = arg_flags.STD_WRITE | arg_flags.WALLET | arg_flags.EXEC 53 54 argparser = chainlib.eth.cli.ArgumentParser() 55 argparser = process_args(argparser, arg, flags) 56 argparser.add_argument('declaration', type=str, help='SHA256 sum of endorsement data to add') 57 args = argparser.parse_args() 58 59 logg = process_log(args, logg) 60 61 config = Config() 62 config = process_config(config, arg, args, flags, positional_name='declaration') 63 config = process_config_local(config, arg, args, flags) 64 logg.debug('config loaded:\n{}'.format(config)) 65 66 settings = ChainSettings() 67 settings = process_settings(settings, config) 68 logg.debug('settings loaded:\n{}'.format(settings)) 69 70 71 def main(): 72 conn = settings.get('CONN') 73 c = AddressDeclarator( 74 settings.get('CHAIN_SPEC'), 75 signer=settings.get('SIGNER'), 76 gas_oracle=settings.get('FEE_ORACLE'), 77 nonce_oracle=settings.get('NONCE_ORACLE'), 78 ) 79 subject_address = to_checksum_address(settings.get('RECIPIENT')) 80 contract_address = to_checksum_address(settings.get('EXEC')) 81 82 (tx_hash_hex, o) = c.add_declaration( 83 settings.get('EXEC'), 84 settings.get('SENDER_ADDRESS'), 85 settings.get('RECIPIENT'), 86 add_0x(config.get('_DECLARATION')), 87 ) 88 89 if settings.get('RPC_SEND'): 90 conn.do(o) 91 if config.true('_WAIT'): 92 r = conn.wait(tx_hash_hex) 93 if r['status'] == 0: 94 sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you') 95 sys.exit(1) 96 97 print(tx_hash_hex) 98 else: 99 print(o) 100 101 102 if __name__ == '__main__': 103 main()