Browse Source
bitcoin.py: dedupe pubkeyhash_to_p2pkh_script
dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight
5 years ago
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
2 changed files with
11 additions and
8 deletions
-
electrum/bitcoin.py
-
electrum/transaction.py
|
|
@ -400,9 +400,7 @@ def address_to_script(addr: str, *, net=None) -> str: |
|
|
|
return script |
|
|
|
addrtype, hash_160_ = b58_address_to_hash160(addr) |
|
|
|
if addrtype == net.ADDRTYPE_P2PKH: |
|
|
|
script = bytes([opcodes.OP_DUP, opcodes.OP_HASH160]).hex() |
|
|
|
script += push_script(bh2u(hash_160_)) |
|
|
|
script += bytes([opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG]).hex() |
|
|
|
script = pubkeyhash_to_p2pkh_script(bh2u(hash_160_)) |
|
|
|
elif addrtype == net.ADDRTYPE_P2SH: |
|
|
|
script = opcodes.OP_HASH160.hex() |
|
|
|
script += push_script(bh2u(hash_160_)) |
|
|
@ -422,6 +420,13 @@ def script_to_scripthash(script: str) -> str: |
|
|
|
def public_key_to_p2pk_script(pubkey: str) -> str: |
|
|
|
return push_script(pubkey) + opcodes.OP_CHECKSIG.hex() |
|
|
|
|
|
|
|
def pubkeyhash_to_p2pkh_script(pubkey_hash160: str) -> str: |
|
|
|
script = bytes([opcodes.OP_DUP, opcodes.OP_HASH160]).hex() |
|
|
|
script += push_script(pubkey_hash160) |
|
|
|
script += bytes([opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG]).hex() |
|
|
|
return script |
|
|
|
|
|
|
|
|
|
|
|
__b58chars = b'123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' |
|
|
|
assert len(__b58chars) == 58 |
|
|
|
|
|
|
|
|
|
@ -909,14 +909,12 @@ class Transaction: |
|
|
|
return preimage_script |
|
|
|
|
|
|
|
pubkeys, x_pubkeys = self.get_sorted_pubkeys(txin) |
|
|
|
if txin['type'] == 'p2pkh': |
|
|
|
return bitcoin.address_to_script(txin['address']) |
|
|
|
elif txin['type'] in ['p2sh', 'p2wsh', 'p2wsh-p2sh']: |
|
|
|
if txin['type'] in ['p2sh', 'p2wsh', 'p2wsh-p2sh']: |
|
|
|
return multisig_script(pubkeys, txin['num_sig']) |
|
|
|
elif txin['type'] in ['p2wpkh', 'p2wpkh-p2sh']: |
|
|
|
elif txin['type'] in ['p2pkh', 'p2wpkh', 'p2wpkh-p2sh']: |
|
|
|
pubkey = pubkeys[0] |
|
|
|
pkh = bh2u(hash_160(bfh(pubkey))) |
|
|
|
return '76a9' + push_script(pkh) + '88ac' |
|
|
|
return bitcoin.pubkeyhash_to_p2pkh_script(pkh) |
|
|
|
elif txin['type'] == 'p2pk': |
|
|
|
pubkey = pubkeys[0] |
|
|
|
return bitcoin.public_key_to_p2pk_script(pubkey) |
|
|
|