Skip to content

Commit 04afe8d

Browse files
committed
Correctly fill the 'next' field in instances when they are spent
1 parent 28a7b16 commit 04afe8d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

matt/manager.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,13 @@ def __init__(self, contract: Union[StandardP2TR, StandardAugmentedP2TR]):
9696
self.outpoint: Optional[COutPoint] = None
9797
self.funding_tx: Optional[CTransaction] = None
9898

99+
# The following fields are filled when the instance is spent
99100
self.spending_tx: Optional[CTransaction] = None
100-
self.spending_vin = None
101-
102-
self.spending_clause = None
103-
self.spending_args = None
104-
105-
# Once spent, the list of ContractInstances produced
106-
self.next = None
101+
self.spending_vin: Optional[int] = None
102+
self.spending_clause: Optional[str] = None
103+
self.spending_args: Optional[dict] = None
104+
# the new instances produced by spending this instance
105+
self.next: Optional[List[ContractInstance]] = None
107106

108107
def is_augm(self) -> bool:
109108
"""
@@ -580,13 +579,16 @@ def wait_for_spend(self, instances: Union[ContractInstance, List[ContractInstanc
580579
# and add them to the manager if they are standard
581580
if isinstance(next_outputs, CTransaction):
582581
# For now, we assume CTV clauses are terminal;
583-
# this might be generalized in the future
582+
# this might be generalized in the future to support tracking
583+
# known output contracts in a CTV template
584584
pass
585585
else:
586+
next_instances: List[ContractInstance] = []
586587
for clause_output in next_outputs:
587588
output_index = vin if clause_output.n == -1 else clause_output.n
588589

589590
if output_index in out_contracts:
591+
next_instances.append(out_contracts[output_index])
590592
continue # output already specified by another input
591593

592594
out_contract = clause_output.next_contract
@@ -610,6 +612,9 @@ def wait_for_spend(self, instances: Union[ContractInstance, List[ContractInstanc
610612

611613
out_contracts[output_index] = new_instance
612614

615+
next_instances.append(new_instance)
616+
instance.next = next_instances
617+
613618
result = list(out_contracts.values())
614619
for instance in result:
615620
self.add_instance(instance)

0 commit comments

Comments
 (0)