Skip to content

Commit

Permalink
tapdb: Update AssetQueryFilters to handle additional filter options
Browse files Browse the repository at this point in the history
  • Loading branch information
itsrachelfish committed Dec 4, 2024
1 parent 4205556 commit 84adc01
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
33 changes: 33 additions & 0 deletions tapdb/assets_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,12 +883,41 @@ func (a *AssetStore) constraintsToDbFilter(
Valid: true,
}
}

if query.MaxAmt != 0 {
assetFilter.MaxAmt = sql.NullInt64{
Int64: int64(query.MaxAmt),
Valid: true,
}
} else {
// If MaxAmt is unspecified, use valid: false to ignore
// the amount option in the SQL query
assetFilter.MaxAmt = sql.NullInt64{
Valid: false,
}
}

if query.MinAnchorHeight != 0 {
assetFilter.MinAnchorHeight = sqlInt32(
query.MinAnchorHeight,
)
}

if query.ScriptKeyID != nil {
assetFilter.ScriptKeyID = sql.NullInt64{
Int64: *query.ScriptKeyID,
Valid: true,
}
}

if query.AnchorPoint != nil {
outpointBytes, err := encodeOutpoint(*query.AnchorPoint)

if err == nil {
assetFilter.AnchorPoint = outpointBytes
}
}

// Add asset ID bytes and group key bytes to the filter. These
// byte arrays are empty if the asset ID or group key is not
// specified in the query.
Expand Down Expand Up @@ -980,6 +1009,10 @@ type AssetQueryFilters struct {
// MinAnchorHeight is the minimum block height the asset's anchor tx
// must have been confirmed at.
MinAnchorHeight int32

ScriptKeyID *int64

AnchorPoint *wire.OutPoint
}

// QueryBalancesByAsset queries the balances for assets or alternatively
Expand Down
17 changes: 10 additions & 7 deletions tapdb/sqlc/assets.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tapdb/sqlc/queries/assets.sql
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ JOIN chain_txns txns
-- specified.
WHERE (
assets.amount >= COALESCE(sqlc.narg('min_amt'), assets.amount) AND
assets.amount <= COALESCE(sqlc.narg('max_amt'), assets.amount) AND
assets.spent = COALESCE(sqlc.narg('spent'), assets.spent) AND
(key_group_info_view.tweaked_group_key = sqlc.narg('key_group_filter') OR
sqlc.narg('key_group_filter') IS NULL) AND
Expand Down
3 changes: 3 additions & 0 deletions tapfreighter/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type CommitmentConstraints struct {
// to satisfy the constraints.
MinAmt uint64

// MaxAmt specifies the maximum amount of minted assets to be selected.
MaxAmt uint64

// CoinSelectType is the type of coins that should be selected.
CoinSelectType tapsend.CoinSelectType
}
Expand Down

0 comments on commit 84adc01

Please sign in to comment.