tMerge pull request #3268 from SomberNight/sweep_minikey - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 91539189d5292bec104585013c4b94c74b115c1a DIR parent c4923ac99d99677883e852d6b0acd610cf76fa8f HTML Author: ThomasV <thomasv@electrum.org> Date: Sat, 11 Nov 2017 11:41:41 +0100 Merge pull request #3268 from SomberNight/sweep_minikey sweeping minikeys: search for both compressed and uncompressed pubkeys Diffstat: M lib/bitcoin.py | 2 +- M lib/wallet.py | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) --- DIR diff --git a/lib/bitcoin.py b/lib/bitcoin.py t@@ -600,7 +600,7 @@ def is_minikey(text): # permits any length of 20 or more provided the minikey is valid. # A valid minikey must begin with an 'S', be in base58, and when # suffixed with '?' have its SHA256 hash begin with a zero byte. - # They are widely used in Casascius physical bitoins. + # They are widely used in Casascius physical bitcoins. return (len(text) >= 20 and text[0] == 'S' and all(ord(c) in __b58chars for c in text) and sha256(text + '?')[0] == 0x00) DIR diff --git a/lib/wallet.py b/lib/wallet.py t@@ -893,15 +893,28 @@ class Abstract_Wallet(PrintError): inputs.append(item) def sweep(self, privkeys, network, config, recipient, fee=None, imax=100): + + def find_utxos_for_privkey(txin_type, privkey, compressed): + pubkey = bitcoin.public_key_from_private_key(privkey, compressed) + self._append_utxos_to_inputs(inputs, network, pubkey, txin_type, imax) + keypairs[pubkey] = privkey, compressed + inputs = [] keypairs = {} for sec in privkeys: txin_type, privkey, compressed = bitcoin.deserialize_privkey(sec) - pubkey = bitcoin.public_key_from_private_key(privkey, compressed) - self._append_utxos_to_inputs(inputs, network, pubkey, txin_type, imax) - if txin_type == 'p2pkh': # WIF serialization is ambiguous :( - self._append_utxos_to_inputs(inputs, network, pubkey, 'p2pk', imax) - keypairs[pubkey] = privkey, compressed + + find_utxos_for_privkey(txin_type, privkey, compressed) + + # do other lookups to increase support coverage + if is_minikey(sec): + # minikeys don't have a compressed byte + # we lookup both compressed and uncompressed pubkeys + find_utxos_for_privkey(txin_type, privkey, not compressed) + elif txin_type == 'p2pkh': + # WIF serialization does not distinguish p2pkh and p2pk + # we also search for pay-to-pubkey outputs + find_utxos_for_privkey('p2pk', privkey, compressed) if not inputs: raise BaseException(_('No inputs found. (Note that inputs need to be confirmed)'))