@@ -669,6 +669,26 @@ func (c *ChainPlanter) newBatch() (*MintingBatch, error) {
669
669
return newBatch , nil
670
670
}
671
671
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
+
672
692
// fundGenesisPsbt generates a PSBT packet we'll use to create an asset. In
673
693
// order to be able to create an asset, we need an initial genesis outpoint. To
674
694
// 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,
681
701
682
702
log .Infof ("Attempting to fund batch: %x" , batchKey )
683
703
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 ()
689
707
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 )
691
710
}
711
+ log .Tracef ("Unfunded batch anchor PSBT: %v" , spew .Sdump (genesisPkt ))
692
712
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.
696
714
var feeRate chainfee.SatPerKWeight
697
715
switch {
698
716
// If a fee rate was manually assigned for this batch, use that instead
@@ -743,7 +761,7 @@ func (c *ChainPlanter) fundGenesisPsbt(ctx context.Context,
743
761
}
744
762
745
763
fundedGenesisPkt , err := c .cfg .Wallet .FundPsbt (
746
- ctx , genesisPkt , 1 , feeRate , - 1 ,
764
+ ctx , & genesisPkt , 1 , feeRate , - 1 ,
747
765
)
748
766
if err != nil {
749
767
return nil , fmt .Errorf ("unable to fund psbt: %w" , err )
0 commit comments