Skip to content

Commit 7b5ff7d

Browse files
committed
multi: add CoinSelectType to specify script key type
1 parent 72b93f8 commit 7b5ff7d

File tree

6 files changed

+47
-18
lines changed

6 files changed

+47
-18
lines changed

tapdb/assets_store.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/lightninglabs/taproot-assets/tapdb/sqlc"
2424
"github.com/lightninglabs/taproot-assets/tapfreighter"
2525
"github.com/lightninglabs/taproot-assets/tappsbt"
26+
"github.com/lightninglabs/taproot-assets/tapsend"
2627
"github.com/lightningnetwork/lnd/clock"
2728
"github.com/lightningnetwork/lnd/keychain"
2829
)
@@ -873,7 +874,11 @@ func (a *AssetStore) constraintsToDbFilter(
873874
// TODO(roasbeef): only want to allow asset ID or other and not
874875
// both?
875876

876-
if query.Bip86ScriptKeysOnly {
877+
switch query.CoinSelectType {
878+
case tapsend.ScriptTreesAllowed:
879+
assetFilter.Bip86ScriptKeysOnly = false
880+
881+
default:
877882
assetFilter.Bip86ScriptKeysOnly = true
878883
}
879884
}

tapdb/assets_store_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/lightninglabs/taproot-assets/proof"
2424
"github.com/lightninglabs/taproot-assets/tapfreighter"
2525
"github.com/lightninglabs/taproot-assets/tapscript"
26+
"github.com/lightninglabs/taproot-assets/tapsend"
2627
"github.com/lightningnetwork/lnd/input"
2728
"github.com/lightningnetwork/lnd/keychain"
2829
"github.com/stretchr/testify/require"
@@ -758,11 +759,11 @@ func TestFetchAllAssets(t *testing.T) {
758759
scriptKey: scriptKeyWithScript,
759760
}}
760761
makeFilter := func(amt uint64, anchorHeight int32,
761-
bip86ScriptKeysOnly bool) *AssetQueryFilters {
762+
coinSelectType tapsend.CoinSelectType) *AssetQueryFilters {
762763

763764
constraints := tapfreighter.CommitmentConstraints{
764-
MinAmt: amt,
765-
Bip86ScriptKeysOnly: bip86ScriptKeysOnly,
765+
MinAmt: amt,
766+
CoinSelectType: coinSelectType,
766767
}
767768
return &AssetQueryFilters{
768769
CommitmentConstraints: constraints,
@@ -795,41 +796,41 @@ func TestFetchAllAssets(t *testing.T) {
795796
numAssets: 10,
796797
}, {
797798
name: "min amount",
798-
filter: makeFilter(12, 0, false),
799+
filter: makeFilter(12, 0, tapsend.ScriptTreesAllowed),
799800
numAssets: 2,
800801
}, {
801802
name: "min amount, include spent",
802-
filter: makeFilter(12, 0, false),
803+
filter: makeFilter(12, 0, tapsend.ScriptTreesAllowed),
803804
includeSpent: true,
804805
numAssets: 4,
805806
}, {
806807
name: "min amount, include leased",
807-
filter: makeFilter(12, 0, false),
808+
filter: makeFilter(12, 0, tapsend.ScriptTreesAllowed),
808809
includeLeased: true,
809810
numAssets: 5,
810811
}, {
811812
name: "min amount, include leased, include spent",
812-
filter: makeFilter(12, 0, false),
813+
filter: makeFilter(12, 0, tapsend.ScriptTreesAllowed),
813814
includeLeased: true,
814815
includeSpent: true,
815816
numAssets: 8,
816817
}, {
817818
name: "default min height, include spent",
818-
filter: makeFilter(0, 500, false),
819+
filter: makeFilter(0, 500, tapsend.ScriptTreesAllowed),
819820
includeSpent: true,
820821
numAssets: 6,
821822
}, {
822823
name: "specific height",
823-
filter: makeFilter(0, 502, false),
824+
filter: makeFilter(0, 502, tapsend.ScriptTreesAllowed),
824825
numAssets: 0,
825826
}, {
826827
name: "default min height, include spent",
827-
filter: makeFilter(0, 502, false),
828+
filter: makeFilter(0, 502, tapsend.ScriptTreesAllowed),
828829
includeSpent: true,
829830
numAssets: 1,
830831
}, {
831832
name: "script key with tapscript",
832-
filter: makeFilter(100, 0, true),
833+
filter: makeFilter(100, 0, tapsend.Bip86Only),
833834
numAssets: 0,
834835
}}
835836

tapfreighter/coin_select.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (s *CoinSelect) SelectCoins(ctx context.Context,
5454
listConstraints := CommitmentConstraints{
5555
AssetSpecifier: constraints.AssetSpecifier,
5656
MinAmt: 1,
57+
CoinSelectType: constraints.CoinSelectType,
5758
}
5859
eligibleCommitments, err := s.coinLister.ListEligibleCoins(
5960
ctx, listConstraints,

tapfreighter/interface.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ 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"
2021
"github.com/lightningnetwork/lnd/keychain"
2122
)
2223

@@ -34,9 +35,8 @@ type CommitmentConstraints struct {
3435
// to satisfy the constraints.
3536
MinAmt uint64
3637

37-
// Bip86ScriptKeysOnly is a flag that when set, will exclude any assets
38-
// that have a script key with a tapscript tree (a non-empty tweak).
39-
Bip86ScriptKeysOnly bool
38+
// CoinSelectType is the type of coins that should be selected.
39+
CoinSelectType tapsend.CoinSelectType
4040
}
4141

4242
// String returns the string representation of the commitment constraints.

tapfreighter/wallet.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ func (f *AssetWallet) FundPacket(ctx context.Context,
365365
// send request. We'll map the address to a set of constraints, so we
366366
// can use that to do Taproot asset coin selection.
367367
constraints := CommitmentConstraints{
368-
AssetSpecifier: fundDesc.AssetSpecifier,
369-
MinAmt: fundDesc.Amount,
370-
Bip86ScriptKeysOnly: true,
368+
AssetSpecifier: fundDesc.AssetSpecifier,
369+
MinAmt: fundDesc.Amount,
370+
CoinSelectType: tapsend.Bip86Only,
371371
}
372372

373373
anchorVersion, err := tappsbt.CommitmentVersion(vPkt.Version)

tapsend/send.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,28 @@ type AssetGroupQuerier interface {
161161
QueryAssetGroup(context.Context, asset.ID) (*asset.AssetGroup, error)
162162
}
163163

164+
// CoinSelectType is a type that indicates the type of coins that should be
165+
// selected. This type is defined in the tapsend package to avoid a circular
166+
// dependency with the freighter package.
167+
type CoinSelectType uint8
168+
169+
const (
170+
// Bip86Only indicates that only coins that have a BIP-086 script key
171+
// should be selected.
172+
Bip86Only CoinSelectType = 0
173+
174+
// ScriptTreesAllowed indicates that coins with any script key type
175+
// should be selected.
176+
ScriptTreesAllowed CoinSelectType = 1
177+
178+
// DefaultCoinSelectType is the default coin selection type that should
179+
// be used when no specific type is specified. We default to allowing
180+
// any script key type to be in line with the RPC values, which are
181+
// intended to be backward compatible with clients that didn't specify
182+
// the type (when funding a vPSBT for example).
183+
DefaultCoinSelectType = ScriptTreesAllowed
184+
)
185+
164186
// FundingDescriptor describes the information that is needed to select and
165187
// verify input assets in order to send to a specific recipient. It is a subset
166188
// of the information contained in a Taproot Asset address.

0 commit comments

Comments
 (0)