transaction: introduce TxOutput namedtuple
This commit is contained in:
@@ -534,9 +534,9 @@ class DigitalBitbox_KeyStore(Hardware_KeyStore):
|
||||
self.give_error("No matching x_key for sign_transaction") # should never happen
|
||||
|
||||
# Build pubkeyarray from outputs
|
||||
for _type, address, amount in tx.outputs():
|
||||
assert _type == TYPE_ADDRESS
|
||||
info = tx.output_info.get(address)
|
||||
for o in tx.outputs():
|
||||
assert o.type == TYPE_ADDRESS
|
||||
info = tx.output_info.get(o.address)
|
||||
if info is not None:
|
||||
index, xpubs, m = info
|
||||
changePath = self.get_derivation() + "/%d/%d" % index
|
||||
|
||||
@@ -28,7 +28,7 @@ from electrum.plugin import BasePlugin, hook
|
||||
from electrum.i18n import _
|
||||
from electrum.bitcoin import is_address, TYPE_SCRIPT
|
||||
from electrum.util import bfh
|
||||
from electrum.transaction import opcodes
|
||||
from electrum.transaction import opcodes, TxOutput
|
||||
|
||||
|
||||
class HW_PluginBase(BasePlugin):
|
||||
@@ -91,13 +91,13 @@ def is_any_tx_output_on_change_branch(tx):
|
||||
return False
|
||||
|
||||
|
||||
def trezor_validate_op_return_output_and_get_data(_type, address, amount):
|
||||
if _type != TYPE_SCRIPT:
|
||||
raise Exception("Unexpected output type: {}".format(_type))
|
||||
script = bfh(address)
|
||||
def trezor_validate_op_return_output_and_get_data(output: TxOutput) -> bytes:
|
||||
if output.type != TYPE_SCRIPT:
|
||||
raise Exception("Unexpected output type: {}".format(output.type))
|
||||
script = bfh(output.address)
|
||||
if not (script[0] == opcodes.OP_RETURN and
|
||||
script[1] == len(script) - 2 and script[1] <= 75):
|
||||
raise Exception(_("Only OP_RETURN scripts, with one constant push, are supported."))
|
||||
if amount != 0:
|
||||
if output.value != 0:
|
||||
raise Exception(_("Amount for OP_RETURN output must be zero."))
|
||||
return script[2:]
|
||||
|
||||
@@ -382,7 +382,7 @@ class KeepKeyPlugin(HW_PluginBase):
|
||||
txoutputtype.amount = amount
|
||||
if _type == TYPE_SCRIPT:
|
||||
txoutputtype.script_type = self.types.PAYTOOPRETURN
|
||||
txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data(_type, address, amount)
|
||||
txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data(o)
|
||||
elif _type == TYPE_ADDRESS:
|
||||
if is_segwit_address(address):
|
||||
txoutputtype.script_type = self.types.PAYTOWITNESS
|
||||
@@ -401,7 +401,8 @@ class KeepKeyPlugin(HW_PluginBase):
|
||||
has_change = False
|
||||
any_output_on_change_branch = is_any_tx_output_on_change_branch(tx)
|
||||
|
||||
for _type, address, amount in tx.outputs():
|
||||
for o in tx.outputs():
|
||||
_type, address, amount = o.type, o.address, o.value
|
||||
use_create_by_derivation = False
|
||||
|
||||
info = tx.output_info.get(address)
|
||||
|
||||
@@ -394,9 +394,9 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
||||
self.give_error("Transaction with more than 2 outputs not supported")
|
||||
has_change = False
|
||||
any_output_on_change_branch = is_any_tx_output_on_change_branch(tx)
|
||||
for _type, address, amount in tx.outputs():
|
||||
assert _type == TYPE_ADDRESS
|
||||
info = tx.output_info.get(address)
|
||||
for o in tx.outputs():
|
||||
assert o.type == TYPE_ADDRESS
|
||||
info = tx.output_info.get(o.address)
|
||||
if (info is not None) and len(tx.outputs()) > 1 \
|
||||
and not has_change:
|
||||
index, xpubs, m = info
|
||||
@@ -407,9 +407,9 @@ class Ledger_KeyStore(Hardware_KeyStore):
|
||||
changePath = self.get_derivation()[2:] + "/%d/%d"%index
|
||||
has_change = True
|
||||
else:
|
||||
output = address
|
||||
output = o.address
|
||||
else:
|
||||
output = address
|
||||
output = o.address
|
||||
|
||||
self.handler.show_message(_("Confirm Transaction on your Ledger device..."))
|
||||
try:
|
||||
|
||||
@@ -453,7 +453,7 @@ class SafeTPlugin(HW_PluginBase):
|
||||
txoutputtype.amount = amount
|
||||
if _type == TYPE_SCRIPT:
|
||||
txoutputtype.script_type = self.types.OutputScriptType.PAYTOOPRETURN
|
||||
txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data(_type, address, amount)
|
||||
txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data(o)
|
||||
elif _type == TYPE_ADDRESS:
|
||||
txoutputtype.script_type = self.types.OutputScriptType.PAYTOADDRESS
|
||||
txoutputtype.address = address
|
||||
@@ -463,7 +463,8 @@ class SafeTPlugin(HW_PluginBase):
|
||||
has_change = False
|
||||
any_output_on_change_branch = is_any_tx_output_on_change_branch(tx)
|
||||
|
||||
for _type, address, amount in tx.outputs():
|
||||
for o in tx.outputs():
|
||||
_type, address, amount = o.type, o.address, o.value
|
||||
use_create_by_derivation = False
|
||||
|
||||
info = tx.output_info.get(address)
|
||||
|
||||
@@ -464,7 +464,7 @@ class TrezorPlugin(HW_PluginBase):
|
||||
txoutputtype.amount = amount
|
||||
if _type == TYPE_SCRIPT:
|
||||
txoutputtype.script_type = self.types.OutputScriptType.PAYTOOPRETURN
|
||||
txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data(_type, address, amount)
|
||||
txoutputtype.op_return_data = trezor_validate_op_return_output_and_get_data(o)
|
||||
elif _type == TYPE_ADDRESS:
|
||||
txoutputtype.script_type = self.types.OutputScriptType.PAYTOADDRESS
|
||||
txoutputtype.address = address
|
||||
@@ -474,7 +474,8 @@ class TrezorPlugin(HW_PluginBase):
|
||||
has_change = False
|
||||
any_output_on_change_branch = is_any_tx_output_on_change_branch(tx)
|
||||
|
||||
for _type, address, amount in tx.outputs():
|
||||
for o in tx.outputs():
|
||||
_type, address, amount = o.type, o.address, o.value
|
||||
use_create_by_derivation = False
|
||||
|
||||
info = tx.output_info.get(address)
|
||||
|
||||
@@ -33,6 +33,7 @@ from urllib.parse import quote
|
||||
|
||||
from electrum import bitcoin, ecc, constants, keystore, version
|
||||
from electrum.bitcoin import *
|
||||
from electrum.transaction import TxOutput
|
||||
from electrum.mnemonic import Mnemonic
|
||||
from electrum.wallet import Multisig_Wallet, Deterministic_Wallet
|
||||
from electrum.i18n import _
|
||||
@@ -273,7 +274,7 @@ class Wallet_2fa(Multisig_Wallet):
|
||||
fee = self.extra_fee(config) if not is_sweep else 0
|
||||
if fee:
|
||||
address = self.billing_info['billing_address']
|
||||
fee_output = (TYPE_ADDRESS, address, fee)
|
||||
fee_output = TxOutput(TYPE_ADDRESS, address, fee)
|
||||
try:
|
||||
tx = mk_tx(outputs + [fee_output])
|
||||
except NotEnoughFunds:
|
||||
@@ -395,9 +396,9 @@ class TrustedCoinPlugin(BasePlugin):
|
||||
def get_tx_extra_fee(self, wallet, tx):
|
||||
if type(wallet) != Wallet_2fa:
|
||||
return
|
||||
for _type, addr, amount in tx.outputs():
|
||||
if _type == TYPE_ADDRESS and wallet.is_billing_address(addr):
|
||||
return addr, amount
|
||||
for o in tx.outputs():
|
||||
if o.type == TYPE_ADDRESS and wallet.is_billing_address(o.address):
|
||||
return o.address, o.value
|
||||
|
||||
def finish_requesting(func):
|
||||
def f(self, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user