mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 01:35:20 +00:00
rebase follow-up: use namedtuples from master in new code (TxOutput, TxMinedStatus)
This commit is contained in:
parent
bab9f163f7
commit
1b030fca78
4 changed files with 24 additions and 21 deletions
|
@ -30,7 +30,7 @@ from .crypto import sha256
|
||||||
from . import constants
|
from . import constants
|
||||||
from . import transaction
|
from . import transaction
|
||||||
from .util import PrintError, bh2u, print_error, bfh
|
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 .lnonion import new_onion_packet, OnionHopsDataSingle, OnionPerHop, decode_onion_error, ONION_FAILURE_CODE_MAP
|
||||||
from .lnaddr import lndecode
|
from .lnaddr import lndecode
|
||||||
from .lnhtlc import UpdateAddHtlc, HTLCStateMachine, RevokeAndAck, SettleHtlc
|
from .lnhtlc import UpdateAddHtlc, HTLCStateMachine, RevokeAndAck, SettleHtlc
|
||||||
|
@ -561,7 +561,7 @@ class Peer(PrintError):
|
||||||
# create funding tx
|
# create funding tx
|
||||||
redeem_script = funding_output_script(local_config, remote_config)
|
redeem_script = funding_output_script(local_config, remote_config)
|
||||||
funding_address = bitcoin.redeem_script_to_address('p2wsh', redeem_script)
|
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_tx = wallet.mktx([funding_output], password, config, 1000)
|
||||||
funding_txid = funding_tx.txid()
|
funding_txid = funding_tx.txid()
|
||||||
funding_index = funding_tx.outputs().index(funding_output)
|
funding_index = funding_tx.outputs().index(funding_output)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from collections import namedtuple
|
||||||
from .transaction import Transaction
|
from .transaction import Transaction
|
||||||
from .ecc import CURVE_ORDER, sig_string_from_der_sig, ECPubkey, string_to_number
|
from .ecc import CURVE_ORDER, sig_string_from_der_sig, ECPubkey, string_to_number
|
||||||
from . import ecc, bitcoin, crypto, transaction
|
from . import ecc, bitcoin, crypto, transaction
|
||||||
from .transaction import opcodes
|
from .transaction import opcodes, TxOutput
|
||||||
from .bitcoin import push_script
|
from .bitcoin import push_script
|
||||||
from . import segwit_addr
|
from . import segwit_addr
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ def make_htlc_tx_output(amount_msat, local_feerate, revocationpubkey, local_dela
|
||||||
fee = fee // 1000 * 1000
|
fee = fee // 1000 * 1000
|
||||||
final_amount_sat = (amount_msat - fee) // 1000
|
final_amount_sat = (amount_msat - fee) // 1000
|
||||||
assert final_amount_sat > 0, final_amount_sat
|
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
|
return output
|
||||||
|
|
||||||
def make_htlc_tx_witness(remotehtlcsig, localhtlcsig, payment_preimage, witness_script):
|
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
|
fee = fee // 1000 * 1000
|
||||||
we_pay_fee = for_us == we_are_initiator
|
we_pay_fee = for_us == we_are_initiator
|
||||||
to_local_amt = local_amount - (fee if we_pay_fee else 0)
|
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_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]
|
c_outputs = [to_local, to_remote]
|
||||||
for script, msat_amount in htlcs:
|
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
|
# trim outputs
|
||||||
c_outputs_filtered = list(filter(lambda x:x[2]>= dust_limit_sat, c_outputs))
|
c_outputs_filtered = list(filter(lambda x:x[2]>= dust_limit_sat, c_outputs))
|
||||||
|
|
|
@ -8,7 +8,7 @@ from .lnutil import (extract_ctn_from_tx, derive_privkey,
|
||||||
from . import lnutil
|
from . import lnutil
|
||||||
from .bitcoin import redeem_script_to_address, TYPE_ADDRESS
|
from .bitcoin import redeem_script_to_address, TYPE_ADDRESS
|
||||||
from . import transaction
|
from . import transaction
|
||||||
from .transaction import Transaction
|
from .transaction import Transaction, TxOutput
|
||||||
from . import ecc
|
from . import ecc
|
||||||
from . import wallet
|
from . import wallet
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ class LNChanCloseHandler(PrintError):
|
||||||
else:
|
else:
|
||||||
raise Exception('{} is supposed to be spent by {}, but none of the inputs spend it'
|
raise Exception('{} is supposed to be spent by {}, but none of the inputs spend it'
|
||||||
.format(funding_outpoint, ctx_candidate_txid))
|
.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:
|
if conf == 0:
|
||||||
return
|
return
|
||||||
keep_watching_this = self.inspect_ctx_candidate(ctx_candidate, i)
|
keep_watching_this = self.inspect_ctx_candidate(ctx_candidate, i)
|
||||||
|
@ -150,7 +150,8 @@ class LNChanCloseHandler(PrintError):
|
||||||
def get_tx_mined_status(self, txid):
|
def get_tx_mined_status(self, txid):
|
||||||
if not txid:
|
if not txid:
|
||||||
return TX_MINED_STATUS_FREE
|
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:
|
if conf > 100:
|
||||||
return TX_MINED_STATUS_DEEP
|
return TX_MINED_STATUS_DEEP
|
||||||
elif conf > 0:
|
elif conf > 0:
|
||||||
|
@ -173,8 +174,8 @@ class LNChanCloseHandler(PrintError):
|
||||||
our_payment_privkey = ecc.ECPrivkey.from_secret_scalar(our_payment_privkey)
|
our_payment_privkey = ecc.ECPrivkey.from_secret_scalar(our_payment_privkey)
|
||||||
our_payment_pubkey = our_payment_privkey.get_public_key_bytes(compressed=True)
|
our_payment_pubkey = our_payment_privkey.get_public_key_bytes(compressed=True)
|
||||||
to_remote_address = make_commitment_output_to_remote_address(our_payment_pubkey)
|
to_remote_address = make_commitment_output_to_remote_address(our_payment_pubkey)
|
||||||
for output_idx, (type_, addr, val) in enumerate(ctx.outputs()):
|
for output_idx, o in enumerate(ctx.outputs()):
|
||||||
if type_ == TYPE_ADDRESS and addr == to_remote_address:
|
if o.type == TYPE_ADDRESS and o.address == to_remote_address:
|
||||||
self.print_error("found to_remote output paying to us: ctx {}:{}".
|
self.print_error("found to_remote output paying to us: ctx {}:{}".
|
||||||
format(ctx.txid(), output_idx))
|
format(ctx.txid(), output_idx))
|
||||||
#self.print_error("ctx {} is normal unilateral close by them".format(ctx.txid()))
|
#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(
|
witness_script = bh2u(lnutil.make_commitment_output_to_local_witness_script(
|
||||||
revocation_pubkey, to_self_delay, delayed_pubkey))
|
revocation_pubkey, to_self_delay, delayed_pubkey))
|
||||||
to_local_address = redeem_script_to_address('p2wsh', witness_script)
|
to_local_address = redeem_script_to_address('p2wsh', witness_script)
|
||||||
for output_idx, (type_, addr, val) in enumerate(ctx.outputs()):
|
for output_idx, o in enumerate(ctx.outputs()):
|
||||||
if type_ == TYPE_ADDRESS and addr == to_local_address:
|
if o.type == TYPE_ADDRESS and o.address == to_local_address:
|
||||||
self.print_error("found to_local output paying to them: ctx {}:{}".
|
self.print_error("found to_local output paying to them: ctx {}:{}".
|
||||||
format(ctx.txid(), output_idx))
|
format(ctx.txid(), output_idx))
|
||||||
break
|
break
|
||||||
|
@ -246,8 +247,8 @@ class LNChanCloseHandler(PrintError):
|
||||||
witness_script = bh2u(lnutil.make_commitment_output_to_local_witness_script(
|
witness_script = bh2u(lnutil.make_commitment_output_to_local_witness_script(
|
||||||
revocation_pubkey, to_self_delay, our_localdelayed_pubkey))
|
revocation_pubkey, to_self_delay, our_localdelayed_pubkey))
|
||||||
to_local_address = redeem_script_to_address('p2wsh', witness_script)
|
to_local_address = redeem_script_to_address('p2wsh', witness_script)
|
||||||
for output_idx, (type_, addr, val) in enumerate(ctx.outputs()):
|
for output_idx, o in enumerate(ctx.outputs()):
|
||||||
if type_ == TYPE_ADDRESS and addr == to_local_address:
|
if o.type == TYPE_ADDRESS and o.address == to_local_address:
|
||||||
self.print_error("found to_local output paying to us (CSV-locked): ctx {}:{}".
|
self.print_error("found to_local output paying to us (CSV-locked): ctx {}:{}".
|
||||||
format(ctx.txid(), output_idx))
|
format(ctx.txid(), output_idx))
|
||||||
break
|
break
|
||||||
|
@ -264,7 +265,7 @@ class LNChanCloseHandler(PrintError):
|
||||||
elif stx_mined_status in (TX_MINED_STATUS_SHALLOW, TX_MINED_STATUS_MEMPOOL):
|
elif stx_mined_status in (TX_MINED_STATUS_SHALLOW, TX_MINED_STATUS_MEMPOOL):
|
||||||
return True
|
return True
|
||||||
# check timelock
|
# 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:
|
if to_self_delay > ctx_num_conf:
|
||||||
self.print_error('waiting for CSV ({} < {}) for ctx {}'.format(ctx_num_conf, to_self_delay, ctx.txid()))
|
self.print_error('waiting for CSV ({} < {}) for ctx {}'.format(ctx_num_conf, to_self_delay, ctx.txid()))
|
||||||
return True
|
return True
|
||||||
|
@ -302,7 +303,7 @@ def create_sweeptx_their_ctx_to_remote(network, address, ctx, output_idx: int, o
|
||||||
except NoDynamicFeeEstimates:
|
except NoDynamicFeeEstimates:
|
||||||
fee_per_kb = network.config.fee_per_kb(dyn=False)
|
fee_per_kb = network.config.fee_per_kb(dyn=False)
|
||||||
fee = network.config.estimate_fee_for_feerate(fee_per_kb, tx_size_bytes)
|
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()
|
locktime = network.get_local_height()
|
||||||
sweep_tx = Transaction.from_io(sweep_inputs, sweep_outputs, locktime=locktime)
|
sweep_tx = Transaction.from_io(sweep_inputs, sweep_outputs, locktime=locktime)
|
||||||
sweep_tx.set_rbf(True)
|
sweep_tx.set_rbf(True)
|
||||||
|
@ -340,7 +341,7 @@ def create_sweeptx_ctx_to_local(network, address, ctx, output_idx: int, witness_
|
||||||
except NoDynamicFeeEstimates:
|
except NoDynamicFeeEstimates:
|
||||||
fee_per_kb = network.config.fee_per_kb(dyn=False)
|
fee_per_kb = network.config.fee_per_kb(dyn=False)
|
||||||
fee = network.config.estimate_fee_for_feerate(fee_per_kb, tx_size_bytes)
|
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()
|
locktime = network.get_local_height()
|
||||||
sweep_tx = Transaction.from_io(sweep_inputs, sweep_outputs, locktime=locktime, version=2)
|
sweep_tx = Transaction.from_io(sweep_inputs, sweep_outputs, locktime=locktime, version=2)
|
||||||
sig = sweep_tx.sign_txin(0, privkey)
|
sig = sweep_tx.sign_txin(0, privkey)
|
||||||
|
|
|
@ -107,7 +107,7 @@ class LNWorker(PrintError):
|
||||||
"""
|
"""
|
||||||
assert chan.get_state() in ["OPEN", "OPENING"]
|
assert chan.get_state() in ["OPEN", "OPENING"]
|
||||||
peer = self.peers[chan.node_id]
|
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:
|
if conf >= chan.constraints.funding_txn_minimum_depth:
|
||||||
block_height, tx_pos = self.wallet.get_txpos(chan.funding_outpoint.txid)
|
block_height, tx_pos = self.wallet.get_txpos(chan.funding_outpoint.txid)
|
||||||
if tx_pos == -1:
|
if tx_pos == -1:
|
||||||
|
@ -154,7 +154,7 @@ class LNWorker(PrintError):
|
||||||
return
|
return
|
||||||
if event == 'fee':
|
if event == 'fee':
|
||||||
peer.on_bitcoin_fee_update(chan)
|
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)
|
peer.on_network_update(chan, conf)
|
||||||
asyncio.run_coroutine_threadsafe(network_jobs(), self.network.asyncio_loop).result()
|
asyncio.run_coroutine_threadsafe(network_jobs(), self.network.asyncio_loop).result()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue