-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Rpc: add filter to getProgramAccounts #10888
Conversation
@mvines , how does this direction look?
|
Codecov Report
@@ Coverage Diff @@
## master #10888 +/- ##
========================================
Coverage 81.8% 81.9%
========================================
Files 308 309 +1
Lines 71447 71602 +155
========================================
+ Hits 58511 58655 +144
- Misses 12936 12947 +11 |
Is there a non-Rpc consumer you had in mind for it?
Yeah that's probably best for now (slowness of base58 aside). Although we could establish a precedent for other encoding types by including an optional "encoding" field with The C developer in me wants to say A "dataSize" filter would also be immediately useful too, with spl-token going in the direction of the multisig account size being different than the rest. I can specific two |
No, nothing specific at present. There's just nothing intrinsically rpc about the filter.
Sure. Yeah, I have regrets about that "binary". It might not too difficult to deprecate that and call it "base58" instead, at some point.
I'm fine with that
Cool, I'll roll that in.
Yep, currently using AND logic between all filters. We could probably support AND NOT cases really easily, but supporting ORs as well would be a can of worms. |
I think I'd keep it Rpc-specific for now. Generalize when we have another user |
3d235a4
to
90914aa
Compare
90914aa
to
4165d07
Compare
4165d07
to
de007b7
Compare
@mvines , this is ready for another look. |
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.
It would be nice to see a test with two filters: two memcmp
s, memcmp
and dataSize
. Looks great
* Add RpcFilterType, and implement CompareBytes for getProgramAccounts * Accept bytes in bs58 * Rename to memcmp * Add Memcmp optional encoding field * Add dataSize filter * Update docs * Clippy * Simplify tests that don't need to test account contents; add multiple-filter tests
* Add RpcFilterType, and implement CompareBytes for getProgramAccounts * Accept bytes in bs58 * Rename to memcmp * Add Memcmp optional encoding field * Add dataSize filter * Update docs * Clippy * Simplify tests that don't need to test account contents; add multiple-filter tests
* Add RpcFilterType, and implement CompareBytes for getProgramAccounts * Accept bytes in bs58 * Rename to memcmp * Add Memcmp optional encoding field * Add dataSize filter * Update docs * Clippy * Simplify tests that don't need to test account contents; add multiple-filter tests
…lana-labs#10932)" This reverts commit 9311a6e.
* Add RpcFilterType, and implement CompareBytes for getProgramAccounts * Accept bytes in bs58 * Rename to memcmp * Add Memcmp optional encoding field * Add dataSize filter * Update docs * Clippy * Simplify tests that don't need to test account contents; add multiple-filter tests
* Add RpcFilterType, and implement CompareBytes for getProgramAccounts * Accept bytes in bs58 * Rename to memcmp * Add Memcmp optional encoding field * Add dataSize filter * Update docs * Clippy * Simplify tests that don't need to test account contents; add multiple-filter tests
* Revert "Rpc: add filter to getProgramAccounts (#10888) (#10932)" This reverts commit 9311a6e. * Add jsonParsed option for EncodedTransactions; add memo parser (#10711) * Add jsonParsed option for EncodedTransactions; add memo parser * Use kebab case for program names * Add account-key parsing * Add parse test * Update transaction encoding docs (#10833) * Add account-decoder utilities (#10846) * Fix comment and make less pub * Add account-decoder crate and use to decode vote and system (nonce) accounts * Update docs * Rename RpcAccount struct * s/Rpc/Display * Call it jsonParsed and update docs * Revert "s/Rpc/Display" This reverts commit 6e7149f. * s/Rpc/Ui * Add tests * Ui more things * Comments * Update struct prefixes to Ui (#10874) * Update comments * Use Ui prefix * Rpc: add filter to getProgramAccounts (#10888) * Add RpcFilterType, and implement CompareBytes for getProgramAccounts * Accept bytes in bs58 * Rename to memcmp * Add Memcmp optional encoding field * Add dataSize filter * Update docs * Clippy * Simplify tests that don't need to test account contents; add multiple-filter tests
Problem
Users will need a way to inspect and manage all the SPL Token accounts they own. This could be accomplished by calling
getProgramAccounts
for the token program-id and deserializing all the accounts to inspect theowner
field. But spl-token::State is not yet ready/published to be pulled in as a dependency, and moreover that deserialization is a lot of overhead.Instead, we can use a generic byte-comparison filter. This gives users flexibility as to what part of account data is matched, and gives us the opportunity to add different types of filters in the future.
Summary of Changes
{"memcmp":{"offset":44,"bytes":"7kgfDmgbEfypBujqn4tyApjf8H7ZWuaL3F6Ah9vQHzgR"}}
, where offset is the offset into account.data that will be matched, and bytes are base-58 encoded string representation of bytes to compareTODO: