Skip to content

Commit 3a99b01

Browse files
SwenSchaeferjohannSwen
andauthored
chore: add memcp filter option to rpc, bump to photon 0.39.0 (#1043)
* bump 1 bump 0.7.0 * fix install-sh * fix test spelling * bump to 40 --------- Co-authored-by: Swen <swen.schaeferjohann@code.berlin>
1 parent 3f172a3 commit 3a99b01

File tree

8 files changed

+59
-7
lines changed

8 files changed

+59
-7
lines changed

cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lightprotocol/zk-compression-cli",
3-
"version": "0.5.1",
3+
"version": "0.7.0",
44
"description": "ZK Compression: Secure Scaling on Solana",
55
"maintainers": [
66
{

cli/src/utils/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const LIGHT_PROVER_PROCESS_NAME = "light-prover";
2121
export const INDEXER_PROCESS_NAME = "photon";
2222
export const FORESTER_PROCESS_NAME = "forester";
2323

24-
export const PHOTON_VERSION = "0.38.0";
24+
export const PHOTON_VERSION = "0.40.0";
2525

2626
export const LIGHT_PROTOCOL_PROGRAMS_DIR_ENV = "LIGHT_PROTOCOL_PROGRAMS_DIR";
2727
export const BASE_PATH = "../../bin/";

js/stateless.js/src/rpc-interface.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PublicKey, DataSizeFilter, MemcmpFilter } from '@solana/web3.js';
1+
import { PublicKey, MemcmpFilter, DataSlice } from '@solana/web3.js';
22
import {
33
type as pick,
44
number,
@@ -37,6 +37,13 @@ export interface LatestNonVotingSignatures {
3737
};
3838
}
3939

40+
export interface GetCompressedAccountsByOwnerConfig {
41+
filters?: GetCompressedAccountsFilter[];
42+
dataSlice?: DataSlice;
43+
cursor?: string;
44+
limit?: BN;
45+
}
46+
4047
export interface LatestNonVotingSignaturesPaginated {
4148
context: { slot: number };
4249
value: {
@@ -107,14 +114,17 @@ export interface GetCompressedTokenAccountsByOwnerOrDelegateOptions {
107114
limit?: BN;
108115
}
109116

110-
export type GetCompressedAccountsFilter = MemcmpFilter | DataSizeFilter;
117+
/**
118+
* Note, DataSizeFilter is currently not available.
119+
*/
120+
export type GetCompressedAccountsFilter = MemcmpFilter; // | DataSizeFilter;
111121

112122
export type GetCompressedAccountConfig = {
113123
encoding?: string;
114124
};
115125

116126
export type GetCompressedAccountsConfig = {
117-
encoding?: string;
127+
dataSlice: DataSlice;
118128
filters?: GetCompressedAccountsFilter[];
119129
};
120130

@@ -131,6 +141,7 @@ export type WithContext<T> = {
131141
/** response value */
132142
value: T;
133143
};
144+
134145
export type WithCursor<T> = {
135146
/** context */
136147
cursor: string | null;
@@ -493,6 +504,7 @@ export interface CompressionApiInterface {
493504

494505
getCompressedAccountsByOwner(
495506
owner: PublicKey,
507+
config?: GetCompressedAccountsByOwnerConfig,
496508
): Promise<WithCursor<CompressedAccountWithMerkleContext[]>>;
497509

498510
getCompressedTokenAccountsByOwner(

js/stateless.js/src/rpc.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
LatestNonVotingSignaturesResultPaginated,
3636
LatestNonVotingSignaturesPaginated,
3737
WithContext,
38+
GetCompressedAccountsByOwnerConfig,
3839
WithCursor,
3940
} from './rpc-interface';
4041
import {
@@ -663,17 +664,25 @@ export class Rpc extends Connection implements CompressionApiInterface {
663664
*/
664665
async getCompressedAccountsByOwner(
665666
owner: PublicKey,
667+
config?: GetCompressedAccountsByOwnerConfig,
666668
): Promise<WithCursor<CompressedAccountWithMerkleContext[]>> {
667669
const unsafeRes = await rpcRequest(
668670
this.compressionApiEndpoint,
669671
'getCompressedAccountsByOwner',
670-
{ owner: owner.toBase58() },
672+
{
673+
owner: owner.toBase58(),
674+
filters: config?.filters || [],
675+
dataSlice: config?.dataSlice,
676+
cursor: config?.cursor,
677+
limit: config?.limit?.toNumber(),
678+
},
671679
);
672680

673681
const res = create(
674682
unsafeRes,
675683
jsonRpcResultAndContext(CompressedAccountsByOwnerResult),
676684
);
685+
677686
if ('error' in res) {
678687
throw new SolanaJSONRPCError(
679688
res.error,

js/stateless.js/src/test-helpers/test-rpc/test-rpc.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { getParsedEvents } from './get-parsed-events';
1616
import { defaultTestStateTreeAccounts } from '../../constants';
1717
import {
1818
CompressedTransaction,
19+
GetCompressedAccountsByOwnerConfig,
1920
LatestNonVotingSignatures,
2021
LatestNonVotingSignaturesPaginated,
2122
SignatureWithMetadata,
@@ -334,7 +335,14 @@ export class TestRpc extends Connection implements CompressionApiInterface {
334335
*/
335336
async getCompressedAccountsByOwner(
336337
owner: PublicKey,
338+
_config?: GetCompressedAccountsByOwnerConfig,
337339
): Promise<WithCursor<CompressedAccountWithMerkleContext[]>> {
340+
if (_config) {
341+
throw new Error(
342+
'dataSlice or filters are not supported in test-rpc. Please use rpc.ts instead.',
343+
);
344+
}
345+
338346
const accounts = await getCompressedAccountsByOwnerTest(this, owner);
339347
return {
340348
items: accounts,

js/stateless.js/tests/e2e/rpc-interop.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ describe('rpc-interop', () => {
4040
const transferAmount = 1e4;
4141
const numberOfTransfers = 15;
4242

43+
it('getCompressedAccountsByOwner [noforester] filter should work', async () => {
44+
let accs = await rpc.getCompressedAccountsByOwner(payer.publicKey, {
45+
filters: [
46+
{
47+
memcmp: {
48+
offset: 1,
49+
bytes: '5Vf',
50+
},
51+
},
52+
],
53+
});
54+
assert.equal(accs.items.length, 0);
55+
56+
accs = await rpc.getCompressedAccountsByOwner(payer.publicKey, {
57+
dataSlice: { offset: 1, length: 2 },
58+
});
59+
60+
assert.equal(accs.items.length, 1);
61+
});
4362
it('getValidityProof [noforester] (inclusion) should match', async () => {
4463
const senderAccounts = await rpc.getCompressedAccountsByOwner(
4564
payer.publicKey,

pnpm-lock.yaml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ VERSIONS=(
1313
"solana:1.18.17"
1414
"anchor:anchor-v0.29.0"
1515
"jq:jq-1.7.1"
16-
"photon:0.38.0"
16+
"photon:0.40.0"
1717
)
1818

1919
# Architecture-specific suffixes

0 commit comments

Comments
 (0)