Merge pull request #4905 from LN-Zap/feat/spend-unconfirmed-estimate

Support spend_unconfirmed in EstimateFee and FundPsbt
This commit is contained in:
Olaoluwa Osuntokun authored and GitHub committed 2021-04-26 15:48:11 -07:00
commit bfcaf02f04
16 files changed
+1068 -906

No files matched your search

+13 -4
View File
@@ -964,7 +964,7 @@ func allowCORS(handler http.Handler, origins []string) http.Handler {
// more addresses specified in the passed payment map. The payment map maps an
// address to a specified output value to be sent to that address.
func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64,
feeRate chainfee.SatPerKWeight, minconf int32,
feeRate chainfee.SatPerKWeight, minConfs int32,
label string) (*chainhash.Hash, error) {
outputs, err := addrPairsToOutputs(paymentMap, r.cfg.ActiveNetParams.Params)
@@ -975,7 +975,7 @@ func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64,
// We first do a dry run, to sanity check we won't spend our wallet
// balance below the reserved amount.
authoredTx, err := r.server.cc.Wallet.CreateSimpleTx(
outputs, feeRate, true,
outputs, feeRate, minConfs, true,
)
if err != nil {
return nil, err
@@ -989,7 +989,7 @@ func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64,
// If that checks out, we're failry confident that creating sending to
// these outputs will keep the wallet balance above the reserve.
tx, err := r.server.cc.Wallet.SendOutputs(
outputs, feeRate, minconf, label,
outputs, feeRate, minConfs, label,
)
if err != nil {
return nil, err
@@ -1073,12 +1073,21 @@ func (r *rpcServer) EstimateFee(ctx context.Context,
return nil, err
}
// Then, we'll extract the minimum number of confirmations that each
// output we use to fund the transaction should satisfy.
minConfs, err := lnrpc.ExtractMinConfs(
in.GetMinConfs(), in.GetSpendUnconfirmed(),
)
if err != nil {
return nil, err
}
// We will ask the wallet to create a tx using this fee rate. We set
// dryRun=true to avoid inflating the change addresses in the db.
var tx *txauthor.AuthoredTx
wallet := r.server.cc.Wallet
err = wallet.WithCoinSelectLock(func() error {
tx, err = wallet.CreateSimpleTx(outputs, feePerKw, true)
tx, err = wallet.CreateSimpleTx(outputs, feePerKw, minConfs, true)
return err
})
if err != nil {