def get_max_amount(self): from electrum.transaction import TxOutput if run_hook('abort_send', self): return '' inputs = self.wallet.get_spendable_coins(None, self.electrum_config) if not inputs: return '' addr = None if self.send_screen: addr = str(self.send_screen.screen.address) if not addr: addr = self.wallet.dummy_address() outputs = [TxOutput(TYPE_ADDRESS, addr, '!')] try: tx = self.wallet.make_unsigned_transaction(inputs, outputs, self.electrum_config) except NoDynamicFeeEstimates as e: Clock.schedule_once( lambda dt, bound_e=e: self.show_error(str(bound_e))) return '' except NotEnoughFunds: return '' except InternalAddressCorruption as e: self.show_error(str(e)) send_exception_to_crash_reporter(e) return '' amount = tx.output_value() __, x_fee_amount = run_hook('get_tx_extra_fee', self.wallet, tx) or (None, 0) amount_after_all_fees = amount - x_fee_amount return format_satoshis_plain(amount_after_all_fees, self.decimal_point())
def do_send(self): if self.screen.is_pr: if self.payment_request.has_expired(): self.app.show_error(_('Payment request has expired')) return outputs = self.payment_request.get_outputs() else: address = str(self.screen.address) if not address: self.app.show_error(_('Recipient not specified.') + ' ' + _('Please scan a Omotenashicoin address or a payment request')) return if not bitcoin.is_address(address): self.app.show_error(_('Invalid Omotenashicoin Address') + ':\n' + address) return try: amount = self.app.get_amount(self.screen.amount) except: self.app.show_error(_('Invalid amount') + ':\n' + self.screen.amount) return outputs = [TxOutput(bitcoin.TYPE_ADDRESS, address, amount)] message = self.screen.message amount = sum(map(lambda x:x[2], outputs)) if self.app.electrum_config.get('use_rbf'): from .dialogs.question import Question d = Question(_('Should this transaction be replaceable?'), lambda b: self._do_send(amount, message, outputs, b)) d.open() else: self._do_send(amount, message, outputs, False)
def test_payto(self, mock_save_db): wallet = restore_wallet_from_text( 'disagree rug lemon bean unaware square alone beach tennis exhibit fix mimic', gap_limit=2, path='if_this_exists_mocking_failed_648151893', config=self.config)['wallet'] # bootstrap wallet funding_tx = Transaction( '0200000000010165806607dd458280cb57bf64a16cf4be85d053145227b98c28932e953076b8e20000000000fdffffff02ac150700000000001600147e3ddfe6232e448a8390f3073c7a3b2044fd17eb102908000000000016001427fbe3707bc57e5bb63d6f15733ec88626d8188a02473044022049ce9efbab88808720aa563e2d9bc40226389ab459c4390ea3e89465665d593502206c1c7c30a2f640af1e463e5107ee4cfc0ee22664cfae3f2606a95303b54cdef80121026269e54d06f7070c1f967eb2874ba60de550dfc327a945c98eb773672d9411fd77181e00' ) funding_txid = funding_tx.txid() self.assertEqual( 'ede61d39e501d65ccf34e6300da439419c43393f793bb9a8a4b06b2d0d80a8a0', funding_txid) wallet.receive_tx_callback(funding_txid, funding_tx, TX_HEIGHT_UNCONFIRMED) cmds = Commands(config=self.config) tx_str = cmds._run( 'payto', (), destination="tb1qsyzgpwa0vg2940u5t6l97etuvedr5dejpf9tdy", amount="0.00123456", feerate=50, locktime=1972344, wallet=wallet) tx = tx_from_any(tx_str) self.assertEqual(2, len(tx.outputs())) txout = TxOutput.from_address_and_value( "tb1qsyzgpwa0vg2940u5t6l97etuvedr5dejpf9tdy", 123456) self.assertTrue(txout in tx.outputs()) self.assertEqual( "02000000000101a0a8800d2d6bb0a4a8b93b793f39439c4139a40d30e634cf5cd601e5391de6ed0100000000fdffffff0240e2010000000000160014810480bbaf62145abf945ebe5f657c665a3a3732462b060000000000160014a5103285eb519f826520a9f7d3227e1eaa7ec5f802473044022057a6f4b1ec63336c7d0ba233e785ec9f2e2d9c2d67617a50e069f4498ee6a3b7022032fb331e0bef06f46e9cb77bfe94413142653c4912516835e941fa7f170c1a53012103001b55f19541faaf7e6d57dd1bdb9fdc37725fc500e12f2418cc11e0aed4154978181e00", tx_str)
def read_invoice(self): address = str(self.screen.address) if not address: self.app.show_error( _('Recipient not specified.') + ' ' + _('Please scan a Tachacoin address or a payment request')) return if not self.screen.amount: self.app.show_error(_('Please enter an amount')) return try: amount = self.app.get_amount(self.screen.amount) except: self.app.show_error( _('Invalid amount') + ':\n' + self.screen.amount) return message = self.screen.message if self.screen.is_lightning: return self.app.wallet.lnworker.parse_bech32_invoice(address) else: if not bitcoin.is_address(address): self.app.show_error( _('Invalid Tachacoin Address') + ':\n' + address) return outputs = [TxOutput(TYPE_ADDRESS, address, amount)] return self.app.wallet.create_invoice(outputs, message, self.payment_request, self.parsed_URI)
def do_send(self): if self.screen.is_pr: if self.payment_request.has_expired(): self.app.show_error(_('Payment request has expired')) return outputs = self.payment_request.get_outputs() else: address = str(self.screen.address) if not address: self.app.show_error( _('Recipient not specified.') + ' ' + _('Please scan a Ravencoin address or a payment request')) return if not ravencoin.is_address(address): self.app.show_error( _('Invalid Ravencoin Address') + ':\n' + address) return try: amount = self.app.get_amount(self.screen.amount) except: self.app.show_error( _('Invalid amount') + ':\n' + self.screen.amount) return outputs = [TxOutput(ravencoin.TYPE_ADDRESS, address, amount)] message = self.screen.message amount = sum(map(lambda x: x[2], outputs)) self._do_send(amount, message, outputs, False)
def make_unsigned_transaction(self, coins, outputs, config, fixed_fee=None, change_addr=None, is_sweep=False): mk_tx = lambda o: Multisig_Wallet.make_unsigned_transaction( self, coins, o, config, fixed_fee, change_addr) fee = self.extra_fee(config) if not is_sweep else 0 if fee: address = self.billing_info['billing_address_segwit'] fee_output = TxOutput(TYPE_ADDRESS, address, fee) try: tx = mk_tx(outputs + [fee_output]) except NotEnoughFunds: # TrustedCoin won't charge if the total inputs is # lower than their fee tx = mk_tx(outputs) if tx.input_value() >= fee: raise self.print_error("not charging for this tx") else: tx = mk_tx(outputs) return tx
def get_outputs(self, is_max): if self.payto_address: if is_max: amount = '!' else: amount = self.amount_edit.get_amount() _type, addr = self.payto_address self.outputs = [TxOutput(_type, addr, amount)] return self.outputs[:]
def read_send_form(send: ObjCInstance) -> tuple: # if self.payment_request and self.payment_request.has_expired(): # parent().show_error(_('Payment request has expired')) # return label = send.descDel.text addr_e = send.payTo fee_e = send.feeTf outputs = [] if False: # self.payment_request: # outputs = self.payment_request.get_outputs() pass else: errors = False # self.payto_e.get_errors() if errors: # self.show_warning(_("Invalid lines found:") + "\n\n" + '\n'.join([ _("Line #") + str(x[0]+1) + ": " + x[1] for x in errors])) # return pass amt_e = send.amt try: typ, addr = Parser().parse_output(addr_e.text) except: utils.show_alert(send, _("Error"), _("Invalid Address")) return None outputs = [ TxOutput(typ, addr, "!" if send.isMax else amt_e.getAmount()) ] # if self.payto_e.is_alias and self.payto_e.validated is False: # alias = self.payto_e.toPlainText() # msg = _('WARNING: the alias "{}" could not be validated via an additional ' # 'security check, DNSSEC, and thus may not be correct.').format(alias) + '\n' # msg += _('Do you wish to continue?') # if not self.question(msg): # return if not outputs: utils.show_alert(send, _("Error"), _('No outputs')) return None for _type, addr, amount in outputs: if amount is None: utils.show_alert(send, _("Error"), _('Invalid Amount')) return None freeze_fee = fee_e.isModified() and fee_e.getAmount( ) # self.fee_e.isVisible() and self.fee_e.isModified() and (self.fee_e.text() or self.fee_e.hasFocus()) fee = fee_e.getAmount() if freeze_fee else None coins = get_coins(send) return outputs, fee, label, coins
def do_send(self): if not is_address(self.str_recipient): print(_('Invalid Bitcoin address')) return try: amount = int(Decimal(self.str_amount) * COIN) except Exception: print(_('Invalid Amount')) return try: fee = int(Decimal(self.str_fee) * COIN) except Exception: print(_('Invalid Fee')) return if self.wallet.has_password(): password = self.password_dialog() if not password: return else: password = None c = "" while c != "y": c = input("ok to send (y/n)?") if c == "n": return try: tx = self.wallet.mktx( [TxOutput(TYPE_ADDRESS, self.str_recipient, amount)], password, self.config, fee) except Exception as e: print(str(e)) return if self.str_description: self.wallet.labels[tx.txid()] = self.str_description print(_("Please wait...")) try: self.network.run_from_another_thread( self.network.broadcast_transaction(tx)) except Exception as e: display_msg = _( 'The server returned an error when broadcasting the transaction.' ) display_msg += '\n' + repr(e) print(display_msg) else: print(_('Payment sent.'))
def do_send(self): if not is_address(self.str_recipient): print(_('Invalid Ravencoin address')) return try: amount = int(Decimal(self.str_amount) * COIN) except Exception: print(_('Invalid Amount')) return try: fee = int(Decimal(self.str_fee) * COIN) except Exception: print(_('Invalid Fee')) return if self.wallet.has_password(): password = self.password_dialog() if not password: return else: password = None c = "" while c != "y": c = input("ok to send (y/n)?") if c == "n": return try: tx = self.wallet.mktx( [TxOutput(TYPE_ADDRESS, self.str_recipient, amount)], password, self.config, fee) except Exception as e: print(str(e)) return if self.str_description: self.wallet.labels[tx.txid()] = self.str_description print(_("Please wait...")) try: self.network.run_from_another_thread( self.network.broadcast_transaction(tx)) except TxBroadcastError as e: msg = e.get_message_for_gui() print(msg) except BestEffortRequestFailed as e: msg = repr(e) print(msg) else: print(_('Payment sent.'))
def get_outputs(self, is_max): if self.payto_address: if is_max: amount = '!' else: amount = self.amount_edit.get_amount() _type, addr = self.payto_address script = ravencoin.address_to_script(addr) self.outputs = [TxOutput(_type, addr, amount, False, '', script)] return self.outputs[:]
def get_outputs(is_max): outputs = [] if addr_e.text: if is_max: amount = '!' else: amount = amount_e.getAmount() try: _type, addr = Parser().parse_output(addr_e.text) outputs = TxOutput(_type, addr, amount) except Exception as e: # print("Testing get_outputs Exception: %s"%str(e)) pass return outputs
def do_send(self): if not is_address(self.str_recipient): print(_('Invalid Bitcoin address')) return try: amount = int(Decimal(self.str_amount) * COIN) except Exception: print(_('Invalid Amount')) return try: fee = int(Decimal(self.str_fee) * COIN) except Exception: print(_('Invalid Fee')) return if self.wallet.has_password(): password = self.password_dialog() if not password: return else: password = None c = "" while c != "y": c = input("ok to send (y/n)?") if c == "n": return try: tx = self.wallet.mktx( [TxOutput(TYPE_ADDRESS, self.str_recipient, amount)], password, self.config, fee) except Exception as e: print(str(e)) return if self.str_description: self.wallet.labels[tx.txid()] = self.str_description print(_("Please wait...")) status, msg = self.network.run_from_another_thread( self.network.broadcast_transaction(tx)) if status: print(_('Payment sent.')) #self.do_clear() #self.update_contacts_tab() else: print(_('Error'))
def do_send(self): if not is_address(self.str_recipient): self.show_message(_('Invalid VIPSTARCOIN address')) return try: amount = int(Decimal(self.str_amount) * COIN) except Exception: self.show_message(_('Invalid Amount')) return try: fee = int(Decimal(self.str_fee) * COIN) except Exception: self.show_message(_('Invalid Fee')) return if self.wallet.has_password(): password = self.password_dialog() if not password: return else: password = None try: tx = self.wallet.mktx( [TxOutput(TYPE_ADDRESS, self.str_recipient, amount)], password, self.config, fee) except Exception as e: self.show_message(str(e)) return if self.str_description: self.wallet.labels[tx.hash()] = self.str_description self.show_message(_("Please wait..."), getchar=False) status, msg = self.network.broadcast_transaction(tx) if status: self.show_message(_('Payment sent.')) self.do_clear() #self.update_contacts_tab() else: display_msg = _( 'The server returned an error when broadcasting the transaction.' ) display_msg += '\n' + str(msg) self.show_message(display_msg)
def do_send(self): if not is_address(self.str_recipient): self.show_message(_('Invalid Bitcoin address')) return try: amount = int(Decimal(self.str_amount) * COIN) except Exception: self.show_message(_('Invalid Amount')) return try: fee = int(Decimal(self.str_fee) * COIN) except Exception: self.show_message(_('Invalid Fee')) return if self.wallet.has_password(): password = self.password_dialog() if not password: return else: password = None try: tx = self.wallet.mktx( [TxOutput(TYPE_ADDRESS, self.str_recipient, amount)], password, self.config, fee) except Exception as e: self.show_message(repr(e)) return if self.str_description: self.wallet.labels[tx.txid()] = self.str_description self.show_message(_("Please wait..."), getchar=False) try: self.network.run_from_another_thread( self.network.broadcast_transaction(tx)) except TxBroadcastError as e: msg = e.get_message_for_gui() self.show_message(msg) except BestEffortRequestFailed as e: msg = repr(e) self.show_message(msg) else: self.show_message(_('Payment sent.')) self.do_clear()
def do_pay_invoice(self, invoice): if invoice['type'] == PR_TYPE_LN: self._do_send_lightning(invoice['invoice'], invoice['amount']) return elif invoice['type'] == PR_TYPE_ADDRESS: address = invoice['address'] amount = invoice['amount'] message = invoice['message'] outputs = [TxOutput(bitcoin.TYPE_ADDRESS, address, amount)] elif invoice['type'] == PR_TYPE_BIP70: outputs = invoice['outputs'] amount = sum(map(lambda x:x[2], outputs)) # onchain payment if self.app.electrum_config.get('use_rbf'): d = Question(_('Should this transaction be replaceable?'), lambda b: self._do_send_onchain(amount, message, outputs, b)) d.open() else: self._do_send_onchain(amount, message, outputs, False)
def do_send(self): if not is_address(self.str_recipient): self.show_message(_('Invalid Bitcoin address')) return try: amount = int(Decimal(self.str_amount) * COIN) except Exception: self.show_message(_('Invalid Amount')) return try: fee = int(Decimal(self.str_fee) * COIN) except Exception: self.show_message(_('Invalid Fee')) return if self.wallet.has_password(): password = self.password_dialog() if not password: return else: password = None try: tx = self.wallet.mktx( [TxOutput(TYPE_ADDRESS, self.str_recipient, amount)], password, self.config, fee) except Exception as e: self.show_message(str(e)) return if self.str_description: self.wallet.labels[tx.txid()] = self.str_description self.show_message(_("Please wait..."), getchar=False) status, msg = self.network.broadcast_transaction_from_non_network_thread( tx) if status: self.show_message(_('Payment sent.')) self.do_clear() #self.update_contacts_tab() else: self.show_message(_('Error'))
def parse_address_and_amount(self, line): x, y = line.split(',') out_type, out = self.parse_output(x) amount = self.parse_amount(y) return TxOutput(out_type, out, amount)
def doUpdateFee(self) -> None: '''Recalculate the fee. If the fee was manually input, retain it, but still build the TX to see if there are enough funds. ''' fee_e = self.feeTf amount_e = self.amt addr_e = self.payTo self.notEnoughFunds = False self.excessiveFee = False def get_outputs(is_max): outputs = [] if addr_e.text: if is_max: amount = '!' else: amount = amount_e.getAmount() try: _type, addr = Parser().parse_output(addr_e.text) outputs = TxOutput(_type, addr, amount) except Exception as e: # print("Testing get_outputs Exception: %s"%str(e)) pass return outputs def get_dummy(): return (bitcoin.TYPE_ADDRESS, wallet().dummy_address()) freeze_fee = (fee_e.isModified() and (fee_e.text or fee_e.isFirstResponder)) # print("freeze_fee=%s"%str(freeze_fee)) amount = '!' if self.isMax else amount_e.getAmount() if amount is None: if not freeze_fee: fee_e.setAmount(None) # TODO # self.statusBar().showMessage('') else: fee = fee_e.getAmount() if freeze_fee else None outputs = get_outputs(self.isMax) if not outputs: _type, addr = get_dummy() outputs = TxOutput(_type, addr, amount) try: tx = wallet().make_unsigned_transaction( get_coins(self), [outputs], config(), fee) if tx and freeze_fee and fee and tx.estimated_size(): self.feeLbl.text = _( "Manual fee") + ": " + parent().format_fee_rate( (fee * 1e3) / tx.estimated_size()) except NotEnoughFunds: self.notEnoughFunds = True if not freeze_fee: fee_e.setAmount_(None) self.chkOk() return except BaseException as e: traceback.print_exc(file=sys.stdout) parent().show_error(str(e)) self.chkOk() return if not freeze_fee: fee = None if self.notEnoughFunds else tx.get_fee() fee_e.setAmount_(fee) if self.isMax: amount = tx.output_value() amount_e.setAmount_(amount) self.chkOk()