Skip to content

Commit

Permalink
fix P2PK support
Browse files Browse the repository at this point in the history
  • Loading branch information
icodeface committed Aug 4, 2020
1 parent 8268bb5 commit e7ad5bc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions electrum/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
var_int, TOTAL_COIN_SUPPLY_LIMIT_IN_BTC, COIN,
int_to_hex, push_script, b58_address_to_hash160,
opcodes, add_number_to_script, script_num_to_hex,
base_decode, is_segwit_script_type, pubkeyhash_to_p2pkh_script)
base_decode, is_segwit_script_type, pubkeyhash_to_p2pkh_script, public_key_to_p2pkh)
from .crypto import sha256d
from .logging import get_logger

Expand Down Expand Up @@ -421,6 +421,7 @@ def is_instance(cls, item):
opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG]
SCRIPTPUBKEY_TEMPLATE_P2SH = [opcodes.OP_HASH160, OPPushDataGeneric(lambda x: x == 20), opcodes.OP_EQUAL]
SCRIPTPUBKEY_TEMPLATE_WITNESS_V0 = [opcodes.OP_0, OPPushDataGeneric(lambda x: x in (20, 32))]
SCRIPTPUBKEY_TEMPLATE_P2PK = [OPPushDataGeneric(lambda x: x in (33, 65)), opcodes.OP_CHECKSIG]


def match_script_against_template(script, template) -> bool:
Expand Down Expand Up @@ -470,6 +471,10 @@ def get_address_from_output_script(_bytes: bytes, *, net=None) -> Optional[str]:
if match_script_against_template(decoded, match):
return hash_to_segwit_addr(decoded[1][1], witver=witver, net=net)

# p2pk
if match_script_against_template(decoded, SCRIPTPUBKEY_TEMPLATE_P2PK):
return public_key_to_p2pkh(decoded[0][1], net=net)

return None


Expand All @@ -487,7 +492,7 @@ def construct_witness(items: Sequence[Union[str, int, bytes]]) -> str:
witness = var_int(len(items))
for item in items:
if type(item) is int:
item = bitcoin.script_num_to_hex(item)
item = script_num_to_hex(item)
elif isinstance(item, (bytes, bytearray)):
item = item.hex()
witness += bitcoin.witness_push(item)
Expand Down

0 comments on commit e7ad5bc

Please sign in to comment.