-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wallet: export coin selection strategy code for re-use #900
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🩰
wallet/createtx.go
Outdated
|
||
// ArrangeCoins takes a list of coins and arranges them according to the | ||
// specified coin selection strategy and fee rate. | ||
func ArrangeCoins[T SelectableCoin](coinSelectionStrategy CoinSelectionStrategy, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type param usage doesn't feel absolutely necessary here? At least in the context of the wallet today, seems like we could jut swap in SelectableCoin
as the interface are here instead of T
. I think reaching for the type param here would make more sense if we already had several other instances of something like ArrangeCoins
that accepted a diff concrete type.
Will take a look at the other dependent PRs here as well. Not a blocker, just mainly curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for using the type parameter here is because Golang doesn't allow using a struct slice when an interface slice is expected.
For example, if ArrangeCoins
took eligigle []SelectableCoin
, we couldn't pass in a slice of []*SelectableCredit
.
Not a big deal here since we're wrapping the wtxmgr.Credit
anyway.
But in lnd
we could pass in chanfunding.Coin
directly if we use the typed parameter.
But wrapping that wouldn't be a big deal either, so I can go with the interface if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I resolved this by just moving the chanfunding.Coin
declaration into the wallet. I think it makes sense to have a specific type that contains just exactly what's needed for coin selection.
2a66eb0
to
25a24d2
Compare
25a24d2
to
f1ba877
Compare
This commit refactors and then exports the DecorateInputs method that adds all required information to a PSBT packet's inputs that are required for signing for them.
f1ba877
to
d27dac3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🦊
@@ -89,17 +89,33 @@ var ( | |||
wtxmgrNamespaceKey = []byte("wtxmgr") | |||
) | |||
|
|||
type CoinSelectionStrategy int | |||
// Coin represents a spendable UTXO which is available for coin selection. | |||
type Coin struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
wallet: export coin selection strategy code for re-use
wallet: export coin selection strategy code for re-use
We want to be able to use the available coin selection strategies outside of just the coin selection methods offered by the wallet. So this PR refactors the code to be re-used.