-
Notifications
You must be signed in to change notification settings - Fork 131
Updated ListAssetRequest to include additional filter options #1199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Updated ListAssetRequest to include additional filter options #1199
Conversation
84ac4c8
to
b6e90aa
Compare
f31d9f4
to
f189364
Compare
Pull Request Test Coverage Report for Build 14005124093Details
💛 - Coveralls |
f189364
to
ccf4b76
Compare
6abd778
to
3c0141b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good!
it's in the right direction 💯
13eabd1
to
241d98d
Compare
f5d1985
to
9c7b7e9
Compare
9c7b7e9
to
4566b97
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lots of improvements! ⬆️
I have one comment on the types of filters
We'll also need that unit test coverage ✔️
tapdb/assets_store.go
Outdated
Int64: int64(query.MaxAmt), | ||
Valid: true, | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole block is not needed, you can just leave query.MaxAmt
initialized to default values (Valid: false
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ can just remove whole else
block
tapdb/assets_store.go
Outdated
@@ -980,6 +1008,10 @@ type AssetQueryFilters struct { | |||
// MinAnchorHeight is the minimum block height the asset's anchor tx | |||
// must have been confirmed at. | |||
MinAnchorHeight int32 | |||
|
|||
ScriptKeyID *int64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing godocs (see MinAnchorHeight
above)
tapdb/assets_store.go
Outdated
if query.MinAnchorHeight != 0 { | ||
assetFilter.MinAnchorHeight = sqlInt32( | ||
query.MinAnchorHeight, | ||
) | ||
} | ||
|
||
if query.ScriptKeyID != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't really have user-facing arguments that reference database IDs
the ScriptKeyID
is the DB identifier for a script key and there's no possible way a user could (...easily) get their hands on one of them in order to filter the assets
Instead we could have *AssetQueryFilters
expose scriptKey []byte
and anchorOutpoint []byte
filters, which the user can easily acquire, then on this point in the code we could map these values to the unique db ID that the underlying layer requires for filtering (that is QueryAssetFilters
struct)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you add some tests with the current way things work, you'll see that when you'll try to query a specific script key you'll have trouble finding the ID to filter by
I think this function can help resolve the issue w.r.t getting the internal ID, you can just specify all the normal bytes (script key, anchor point, etc): taproot-assets/tapdb/assets_store.go Lines 904 to 935 in ec84760
|
ccaf4e4
to
ffa733e
Compare
ffa733e
to
485cbad
Compare
c74c44a
to
8b0d382
Compare
8b0d382
to
6951f28
Compare
@GeorgeTsagk @guggero I updated the code to filter assets based on the tweaked script key instead of the internal script key ID. I ran into some weird issues with the automated tests, for some reason I was unable to filter the 10th asset:
Oli said this might have something to do with an underlying issue with the specific anchor point or asset generation, but I'm not sure why this particular asset is "cursed" 😅 I worked around the issue by adding a script key to the 3rd asset and was able to filter it as expected. |
6951f28
to
856d9e3
Compare
856d9e3
to
cf0ef8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super close 💯
mostly styling related comments
should also add the filter options to the cmd command but since they weren't there in the first place this can be done in a different PR
tapdb/assets_store.go
Outdated
Int64: int64(query.MaxAmt), | ||
Valid: true, | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ can just remove whole else
block
cf0ef8e
to
86bdfff
Compare
517d54a
to
402d754
Compare
a2be556
to
402d754
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there.
@@ -873,12 +873,38 @@ func (a *AssetStore) constraintsToDbFilter( | |||
Valid: true, | |||
} | |||
} | |||
|
|||
if query.MaxAmt != 0 { | |||
assetFilter.MaxAmt = sql.NullInt64{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can use sqlInt64(query.MaxAmt)
(and change it above for the MinAmt
as well).
if err != nil { | ||
return QueryAssetFilters{}, fmt.Errorf( | ||
"unable to encode outpoint: %w", err, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: calls to Errorf()
can have the closing parenthesis on the same line as the arguments (see formatting exception in the formatting doc).
nil, groupKey, nil, false, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: inconsistent with other formatting. Can be:
return nil, fmt.Errorf("error creating asset "+
"specifier: %w", err)
CoinSelectType: tapsend.ScriptTreesAllowed, | ||
} | ||
|
||
if req.GroupKey != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should check the length here instead, which asserts nil
as well as an empty slice.
} | ||
|
||
if req.GroupKey != nil { | ||
groupKey, err := btcec.ParsePubKey(req.GroupKey[:]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
req.GroupKey
is already a slice, no need to use slice operator.
} | ||
|
||
// Construct an asset specifier using the requested group key. | ||
groupSpecifier, err := asset.NewSpecifier( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use NewSpecifierFromGroupKey
instead.
CommitmentConstraints: constraints, | ||
} | ||
|
||
if req.ScriptKey != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, should be length check, not nil
check.
constraints := tapfreighter.CommitmentConstraints{ | ||
MinAmt: req.MinAmount, | ||
MaxAmt: req.MaxAmount, | ||
CoinSelectType: tapsend.ScriptTreesAllowed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably use tapsend.DefaultCoinSelectType
here.
@GeorgeTsagk: review reminder |
Resolves #876
This PR adds new filter options to the
ListAssets
RPC call.ListAssetRequest
proto definition was updated to include the new filter options.fetchRpcAssets
function was refactored to accept aAssetQueryFilters
argument so that separate arguments don't need to be added for each filter option.constraintsToDbFilter
function was updated to use the new filter options.assets.sql
file was updated to include a newmaxAmount
option.