From 07ef71361f23eb1c85da99ee80e2a1c58277538f Mon Sep 17 00:00:00 2001 From: ziggie Date: Mon, 13 Feb 2023 14:20:41 +0100 Subject: [PATCH] wallet: adopting changes for the new input selection The new NewUnsignedTransaction function requires all inputs and the input selection logic for the input selection to work. --- wallet/createtx.go | 12 +++++++----- wallet/psbt.go | 11 +++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/wallet/createtx.go b/wallet/createtx.go index 7f0d75847c..34d63865a8 100644 --- a/wallet/createtx.go +++ b/wallet/createtx.go @@ -139,13 +139,15 @@ func (w *Wallet) txToOutputs(outputs []*wire.TxOut, return err } - var inputSource txauthor.InputSource + // var inputSource txauthor.InputSource + // We need to define the Selection Strategy + var inputSelectionStrategy txauthor.InputSelectionStrategy = txauthor.ConstantSelection switch coinSelectionStrategy { // Pick largest outputs first. case CoinSelectionLargest: sort.Sort(sort.Reverse(byAmount(eligible))) - inputSource = makeInputSource(eligible) + inputSelectionStrategy = txauthor.PositiveYieldingSelection // Select coins at random. This prevents the creation of ever // smaller utxos over time that may never become economical to @@ -170,12 +172,12 @@ func (w *Wallet) txToOutputs(outputs []*wire.TxOut, positivelyYielding[i], positivelyYielding[j] = positivelyYielding[j], positivelyYielding[i] }) - - inputSource = makeInputSource(positivelyYielding) + inputSelectionStrategy = txauthor.RandomSelection + eligible = positivelyYielding } tx, err = txauthor.NewUnsignedTransaction( - outputs, feeSatPerKb, inputSource, changeSource, + outputs, feeSatPerKb, eligible, inputSelectionStrategy, changeSource, ) if err != nil { return err diff --git a/wallet/psbt.go b/wallet/psbt.go index 8b81bfad28..e69a2e7895 100644 --- a/wallet/psbt.go +++ b/wallet/psbt.go @@ -178,7 +178,6 @@ func (w *Wallet) FundPsbt(packet *psbt.Packet, keyScope *waddrmgr.KeyScope, PkScript: utxo.PkScript, } } - inputSource := constantInputSource(credits) // Build the TxCreateOption to retrieve the change scope. opts := defaultTxCreateOptions() @@ -197,25 +196,25 @@ func (w *Wallet) FundPsbt(packet *psbt.Packet, keyScope *waddrmgr.KeyScope, dbtx, opts.changeKeyScope, account, ) if err != nil { - return err + return fmt.Errorf("could not add change address to "+ + "database: %v", err) } // Ask the txauthor to create a transaction with our // selected coins. This will perform fee estimation and // add a change output if necessary. tx, err = txauthor.NewUnsignedTransaction( - txOut, feeSatPerKB, inputSource, changeSource, + txOut, feeSatPerKB, credits, txauthor.ConstantSelection, changeSource, ) if err != nil { return fmt.Errorf("fee estimation not "+ - "successful: %v", err) + "successful: %w", err) } return nil }) if err != nil { - return 0, fmt.Errorf("could not add change address to "+ - "database: %v", err) + return 0, err } }