From 487a0a6bd026c25e990914d0dd097750cb5763cc Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Sat, 7 Dec 2024 12:27:32 +0000 Subject: [PATCH] fixes --- .../counterpartycore/lib/gettxinfo.py | 16 +++--- .../test/regtest/regtestnode.py | 50 ++++++++++++------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/counterparty-core/counterpartycore/lib/gettxinfo.py b/counterparty-core/counterpartycore/lib/gettxinfo.py index a444d5b97c..ce9bdb5483 100644 --- a/counterparty-core/counterpartycore/lib/gettxinfo.py +++ b/counterparty-core/counterpartycore/lib/gettxinfo.py @@ -165,6 +165,8 @@ def get_der_signature_sighash_flag(value): return value[-1:] if value.startswith(binascii.unhexlify("3045")) and len(value) == 72: return value[-1:] + if value.startswith(binascii.unhexlify("3046")) and len(value) == 73: + return value[-1:] return None @@ -242,20 +244,18 @@ def check_signatures_sighash_flag(decoded_tx): flags = collect_sighash_flagss(script_sig, witnesses) - print("script_sig", script_sig) - print("witnesses", witnesses) - print("flags", flags) - if len(flags) == 0: - raise SighashFlagError( - f"impossible to determine SIGHASH flag for transaction {decoded_tx['tx_hash']}" - ) + error = f"impossible to determine SIGHASH flag for transaction {decoded_tx['tx_hash']}" + logger.debug(error) + raise SighashFlagError(error) # first input must be signed with SIGHASH_ALL or SIGHASH_ALL|SIGHASH_ANYONECANPAY authorized_flags = [b"\x01", b"\x81"] for flag in flags: if flag not in authorized_flags: - raise SighashFlagError(f"invalid SIGHASH flag for transaction {decoded_tx['tx_hash']}") + error = f"invalid SIGHASH flag for transaction {decoded_tx['tx_hash']}" + logger.debug(error) + raise SighashFlagError(error) def get_transaction_sources(decoded_tx): diff --git a/counterparty-core/counterpartycore/test/regtest/regtestnode.py b/counterparty-core/counterpartycore/test/regtest/regtestnode.py index 7ed4881383..a2cc9dd45d 100644 --- a/counterparty-core/counterpartycore/test/regtest/regtestnode.py +++ b/counterparty-core/counterpartycore/test/regtest/regtestnode.py @@ -18,10 +18,10 @@ from bitcoinutils.transactions import Transaction, TxInput, TxOutput from counterpartycore.lib import arc4, config, database -WALLET_NAME = "xcpwallet" - setup("regtest") +WALLET_NAME = "xcpwallet" + class ServerNotReady(Exception): pass @@ -56,6 +56,7 @@ def __init__( f"-datadir={self.datadir}/node2", ) self.bitcoin_wallet = self.bitcoin_cli.bake(f"-rpcwallet={WALLET_NAME}") + self.bitcoin_wallet_2 = self.bitcoin_cli_2.bake(f"-rpcwallet={WALLET_NAME}") self.bitcoind_process = None self.addresses = [] self.block_count = 0 @@ -163,6 +164,22 @@ def compose_and_send_transaction( return f"{utxo['txid']}:{utxo['vout']}", tx_hash + def compose(self, source, tx_name, params): + query_string = [] + for key, value in params.items(): + if not isinstance(value, list): + query_string.append(urllib.parse.urlencode({key: value})) + else: + for i in range(len(value)): + query_string.append(urllib.parse.urlencode({key: value[i]})) + query_string = "&".join(query_string) + + if tx_name in ["detach", "movetoutxo"]: + compose_url = f"utxos/{source}/compose/{tx_name}?{query_string}" + else: + compose_url = f"addresses/{source}/compose/{tx_name}?{query_string}" + return self.api_call(compose_url) + def send_transaction( self, source, @@ -182,20 +199,8 @@ def send_transaction( # params["inputs_set"] = self.get_inputs_set(source) # print("Inputs set:", params["inputs_set"]) - query_string = [] - for key, value in params.items(): - if not isinstance(value, list): - query_string.append(urllib.parse.urlencode({key: value})) - else: - for i in range(len(value)): - query_string.append(urllib.parse.urlencode({key: value[i]})) - query_string = "&".join(query_string) + result = self.compose(source, tx_name, params) - if tx_name in ["detach", "movetoutxo"]: - compose_url = f"utxos/{source}/compose/{tx_name}?{query_string}" - else: - compose_url = f"addresses/{source}/compose/{tx_name}?{query_string}" - result = self.api_call(compose_url) # print(result) if "error" in result: if result["error"] == "Counterparty not ready": @@ -317,10 +322,15 @@ def generate_xcp(self): self.mine_blocks(1) self.wait_for_counterparty_server() - def get_inputs_set(self, address): - list_unspent = json.loads( - self.bitcoin_cli("listunspent", 0, 9999999, json.dumps([address])).strip() - ) + def get_inputs_set(self, address, node=1): + if node == 1: + list_unspent = json.loads( + self.bitcoin_cli("listunspent", 0, 9999999, json.dumps([address])).strip() + ) + else: + list_unspent = json.loads( + self.bitcoin_cli_2("listunspent", 0, 9999999, json.dumps([address])).strip() + ) sorted(list_unspent, key=lambda x: -x["amount"]) inputs = [] for utxo in list_unspent: @@ -575,6 +585,8 @@ def get_burn_count(self, address): def get_xcp_balance(self, address): try: return self.api_call(f"addresses/{address}/balances/XCP")["result"][0]["quantity"] + except IndexError: # no XCP balance + return 0 except KeyError: print("Error getting XCP balance, retrying in 2 seconds...") time.sleep(2)