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 b70a2b3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions electrum/transaction.py
Original file line number Diff line number Diff line change
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 bitcoin.pubkey_to_address('p2pkh', decoded[0][1].hex(), net=net)

return None


Expand Down

0 comments on commit b70a2b3

Please sign in to comment.