view.py (2899B)
1 """View address declaration, and attempt to resolve contents 2 3 .. moduleauthor:: Louis Holbrook <dev@holbrook.no> 4 .. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 5 6 """ 7 8 # standard imports 9 import os 10 import logging 11 import sys 12 13 # external imports 14 import chainlib.eth.cli 15 from chainlib.chain import ChainSpec 16 from chainlib.error import JSONRPCException 17 from chainlib.eth.address import to_checksum_address 18 from chainlib.eth.constant import ZERO_ADDRESS 19 from hexathon import ( 20 add_0x, 21 strip_0x, 22 ) 23 from chainlib.eth.cli.arg import ( 24 Arg, 25 ArgFlag, 26 process_args, 27 ) 28 from chainlib.eth.cli.config import ( 29 Config, 30 process_config, 31 ) 32 from chainlib.eth.cli.log import process_log 33 from chainlib.eth.settings import process_settings 34 from chainlib.settings import ChainSettings 35 36 37 # local imports 38 from eth_address_declarator import Declarator 39 from eth_address_declarator.declarator import AddressDeclarator 40 41 logging.basicConfig(level=logging.WARNING) 42 logg = logging.getLogger() 43 44 45 def process_config_local(config, arg, args, flags): 46 a = strip_0x(config.get('_POSARG')) 47 ac = to_checksum_address(a) 48 if config.true('_UNSAFE'): 49 a = ac 50 else: 51 if a != ac: 52 raise ValueError('declarator is not a valid checksum address') 53 config.add(a, '_DECLARATOR') 54 return config 55 56 57 arg_flags = ArgFlag() 58 arg = Arg(arg_flags) 59 flags = arg_flags.STD_WRITE | arg_flags.WALLET | arg_flags.EXEC | arg_flags.SENDER 60 61 argparser = chainlib.eth.cli.ArgumentParser() 62 argparser = process_args(argparser, arg, flags) 63 argparser.add_argument('declarator', type=str, help='Ethereum declaration address to look up') 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='declarator') 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 out_element(e, w=sys.stdout): 79 w.write(e[1] + '\n') 80 81 82 def ls(ifc, conn, contract_address, declarator_address, subject_address, w=sys.stdout, sender_address=ZERO_ADDRESS): 83 o = ifc.declaration(contract_address, declarator_address, subject_address, sender_address=sender_address) 84 r = conn.do(o) 85 declarations = ifc.parse_declaration(r) 86 87 for i, d in enumerate(declarations): 88 out_element((i, d), w) 89 90 91 def main(): 92 93 c = Declarator( 94 settings.get('CHAIN_SPEC') 95 ) 96 97 ls( 98 c, 99 settings.get('CONN'), 100 settings.get('EXEC'), 101 config.get('_DECLARATOR'), 102 settings.get('RECIPIENT'), 103 sender_address=settings.get('SENDER_ADDRESS'), 104 ) 105 106 declarations = [] 107 108 109 if __name__ == '__main__': 110 main()