lnbase: more work on make_htlc_tx
This commit is contained in:
@@ -279,42 +279,51 @@ def overall_weight(num_htlc):
|
||||
HTLC_TIMEOUT_WEIGHT = 663
|
||||
HTLC_SUCCESS_WEIGHT = 703
|
||||
|
||||
def make_htlc_tx(cltv_timeout, htlc_output_txid, htlc_output_index, remotehtlcsig, localhtlcsig, payment_preimage, amount_msat, local_feerate, revocationpubkey, local_delayedpubkey):
|
||||
assert type(cltv_timeout) is int
|
||||
def make_htlc_tx_output(amount_msat, local_feerate, revocationpubkey, local_delayedpubkey, success):
|
||||
assert type(amount_msat) is int
|
||||
assert type(local_feerate) is int
|
||||
assert type(revocationpubkey) is bytes
|
||||
assert type(local_delayedpubkey) is bytes
|
||||
script = bytes([opcodes.OP_IF]) \
|
||||
+ bfh(push_script(bh2u(revocationpubkey))) \
|
||||
+ bytes([opcodes.OP_ELSE]) \
|
||||
+ bitcoin.add_number_to_script(144) \
|
||||
+ bytes([opcodes.OP_CSV, opcodes.OP_DROP]) \
|
||||
+ bfh(push_script(bh2u(local_delayedpubkey))) \
|
||||
+ bytes([opcodes.OP_ENDIF, opcodes.OP_CHECKSIG])
|
||||
|
||||
p2wsh = bitcoin.redeem_script_to_address('p2wsh', bh2u(script))
|
||||
weight = HTLC_SUCCESS_WEIGHT if success else HTLC_TIMEOUT_WEIGHT
|
||||
fee = local_feerate * weight
|
||||
output = (bitcoin.TYPE_ADDRESS, p2wsh, amount_msat // 1000 - fee)
|
||||
return output
|
||||
|
||||
def make_htlc_tx_inputs(htlc_output_txid, htlc_output_index, remotehtlcsig, localhtlcsig, payment_preimage, revocationpubkey, local_delayedpubkey, amount_msat):
|
||||
assert type(htlc_output_txid) is str
|
||||
assert type(htlc_output_index) is int
|
||||
assert type(remotehtlcsig) is bytes
|
||||
assert type(localhtlcsig) is bytes
|
||||
assert type(payment_preimage) is bytes
|
||||
assert type(amount_msat) is int
|
||||
assert type(local_feerate) is int
|
||||
assert type(revocationpubkey) is bytes
|
||||
assert type(local_delayedpubkey) is bytes
|
||||
assert type(amount_msat) is int
|
||||
c_inputs = [{
|
||||
'type': 'p2wsh',
|
||||
'x_pubkeys': [bh2u(x) for x in [revocationpubkey, local_delayedpubkey]],
|
||||
'signatures': [bh2u(x) for x in [remotehtlcsig, localhtlcsig, payment_preimage]],
|
||||
'num_sig': 2,
|
||||
'num_sig': 3,
|
||||
'prevout_n': htlc_output_index,
|
||||
'prevout_hash': htlc_output_txid,
|
||||
'value': amount_msat // 1000,
|
||||
'coinbase': False,
|
||||
'sequence': 0x0
|
||||
}]
|
||||
script = bytes([opcodes.OP_IF]) \
|
||||
+ bfh(push_script(bh2u(revocationpubkey))) \
|
||||
+ bytes([opcodes.OP_ELSE]) \
|
||||
+ bitcoin.add_number_to_script(0) \
|
||||
+ bytes([opcodes.OP_CSV, opcodes.OP_DROP]) \
|
||||
+ bfh(push_script(bh2u(local_delayedpubkey))) \
|
||||
+ bytes([opcodes.OP_ENDIF, opcodes.OP_CHECKSIG])
|
||||
return c_inputs
|
||||
|
||||
p2wsh = bitcoin.redeem_script_to_address('p2wsh', bh2u(script))
|
||||
weight = HTLC_SUCCESS_WEIGHT if cltv_timeout == 0 else HTLC_TIMEOUT_WEIGHT
|
||||
fee = local_feerate * weight
|
||||
output = (bitcoin.TYPE_ADDRESS, p2wsh, amount_msat // 1000 - fee)
|
||||
def make_htlc_tx(cltv_timeout, inputs, output):
|
||||
assert type(cltv_timeout) is int
|
||||
c_outputs = [output]
|
||||
tx = Transaction.from_io(c_inputs, c_outputs, locktime=cltv_timeout, version=2)
|
||||
tx = Transaction.from_io(inputs, c_outputs, locktime=cltv_timeout, version=2)
|
||||
tx.BIP_LI01_sort()
|
||||
return tx
|
||||
|
||||
|
||||
Reference in New Issue
Block a user