URI: 
       tlnbase: make_htlc_tx - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit d7244f67088ad9516c948db0e3fdf31ea1ef03bb
   DIR parent ab7a854f9a716192a52b179004ae9d625b9e1bd8
  HTML Author: Janus <ysangkok@gmail.com>
       Date:   Tue, 17 Apr 2018 12:35:22 +0200
       
       lnbase: make_htlc_tx
       
       Diffstat:
         M lib/lnbase.py                       |      43 ++++++++++++++++++++++++++++++-
         M lib/tests/test_lnbase.py            |      18 ++++++++++++++----
       
       2 files changed, 56 insertions(+), 5 deletions(-)
       ---
   DIR diff --git a/lib/lnbase.py b/lib/lnbase.py
       t@@ -21,7 +21,6 @@ import binascii
        import hashlib
        import hmac
        import cryptography.hazmat.primitives.ciphers.aead as AEAD
       -from . import ripemd
        
        from .bitcoin import (public_key_from_private_key, ser_to_point, point_to_ser,
                              string_to_number, deserialize_privkey, EC_KEY, rev_hex, int_to_hex,
       t@@ -277,6 +276,48 @@ def derive_blinded_pubkey(basepoint, per_commitment_point):
        def overall_weight(num_htlc):
            return 500 + 172 * num_htlc + 224
        
       +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
       +    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
       +    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,
       +        '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])
       +
       +    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)
       +    c_outputs = [output]
       +    tx = Transaction.from_io(c_inputs, c_outputs, locktime=cltv_timeout, version=2)
       +    tx.BIP_LI01_sort()
       +    return tx
       +
        def make_offered_htlc(revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, payment_preimage):
            assert type(revocation_pubkey) is bytes
            assert type(remote_htlcpubkey) is bytes
   DIR diff --git a/lib/tests/test_lnbase.py b/lib/tests/test_lnbase.py
       t@@ -3,7 +3,7 @@ import json
        import unittest
        
        from lib.util import bh2u, bfh
       -from lib.lnbase import make_commitment, get_obscured_ctn, Peer, make_offered_htlc, make_received_htlc
       +from lib.lnbase import make_commitment, get_obscured_ctn, Peer, make_offered_htlc, make_received_htlc, make_htlc_tx
        from lib.lnbase import secret_to_pubkey, derive_pubkey, derive_privkey, derive_blinded_pubkey
        from lib.transaction import Transaction
        from lib import bitcoin
       t@@ -116,7 +116,12 @@ class Test_LNBase(unittest.TestCase):
                # local_signature = 30440220275b0c325a5e9355650dc30c0eccfbc7efb23987c24b556b9dfdd40effca18d202206caceb2c067836c51f296740c7ae807ffcbfbf1dd3a0d56b6de9a5b247985f06
parazyd.org:70 /git/electrum/commit/d7244f67088ad9516c948db0e3fdf31ea1ef03bb.gph:91: line too long