def main(self): add_menu() welcome = 'Use the menu to scan a transaction.' droid.fullShow(qr_layout(welcome)) while True: event = droid.eventWait().result if not event: continue elif event["name"] == "key": if event["data"]["key"] == '4': if self.qr_data: self.show_qr(None) self.show_title(welcome) else: break elif event["name"] == "seed": password = self.get_password() if password is False: modal_dialog('Error','incorrect password') continue seed = wallet.get_mnemonic(password) modal_dialog('Your seed is', seed) elif event["name"] == "password": self.change_password_dialog() elif event["name"] == "xpub": mpk = wallet.get_master_public_key() self.show_qr(mpk) self.show_title('master public key') elif event["name"] == "scan": r = droid.scanBarcode() r = r.result if not r: continue data = r['extras']['SCAN_RESULT'] data = base_decode(data.encode('utf8'), None, base=43) data = ''.join(chr(ord(b)) for b in data).encode('hex') tx = Transaction(data) #except: # modal_dialog('Error', 'Cannot parse transaction') # continue if not wallet.can_sign(tx): modal_dialog('Error', 'Cannot sign this transaction') continue lines = map(lambda x: x[0] + u'\t\t' + format_satoshis(x[1]) if x[1] else x[0], tx.get_outputs()) if not modal_question('Sign?', '\n'.join(lines)): continue password = self.get_password() if password is False: modal_dialog('Error','incorrect password') continue droid.dialogCreateSpinnerProgress("Signing") droid.dialogShow() wallet.sign_transaction(tx, password) droid.dialogDismiss() data = base_encode(str(tx).decode('hex'), base=43) self.show_qr(data) self.show_title('Signed Transaction') droid.makeToast("Bye!")
def Tx_test(self): global GRowTransaction global GFileID global ST4del global Tx_IOSave try: XTr = Transaction(GRowTransaction) except: return 0 #print('XTr = ',XTr) Flv , FLfee , TTime = FFS.FilePP[GFileID] if( Flv + FLfee == 0. ): return 1 try: amount,fee = Tx_IOSave[self.IDTran] except: if not XTr.is_complete(): return 0 try: #is_relevant, is_mine, v, fee = self.window.wallet.get_wallet_delta(XTr) self.netw = Network(None) self.netw.start() InputAdrs = {} for x in XTr.inputs(): InputAdrs[x['address']]=None for x in InputAdrs: InputAdrs[x]=self.netw.synchronous_get(('blockchain.address.listunspent', [x])) fee = 0 amount = 0 for x in XTr.inputs(): print(InputAdrs[x['address']] ) for y in InputAdrs[x['address']]: if y['tx_hash'] == x['prevout_hash']: fee += int( y['value']) for addr, value in XTr.get_outputs(): print('get_outputs=',addr, value , FFS.ReceivAddress ) fee -= value if addr == FFS.ReceivAddress: amount += value if len(ST4del) > 9: del Tx_IOSave[ST4del[0]] del ST4del[0] Tx_IOSave[self.IDTran] = amount,fee ST4del.append(self.IDTran) except: return 0 dFlv = abs (Flv * 1e8 - amount ) dFLfee = abs (FLfee * 1e8 - fee * 1000. / (len(GRowTransaction)/2) ) if dFLfee + dFlv < 1000 : msg = 'MemPoolLimit' if amount > MemPoolLimit * 1e8 : status, msg = None,None try: status, msg = self.window.network.broadcast(XTr) print('broadcast_try=',status, msg) except: pass print('broadcast=',status, msg) return 1 return 0
def Tx_test(self): global GRowTransaction global GFileID global Tx_res global GIDTran global ST4del try: XTr = Transaction(GRowTransaction) except: Tx_res = 0 return print('XTr = ', XTr) Flv, FLfee, TTime = FilePP[GFileID] if (Flv + FLfee == 0.): Tx_res = 1 return try: amount, fee = Tx_IOSave[GIDTran] except: try: #is_relevant, is_mine, v, fee = self.window.wallet.get_wallet_delta(XTr) tx_hash, status, label, can_broadcast, can_rbf, amount, fee, height, conf, timestamp, exp_n = self.window.wallet.get_tx_info( XTr) if status != u'Signed': Tx_res = 0 return InputAdrs = {} for x in XTr.inputs(): InputAdrs[x['address']] = None for x in InputAdrs: InputAdrs[x] = self.window.network.synchronous_get( ('blockchain.address.listunspent', [x])) fee = 0 amount = 0 for x in XTr.inputs(): #print(InputAdrs[x['address']] ) for y in InputAdrs[x['address']]: if y['tx_hash'] == x['prevout_hash']: fee += int(y['value']) for addr, value in XTr.get_outputs(): #print('get_outputs=',addr, value , FFS.ReceivAddress ) fee -= value if addr == FFS.ReceivAddress: amount += value if len(ST4del) > 9: del Tx_IOSave[ST4del[0]] del ST4del[0] Tx_IOSave[GIDTran] = amount, fee ST4del.append(GIDTran) except: Tx_res = 0 return #fee = amount - XTr.output_value() self.window.show_transaction(XTr, u'') print("amount, fee =", amount, fee, Flv, FLfee, TTime, len(GRowTransaction)) dFlv = abs(Flv * 1e8 - amount) dFLfee = abs(FLfee * 1e8 - fee * 1000. / (len(GRowTransaction) / 2)) if dFLfee + dFlv < 1000: msg = 'MemPoolLimit' if amount > MemPoolLimit * 1e8: status, msg = None, None try: status, msg = self.window.network.broadcast(XTr) print('broadcast_try=', status, msg) except: pass print('broadcast=', status, msg) Tx_res = 1 return Tx_res = 0