electrum

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

commit fcea2a065d50c852a8e74911ef9de6c1fec028f9
parent d1e897bf8f0bb8dd3a9a394b8284dd4c9dd8622d
Author: ThomasV <thomasv@electrum.org>
Date:   Mon, 18 Sep 2017 08:52:06 +0200

add support for p2wsh-in-p2sh

Diffstat:
Mlib/transaction.py | 18++++++++++++++----
Mlib/wallet.py | 22++++++++--------------
2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/lib/transaction.py b/lib/transaction.py @@ -491,11 +491,17 @@ def deserialize(raw): # pay & redeem scripts -def segwit_script(pubkey): +def p2wpkh_nested_script(pubkey): pubkey = safe_parse_pubkey(pubkey) pkh = bh2u(hash_160(bfh(pubkey))) return '00' + push_script(pkh) +def p2wsh_nested_script(witness_script): + print('wit', witness_script) + wsh = bh2u(sha256(bfh(witness_script))) + print(len(wsh)//2) + return '00' + push_script(wsh) + def multisig_script(public_keys, m): n = len(public_keys) @@ -676,9 +682,13 @@ class Transaction: script += push_script(pubkeys[0]) elif _type in ['p2wpkh', 'p2wsh']: return segwit_value - elif _type in ['p2wpkh-p2sh', 'p2wsh-p2sh']: - redeem_script = txin.get('redeemScript') or segwit_script(pubkeys[0]) - return segwit_value + push_script(redeem_script) + elif _type == 'p2wpkh-p2sh': + scriptSig = p2wpkh_nested_script(pubkeys[0]) + return segwit_value + push_script(scriptSig) + elif _type == 'p2wsh-p2sh': + witness_script = self.get_preimage_script(txin) + scriptSig = p2wsh_nested_script(witness_script) + return segwit_value + push_script(scriptSig) elif _type == 'address': script += push_script(pubkeys[0]) elif _type == 'unknown': diff --git a/lib/wallet.py b/lib/wallet.py @@ -1646,17 +1646,14 @@ class Simple_Deterministic_Wallet(Deterministic_Wallet, Simple_Wallet): class Standard_Wallet(Simple_Deterministic_Wallet): wallet_type = 'standard' - def pubkeys_to_redeem_script(self, pubkey): - return transaction.segwit_script(pubkey) - def pubkeys_to_address(self, pubkey): if self.txin_type == 'p2pkh': return bitcoin.public_key_to_p2pkh(bfh(pubkey)) elif self.txin_type == 'p2wpkh': return bitcoin.hash_to_segwit_addr(hash_160(bfh(pubkey))) elif self.txin_type == 'p2wpkh-p2sh': - redeem_script = self.pubkeys_to_redeem_script(pubkey) - return bitcoin.hash160_to_p2sh(hash_160(bfh(redeem_script))) + scriptSig = transaction.p2wpkh_nested_script(pubkey) + return bitcoin.hash160_to_p2sh(hash_160(bfh(scriptSig))) else: raise NotImplementedError(self.txin_type) @@ -1673,23 +1670,20 @@ class Multisig_Wallet(Deterministic_Wallet): def get_pubkeys(self, c, i): return self.derive_pubkeys(c, i) - def pubkeys_to_address(self, pubkey): + def pubkeys_to_address(self, pubkeys): if self.txin_type == 'p2sh': - redeem_script = self.pubkeys_to_redeem_script(pubkey) + redeem_script = self.pubkeys_to_redeem_script(pubkeys) return bitcoin.hash160_to_p2sh(hash_160(bfh(redeem_script))) elif self.txin_type == 'p2wsh': - witness_script = self.pubkeys_to_redeem_script(pubkey) + witness_script = self.pubkeys_to_redeem_script(pubkeys) return bitcoin.script_to_p2wsh(witness_script) elif self.txin_type == 'p2wsh-p2sh': - redeem_script = self.pubkeys_to_redeem_script(pubkey) - return bitcoin.hash160_to_p2sh(hash_160(bfh(redeem_script))) + witness_script = self.pubkeys_to_redeem_script(pubkeys) + scriptSig = transaction.p2wsh_nested_script(witness_script) + return bitcoin.hash160_to_p2sh(hash_160(bfh(scriptSig))) else: raise NotImplementedError(self.txin_type) - #def redeem_script(self, c, i): - # pubkeys = self.get_pubkeys(c, i) - # return transaction.multisig_script(sorted(pubkeys), self.m) - def pubkeys_to_redeem_script(self, pubkeys): return transaction.multisig_script(sorted(pubkeys), self.m)