transaction: introduce TxOutput namedtuple
This commit is contained in:
@@ -713,13 +713,14 @@ class ElectrumWindow(App):
|
||||
self.fiat_balance = self.fx.format_amount(c+u+x) + ' [size=22dp]%s[/size]'% self.fx.ccy
|
||||
|
||||
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 = str(self.send_screen.screen.address) or self.wallet.dummy_address()
|
||||
outputs = [(TYPE_ADDRESS, addr, '!')]
|
||||
outputs = [TxOutput(TYPE_ADDRESS, addr, '!')]
|
||||
try:
|
||||
tx = self.wallet.make_unsigned_transaction(inputs, outputs, self.electrum_config)
|
||||
except NoDynamicFeeEstimates as e:
|
||||
|
||||
@@ -206,9 +206,9 @@ class OutputList(RecycleView):
|
||||
|
||||
def update(self, outputs):
|
||||
res = []
|
||||
for (type, address, amount) in outputs:
|
||||
value = self.app.format_amount_and_units(amount)
|
||||
res.append({'address': address, 'value': value})
|
||||
for o in outputs:
|
||||
value = self.app.format_amount_and_units(o.value)
|
||||
res.append({'address': o.address, 'value': value})
|
||||
self.data = res
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ from kivy.utils import platform
|
||||
|
||||
from electrum.util import profiler, parse_URI, format_time, InvalidPassword, NotEnoughFunds, Fiat
|
||||
from electrum import bitcoin
|
||||
from electrum.transaction import TxOutput
|
||||
from electrum.util import timestamp_to_datetime
|
||||
from electrum.paymentrequest import PR_UNPAID, PR_PAID, PR_UNKNOWN, PR_EXPIRED
|
||||
from electrum.plugin import run_hook
|
||||
@@ -256,7 +257,7 @@ class SendScreen(CScreen):
|
||||
except:
|
||||
self.app.show_error(_('Invalid amount') + ':\n' + self.screen.amount)
|
||||
return
|
||||
outputs = [(bitcoin.TYPE_ADDRESS, address, amount)]
|
||||
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'):
|
||||
|
||||
@@ -50,7 +50,7 @@ from electrum.util import (format_time, format_satoshis, format_fee_satoshis,
|
||||
export_meta, import_meta, bh2u, bfh, InvalidPassword,
|
||||
base_units, base_units_list, base_unit_name_to_decimal_point,
|
||||
decimal_point_to_base_unit_name, quantize_feerate)
|
||||
from electrum.transaction import Transaction
|
||||
from electrum.transaction import Transaction, TxOutput
|
||||
from electrum.address_synchronizer import AddTransactionException
|
||||
from electrum.wallet import Multisig_Wallet, CannotBumpFee
|
||||
|
||||
@@ -1306,7 +1306,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
outputs = self.payto_e.get_outputs(self.is_max)
|
||||
if not outputs:
|
||||
_type, addr = self.get_payto_or_dummy()
|
||||
outputs = [(_type, addr, amount)]
|
||||
outputs = [TxOutput(_type, addr, amount)]
|
||||
is_sweep = bool(self.tx_external_keypairs)
|
||||
make_tx = lambda fee_est: \
|
||||
self.wallet.make_unsigned_transaction(
|
||||
@@ -1485,14 +1485,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
self.show_error(_('No outputs'))
|
||||
return
|
||||
|
||||
for _type, addr, amount in outputs:
|
||||
if addr is None:
|
||||
for o in outputs:
|
||||
if o.address is None:
|
||||
self.show_error(_('Bitcoin Address is None'))
|
||||
return
|
||||
if _type == TYPE_ADDRESS and not bitcoin.is_address(addr):
|
||||
if o.type == TYPE_ADDRESS and not bitcoin.is_address(o.address):
|
||||
self.show_error(_('Invalid Bitcoin Address'))
|
||||
return
|
||||
if amount is None:
|
||||
if o.value is None:
|
||||
self.show_error(_('Invalid Amount'))
|
||||
return
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ from decimal import Decimal
|
||||
|
||||
from electrum import bitcoin
|
||||
from electrum.util import bfh
|
||||
from electrum.transaction import TxOutput
|
||||
|
||||
from .qrtextedit import ScanQRTextEdit
|
||||
from .completion_text_edit import CompletionTextEdit
|
||||
@@ -77,7 +78,7 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit):
|
||||
x, y = line.split(',')
|
||||
out_type, out = self.parse_output(x)
|
||||
amount = self.parse_amount(y)
|
||||
return out_type, out, amount
|
||||
return TxOutput(out_type, out, amount)
|
||||
|
||||
def parse_output(self, x):
|
||||
try:
|
||||
@@ -139,16 +140,16 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit):
|
||||
is_max = False
|
||||
for i, line in enumerate(lines):
|
||||
try:
|
||||
_type, to_address, amount = self.parse_address_and_amount(line)
|
||||
output = self.parse_address_and_amount(line)
|
||||
except:
|
||||
self.errors.append((i, line.strip()))
|
||||
continue
|
||||
|
||||
outputs.append((_type, to_address, amount))
|
||||
if amount == '!':
|
||||
outputs.append(output)
|
||||
if output.value == '!':
|
||||
is_max = True
|
||||
else:
|
||||
total += amount
|
||||
total += output.value
|
||||
|
||||
self.win.is_max = is_max
|
||||
self.outputs = outputs
|
||||
@@ -174,7 +175,7 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit):
|
||||
amount = self.amount_edit.get_amount()
|
||||
|
||||
_type, addr = self.payto_address
|
||||
self.outputs = [(_type, addr, amount)]
|
||||
self.outputs = [TxOutput(_type, addr, amount)]
|
||||
|
||||
return self.outputs[:]
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ _ = lambda x:x
|
||||
from electrum import WalletStorage, Wallet
|
||||
from electrum.util import format_satoshis, set_verbosity
|
||||
from electrum.bitcoin import is_address, COIN, TYPE_ADDRESS
|
||||
from electrum.transaction import TxOutput
|
||||
import getpass, datetime
|
||||
|
||||
# minimal fdisk like gui for console usage
|
||||
@@ -189,7 +190,8 @@ class ElectrumGui:
|
||||
if c == "n": return
|
||||
|
||||
try:
|
||||
tx = self.wallet.mktx([(TYPE_ADDRESS, self.str_recipient, amount)], password, self.config, fee)
|
||||
tx = self.wallet.mktx([TxOutput(TYPE_ADDRESS, self.str_recipient, amount)],
|
||||
password, self.config, fee)
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return
|
||||
|
||||
@@ -6,6 +6,7 @@ import getpass
|
||||
import electrum
|
||||
from electrum.util import format_satoshis, set_verbosity
|
||||
from electrum.bitcoin import is_address, COIN, TYPE_ADDRESS
|
||||
from electrum.transaction import TxOutput
|
||||
from .. import Wallet, WalletStorage
|
||||
|
||||
_ = lambda x:x
|
||||
@@ -340,7 +341,8 @@ class ElectrumGui:
|
||||
else:
|
||||
password = None
|
||||
try:
|
||||
tx = self.wallet.mktx([(TYPE_ADDRESS, self.str_recipient, amount)], password, self.config, fee)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user