URI: 
       tfixes for make_commitment, but still incorrect destination address (csv arg?) - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit aaa67adb5ab421c75ebe8cae6a4989ab88d62008
   DIR parent eca8d13e37920ffef999aab01f9c60a0a8dce9f6
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Fri, 13 Apr 2018 18:47:47 +0200
       
       fixes for make_commitment, but still incorrect destination address (csv arg?)
       
       Diffstat:
         M lib/lnbase.py                       |      16 +++++++++-------
         M lib/tests/test_lnbase.py            |      15 ++++++++++-----
       
       2 files changed, 19 insertions(+), 12 deletions(-)
       ---
   DIR diff --git a/lib/lnbase.py b/lib/lnbase.py
       t@@ -21,12 +21,12 @@ import hashlib
        import hmac
        import cryptography.hazmat.primitives.ciphers.aead as AEAD
        
       -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
       +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, push_script, var_int, op_push
        from . import bitcoin
        from .constants import set_testnet, set_simnet
        from . import constants
        from . import transaction
       -from .util import PrintError, bh2u, print_error
       +from .util import PrintError, bh2u, print_error, bfh
        from .wallet import Wallet
        from .storage import WalletStorage
        from .transaction import opcodes, Transaction
       t@@ -255,11 +255,11 @@ def get_obscured_ctn(ctn, local, remote):
        def overall_weight(num_htlc):
            return 500 + 172 * num_htlc + 224
        
       -def make_commitment(local_pubkey, remote_pubkey,
       +def make_commitment(local_funding_pubkey, remote_funding_pubkey, remotepubkey,
                            payment_pubkey, remote_payment_pubkey, revocation_pubkey, delayed_pubkey,
                            funding_txid, funding_pos, funding_satoshis,
       -                    to_local_msat, to_remote_msat, local_feerate):
       -    pubkeys = sorted([bh2u(local_pubkey), bh2u(remote_pubkey)])
       +                    to_local_msat, to_remote_msat, local_feerate, local_delay):
       +    pubkeys = sorted([bh2u(local_funding_pubkey), bh2u(remote_funding_pubkey)])
            obs = get_obscured_ctn(0, payment_pubkey, remote_payment_pubkey)
            locktime = (0x20 << 24) + (obs & 0xffffff)
            sequence = (0x80 << 24) + (obs >> 24)
       t@@ -277,11 +277,12 @@ def make_commitment(local_pubkey, remote_pubkey,
                'sequence':sequence
            }]
            # commitment tx outputs
       -    local_script = bytes([opcodes.OP_IF]) + revocation_pubkey + bytes([opcodes.OP_ELSE, opcodes.OP_CSV, opcodes.OP_DROP]) + delayed_pubkey + bytes([opcodes.OP_ENDIF, opcodes.OP_CHECKSIG])
       +    local_script = bytes([opcodes.OP_IF]) + bfh(push_script(bh2u(revocation_pubkey))) + bytes([opcodes.OP_ELSE]) + bfh(push_script(int_to_hex(local_delay, 5))) \
       +                   + bytes([opcodes.OP_CSV, opcodes.OP_DROP]) + bfh(push_script(bh2u(delayed_pubkey))) + bytes([opcodes.OP_ENDIF, opcodes.OP_CHECKSIG])
            local_address = bitcoin.redeem_script_to_address('p2wsh', bh2u(local_script))
            fee = local_feerate * overall_weight(0) // 1000
            local_amount = to_local_msat // 1000 - fee
       -    remote_address = bitcoin.pubkey_to_address('p2wpkh', bh2u(remote_pubkey))
       +    remote_address = bitcoin.pubkey_to_address('p2wpkh', bh2u(remotepubkey))
            remote_amount = to_remote_msat // 1000
            to_local = (bitcoin.TYPE_ADDRESS, local_address, local_amount)
            to_remote = (bitcoin.TYPE_ADDRESS, remote_address, remote_amount)
       t@@ -289,6 +290,7 @@ def make_commitment(local_pubkey, remote_pubkey,
            c_outputs = [to_local, to_remote]
            # create commitment tx
            tx = Transaction.from_io(c_inputs, c_outputs, locktime=locktime, version=2)
       +    tx.BIP_LI01_sort()
            return tx
        
        class Peer(PrintError):
   DIR diff --git a/lib/tests/test_lnbase.py b/lib/tests/test_lnbase.py
       t@@ -39,11 +39,11 @@ class Test_LNBase(unittest.TestCase):
                # local_signature = 3044022051b75c73198c6deee1a875871c3961832909acd297c6b908d59e3319e5185a46022055c419379c5051a78d00dbbce11b5b664a0c22815fbcc6fcef6b1937c3836939
                #num_htlcs: 0
                our_commit_tx = make_commitment(
       -            local_funding_pubkey, remote_funding_pubkey,
       +            local_funding_pubkey, remote_funding_pubkey, remotepubkey,
                    local_payment_basepoint, remote_payment_basepoint,
                    local_revocation_pubkey, local_delayedpubkey,
                    funding_tx_id, funding_output_index, funding_amount_satoshi,
       -            to_local_msat, to_remote_msat, local_feerate_per_kw)
       +            to_local_msat, to_remote_msat, local_feerate_per_kw, local_delay)
                our_commit_tx.sign({bh2u(local_funding_pubkey): (local_funding_privkey[:-1], True)})
                ref_commit_tx_str = '02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8002c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de84311054a56a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0400473044022051b75c73198c6deee1a875871c3961832909acd297c6b908d59e3319e5185a46022055c419379c5051a78d00dbbce11b5b664a0c22815fbcc6fcef6b1937c383693901483045022100f51d2e566a70ba740fc5d8c0f07b9b93d2ed741c3c0860c613173de7d39e7968022041376d520e9c0e1ad52248ddf4b22e12be8763007df977253ef45a4ca3bdb7c001475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220'
                ref_commit_tx = Transaction(ref_commit_tx_str)
       t@@ -51,9 +51,14 @@ class Test_LNBase(unittest.TestCase):
                pubkeys, _x_pubkeys = our_commit_tx.get_sorted_pubkeys(our_commit_tx.inputs()[0])
                index_of_pubkey = pubkeys.index(bh2u(remote_funding_pubkey))
                our_commit_tx._inputs[0]["signatures"][index_of_pubkey] = remote_signature + "01"
       -        print("our tx", str(our_commit_tx))
       -        print("Reference inputs", json.dumps(ref_commit_tx.inputs(), indent=2))
       -        print("Our inputs", json.dumps(our_commit_tx.inputs(), indent=2))
       +
       +        #print("Reference inputs", json.dumps(ref_commit_tx.inputs(), indent=2))
       +        #print("Our inputs", json.dumps(our_commit_tx.inputs(), indent=2))
       +        print("Reference outputs", ref_commit_tx.outputs())
       +        print("Our outputs", our_commit_tx.outputs())
       +        #print("Reference tx", ref_commit_tx)
       +        #print("Our tx", our_commit_tx)
       +
        
                for idx, inp in enumerate(our_commit_tx.inputs()):
                    for field in inp.keys():