electrum

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

commit 22f6deacb81da191e0ecea22d7a1df36c4668af0
parent d055507003eef1d910ceeba6deb9cadfa9f5bb71
Author: SomberNight <somber.night@protonmail.com>
Date:   Wed, 18 Apr 2018 19:00:14 +0200

transaction.py: shortcut witness/scriptSig serialisation

Diffstat:
Mlib/lnbase.py | 13+++++++------
Mlib/tests/test_lnbase.py | 5+++--
2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/lib/lnbase.py b/lib/lnbase.py @@ -25,7 +25,7 @@ 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, push_script, script_num_to_hex, add_data_to_script, - add_number_to_script) + add_number_to_script, var_int, witness_push) from . import bitcoin from . import constants from . import transaction @@ -341,7 +341,7 @@ def make_htlc_tx_output(amount_msat, local_feerate, revocationpubkey, local_dela 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): +def make_htlc_tx_inputs(htlc_output_txid, htlc_output_index, remotehtlcsig, localhtlcsig, payment_preimage, revocationpubkey, local_delayedpubkey, amount_msat, witness_script): assert type(htlc_output_txid) is str assert type(htlc_output_index) is int assert type(remotehtlcsig) is bytes @@ -352,14 +352,15 @@ def make_htlc_tx_inputs(htlc_output_txid, htlc_output_index, remotehtlcsig, loca 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': 3, + 'x_pubkeys': [], #[bh2u(x) for x in [revocationpubkey, local_delayedpubkey]], + 'signatures': [], #[bh2u(x) for x in [remotehtlcsig, localhtlcsig, payment_preimage]], + 'num_sig': 0, 'prevout_n': htlc_output_index, 'prevout_hash': htlc_output_txid, 'value': amount_msat // 1000, 'coinbase': False, - 'sequence': 0x0 + 'sequence': 0x0, + 'witness': var_int(5) + '00' + ''.join([witness_push(x) for x in [bh2u(remotehtlcsig), bh2u(localhtlcsig), bh2u(payment_preimage), witness_script]]), }] return c_inputs diff --git a/lib/tests/test_lnbase.py b/lib/tests/test_lnbase.py @@ -166,14 +166,15 @@ class Test_LNBase(unittest.TestCase): payment_preimage=htlc0_payment_preimage, revocationpubkey=local_revocation_pubkey, local_delayedpubkey=local_delayedpubkey, - amount_msat=htlc0_msat) + amount_msat=htlc0_msat, + witness_script=ref_htlc0_wscript) self.assertTrue(Transaction.is_txin_complete(our_htlc0_tx_inputs[0])) self.assertEqual(bfh("050047"), bfh(Transaction.serialize_witness(our_htlc0_tx_inputs[0]))[:3]) our_htlc0_tx = make_htlc_tx(0, - inputs=out_htlc0_tx_inputs, + inputs=our_htlc0_tx_inputs, output=our_htlc0_tx_output) self.assertEqual(str(our_htlc0_tx), output_htlc_success_tx_0)