Skip to content

Commit f6dd6a7

Browse files
committed
multi: turn coin selection type into script key filter
1 parent 231a60b commit f6dd6a7

File tree

7 files changed

+27
-73
lines changed

7 files changed

+27
-73
lines changed

rpcserver.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,9 +1060,8 @@ func (r *rpcServer) ListAssets(ctx context.Context,
10601060
}
10611061

10621062
constraints := tapfreighter.CommitmentConstraints{
1063-
MinAmt: req.MinAmount,
1064-
MaxAmt: req.MaxAmount,
1065-
CoinSelectType: tapsend.DefaultCoinSelectType,
1063+
MinAmt: req.MinAmount,
1064+
MaxAmt: req.MaxAmount,
10661065
}
10671066

10681067
if len(req.GroupKey) > 0 {
@@ -2203,7 +2202,7 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
22032202
req *wrpc.FundVirtualPsbtRequest) (*wrpc.FundVirtualPsbtResponse,
22042203
error) {
22052204

2206-
coinSelectType, err := unmarshalCoinSelectType(req.CoinSelectType)
2205+
scriptKeyType, err := unmarshalCoinSelectType(req.CoinSelectType)
22072206
if err != nil {
22082207
return nil, fmt.Errorf("error parsing coin select type: %w",
22092208
err)
@@ -2230,7 +2229,7 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
22302229
"recipients: %w", err)
22312230
}
22322231

2233-
desc.CoinSelectType = coinSelectType
2232+
desc.ScriptKeyType = scriptKeyType
22342233
fundedVPkt, err = r.cfg.AssetWallet.FundPacket(ctx, desc, vPkt)
22352234
if err != nil {
22362235
return nil, fmt.Errorf("error funding packet: %w", err)
@@ -2300,7 +2299,7 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
23002299
}
23012300

