Skip to content

Commit 1b8e849

Browse files
committed
tapgarden: ensure change output index is set after anchor funding
Add a check to verify that the change output index is defined after anchor funding. Since the funding request guarantees a change output, the index should be known. Modify the `MockWalletAnchor.FundPsbt` method to compute a reasonable change output index.
1 parent 5dc74e7 commit 1b8e849

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

tapgarden/mock.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ func (m *MockWalletAnchor) FundPsbt(_ context.Context, packet *psbt.Packet,
182182
packet.UnsignedTx.AddTxOut(&changeOutput)
183183
packet.Outputs = append(packet.Outputs, psbt.POutput{})
184184

185+
// The change output was added last, so it will be the last output in
186+
// the list. Update the change index to reflect this.
187+
changeIdx = int32(len(packet.Outputs) - 1)
188+
185189
// We always have the change output be the second output, so this means
186190
// the Taproot Asset commitment will live in the first output.
187191
pkt := &tapsend.FundedPsbt{

tapgarden/planter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,12 @@ func (c *ChainPlanter) fundGenesisPsbt(ctx context.Context,
749749
return nil, fmt.Errorf("unable to fund psbt: %w", err)
750750
}
751751

752+
// Sanity check the funded PSBT.
753+
if fundedGenesisPkt.ChangeOutputIndex == -1 {
754+
return nil, fmt.Errorf("undefined change output index in " +
755+
"funded anchor transaction")
756+
}
757+
752758
log.Infof("Funded GenesisPacket for batch: %x", batchKey)
753759
log.Tracef("GenesisPacket: %v", spew.Sdump(fundedGenesisPkt))
754760

0 commit comments

Comments
 (0)