-
Notifications
You must be signed in to change notification settings - Fork 126
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
Updated ListAssetRequest to include additional filter options #1199
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 13776255223Details
💛 - 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 ✔️
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
@GeorgeTsagk: review reminder |
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
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
@@ -970,6 +1002,14 @@ type AssetQueryFilters struct { | |||
// MinAnchorHeight is the minimum block height the asset's anchor tx | |||
// must have been confirmed at. | |||
MinAnchorHeight int32 | |||
|
|||
// ScriptKey allows filtering by the pubkey that individual assets |
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.
// ScriptKey allows filtering by the pubkey that individual assets | |
// ScriptKey allows filtering by asset script key. |
// are locked behind. | ||
ScriptKey *asset.ScriptKey | ||
|
||
// AnchorPoint allows filtering by the specific on-chain UTXO which |
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.
// AnchorPoint allows filtering by the specific on-chain UTXO which | |
// AnchorPoint allows filtering by the outpoint the asset is anchored to. |
@@ -35,6 +35,9 @@ type CommitmentConstraints struct { | |||
// to satisfy the constraints. | |||
MinAmt uint64 | |||
|
|||
// MaxAmt specifies the maximum amount of minted assets to be selected. |
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.
// MaxAmt specifies the maximum amount of minted assets to be selected. | |
// MaxAmt specifies the maximum amount that an asset commitment needs to hold | |
// to satisfy the constraints. |
err) | ||
} | ||
|
||
// Construct an asset specifier using the requested group key |
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 .
at the end of comment
rpcAssets, err := r.fetchRpcAssets( | ||
ctx, false, false, req.IncludeLeased, 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.
unnecessary newline
makeFilter := func( | ||
minAmt, maxAmt uint64, | ||
anchorHeight int32, | ||
scriptKey *asset.ScriptKey, | ||
anchorPoint *wire.OutPoint, | ||
coinSelectType tapsend.CoinSelectType, | ||
) *AssetQueryFilters { |
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.
need to fix styling of func definition
name: "script key", | ||
filter: makeFilter( | ||
0, 0, 0, scriptKeyWithScript, | ||
nil, 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.
no need to break the line early if it can fit in the same line
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.
also applies to makeFilter
calls below
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.