lnrpc+lnd+config: add coin selection strategy to all on-chain rpcs

In this commit, we add the coin selection strategy option
to all on-chain RPCs `FundPsbt`, `BatchOpenChannel`, `EstimateFee`,
`SendMany`, `SendCoins`, `SendOutputs`.
This commit is contained in:
Mohamed Awnallah
2024-03-26 19:01:48 +02:00
parent 5599b3c9e2
commit 7c2c0dcf98
7 changed files with 4081 additions and 3816 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcwallet/wallet"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
)
@ -179,3 +180,30 @@ func MarshalOutPoint(op *wire.OutPoint) *OutPoint {
OutputIndex: op.Index,
}
}
// UnmarshallCoinSelectionStrategy converts a lnrpc.CoinSelectionStrategy proto
// type to its wallet.CoinSelectionStrategy counterpart type, considering
// a global default strategy if necessary.
//
// The globalStrategy parameter specifies the default coin selection strategy
// to use if the strategy is set to STRATEGY_USE_GLOBAL_CONFIG. This allows
// flexibility in defining a default strategy at a global level.
func UnmarshallCoinSelectionStrategy(strategy CoinSelectionStrategy,
globalStrategy wallet.CoinSelectionStrategy) (
wallet.CoinSelectionStrategy, error) {
switch strategy {
case CoinSelectionStrategy_STRATEGY_USE_GLOBAL_CONFIG:
return globalStrategy, nil
case CoinSelectionStrategy_STRATEGY_LARGEST:
return wallet.CoinSelectionLargest, nil
case CoinSelectionStrategy_STRATEGY_RANDOM:
return wallet.CoinSelectionRandom, nil
default:
return nil, fmt.Errorf("unknown coin selection strategy "+
"%v", strategy)
}
}