From d97ff4119b3edc4c97ee28ae6eb76ef7ad8406fa Mon Sep 17 00:00:00 2001 From: Salvatore Ingala <6681844+bigspider@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:16:56 +0200 Subject: [PATCH] Generalize txmaker to key expressions with /* --- test_utils/txmaker.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test_utils/txmaker.py b/test_utils/txmaker.py index 8eebb07d..2228e38f 100644 --- a/test_utils/txmaker.py +++ b/test_utils/txmaker.py @@ -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 @@ -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 '/*' 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()