Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
raypan2022 committed Apr 29, 2024
1 parent f6e547f commit f3c0dd5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ def load_transactions(mempool_dir):

def validate_transaction(transaction):
try:
txid = transaction['vin'][0]['txid']
signature_hex = transaction['vin'][0]['witness'][0]
public_key_hex = transaction['vin'][0]['witness'][1]
vin = transaction['vin'][0]
if 'witness' not in vin or len(vin['witness']) < 2:
return False

txid = vin['txid']
signature_hex = vin['witness'][0]
public_key_hex = vin['witness'][1]

sighash_type = signature_hex[-2:]
signature_bytes = bytes.fromhex(signature_hex[:-2])
Expand All @@ -59,7 +63,7 @@ def validate_transaction(transaction):

vk = VerifyingKey.from_string(bytes.fromhex(public_key_hex), curve=SECP256k1)
return vk.verify(signature_bytes, message_hash, sigdecode=sigdecode_der)
except (KeyError, ValueError, BadSignatureError):
except (KeyError, ValueError, BadSignatureError, IndexError):
return False

def mine_block(transactions, difficulty_target):
Expand Down

0 comments on commit f3c0dd5

Please sign in to comment.