electrum

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

commit c7e3f7e4e497bf7f01deaa7245e52919fc1b09cd
parent f32149e609b9bd939f4a737278fe583ef2ffe688
Author: ThomasV <thomasv@electrum.org>
Date:   Thu, 26 Apr 2018 17:17:59 +0200

simplification

Diffstat:
Mlib/lnbase.py | 18++++++------------
Mlib/tests/test_lnbase.py | 6+++---
2 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/lib/lnbase.py b/lib/lnbase.py @@ -443,7 +443,8 @@ def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, remotepubk payment_basepoint, remote_payment_basepoint, revocation_pubkey, delayed_pubkey, to_self_delay, funding_txid, funding_pos, funding_satoshis, - local_amount, remote_amount, dust_limit_satoshis, local_feerate, commitment_owner, htlcs): + local_amount, remote_amount, + dust_limit_satoshis, local_feerate, for_us, htlcs): pubkeys = sorted([bh2u(local_funding_pubkey), bh2u(remote_funding_pubkey)]) obs = get_obscured_ctn(ctn, payment_basepoint, remote_payment_basepoint) @@ -469,15 +470,8 @@ def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, remotepubk remote_address = bitcoin.pubkey_to_address('p2wpkh', bh2u(remotepubkey)) # TODO trim htlc outputs here while also considering 2nd stage htlc transactions fee = local_feerate * overall_weight(len(htlcs)) // 1000 # TODO incorrect if anything is trimmed - fee_local, fee_remote = 0, 0 - if commitment_owner == FOR_US: - fee_local = fee - elif commitment_owner == FOR_REMOTE: - fee_remote = fee - else: - raise Exception("unexpected commitment owner") - to_local = (bitcoin.TYPE_ADDRESS, local_address, local_amount - fee_local) - to_remote = (bitcoin.TYPE_ADDRESS, remote_address, remote_amount - fee_remote) + to_local = (bitcoin.TYPE_ADDRESS, local_address, local_amount - (fee if for_us else 0)) + to_remote = (bitcoin.TYPE_ADDRESS, remote_address, remote_amount - (fee if not for_us else 0)) 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)] @@ -806,7 +800,7 @@ class Peer(PrintError): base_point, remote_payment_basepoint, revocation_pubkey, remote_delayedpubkey, remote_delay, funding_txid, funding_index, funding_satoshis, - remote_amount, local_amount, remote_dust_limit_satoshis, local_feerate, FOR_REMOTE, htlcs=[]) + remote_amount, local_amount, remote_dust_limit_satoshis, local_feerate, False, htlcs=[]) remote_ctx.sign({bh2u(funding_pubkey): (funding_privkey, True)}) sig_index = pubkeys.index(bh2u(funding_pubkey)) sig = bytes.fromhex(remote_ctx.inputs()[0]["signatures"][sig_index]) @@ -829,7 +823,7 @@ class Peer(PrintError): base_point, remote_payment_basepoint, remote_revocation_pubkey, local_delayedpubkey, to_self_delay, funding_txid, funding_index, funding_satoshis, - local_amount, remote_amount, dust_limit_satoshis, local_feerate, FOR_US) + local_amount, remote_amount, dust_limit_satoshis, local_feerate, True) local_ctx = make_commitment(*local_ctx_args, htlcs=[]) pre_hash = bitcoin.Hash(bfh(local_ctx.serialize_preimage(0))) if not bitcoin.verify_signature(remote_funding_pubkey, remote_sig, pre_hash): diff --git a/lib/tests/test_lnbase.py b/lib/tests/test_lnbase.py @@ -3,7 +3,6 @@ import json import unittest from lib.util import bh2u, bfh -from lib.lnbase import FOR_US, FOR_REMOTE 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, overall_weight from lib.lnbase import make_htlc_tx_output, make_htlc_tx_inputs, get_per_commitment_secret_from_seed @@ -70,7 +69,8 @@ class Test_LNBase(unittest.TestCase): local_payment_basepoint, remote_payment_basepoint, local_revocation_pubkey, local_delayedpubkey, local_delay, funding_tx_id, funding_output_index, funding_amount_satoshi, - local_amount, remote_amount, local_dust_limit_satoshi, local_feerate=local_feerate_per_kw, commitment_owner=FOR_US, htlcs=[]) + local_amount, remote_amount, local_dust_limit_satoshi, + local_feerate_per_kw, True, htlcs=[]) self.sign_and_insert_remote_sig(our_commit_tx, remote_funding_pubkey, remote_signature, local_funding_pubkey, local_funding_privkey) ref_commit_tx_str = '02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8002c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de84311054a56a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0400473044022051b75c73198c6deee1a875871c3961832909acd297c6b908d59e3319e5185a46022055c419379c5051a78d00dbbce11b5b664a0c22815fbcc6fcef6b1937c383693901483045022100f51d2e566a70ba740fc5d8c0f07b9b93d2ed741c3c0860c613173de7d39e7968022041376d520e9c0e1ad52248ddf4b22e12be8763007df977253ef45a4ca3bdb7c001475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220' self.assertEqual(str(our_commit_tx), ref_commit_tx_str) @@ -159,7 +159,7 @@ class Test_LNBase(unittest.TestCase): local_revocation_pubkey, local_delayedpubkey, local_delay, funding_tx_id, funding_output_index, funding_amount_satoshi, local_amount, remote_amount, local_dust_limit_satoshi, - local_feerate=local_feerate_per_kw, commitment_owner=FOR_US, htlcs=htlcs) + local_feerate_per_kw, True, htlcs=htlcs) self.sign_and_insert_remote_sig(our_commit_tx, remote_funding_pubkey, remote_signature, local_funding_pubkey, local_funding_privkey) self.assertEqual(str(our_commit_tx), output_commit_tx)