electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 5f3408dd70f39db363abe7296df814e2cb100332
parent b4b1de088ab88fe0e01b9f19ff48da9d71eac334
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue, 14 Aug 2018 19:15:15 +0200

transaction.py: introduce TxOutputHwInfo namedtuple

Diffstat:
Melectrum/plugins/digitalbitbox/digitalbitbox.py | 2+-
Melectrum/plugins/hw_wallet/plugin.py | 2+-
Melectrum/plugins/keepkey/keepkey.py | 7+++----
Melectrum/plugins/ledger/ledger.py | 2+-
Melectrum/plugins/safe_t/safe_t.py | 7+++----
Melectrum/plugins/trezor/trezor.py | 7+++----
Melectrum/transaction.py | 7++++++-
Melectrum/wallet.py | 5+++--
8 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/electrum/plugins/digitalbitbox/digitalbitbox.py b/electrum/plugins/digitalbitbox/digitalbitbox.py @@ -538,7 +538,7 @@ class DigitalBitbox_KeyStore(Hardware_KeyStore): assert o.type == TYPE_ADDRESS info = tx.output_info.get(o.address) if info is not None: - index, xpubs, m = info + index = info.address_index changePath = self.get_derivation() + "/%d/%d" % index changePubkey = self.derive_pubkey(index[0], index[1]) pubkeyarray_i = {'pubkey': changePubkey, 'keypath': changePath} diff --git a/electrum/plugins/hw_wallet/plugin.py b/electrum/plugins/hw_wallet/plugin.py @@ -85,7 +85,7 @@ def is_any_tx_output_on_change_branch(tx): for _type, address, amount in tx.outputs(): info = tx.output_info.get(address) if info is not None: - index, xpubs, m = info + index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig if index[0] == 1: return True return False diff --git a/electrum/plugins/keepkey/keepkey.py b/electrum/plugins/keepkey/keepkey.py @@ -351,8 +351,7 @@ class KeepKeyPlugin(HW_PluginBase): def tx_outputs(self, derivation, tx, segwit=False): - def create_output_by_derivation(info): - index, xpubs, m = info + def create_output_by_derivation(): if len(xpubs) == 1: script_type = self.types.PAYTOP2SHWITNESS if segwit else self.types.PAYTOADDRESS address_n = self.client_class.expand_path(derivation + "/%d/%d" % index) @@ -407,7 +406,7 @@ class KeepKeyPlugin(HW_PluginBase): info = tx.output_info.get(address) if info is not None and not has_change: - index, xpubs, m = info + index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig on_change_branch = index[0] == 1 # prioritise hiding outputs on the 'change' branch from user # because no more than one change address allowed @@ -416,7 +415,7 @@ class KeepKeyPlugin(HW_PluginBase): has_change = True if use_create_by_derivation: - txoutputtype = create_output_by_derivation(info) + txoutputtype = create_output_by_derivation() else: txoutputtype = create_output_by_address() outputs.append(txoutputtype) diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py @@ -399,7 +399,7 @@ class Ledger_KeyStore(Hardware_KeyStore): 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 + index = info.address_index on_change_branch = index[0] == 1 # prioritise hiding outputs on the 'change' branch from user # because no more than one change address allowed diff --git a/electrum/plugins/safe_t/safe_t.py b/electrum/plugins/safe_t/safe_t.py @@ -413,8 +413,7 @@ class SafeTPlugin(HW_PluginBase): def tx_outputs(self, derivation, tx, script_gen=SCRIPT_GEN_LEGACY): - def create_output_by_derivation(info): - index, xpubs, m = info + def create_output_by_derivation(): if len(xpubs) == 1: if script_gen == SCRIPT_GEN_NATIVE_SEGWIT: script_type = self.types.OutputScriptType.PAYTOWITNESS @@ -469,7 +468,7 @@ class SafeTPlugin(HW_PluginBase): info = tx.output_info.get(address) if info is not None and not has_change: - index, xpubs, m = info + index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig on_change_branch = index[0] == 1 # prioritise hiding outputs on the 'change' branch from user # because no more than one change address allowed @@ -480,7 +479,7 @@ class SafeTPlugin(HW_PluginBase): has_change = True if use_create_by_derivation: - txoutputtype = create_output_by_derivation(info) + txoutputtype = create_output_by_derivation() else: txoutputtype = create_output_by_address() outputs.append(txoutputtype) diff --git a/electrum/plugins/trezor/trezor.py b/electrum/plugins/trezor/trezor.py @@ -424,8 +424,7 @@ class TrezorPlugin(HW_PluginBase): def tx_outputs(self, derivation, tx, script_gen=SCRIPT_GEN_LEGACY): - def create_output_by_derivation(info): - index, xpubs, m = info + def create_output_by_derivation(): if len(xpubs) == 1: if script_gen == SCRIPT_GEN_NATIVE_SEGWIT: script_type = self.types.OutputScriptType.PAYTOWITNESS @@ -480,7 +479,7 @@ class TrezorPlugin(HW_PluginBase): info = tx.output_info.get(address) if info is not None and not has_change: - index, xpubs, m = info + index, xpubs, m = info.address_index, info.sorted_xpubs, info.num_sig on_change_branch = index[0] == 1 # prioritise hiding outputs on the 'change' branch from user # because no more than one change address allowed @@ -491,7 +490,7 @@ class TrezorPlugin(HW_PluginBase): has_change = True if use_create_by_derivation: - txoutputtype = create_output_by_derivation(info) + txoutputtype = create_output_by_derivation() else: txoutputtype = create_output_by_address() outputs.append(txoutputtype) diff --git a/electrum/transaction.py b/electrum/transaction.py @@ -27,7 +27,7 @@ # Note: The deserialization code originally comes from ABE. -from typing import Sequence, Union, NamedTuple +from typing import Sequence, Union, NamedTuple, Tuple, Optional, Iterable from .util import print_error, profiler @@ -63,6 +63,11 @@ TxOutput = NamedTuple("TxOutput", [('type', int), ('address', str), ('value', Un # ^ value is str when the output is set to max: '!' +TxOutputHwInfo = NamedTuple("TxOutputHwInfo", [('address_index', Tuple), + ('sorted_xpubs', Iterable[str]), + ('num_sig', Optional[int])]) + + class BCDataStream(object): def __init__(self): self.input = None diff --git a/electrum/wallet.py b/electrum/wallet.py @@ -51,7 +51,7 @@ from .keystore import load_keystore, Hardware_KeyStore from .storage import multisig_type, STO_EV_PLAINTEXT, STO_EV_USER_PW, STO_EV_XPUB_PW from . import transaction, bitcoin, coinchooser, paymentrequest, contacts -from .transaction import Transaction, TxOutput +from .transaction import Transaction, TxOutput, TxOutputHwInfo from .plugin import run_hook from .address_synchronizer import (AddressSynchronizer, TX_HEIGHT_LOCAL, TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_UNCONFIRMED) @@ -786,7 +786,8 @@ class Abstract_Wallet(AddressSynchronizer): pubkeys = self.get_public_keys(addr) # sort xpubs using the order of pubkeys sorted_pubkeys, sorted_xpubs = zip(*sorted(zip(pubkeys, xpubs))) - info[addr] = index, sorted_xpubs, self.m if isinstance(self, Multisig_Wallet) else None + num_sig = self.m if isinstance(self, Multisig_Wallet) else None + info[addr] = TxOutputHwInfo(index, sorted_xpubs, num_sig) tx.output_info = info def sign_transaction(self, tx, password):