Skip to content

Commit

Permalink
Generalize txmaker to key expressions with <NUM;NUM>/*
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspider committed Jun 19, 2024
1 parent 2c3cc2e commit c943cea
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test_utils/txmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from io import BytesIO
from random import randint
import re

from typing import List, Tuple, Optional, Union
from bitcoin_client.ledger_bitcoin import WalletPolicy, WalletType
Expand Down Expand Up @@ -78,6 +79,11 @@ def getScriptPubkeyFromWallet(wallet: WalletPolicy, change: bool, address_index:
# by doing the text substitution of '/**' at the end, this works for either V1 or V2
descriptor_str = descriptor_str.replace("/**", f"/{1 if change else 0}/*")

# Substitute '<NUM1;NUM2>/*' with either `NUM1/*` (not change) or `NUM2/*` (change)
pattern = re.compile(r'<(\d+);(\d+)>(/\*)')
descriptor_str = pattern.sub(lambda m: (
m.group(2) if change else m.group(1)) + m.group(3), descriptor_str)

return Descriptor.from_string(descriptor_str).derive(address_index).script_pubkey()


Expand Down

0 comments on commit c943cea

Please sign in to comment.