def show_bals(): for i in range(2): tk = Token(self.read_from_tmpfile('token_addr{}'.format(i+1)).strip()) imsg('Token: {}'.format(tk.symbol())) imsg('dev token balance: {}'.format(tk.balance(dfl_addr))) imsg('usr token balance: {} ({} {})'.format( tk.balance(usr_addrs[i]),usr_mmaddrs[i],usr_addrs[i]))
def show_bals(): for i in range(2): tk = Token( self.read_from_tmpfile('token_addr{}'.format(i + 1)).strip()) imsg('Token: {}'.format(tk.symbol())) imsg('dev token balance: {}'.format(tk.balance(dfl_addr))) imsg('usr token balance: {} ({} {})'.format( tk.balance(usr_addrs[i]), usr_mmaddrs[i], usr_addrs[i]))
def make_txobj(self): super(EthereumTokenMMGenTX,self).make_txobj() t = Token(g.token) o = t.txcreate( self.inputs[0].addr, self.outputs[0].addr, (self.inputs[0].amt if self.outputs[0].is_chg else self.outputs[0].amt), self.start_gas, self.usr_rel_fee or self.fee_abs2rel(self.fee,to_unit='eth')) self.txobj['token_addr'] = self.token_addr = t.addr self.txobj['decimals'] = t.decimals()
def do_transfer(): for i in range(2): tk = Token(self.read_from_tmpfile('token_addr{}'.format(i+1)).strip()) imsg_r('\n'+tk.info()) imsg('dev token balance (pre-send): {}'.format(tk.balance(dfl_addr))) imsg('Sending {} {} to address {} ({})'.format(amt,g.coin,usr_addrs[i],usr_mmaddrs[i])) from mmgen.obj import ETHAmt txid = tk.transfer( dfl_addr, usr_addrs[i], amt, dfl_privkey, start_gas = ETHAmt(60000,'wei'), gasPrice = ETHAmt(8,'Gwei') ) assert etx.get_exec_status(txid,True) != 0,'Transfer of token funds failed. Aborting'
def check_txfile_hex_data(self): d = super(EthereumTokenMMGenTX,self).check_txfile_hex_data() o = self.txobj if self.check_sigs(): # online, from rlp rpc_init() o['token_addr'] = TokenAddr(o['to']) o['amt'] = Token(o['token_addr']).transferdata2amt(o['data']) else: # offline, from json o['token_addr'] = TokenAddr(d['token_addr']) o['decimals'] = Int(d['decimals']) t = Token(o['token_addr'],o['decimals']) self.data = o['data'] = t.create_data(o['to'],o['amt'])
def do_sign(self,d,wif,tx_num_str): d = self.txobj msg_r('Signing transaction{}...'.format(tx_num_str)) try: t = Token(d['token_addr'],decimals=d['decimals']) tx_in = t.txcreate(d['from'],d['to'],d['amt'],self.start_gas,d['gasPrice'],nonce=d['nonce']) (self.hex,self.coin_txid) = t.txsign(tx_in,wif,d['from'],chain_id=d['chainId']) msg('OK') except Exception as e: m = "{!r}: transaction signing failed!" msg(m.format(e.message)) return False return self.check_sigs()
def resolve_token_arg(token_arg): from mmgen.tw import TrackingWallet from mmgen.obj import CoinAddr from mmgen.altcoins.eth.contract import Token try: addr = CoinAddr(token_arg,on_fail='raise') except: addr = TrackingWallet().sym2addr(token_arg) else: Token(addr) # test for presence in blockchain if not addr: m = "'{}': unrecognized token symbol" raise UnrecognizedTokenSymbol(m.format(token_arg)) sym = Token(addr).symbol().upper() vmsg('ERC20 token resolved: {} ({})'.format(addr,sym)) return addr,sym
def do_transfer(): for i in range(2): tk = Token( self.read_from_tmpfile('token_addr{}'.format(i + 1)).strip()) imsg_r('\n' + tk.info()) imsg('dev token balance (pre-send): {}'.format( tk.balance(dfl_addr))) imsg('Sending {} {} to address {} ({})'.format( amt, g.coin, usr_addrs[i], usr_mmaddrs[i])) from mmgen.obj import ETHAmt txid = tk.transfer(dfl_addr, usr_addrs[i], amt, dfl_privkey, start_gas=ETHAmt(60000, 'wei'), gasPrice=ETHAmt(8, 'Gwei')) assert etx.get_exec_status( txid, True) != 0, 'Transfer of token funds failed. Aborting'
def __init__(self,usr_addr_list,minconf,showempty,showbtcaddrs,all_labels): rpc_init() if g.token: self.token = Token(g.token) tw = TrackingWallet().mmid_ordered_dict() self.total = g.proto.coin_amt('0') from mmgen.obj import CoinAddr for mmid,d in tw.items(): # if d['confirmations'] < minconf: continue # cannot get confirmations for eth account label = TwLabel(mmid+' '+d['comment'],on_fail='raise') if usr_addr_list and (label.mmid not in usr_addr_list): continue bal = self.get_addr_balance(d['addr']) if bal == 0 and not showempty: if not label.comment: continue if not all_labels: continue self[label.mmid] = {'amt': g.proto.coin_amt('0'), 'lbl': label } if showbtcaddrs: self[label.mmid]['addr'] = CoinAddr(d['addr']) self[label.mmid]['lbl'].mmid.confs = None self[label.mmid]['amt'] += bal self.total += bal
def final_inputs_ok_msg(self,change_amt): m = u"Transaction leaves ≈{} {} and {} {} in the sender's account" send_acct_tbal = 0 if self.outputs[0].is_chg else \ Token(g.token).balance(self.inputs[0].addr) - self.outputs[0].amt return m.format(ETHAmt(change_amt).hl(),g.coin,ETHAmt(send_acct_tbal).hl(),g.dcoin)
def get_addr_balance(self,addr): return Token(g.token).balance(addr)
def sym2addr(self,sym): # online for addr in self.data['tokens']: if Token(addr).symbol().upper() == sym.upper(): return addr return None
def data_root_desc(self): return 'token ' + Token(g.token).symbol()