From 07d5e0d0b111cbb161b932f867a27267ab84ab21 Mon Sep 17 00:00:00 2001 From: Salvatore Ingala <6681844+bigspider@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:37:04 +0200 Subject: [PATCH 1/3] Fix behavior of wait_for_spend so it tracks known StandardP2TR outputs in the manager --- matt/manager.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/matt/manager.py b/matt/manager.py index 0cddc04..0a45e32 100644 --- a/matt/manager.py +++ b/matt/manager.py @@ -599,25 +599,26 @@ def wait_for_spend(self, instances: Union[ContractInstance, List[ContractInstanc out_contract = clause_output.next_contract new_instance = ContractInstance(out_contract) - if isinstance(out_contract, (P2TR, OpaqueP2TR, StandardP2TR)): - continue # nothing to do, will not track this output - elif isinstance(out_contract, StandardAugmentedP2TR): - if clause_output.next_state is None: - raise ValueError("Missing data for augmented output") - new_instance.data = clause_output.next_state.encode() - new_instance.data_expanded = clause_output.next_state - else: - raise ValueError("Unsupported contract type") + if isinstance(out_contract, (StandardP2TR, StandardAugmentedP2TR)): + if isinstance(out_contract, StandardAugmentedP2TR): + if clause_output.next_state is None: + raise ValueError("Missing data for augmented output") + new_instance.data = clause_output.next_state.encode() + new_instance.data_expanded = clause_output.next_state - new_instance.last_height = instance.last_height + new_instance.last_height = instance.last_height - new_instance.outpoint = COutPoint(int(tx.hash, 16), output_index) - new_instance.funding_tx = tx - new_instance.status = ContractInstanceStatus.FUNDED + new_instance.outpoint = COutPoint(int(tx.hash, 16), output_index) + new_instance.funding_tx = tx + new_instance.status = ContractInstanceStatus.FUNDED - out_contracts[output_index] = new_instance + out_contracts[output_index] = new_instance - next_instances.append(new_instance) + next_instances.append(new_instance) + elif isinstance(out_contract, (P2TR, OpaqueP2TR)): + continue # nothing to do, will not track this output + else: + raise ValueError("Unsupported contract type") instance.next = next_instances result = list(out_contracts.values()) From 4b8a17af9387776770c4c2a3fa3700d596a7b895 Mon Sep 17 00:00:00 2001 From: Salvatore Ingala <6681844+bigspider@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:57:02 +0200 Subject: [PATCH 2/3] Make sure that wait_for_spend produces the output instances in order or output index --- matt/manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matt/manager.py b/matt/manager.py index 0a45e32..1a6a9ae 100644 --- a/matt/manager.py +++ b/matt/manager.py @@ -621,7 +621,7 @@ def wait_for_spend(self, instances: Union[ContractInstance, List[ContractInstanc raise ValueError("Unsupported contract type") instance.next = next_instances - result = list(out_contracts.values()) + result = [out_contracts[idx] for idx in sorted(out_contracts.keys())] for instance in result: self.add_instance(instance) return result From cea56fdfaef1065df04d00515a62c0a5c884446e Mon Sep 17 00:00:00 2001 From: Salvatore Ingala <6681844+bigspider@users.noreply.github.com> Date: Mon, 29 Apr 2024 00:00:37 +0200 Subject: [PATCH 3/3] Fix vault test with revault, checking also the revaulted instance --- tests/test_vault.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_vault.py b/tests/test_vault.py index fb6084e..41410f0 100644 --- a/tests/test_vault.py +++ b/tests/test_vault.py @@ -1,7 +1,7 @@ from typing import Tuple import pytest -from examples.vault.vault_contracts import Vault +from examples.vault.vault_contracts import Vault, Unvaulting from matt.btctools import key from matt.btctools.auth_proxy import AuthServiceProxy, JSONRPCException @@ -183,7 +183,12 @@ def test_vault_trigger_with_revault_and_withdraw(vault_specs: VaultSpecs, rpc: A {**args, "sig": sigs[i]} )) - [U_inst] = manager.spend_and_wait([V_inst_1, V_inst_2, V_inst_3], spend_tx) + [U_inst, V_revault_inst] = manager.spend_and_wait([V_inst_1, V_inst_2, V_inst_3], spend_tx) + + assert isinstance(U_inst.contract, Unvaulting) + assert isinstance(V_revault_inst.contract, Vault) + assert manager.instances.index(U_inst) >= 0 + assert manager.instances.index(V_revault_inst) >= 0 report.write(vault_description, format_tx_markdown(spend_tx, "Trigger (with revault) [3 vault inputs]"))