Esempio n. 1
0
		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]))
Esempio n. 2
0
 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]))
Esempio n. 3
0
	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()
Esempio n. 4
0
		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'
Esempio n. 5
0
	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'])
Esempio n. 6
0
	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()
Esempio n. 7
0
	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
Esempio n. 8
0
 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'
Esempio n. 9
0
	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
Esempio n. 10
0
	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)
Esempio n. 11
0
	def get_addr_balance(self,addr):
		return Token(g.token).balance(addr)
Esempio n. 12
0
	def sym2addr(self,sym): # online
		for addr in self.data['tokens']:
			if Token(addr).symbol().upper() == sym.upper():
				return addr
		return None
Esempio n. 13
0
	def data_root_desc(self):
		return 'token ' + Token(g.token).symbol()