Skip to content

Commit 563b84c

Browse files
committed
tapgarden: refactor fundGenesisPsbt to extract unfundedAnchorPsbt method
1 parent 1b8e849 commit 563b84c

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

tapgarden/planter.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,26 @@ func (c *ChainPlanter) newBatch() (*MintingBatch, error) {
669669
return newBatch, nil
670670
}
671671

672+
// unfundedAnchorPsbt creates an unfunded PSBT packet for the minting anchor
673+
// transaction.
674+
func unfundedAnchorPsbt() (psbt.Packet, error) {
675+
var zero psbt.Packet
676+
677+
// Construct a template transaction for our minting anchor transaction.
678+
txTemplate := wire.NewMsgTx(2)
679+
680+
// Add one output to anchor all assets which are being minted.
681+
txTemplate.AddTxOut(tapsend.CreateDummyOutput())
682+
683+
// Formulate the PSBT packet from the template transaction.
684+
genesisPkt, err := psbt.NewFromUnsignedTx(txTemplate)
685+
if err != nil {
686+
return zero, fmt.Errorf("unable to make psbt packet: %w", err)
687+
}
688+
689+
return *genesisPkt, nil
690+
}
691+
672692
// fundGenesisPsbt generates a PSBT packet we'll use to create an asset. In
673693
// order to be able to create an asset, we need an initial genesis outpoint. To
674694
// obtain this we'll ask the wallet to fund a PSBT template for GenesisAmtSats
@@ -681,18 +701,16 @@ func (c *ChainPlanter) fundGenesisPsbt(ctx context.Context,
681701

682702
log.Infof("Attempting to fund batch: %x", batchKey)
683703

684-
// Construct a 1-output TX as a template for our genesis TX, which the
685-
// backing wallet will fund.
686-
txTemplate := wire.NewMsgTx(2)
687-
txTemplate.AddTxOut(tapsend.CreateDummyOutput())
688-
genesisPkt, err := psbt.NewFromUnsignedTx(txTemplate)
704+
// Construct an unfunded anchor PSBT which will eventually become a
705+
// funded minting anchor transaction.
706+
genesisPkt, err := unfundedAnchorPsbt()
689707
if err != nil {
690-
return nil, fmt.Errorf("unable to make psbt packet: %w", err)
708+
return nil, fmt.Errorf("unable to create anchor template tx: "+
709+
"%w", err)
691710
}
711+
log.Tracef("Unfunded batch anchor PSBT: %v", spew.Sdump(genesisPkt))
692712

693-
log.Infof("creating skeleton PSBT for batch: %x", batchKey)
694-
log.Tracef("PSBT: %v", spew.Sdump(genesisPkt))
695-
713+
// Compute the anchor transaction fee rate.
696714
var feeRate chainfee.SatPerKWeight
697715
switch {
698716
// If a fee rate was manually assigned for this batch, use that instead
@@ -743,7 +761,7 @@ func (c *ChainPlanter) fundGenesisPsbt(ctx context.Context,
743761
}
744762

745763
fundedGenesisPkt, err := c.cfg.Wallet.FundPsbt(
746-
ctx, genesisPkt, 1, feeRate, -1,
764+
ctx, &genesisPkt, 1, feeRate, -1,
747765
)
748766
if err != nil {
749767
return nil, fmt.Errorf("unable to fund psbt: %w", err)

0 commit comments

Comments
 (0)