@@ -858,7 +858,7 @@ func (a *AssetStore) dbAssetsToChainAssets(dbAssets []ConfirmedAsset,
858858// constraintsToDbFilter maps application level constraints to the set of
859859// filters we use in the SQL queries.
860860func (a * AssetStore ) constraintsToDbFilter (
861- query * AssetQueryFilters ) QueryAssetFilters {
861+ query * AssetQueryFilters ) ( QueryAssetFilters , error ) {
862862
863863 assetFilter := QueryAssetFilters {
864864 Now : sql.NullTime {
@@ -868,17 +868,36 @@ func (a *AssetStore) constraintsToDbFilter(
868868 }
869869 if query != nil {
870870 if query .MinAmt != 0 {
871- assetFilter .MinAmt = sql.NullInt64 {
872- Int64 : int64 (query .MinAmt ),
873- Valid : true ,
874- }
871+ assetFilter .MinAmt = sqlInt64 (query .MinAmt )
872+ }
873+
874+ if query .MaxAmt != 0 {
875+ assetFilter .MaxAmt = sqlInt64 (query .MaxAmt )
875876 }
877+
876878 if query .MinAnchorHeight != 0 {
877879 assetFilter .MinAnchorHeight = sqlInt32 (
878880 query .MinAnchorHeight ,
879881 )
880882 }
881883
884+ if query .ScriptKey != nil {
885+ key := query .ScriptKey .PubKey
886+ assetFilter .TweakedScriptKey = key .SerializeCompressed ()
887+ }
888+
889+ if query .AnchorPoint != nil {
890+ anchorPointBytes , err := encodeOutpoint (
891+ * query .AnchorPoint ,
892+ )
893+ if err != nil {
894+ return QueryAssetFilters {}, fmt .Errorf (
895+ "unable to encode outpoint: %w" , err )
896+ }
897+
898+ assetFilter .AnchorPoint = anchorPointBytes
899+ }
900+
882901 // Add asset ID bytes and group key bytes to the filter. These
883902 // byte arrays are empty if the asset ID or group key is not
884903 // specified in the query.
@@ -903,7 +922,7 @@ func (a *AssetStore) constraintsToDbFilter(
903922 }
904923 }
905924
906- return assetFilter
925+ return assetFilter , nil
907926}
908927
909928// specificAssetFilter maps the given asset parameters to the set of filters
@@ -975,6 +994,13 @@ type AssetQueryFilters struct {
975994 // MinAnchorHeight is the minimum block height the asset's anchor tx
976995 // must have been confirmed at.
977996 MinAnchorHeight int32
997+
998+ // ScriptKey allows filtering by asset script key.
999+ ScriptKey * asset.ScriptKey
1000+
1001+ // AnchorPoint allows filtering by the outpoint the asset is anchored
1002+ // to.
1003+ AnchorPoint * wire.OutPoint
9781004}
9791005
9801006// QueryBalancesByAsset queries the balances for assets or alternatively
@@ -1194,7 +1220,10 @@ func (a *AssetStore) FetchAllAssets(ctx context.Context, includeSpent,
11941220
11951221 // We'll now map the application level filtering to the type of
11961222 // filtering our database query understands.
1197- assetFilter := a .constraintsToDbFilter (query )
1223+ assetFilter , err := a .constraintsToDbFilter (query )
1224+ if err != nil {
1225+ return nil , err
1226+ }
11981227
11991228 // By default, the spent boolean is null, which means we'll fetch all
12001229 // assets. Only if we should exclude spent assets, we'll set the spent
@@ -1995,9 +2024,12 @@ func (a *AssetStore) ListEligibleCoins(ctx context.Context,
19952024
19962025 // First, we'll map the commitment constraints to our database query
19972026 // filters.
1998- assetFilter := a .constraintsToDbFilter (& AssetQueryFilters {
2027+ assetFilter , err := a .constraintsToDbFilter (& AssetQueryFilters {
19992028 CommitmentConstraints : constraints ,
20002029 })
2030+ if err != nil {
2031+ return nil , err
2032+ }
20012033
20022034 // We only want to select unspent and non-leased commitments.
20032035 assetFilter .Spent = sqlBool (false )
0 commit comments