async def __ainit__(self,proto,mode='r',token_addr=None): await super().__ainit__(proto,mode=mode) for v in self.data['tokens'].values(): self.conv_types(v) if self.importing and token_addr: if not is_coin_addr(proto,token_addr): raise InvalidTokenAddress(f'{token_addr!r}: invalid token address') else: assert token_addr == None,'EthereumTokenTrackingWallet_chk1' token_addr = await self.sym2addr(proto.tokensym) # returns None on failure if not is_coin_addr(proto,token_addr): raise UnrecognizedTokenSymbol(f'Specified token {proto.tokensym!r} could not be resolved!') from mmgen.obj import TokenAddr self.token = TokenAddr(proto,token_addr) if self.token not in self.data['tokens']: if self.importing: await self.import_token(self.token) else: raise TokenNotInWallet(f'Specified token {self.token!r} not in wallet!') self.decimals = self.get_param('decimals') self.symbol = self.get_param('symbol') proto.tokensym = self.symbol
async def __ainit__(self, mode='r'): await super().__ainit__(mode=mode) for v in self.data['tokens'].values(): self.conv_types(v) if not is_coin_addr(g.token): g.token = await self.sym2addr(g.token) # returns None on failure if not is_coin_addr(g.token): if self.importing: m = 'When importing addresses for a new token, the token must be specified by address, not symbol.' raise InvalidTokenAddress( f'{g.token!r}: invalid token address\n{m}') else: raise UnrecognizedTokenSymbol( f'Specified token {g.token!r} could not be resolved!') if g.token in self.data['tokens']: self.decimals = self.data['tokens'][g.token]['params']['decimals'] self.symbol = self.data['tokens'][g.token]['params']['symbol'] elif not self.importing: raise TokenNotInWallet( 'Specified token {!r} not in wallet!'.format(g.token)) self.token = g.token g.proto.dcoin = self.symbol
def __init__(self, mode='r', no_rpc=False): TrackingWallet.__init__(self, mode=mode) for v in self.data['tokens'].values(): self.conv_types(v) if g.token and not is_coin_addr(g.token): ret = self.sym2addr(g.token, no_rpc=no_rpc) if ret: g.token = ret
async def remove_address(self,addr): r = self.data_root if is_coin_addr(self.proto,addr): have_match = lambda k: k == addr elif is_mmgen_id(self.proto,addr): have_match = lambda k: r[k]['mmid'] == addr else: die(1,f'{addr!r} is not an Ethereum address or MMGen ID') for k in r: if have_match(k): # return the addr resolved to mmid if possible ret = r[k]['mmid'] if is_mmgen_id(self.proto,r[k]['mmid']) else addr del r[k] self.write() return ret else: msg(f'Address {addr!r} not found in {self.data_root_desc!r} section of tracking wallet') return None
def remove_address(self, addr): r = self.data_root if is_coin_addr(addr): have_match = lambda k: k == addr elif is_mmgen_id(addr): have_match = lambda k: r[k]['mmid'] == addr else: die(1, "'{}' is not an Ethereum address or MMGen ID".format(addr)) for k in r: if have_match(k): # return the addr resolved to mmid if possible ret = r[k]['mmid'] if is_mmgen_id(r[k]['mmid']) else addr del r[k] self.write() return ret else: m = "Address '{}' not found in '{}' section of tracking wallet" msg(m.format(addr, self.data_root_desc)) return None
def remove_address(self,addr): root = self.data_root() from mmgen.obj import is_coin_addr,is_mmgen_id if is_coin_addr(addr): have_match = lambda k: k == addr elif is_mmgen_id(addr): have_match = lambda k: root[k]['mmid'] == addr else: die(1,"'{}' is not an Ethereum address or MMGen ID".format(addr)) for k in root: if have_match(k): # return the addr resolved to mmid if possible ret = root[k]['mmid'] if is_mmgen_id(root[k]['mmid']) else addr del root[k] self.write() return ret else: m = "Address '{}' not found in '{}' section of tracking wallet" msg(m.format(addr,self.data_root_desc())) return None
def __init__(self, mode='r', no_rpc=False): EthereumTrackingWallet.__init__(self, mode=mode, no_rpc=no_rpc) self.desc = 'Ethereum token tracking wallet' if not is_coin_addr(g.token): raise UnrecognizedTokenSymbol( 'Specified token {!r} could not be resolved!'.format(g.token)) if mode == 'r' and not g.token in self.data['tokens']: raise TokenNotInWallet( 'Specified token {!r} not in wallet!'.format(g.token)) self.token = g.token if self.token in self.data['tokens']: for k in ('decimals', 'symbol'): setattr(self, k, self.get_param(k)) if getattr(self, k) == None: setattr(self, k, getattr(Token(self.token, self.decimals), k)()) if getattr(self, k) != None: self.set_param(k, getattr(self, k)) self.write()
'usage':'[opts] <owner address>', 'options': """ -h, --help Print this help message -o, --outdir= d Specify output directory for *.bin files -d, --decimals=d Number of decimals for the token (default: {d}) -n, --name=n Token name (default: {n}) -t, --supply= t Total supply of the token (default: {t}) -s, --symbol= s Token symbol (default: {s}) -S, --stdout Output data in JSON format to stdout instead of files """.format(d=decimals,n=name,s=symbol,t=supply) } cmd_args = opts.init(opts_data) assert g.coin in ('ETH','ETC'),'--coin option must be set to ETH or ETC' if not len(cmd_args) == 1 or not is_coin_addr(cmd_args[0]): opts.usage() owner_addr = '0x' + CoinAddr(cmd_args[0]) # ERC Token Standard #20 Interface # https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md code_in = """ pragma solidity ^0.4.18; contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a); } function safeSub(uint a, uint b) public pure returns (uint c) {
def is_coin_addr_loc(s): return is_coin_addr(proto,s)
-v, --verbose Produce more verbose output """ }, 'code': { 'options': lambda s: s.format( d=decimals, n=name, s=symbol, t=supply) } } cmd_args = opts.init(opts_data) assert g.coin in ('ETH','ETC'),'--coin option must be set to ETH or ETC' if not len(cmd_args) == 1 or not is_coin_addr(cmd_args[0].lower()): opts.usage() owner_addr = '0x' + cmd_args[0] # ERC Token Standard #20 Interface # https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md code_in = """ pragma solidity >0.5.0 <0.5.4; contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a);
-v, --verbose Produce more verbose output """ }, 'code': { 'options': lambda s: s.format(d=decimals, n=name, s=symbol, t=supply) } } cmd_args = opts.init(opts_data) from mmgen.protocol import init_proto_from_opts proto = init_proto_from_opts() assert proto.coin in ('ETH', 'ETC'), '--coin option must be set to ETH or ETC' if not len(cmd_args) == 1 or not is_coin_addr(proto, cmd_args[0].lower()): opts.usage() owner_addr = '0x' + cmd_args[0] # ERC Token Standard #20 Interface # https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md code_in = """ pragma solidity >0.5.0 <0.5.4; contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a);
elif len(cmd_args) == 0 and opt.address: al = AddrList(addrlist=[opt.address]) infile = 'command line' else: die(1, ai_msgs('bad_args')) m = ' from Seed ID {}'.format(al.al_id.sid) if hasattr(al.al_id, 'sid') else '' qmsg('OK. {} addresses{}'.format(al.num_addrs, m)) err_msg = None from mmgen.tw import TrackingWallet tw = TrackingWallet(mode='w') if g.token: if not is_coin_addr(g.token): m = "When importing addresses for a new token, the token must be specified by address, not symbol." raise InvalidTokenAddress('{!r}: invalid token address\n{}'.format(m)) sym = tw.addr2sym( g.token ) # check for presence in wallet or blockchain; raises exception on failure if opt.rescan and not 'rescan' in tw.caps: msg("'--rescan' ignored: not supported by {}".format(type(tw).__name__)) opt.rescan = False if opt.rescan and not opt.quiet: confirm_or_raise(ai_msgs('rescan'), 'continue', expect='YES') if opt.batch and not 'batch' in tw.caps: msg("'--batch' ignored: not supported by {}".format(type(tw).__name__))