@@ -927,6 +927,10 @@ func (c *ChainPlanter) anchorTxFeeRate(ctx context.Context,
927
927
return feeRate , nil
928
928
}
929
929
930
+ // WalletFundPsbt is a function that funds a PSBT packet.
931
+ type WalletFundPsbt = func (ctx context.Context ,
932
+ anchorPkt psbt.Packet ) (tapsend.FundedPsbt , error )
933
+
930
934
// fundGenesisPsbt generates a PSBT packet we'll use to create an asset. In
931
935
// order to be able to create an asset, we need an initial genesis outpoint. To
932
936
// obtain this we'll ask the wallet to fund a PSBT template for GenesisAmtSats
@@ -935,7 +939,7 @@ func (c *ChainPlanter) anchorTxFeeRate(ctx context.Context,
935
939
// that's dependent on the genesis outpoint.
936
940
func (c * ChainPlanter ) fundGenesisPsbt (ctx context.Context ,
937
941
batchKey asset.SerializedKey ,
938
- feeRate chainfee. SatPerKWeight ) (FundedMintAnchorPsbt , error ) {
942
+ walletFundPsbt WalletFundPsbt ) (FundedMintAnchorPsbt , error ) {
939
943
940
944
var zero FundedMintAnchorPsbt
941
945
log .Infof ("Attempting to fund batch: %x" , batchKey )
@@ -979,9 +983,7 @@ func (c *ChainPlanter) fundGenesisPsbt(ctx context.Context,
979
983
}
980
984
log .Tracef ("Unfunded batch anchor PSBT: %v" , spew .Sdump (genesisPkt ))
981
985
982
- fundedGenesisPkt , err := c .cfg .Wallet .FundPsbt (
983
- ctx , & genesisPkt , 1 , feeRate , - 1 ,
984
- )
986
+ fundedGenesisPkt , err := walletFundPsbt (ctx , genesisPkt )
985
987
if err != nil {
986
988
return zero , fmt .Errorf ("unable to fund psbt: %w" , err )
987
989
}
@@ -997,7 +999,7 @@ func (c *ChainPlanter) fundGenesisPsbt(ctx context.Context,
997
999
998
1000
// Classify anchor transaction output indexes.
999
1001
anchorOutIndexes , err := anchorTxOutputIndexes (
1000
- * fundedGenesisPkt , preCommitmentTxOut ,
1002
+ fundedGenesisPkt , preCommitmentTxOut ,
1001
1003
)
1002
1004
if err != nil {
1003
1005
return zero , fmt .Errorf ("unable to determine output indexes: " +
@@ -1034,7 +1036,7 @@ func (c *ChainPlanter) fundGenesisPsbt(ctx context.Context,
1034
1036
1035
1037
// Formulate a funded minting anchor PSBT from the funded PSBT.
1036
1038
fundedMintAnchorPsbt , err := NewFundedMintAnchorPsbt (
1037
- * fundedGenesisPkt , anchorOutIndexes , preCommitmentOut ,
1039
+ fundedGenesisPkt , anchorOutIndexes , preCommitmentOut ,
1038
1040
)
1039
1041
if err != nil {
1040
1042
return zero , fmt .Errorf ("unable to create funded minting " +
@@ -2024,7 +2026,27 @@ func (c *ChainPlanter) fundBatch(ctx context.Context, params FundParams,
2024
2026
}
2025
2027
2026
2028
batchKey := asset .ToSerialized (batch .BatchKey .PubKey )
2027
- mintAnchorTx , err := c .fundGenesisPsbt (ctx , batchKey , feeRate )
2029
+
2030
+ // walletFundPsbt is a closure that will be used to fund the
2031
+ // batch with the specified fee rate.
2032
+ walletFundPsbt := func (ctx context.Context ,
2033
+ anchorPkt psbt.Packet ) (tapsend.FundedPsbt , error ) {
2034
+
2035
+ var zero tapsend.FundedPsbt
2036
+
2037
+ fundedPkt , err := c .cfg .Wallet .FundPsbt (
2038
+ ctx , & anchorPkt , 1 , feeRate , - 1 ,
2039
+ )
2040
+ if err != nil {
2041
+ return zero , err
2042
+ }
2043
+
2044
+ return * fundedPkt , nil
2045
+ }
2046
+
2047
+ mintAnchorTx , err := c .fundGenesisPsbt (
2048
+ ctx , batchKey , walletFundPsbt ,
2049
+ )
2028
2050
if err != nil {
2029
2051
return fmt .Errorf ("unable to fund minting PSBT for " +
2030
2052
"batch: %x %w" , batchKey [:], err )
0 commit comments