23022301
fundedVPkt, err = r.cfg.AssetWallet.FundAddressSend(
2303-
ctx, coinSelectType, prevIDs, addr,
2302+
ctx, scriptKeyType, prevIDs, addr,
23042303
)
23052304
if err != nil {
23062305
return nil, fmt.Errorf("error funding address send: "+
@@ -2351,21 +2350,21 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
23512350

23522351
// unmarshalCoinSelectType converts an RPC select type into a native one.
23532352
func unmarshalCoinSelectType(
2354-
coinSelectType wrpc.CoinSelectType) (tapsend.CoinSelectType, error) {
2353+
coinSelectType wrpc.CoinSelectType) (fn.Option[asset.ScriptKeyType],
2354+
error) {
23552355

23562356
switch coinSelectType {
2357-
case wrpc.CoinSelectType_COIN_SELECT_DEFAULT:
2358-
return tapsend.DefaultCoinSelectType, nil
2357+
case wrpc.CoinSelectType_COIN_SELECT_DEFAULT,
2358+
wrpc.CoinSelectType_COIN_SELECT_SCRIPT_TREES_ALLOWED:
23592359

2360-
case wrpc.CoinSelectType_COIN_SELECT_BIP86_ONLY:
2361-
return tapsend.Bip86Only, nil
2360+
return fn.None[asset.ScriptKeyType](), nil
23622361

2363-
case wrpc.CoinSelectType_COIN_SELECT_SCRIPT_TREES_ALLOWED:
2364-
return tapsend.ScriptTreesAllowed, nil
2362+
case wrpc.CoinSelectType_COIN_SELECT_BIP86_ONLY:
2363+
return fn.Some(asset.ScriptKeyBip86), nil
23652364

23662365
default:
2367-
return 0, fmt.Errorf("unknown coin select type: %d",
2368-
coinSelectType)
2366+
return fn.None[asset.ScriptKeyType](), fmt.Errorf("unknown "+
2367+
"coin select type: %d", coinSelectType)
23692368
}
23702369
}
23712370

tapdb/assets_store_test.go

Lines changed: 7 additions & 22 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"
@@ -730,12 +729,6 @@ func filterMaxAmt(amt uint64) filterOpt {
730729
}
731730
}
732731

733-
func filterCoinSelectType(typ tapsend.CoinSelectType) filterOpt {
734-
return func(f *AssetQueryFilters) {
735-
f.CoinSelectType = typ
736-
}
737-
}
738-
739732
func filterDistinctSpecifier() filterOpt {
740733
return func(f *AssetQueryFilters) {
741734
f.DistinctSpecifier = true
@@ -760,6 +753,12 @@ func filterScriptKey(key *asset.ScriptKey) filterOpt {
760753
}
761754
}
762755

756+
func filterScriptKeyType(keyType asset.ScriptKeyType) filterOpt {
757+
return func(f *AssetQueryFilters) {
758+
f.ScriptKeyType = fn.Some(keyType)
759+
}
760+
}
761+
763762
// TestFetchAllAssets tests that the different AssetQueryFilters work as
764763
// expected.
765764
func TestFetchAllAssets(t *testing.T) {
@@ -889,30 +888,26 @@ func TestFetchAllAssets(t *testing.T) {
889888
name: "min amount",
890889
filter: makeFilter(
891890
filterMinAmt(12),
892-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
893891
),
894892
numAssets: 2,
895893
}, {
896894
name: "min amount, include spent",
897895
filter: makeFilter(
898896
filterMinAmt(12),
899-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
900897
),
901898
includeSpent: true,
902899
numAssets: 4,
903900
}, {
904901
name: "min amount, include leased",
905902
filter: makeFilter(
906903
filterMinAmt(12),
907-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
908904
),
909905
includeLeased: true,
910906
numAssets: 5,
911907
}, {
912908
name: "min amount, include leased, include spent",
913909
filter: makeFilter(
914910
filterMinAmt(12),
915-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
916911
),
917912
includeLeased: true,
918913
includeSpent: true,
@@ -921,30 +916,26 @@ func TestFetchAllAssets(t *testing.T) {
921916
name: "max amount",
922917
filter: makeFilter(
923918
filterMaxAmt(100),
924-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
925919
),
926920
numAssets: 6,
927921
}, {
928922
name: "max amount, include spent",
929923
filter: makeFilter(
930924
filterMaxAmt(100),
931-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
932925
),
933926
includeSpent: true,
934927
numAssets: 7,
935928
}, {
936929
name: "max amount, include leased",
937930
filter: makeFilter(
938931
filterMaxAmt(100),
939-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
940932
),
941933
includeLeased: true,
942934
numAssets: 8,
943935
}, {
944936
name: "max amount, include leased, include spent",
945937
filter: makeFilter(
946938
filterMaxAmt(100),
947-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
948939
),
949940
includeLeased: true,
950941
includeSpent: true,
@@ -953,44 +944,39 @@ func TestFetchAllAssets(t *testing.T) {
953944
name: "default min height, include spent",
954945
filter: makeFilter(
955946
filterAnchorHeight(500),
956-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
957947
),
958948
includeSpent: true,
959949
numAssets: 8,
960950
}, {
961951
name: "specific height",
962952
filter: makeFilter(
963953
filterAnchorHeight(512),
964-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
965954
),
966955
numAssets: 0,
967956
}, {
968957
name: "specific height, include spent",
969958
filter: makeFilter(
970959
filterAnchorHeight(502),
971-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
972960
),
973961
includeSpent: true,
974962
numAssets: 3,
975963
}, {
976964
name: "script key with tapscript",
977965
filter: makeFilter(
978966
filterMinAmt(100),
979-
filterCoinSelectType(tapsend.Bip86Only),
967+
filterScriptKeyType(asset.ScriptKeyBip86),
980968
),
981969
numAssets: 0,
982970
}, {
983971
name: "query by script key",
984972
filter: makeFilter(
985973
filterScriptKey(scriptKeyWithScript),
986-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
987974
),
988975
numAssets: 1,
989976
}, {
990977
name: "query by script key, include leased",
991978
filter: makeFilter(
992979
filterScriptKey(scriptKeyWithScript),
993-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
994980
),
995981
includeLeased: true,
996982
numAssets: 2,
@@ -1022,7 +1008,6 @@ func TestFetchAllAssets(t *testing.T) {
10221008
name: "query by anchor point",
10231009
filter: makeFilter(
10241010
filterAnchorPoint(&assetGen.anchorPoints[0]),
1025-
filterCoinSelectType(tapsend.ScriptTreesAllowed),
10261011
),
10271012
numAssets: 3,
10281013
}}

tapfreighter/chain_porter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,8 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
12391239
"address parcel")
12401240
}
12411241
fundSendRes, err := p.cfg.AssetWallet.FundAddressSend(
1242-
ctx, tapsend.Bip86Only, nil, addrParcel.destAddrs...,
1242+
ctx, fn.Some(asset.ScriptKeyBip86), nil,
1243+
addrParcel.destAddrs...,
12431244
)
12441245
if err != nil {
12451246
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
DistinctSpecifier: constraints.DistinctSpecifier,

tapfreighter/interface.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/lightninglabs/taproot-assets/tapgarden"
2222
"github.com/lightninglabs/taproot-assets/tappsbt"
2323
"github.com/lightninglabs/taproot-assets/tapscript"
24-
"github.com/lightninglabs/taproot-assets/tapsend"
2524
"github.com/lightningnetwork/lnd/keychain"
2625
)
2726

@@ -46,9 +45,6 @@ type CommitmentConstraints struct {
4645
// PrevIDs are the set of inputs allowed to be used.
4746
PrevIDs []asset.PrevID
4847

49-
// CoinSelectType is the type of coins that should be selected.
50-
CoinSelectType tapsend.CoinSelectType
51-
5248
// DistinctSpecifier indicates whether we _only_ look at either the
5349
// group key _or_ the asset ID but not both. That means, if the group
5450
// key is set, we ignore the asset ID and allow multiple inputs of the

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
DistinctSpecifier: fundDesc.DistinctSpecifier,

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
// DistinctSpecifier indicates whether we _only_ look at either the
213188
// group key _or_ the asset ID but not both. That means, if the group
214189
// key is set, we ignore the asset ID and allow multiple inputs of the

0 commit comments

Comments
 (0)