electrum

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

commit 38f1436d789af4189dbd4316f33c465eddaf07ec
parent b215d6c4b720cf85cf736a3447bc7daef23d7909
Author: ThomasV <thomasv@electrum.org>
Date:   Wed,  6 Mar 2019 16:13:28 +0100

post rebase fixes

Diffstat:
Melectrum/lnutil.py | 6+++---
Melectrum/lnwatcher.py | 4++--
Melectrum/lnworker.py | 5+++--
Melectrum/tests/test_lnchannel.py | 5++---
Melectrum/verifier.py | 2--
5 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/electrum/lnutil.py b/electrum/lnutil.py @@ -237,7 +237,7 @@ def make_htlc_tx_output(amount_msat, local_feerate, revocationpubkey, local_dela + bfh(push_script(bh2u(revocationpubkey))) \ + bytes([opcodes.OP_ELSE]) \ + bitcoin.add_number_to_script(to_self_delay) \ - + bytes([opcodes.OP_CSV, opcodes.OP_DROP]) \ + + bytes([opcodes.OP_CHECKSEQUENCEVERIFY, opcodes.OP_DROP]) \ + bfh(push_script(bh2u(local_delayedpubkey))) \ + bytes([opcodes.OP_ENDIF, opcodes.OP_CHECKSIG]) @@ -319,7 +319,7 @@ def make_received_htlc(revocation_pubkey: bytes, remote_htlcpubkey: bytes, + bitcoin.add_number_to_script(2) \ + bytes([opcodes.OP_CHECKMULTISIG, opcodes.OP_ELSE, opcodes.OP_DROP]) \ + bitcoin.add_number_to_script(cltv_expiry) \ - + bytes([opcodes.OP_CLTV, opcodes.OP_DROP, opcodes.OP_CHECKSIG, opcodes.OP_ENDIF, opcodes.OP_ENDIF]) + + bytes([opcodes.OP_CHECKLOCKTIMEVERIFY, opcodes.OP_DROP, opcodes.OP_CHECKSIG, opcodes.OP_ENDIF, opcodes.OP_ENDIF]) def make_htlc_output_witness_script(is_received_htlc: bool, remote_revocation_pubkey: bytes, remote_htlc_pubkey: bytes, local_htlc_pubkey: bytes, payment_hash: bytes, cltv_expiry: Optional[int]) -> bytes: @@ -473,7 +473,7 @@ def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, def make_commitment_output_to_local_witness_script( revocation_pubkey: bytes, to_self_delay: int, delayed_pubkey: bytes) -> bytes: local_script = bytes([opcodes.OP_IF]) + bfh(push_script(bh2u(revocation_pubkey))) + bytes([opcodes.OP_ELSE]) + bitcoin.add_number_to_script(to_self_delay) \ - + bytes([opcodes.OP_CSV, opcodes.OP_DROP]) + bfh(push_script(bh2u(delayed_pubkey))) + bytes([opcodes.OP_ENDIF, opcodes.OP_CHECKSIG]) + + bytes([opcodes.OP_CHECKSEQUENCEVERIFY, opcodes.OP_DROP]) + bfh(push_script(bh2u(delayed_pubkey))) + bytes([opcodes.OP_ENDIF, opcodes.OP_CHECKSIG]) return local_script def make_commitment_output_to_local_address( diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py @@ -211,7 +211,7 @@ class LNWatcher(AddressSynchronizer): # FIXME: instead of stopping recursion at n == 2, # we should detect which outputs are HTLCs prev_txid, index = outpoint.split(':') - txid = self.spent_outpoints[prev_txid].get(int(index)) + txid = self.db.get_spent_outpoint(prev_txid, int(index)) result = {outpoint:txid} if txid is None: self.channel_status[outpoint] = 'open' @@ -224,7 +224,7 @@ class LNWatcher(AddressSynchronizer): else: self.channel_status[outpoint] = 'closed (deep)' - tx = self.transactions[txid] + tx = self.db.get_transaction(txid) for i, o in enumerate(tx.outputs()): if o.address not in self.get_addresses(): self.add_address(o.address) diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -25,7 +25,7 @@ from .keystore import BIP32_KeyStore from .bitcoin import COIN from .transaction import Transaction from .crypto import sha256 -from .bip32 import bip32_root +from .bip32 import BIP32Node from .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions from .util import timestamp_to_datetime from .lntransport import LNTransport, LNResponderTransport @@ -217,7 +217,8 @@ class LNWorker(PrintError): # TODO derive this deterministically from wallet.keystore at keystore generation time # probably along a hardened path ( lnd-equivalent would be m/1017'/coinType'/ ) seed = os.urandom(32) - xprv, xpub = bip32_root(seed, xtype='standard') + node = BIP32Node.from_rootseed(seed, xtype='standard') + xprv = node.to_xprv() self.storage.put('lightning_privkey2', xprv) return keystore.from_xprv(xprv) diff --git a/electrum/tests/test_lnchannel.py b/electrum/tests/test_lnchannel.py @@ -99,9 +99,8 @@ def create_channel_state(funding_txid, funding_index, funding_sat, local_feerate } def bip32(sequence): - xprv, xpub = bip32_utils.bip32_root(b"9dk", 'standard') - xprv, xpub = bip32_utils.bip32_private_derivation(xprv, "m/", sequence) - xtype, depth, fingerprint, child_number, c, k = bip32_utils.deserialize_xprv(xprv) + node = bip32_utils.BIP32Node.from_rootseed(b"9dk", xtype='standard').subkey_at_private_derivation(sequence) + k = node.eckey.get_secret_bytes() assert len(k) == 32 assert type(k) is bytes return k diff --git a/electrum/verifier.py b/electrum/verifier.py @@ -133,8 +133,6 @@ class SPV(NetworkJobOnDefaultServer): txpos=pos, header_hash=header_hash) self.wallet.add_verified_tx(tx_hash, tx_info) - if self.is_up_to_date() and self.wallet.is_up_to_date(): - self.wallet.save_verified_tx(write=True) @classmethod def hash_merkle_root(cls, merkle_branch: Sequence[str], tx_hash: str, leaf_pos_in_tree: int):