Skip to content

Commit d6905ed

Browse files
committed
multi: turn coin selection type into script key filter
1 parent 861b1b2 commit d6905ed

File tree

7 files changed

+41
-64
lines changed

7 files changed

+41
-64
lines changed

rpcserver.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,7 +2154,7 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
21542154
req *wrpc.FundVirtualPsbtRequest) (*wrpc.FundVirtualPsbtResponse,
21552155
error) {
21562156

2157-
coinSelectType, err := unmarshalCoinSelectType(req.CoinSelectType)
2157+
scriptKeyType, err := unmarshalCoinSelectType(req.CoinSelectType)
21582158
if err != nil {
21592159
return nil, fmt.Errorf("error parsing coin select type: %w",
21602160
err)
@@ -2181,7 +2181,7 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
21812181
"recipients: %w", err)
21822182
}
21832183

2184-
desc.CoinSelectType = coinSelectType
2184+
desc.ScriptKeyType = scriptKeyType
21852185
fundedVPkt, err = r.cfg.AssetWallet.FundPacket(ctx, desc, vPkt)
21862186
if err != nil {
21872187
return nil, fmt.Errorf("error funding packet: %w", err)
@@ -2251,7 +2251,7 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
22512251
}
22522252

22532253
fundedVPkt, err = r.cfg.AssetWallet.FundAddressSend(
2254-
ctx, coinSelectType, prevIDs, addr,
2254+
ctx, scriptKeyType, prevIDs, addr,
22552255
)
22562256
if err != nil {
22572257
return nil, fmt.Errorf("error funding address send: "+
@@ -2302,21 +2302,21 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
23022302

23032303
// unmarshalCoinSelectType converts an RPC select type into a native one.
23042304
func unmarshalCoinSelectType(
2305-
coinSelectType wrpc.CoinSelectType) (tapsend.CoinSelectType, error) {
2305+
coinSelectType wrpc.CoinSelectType) (fn.Option[asset.ScriptKeyType],
2306+
error) {
23062307

23072308
switch coinSelectType {
2308-
case wrpc.CoinSelectType_COIN_SELECT_DEFAULT:
2309-
return tapsend.DefaultCoinSelectType, nil
2309+
case wrpc.CoinSelectType_COIN_SELECT_DEFAULT,
2310+
wrpc.CoinSelectType_COIN_SELECT_SCRIPT_TREES_ALLOWED:
23102311

2311-
case wrpc.CoinSelectType_COIN_SELECT_BIP86_ONLY:
2312-
return tapsend.Bip86Only, nil
2312+
return fn.None[asset.ScriptKeyType](), nil
23132313

2314-
case wrpc.CoinSelectType_COIN_SELECT_SCRIPT_TREES_ALLOWED:
2315-
return tapsend.ScriptTreesAllowed, nil
2314+
case wrpc.CoinSelectType_COIN_SELECT_BIP86_ONLY:
2315+
return fn.Some(asset.ScriptKeyBip86), nil
23162316

23172317
default:
2318-
return 0, fmt.Errorf("unknown coin select type: %d",
2319-
coinSelectType)
2318+
return fn.None[asset.ScriptKeyType](), fmt.Errorf("unknown "+
2319+
"coin select type: %d", coinSelectType)
23202320
}
23212321
}
23222322

tapdb/assets_store_test.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/lightninglabs/taproot-assets/tapdb/sqlc"
2525
"github.com/lightninglabs/taproot-assets/tapfreighter"
2626
"github.com/lightninglabs/taproot-assets/tapscript"
27-
"github.com/lightninglabs/taproot-assets/tapsend"
2827
"github.com/lightningnetwork/lnd/input"
2928
"github.com/lightningnetwork/lnd/keychain"
3029
"github.com/stretchr/testify/require"
@@ -779,11 +778,11 @@ func TestFetchAllAssets(t *testing.T) {
779778
scriptKey: scriptKeyWithScript,
780779
}}
781780
makeFilter := func(amt uint64, anchorHeight int32,
782-
coinSelectType tapsend.CoinSelectType) *AssetQueryFilters {
781+
skt fn.Option[asset.ScriptKeyType]) *AssetQueryFilters {
783782

784783
constraints := tapfreighter.CommitmentConstraints{
785-
MinAmt: amt,
786-
CoinSelectType: coinSelectType,
784+
MinAmt: amt,
785+
ScriptKeyType: skt,
787786
}
788787
return &AssetQueryFilters{
789788
CommitmentConstraints: constraints,
@@ -816,41 +815,49 @@ func TestFetchAllAssets(t *testing.T) {
816815
numAssets: 10,
817816
}, {
818817
name: "min amount",
819-
filter: makeFilter(12, 0, tapsend.ScriptTreesAllowed),
818+
filter: makeFilter(12, 0, fn.None[asset.ScriptKeyType]()),
820819
numAssets: 2,
821820
}, {
822821
name: "min amount, include spent",
823-
filter: makeFilter(12, 0, tapsend.ScriptTreesAllowed),
822+
filter: makeFilter(12, 0, fn.None[asset.ScriptKeyType]()),
824823
includeSpent: true,
825824
numAssets: 4,
826825
}, {
827-
name: "min amount, include leased",
828-
filter: makeFilter(12, 0, tapsend.ScriptTreesAllowed),
826+
name: "min amount, include leased",
827+
filter: makeFilter(
828+
12, 0, fn.None[asset.ScriptKeyType](),
829+
),
829830
includeLeased: true,
830831
numAssets: 5,
831832
}, {
832-
name: "min amount, include leased, include spent",
833-
filter: makeFilter(12, 0, tapsend.ScriptTreesAllowed),
833+
name: "min amount, include leased, include spent",
834+
filter: makeFilter(
835+
12, 0, fn.None[asset.ScriptKeyType](),
836+
),
834837
includeLeased: true,
835838
includeSpent: true,
836839
numAssets: 8,
837840
}, {
838-
name: "default min height, include spent",
839-
filter: makeFilter(0, 500, tapsend.ScriptTreesAllowed),
841+
name: "default min height, include spent",
842+
filter: makeFilter(
843+
0, 500, fn.None[asset.ScriptKeyType](),
844+
),
840845
includeSpent: true,
841846
numAssets: 6,
842847
}, {
843848
name: "specific height",
844-
filter: makeFilter(0, 502, tapsend.ScriptTreesAllowed),
849+
filter: makeFilter(0, 502, fn.None[asset.ScriptKeyType]()),
845850
numAssets: 0,
846851
}, {
847-
name: "default min height, include spent",
848-
filter: makeFilter(0, 502, tapsend.ScriptTreesAllowed),
852+
name: "default min height, include spent",
853+
filter: makeFilter(
854+
0, 502, fn.None[asset.ScriptKeyType](),
855+
),
849856
includeSpent: true,
850857
numAssets: 1,
851858
}, {
852859
name: "script key with tapscript",
853-
filter: makeFilter(100, 0, tapsend.Bip86Only),
860+
filter: makeFilter(100, 0, fn.Some(asset.ScriptKeyBip86)),
854861
numAssets: 0,
855862
}}
856863

tapfreighter/chain_porter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,8 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
10831083
"address parcel")
10841084
}
10851085
fundSendRes, err := p.cfg.AssetWallet.FundAddressSend(
1086-
ctx, tapsend.Bip86Only, nil, addrParcel.destAddrs...,
1086+
ctx, fn.Some(asset.ScriptKeyBip86), nil,
1087+
addrParcel.destAddrs...,
10871088
)
10881089
if err != nil {
10891090
return nil, fmt.Errorf("unable to fund address send: "+

tapfreighter/coin_select.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func (s *CoinSelect) SelectCoins(ctx context.Context,
5454
listConstraints := CommitmentConstraints{
5555
AssetSpecifier: constraints.AssetSpecifier,
5656
MinAmt: 1,
57-
CoinSelectType: constraints.CoinSelectType,
5857
ScriptKeyType: constraints.ScriptKeyType,
5958
PrevIDs: constraints.PrevIDs,
6059
}

tapfreighter/interface.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/lightninglabs/taproot-assets/tapgarden"
1818
"github.com/lightninglabs/taproot-assets/tappsbt"
1919
"github.com/lightninglabs/taproot-assets/tapscript"
20-
"github.com/lightninglabs/taproot-assets/tapsend"
2120
"github.com/lightningnetwork/lnd/keychain"
2221
)
2322

@@ -38,9 +37,6 @@ type CommitmentConstraints struct {
3837
// PrevIDs are the set of inputs allowed to be used.
3938
PrevIDs []asset.PrevID
4039

41-
// CoinSelectType is the type of coins that should be selected.
42-
CoinSelectType tapsend.CoinSelectType
43-
4440
// ScriptKeyType is the type of script key the assets are expected to
4541
// have. If this is fn.None, then any script key type is allowed.
4642
ScriptKeyType fn.Option[asset.ScriptKeyType]

tapfreighter/wallet.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ type Wallet interface {
6969
// asset re-anchors and the Taproot Asset level commitment of the
7070
// selected assets.
7171
FundAddressSend(ctx context.Context,
72-
coinSelectType tapsend.CoinSelectType, prevIDs []asset.PrevID,
72+
scriptKeyType fn.Option[asset.ScriptKeyType],
73+
prevIDs []asset.PrevID,
7374
receiverAddrs ...*address.Tap) (*FundedVPacket, error)
7475

7576
// FundPacket funds a virtual transaction, selecting assets to spend
@@ -240,8 +241,7 @@ type FundedVPacket struct {
240241
//
241242
// NOTE: This is part of the Wallet interface.
242243
func (f *AssetWallet) FundAddressSend(ctx context.Context,
243-
coinSelectType tapsend.CoinSelectType,
244-
prevIDs []asset.PrevID,
244+
scriptKeyType fn.Option[asset.ScriptKeyType], prevIDs []asset.PrevID,
245245
receiverAddrs ...*address.Tap) (*FundedVPacket, error) {
246246

247247
// We start by creating a new virtual transaction that will be used to
@@ -264,7 +264,7 @@ func (f *AssetWallet) FundAddressSend(ctx context.Context,
264264
fundDesc.PrevIDs = prevIDs
265265
}
266266

267-
fundDesc.CoinSelectType = coinSelectType
267+
fundDesc.ScriptKeyType = scriptKeyType
268268
fundedVPkt, err := f.FundPacket(ctx, fundDesc, vPkt)
269269
if err != nil {
270270
return nil, err
@@ -413,7 +413,6 @@ func (f *AssetWallet) FundPacket(ctx context.Context,
413413
constraints := CommitmentConstraints{
414414
AssetSpecifier: fundDesc.AssetSpecifier,
415415
MinAmt: fundDesc.Amount,
416-
CoinSelectType: fundDesc.CoinSelectType,
417416
ScriptKeyType: fundDesc.ScriptKeyType,
418417
PrevIDs: fundDesc.PrevIDs,
419418
}

tapsend/send.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -171,28 +171,6 @@ type AssetGroupQuerier interface {
171171
QueryAssetGroup(context.Context, asset.ID) (*asset.AssetGroup, error)
172172
}
173173

174-
// CoinSelectType is a type that indicates the type of coins that should be
175-
// selected. This type is defined in the tapsend package to avoid a circular
176-
// dependency with the freighter package.
177-
type CoinSelectType uint8
178-
179-
const (
180-
// Bip86Only indicates that only coins that have a BIP-086 script key
181-
// should be selected.
182-
Bip86Only CoinSelectType = 0
183-
184-
// ScriptTreesAllowed indicates that coins with any script key type
185-
// should be selected.
186-
ScriptTreesAllowed CoinSelectType = 1
187-
188-
// DefaultCoinSelectType is the default coin selection type that should
189-
// be used when no specific type is specified. We default to allowing
190-
// any script key type to be in line with the RPC values, which are
191-
// intended to be backward compatible with clients that didn't specify
192-
// the type (when funding a vPSBT for example).
193-
DefaultCoinSelectType = ScriptTreesAllowed
194-
)
195-
196174
// FundingDescriptor describes the information that is needed to select and
197175
// verify input assets in order to send to a specific recipient. It is a subset
198176
// of the information contained in a Taproot Asset address.
@@ -206,9 +184,6 @@ type FundingDescriptor struct {
206184
// PrevIDs is the set of inputs that can be used to fund the transfer.
207185
PrevIDs []asset.PrevID
208186

209-
// CoinSelectType specifies the type of coins that should be selected.
210-
CoinSelectType CoinSelectType
211-
212187
// ScriptKeyType is the type of script key the assets are expected to
213188
// have. If this is fn.None, then any script key type is allowed.
214189
ScriptKeyType fn.Option[asset.ScriptKeyType]

0 commit comments

Comments
 (0)