electrum

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

commit 1b030fca7887e7691211c15f71e9adf0f135e895
parent bab9f163f7a7dcae2fbcf91675e7993ef8b55163
Author: SomberNight <somber.night@protonmail.com>
Date:   Wed, 15 Aug 2018 17:48:40 +0200

rebase follow-up: use namedtuples from master in new code (TxOutput, TxMinedStatus)

Diffstat:
Melectrum/lnbase.py | 4++--
Melectrum/lnutil.py | 12+++++++-----
Melectrum/lnwatcher.py | 25+++++++++++++------------
Melectrum/lnworker.py | 4++--
4 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/electrum/lnbase.py b/electrum/lnbase.py @@ -30,7 +30,7 @@ from .crypto import sha256 from . import constants from . import transaction from .util import PrintError, bh2u, print_error, bfh -from .transaction import opcodes, Transaction +from .transaction import opcodes, Transaction, TxOutput from .lnonion import new_onion_packet, OnionHopsDataSingle, OnionPerHop, decode_onion_error, ONION_FAILURE_CODE_MAP from .lnaddr import lndecode from .lnhtlc import UpdateAddHtlc, HTLCStateMachine, RevokeAndAck, SettleHtlc @@ -561,7 +561,7 @@ class Peer(PrintError): # create funding tx redeem_script = funding_output_script(local_config, remote_config) funding_address = bitcoin.redeem_script_to_address('p2wsh', redeem_script) - funding_output = (bitcoin.TYPE_ADDRESS, funding_address, funding_sat) + funding_output = TxOutput(bitcoin.TYPE_ADDRESS, funding_address, funding_sat) funding_tx = wallet.mktx([funding_output], password, config, 1000) funding_txid = funding_tx.txid() funding_index = funding_tx.outputs().index(funding_output) diff --git a/electrum/lnutil.py b/electrum/lnutil.py @@ -5,7 +5,7 @@ from collections import namedtuple from .transaction import Transaction from .ecc import CURVE_ORDER, sig_string_from_der_sig, ECPubkey, string_to_number from . import ecc, bitcoin, crypto, transaction -from .transaction import opcodes +from .transaction import opcodes, TxOutput from .bitcoin import push_script from . import segwit_addr @@ -157,7 +157,7 @@ def make_htlc_tx_output(amount_msat, local_feerate, revocationpubkey, local_dela fee = fee // 1000 * 1000 final_amount_sat = (amount_msat - fee) // 1000 assert final_amount_sat > 0, final_amount_sat - output = (bitcoin.TYPE_ADDRESS, p2wsh, final_amount_sat) + output = TxOutput(bitcoin.TYPE_ADDRESS, p2wsh, final_amount_sat) return output def make_htlc_tx_witness(remotehtlcsig, localhtlcsig, payment_preimage, witness_script): @@ -300,12 +300,14 @@ def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, fee = fee // 1000 * 1000 we_pay_fee = for_us == we_are_initiator to_local_amt = local_amount - (fee if we_pay_fee else 0) - to_local = (bitcoin.TYPE_ADDRESS, local_address, to_local_amt // 1000) + to_local = TxOutput(bitcoin.TYPE_ADDRESS, local_address, to_local_amt // 1000) to_remote_amt = remote_amount - (fee if not we_pay_fee else 0) - to_remote = (bitcoin.TYPE_ADDRESS, remote_address, to_remote_amt // 1000) + to_remote = TxOutput(bitcoin.TYPE_ADDRESS, remote_address, to_remote_amt // 1000) c_outputs = [to_local, to_remote] for script, msat_amount in htlcs: - c_outputs += [(bitcoin.TYPE_ADDRESS, bitcoin.redeem_script_to_address('p2wsh', bh2u(script)), msat_amount // 1000)] + c_outputs += [TxOutput(bitcoin.TYPE_ADDRESS, + bitcoin.redeem_script_to_address('p2wsh', bh2u(script)), + msat_amount // 1000)] # trim outputs c_outputs_filtered = list(filter(lambda x:x[2]>= dust_limit_sat, c_outputs)) diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py @@ -8,7 +8,7 @@ from .lnutil import (extract_ctn_from_tx, derive_privkey, from . import lnutil from .bitcoin import redeem_script_to_address, TYPE_ADDRESS from . import transaction -from .transaction import Transaction +from .transaction import Transaction, TxOutput from . import ecc from . import wallet @@ -101,7 +101,7 @@ class LNChanCloseHandler(PrintError): else: raise Exception('{} is supposed to be spent by {}, but none of the inputs spend it' .format(funding_outpoint, ctx_candidate_txid)) - height, conf, timestamp = self.wallet.get_tx_height(ctx_candidate_txid) + conf = self.wallet.get_tx_height(ctx_candidate_txid).conf if conf == 0: return keep_watching_this = self.inspect_ctx_candidate(ctx_candidate, i) @@ -150,7 +150,8 @@ class LNChanCloseHandler(PrintError): def get_tx_mined_status(self, txid): if not txid: return TX_MINED_STATUS_FREE - height, conf, timestamp = self.wallet.get_tx_height(txid) + tx_mined_status = self.wallet.get_tx_height(txid) + height, conf = tx_mined_status.height, tx_mined_status.conf if conf > 100: return TX_MINED_STATUS_DEEP elif conf > 0: @@ -173,8 +174,8 @@ class LNChanCloseHandler(PrintError): our_payment_privkey = ecc.ECPrivkey.from_secret_scalar(our_payment_privkey) our_payment_pubkey = our_payment_privkey.get_public_key_bytes(compressed=True) to_remote_address = make_commitment_output_to_remote_address(our_payment_pubkey) - for output_idx, (type_, addr, val) in enumerate(ctx.outputs()): - if type_ == TYPE_ADDRESS and addr == to_remote_address: + for output_idx, o in enumerate(ctx.outputs()): + if o.type == TYPE_ADDRESS and o.address == to_remote_address: self.print_error("found to_remote output paying to us: ctx {}:{}". format(ctx.txid(), output_idx)) #self.print_error("ctx {} is normal unilateral close by them".format(ctx.txid())) @@ -210,8 +211,8 @@ class LNChanCloseHandler(PrintError): witness_script = bh2u(lnutil.make_commitment_output_to_local_witness_script( revocation_pubkey, to_self_delay, delayed_pubkey)) to_local_address = redeem_script_to_address('p2wsh', witness_script) - for output_idx, (type_, addr, val) in enumerate(ctx.outputs()): - if type_ == TYPE_ADDRESS and addr == to_local_address: + for output_idx, o in enumerate(ctx.outputs()): + if o.type == TYPE_ADDRESS and o.address == to_local_address: self.print_error("found to_local output paying to them: ctx {}:{}". format(ctx.txid(), output_idx)) break @@ -246,8 +247,8 @@ class LNChanCloseHandler(PrintError): witness_script = bh2u(lnutil.make_commitment_output_to_local_witness_script( revocation_pubkey, to_self_delay, our_localdelayed_pubkey)) to_local_address = redeem_script_to_address('p2wsh', witness_script) - for output_idx, (type_, addr, val) in enumerate(ctx.outputs()): - if type_ == TYPE_ADDRESS and addr == to_local_address: + for output_idx, o in enumerate(ctx.outputs()): + if o.type == TYPE_ADDRESS and o.address == to_local_address: self.print_error("found to_local output paying to us (CSV-locked): ctx {}:{}". format(ctx.txid(), output_idx)) break @@ -264,7 +265,7 @@ class LNChanCloseHandler(PrintError): elif stx_mined_status in (TX_MINED_STATUS_SHALLOW, TX_MINED_STATUS_MEMPOOL): return True # check timelock - ctx_num_conf = self.wallet.get_tx_height(ctx.txid())[1] + ctx_num_conf = self.wallet.get_tx_height(ctx.txid()).conf if to_self_delay > ctx_num_conf: self.print_error('waiting for CSV ({} < {}) for ctx {}'.format(ctx_num_conf, to_self_delay, ctx.txid())) return True @@ -302,7 +303,7 @@ def create_sweeptx_their_ctx_to_remote(network, address, ctx, output_idx: int, o except NoDynamicFeeEstimates: fee_per_kb = network.config.fee_per_kb(dyn=False) fee = network.config.estimate_fee_for_feerate(fee_per_kb, tx_size_bytes) - sweep_outputs = [(TYPE_ADDRESS, address, val-fee)] + sweep_outputs = [TxOutput(TYPE_ADDRESS, address, val-fee)] locktime = network.get_local_height() sweep_tx = Transaction.from_io(sweep_inputs, sweep_outputs, locktime=locktime) sweep_tx.set_rbf(True) @@ -340,7 +341,7 @@ def create_sweeptx_ctx_to_local(network, address, ctx, output_idx: int, witness_ except NoDynamicFeeEstimates: fee_per_kb = network.config.fee_per_kb(dyn=False) fee = network.config.estimate_fee_for_feerate(fee_per_kb, tx_size_bytes) - sweep_outputs = [(TYPE_ADDRESS, address, val - fee)] + sweep_outputs = [TxOutput(TYPE_ADDRESS, address, val - fee)] locktime = network.get_local_height() sweep_tx = Transaction.from_io(sweep_inputs, sweep_outputs, locktime=locktime, version=2) sig = sweep_tx.sign_txin(0, privkey) diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -107,7 +107,7 @@ class LNWorker(PrintError): """ assert chan.get_state() in ["OPEN", "OPENING"] peer = self.peers[chan.node_id] - conf = self.wallet.get_tx_height(chan.funding_outpoint.txid)[1] + conf = self.wallet.get_tx_height(chan.funding_outpoint.txid).conf if conf >= chan.constraints.funding_txn_minimum_depth: block_height, tx_pos = self.wallet.get_txpos(chan.funding_outpoint.txid) if tx_pos == -1: @@ -154,7 +154,7 @@ class LNWorker(PrintError): return if event == 'fee': peer.on_bitcoin_fee_update(chan) - conf = self.wallet.get_tx_height(chan.funding_outpoint.txid)[1] + conf = self.wallet.get_tx_height(chan.funding_outpoint.txid).conf peer.on_network_update(chan, conf) asyncio.run_coroutine_threadsafe(network_jobs(), self.network.asyncio_loop).result()