electrum

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

commit af54ba023bd67ba9a3321b23e079b145370732bd
parent 6f083a712d6757d7c011f6e4a1bc65d620245197
Author: ThomasV <thomasv@electrum.org>
Date:   Tue, 31 Jan 2017 11:56:59 +0100

add wallet.is_segwit

Diffstat:
Mlib/keystore.py | 4++++
Mlib/wallet.py | 8++++----
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/keystore.py b/lib/keystore.py @@ -217,6 +217,8 @@ class Deterministic_KeyStore(Software_KeyStore): def get_passphrase(self, password): return pw_decode(self.passphrase, password) if self.passphrase else '' + def is_segwit(self): + return False class Xpub: @@ -333,6 +335,8 @@ class BIP32_KeyStore(Deterministic_KeyStore, Xpub): pk = bip32_private_key(sequence, k, c) return pk + def is_segwit(self): + return bool(deserialize_xpub(self.xpub)[0]) class Old_KeyStore(Deterministic_KeyStore): diff --git a/lib/wallet.py b/lib/wallet.py @@ -1516,7 +1516,7 @@ class Simple_Wallet(Abstract_Wallet): def load_keystore(self): self.keystore = load_keystore(self.storage, 'keystore') - self.xpub_type = deserialize_xpub(self.keystore.xpub)[0] + self.is_segwit = self.keystore.is_segwit() def get_pubkey(self, c, i): pubkey_list = self.change_pubkeys if c else self.receiving_pubkeys @@ -1632,13 +1632,13 @@ class Standard_Wallet(Simple_Deterministic_Wallet): wallet_type = 'standard' def pubkeys_to_redeem_script(self, pubkey): - if self.xpub_type == 1: + if self.is_segwit: return transaction.segwit_script(pubkey) def pubkeys_to_address(self, pubkey): - if self.xpub_type == 0: + if not self.is_segwit: return bitcoin.public_key_to_p2pkh(pubkey.decode('hex')) - elif self.xpub_type == 1 and bitcoin.TESTNET: + elif bitcoin.TESTNET: redeem_script = self.pubkeys_to_redeem_script(pubkey) return bitcoin.hash160_to_p2sh(hash_160(redeem_script.decode('hex'))) else: