Skip to content

Commit 74989af

Browse files
wip getAssetSignatures
1 parent b0c9956 commit 74989af

File tree

3 files changed

+96
-17
lines changed

3 files changed

+96
-17
lines changed

clients/js/src/decorator.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
SearchAssetsRpcInput,
1212
GetAssetSignaturesRpcResponse,
1313
GetAssetProofsRpcResponse,
14+
GetAssetSignaturesRpcInput,
1415
} from './types';
1516

1617
export interface DasApiInterface {
@@ -84,10 +85,10 @@ export interface DasApiInterface {
8485
/**
8586
* Return the transaction signatures for a compressed asset
8687
*
87-
* @param assetId the id of the asset to fetch the signatures for
88+
* @param input the input parameters for the RPC call
8889
*/
8990
getAssetSignatures(
90-
assetId: PublicKey
91+
input: GetAssetSignaturesRpcInput
9192
): Promise<GetAssetSignaturesRpcResponse>;
9293
}
9394

@@ -256,13 +257,22 @@ export const createDasApiDecorator = (
256257
}
257258
return assetList;
258259
},
259-
getAssetSignatures: async (assetId: PublicKey) => {
260+
getAssetSignatures: async (input: GetAssetSignaturesRpcInput) => {
260261
const signatures = await rpc.call<GetAssetSignaturesRpcResponse | null>(
261262
'getAssetSignaturesV2',
262-
[assetId]
263+
[ input.assetId,
264+
input.limit ?? null,
265+
input.page ?? null,
266+
input.before ?? null,
267+
input.after ?? null,
268+
input.tree ?? null,
269+
input.leaf_index ?? null,
270+
input.cursor ?? null,
271+
input.sort_direction ?? null,
272+
]
263273
);
264274
if (!signatures)
265-
throw new DasApiError(`No signatures found for asset: ${assetId}`);
275+
throw new DasApiError(`No signatures found for asset: ${input.assetId}`);
266276
return signatures;
267277
},
268278
});

clients/js/src/types.ts

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
Nullable,
33
PublicKey,
4-
TransactionSignature,
54
} from '@metaplex-foundation/umi';
65

76
// ---------------------------------------- //
@@ -451,6 +450,59 @@ export type GetAssetProofsRpcResponse = Record<
451450
GetAssetProofRpcResponse
452451
>;
453452

453+
export type GetAssetSignaturesRpcInput = {
454+
/**
455+
* The Asset ID to retrieve signatures for.
456+
*/
457+
assetId?: Nullable<PublicKey>;
458+
459+
/**
460+
* The maximum number of assets to retrieve.
461+
*/
462+
limit?: Nullable<number>;
463+
464+
/**
465+
* The page number of the signatures.
466+
*/
467+
page?: Nullable<number>;
468+
469+
/**
470+
* Retrieve signatures before the specified `ID` value.
471+
*/
472+
before?: Nullable<string>;
473+
474+
/**
475+
* Retrieve signatures after the specified `ID` value.
476+
*/
477+
after?: Nullable<string>;
478+
479+
/**
480+
* The tree ID to retrieve signatures for.
481+
*/
482+
tree?: Nullable<PublicKey>;
483+
484+
/**
485+
* The leaf index to retrieve signatures for.
486+
*/
487+
leaf_index?: Nullable<number>;
488+
489+
/**
490+
*
491+
*/
492+
cursor?: Nullable<string>;
493+
494+
/**
495+
* The sort direction.
496+
*/
497+
sort_direction?: Nullable<'asc' | 'desc'>;
498+
};
499+
500+
export type DasApiTransactionSignature = {
501+
signature: string;
502+
instruction: string;
503+
slot: number;
504+
};
505+
454506
export type GetAssetSignaturesRpcResponse = {
455507
/**
456508
* total number of signatures in the list.
@@ -464,13 +516,16 @@ export type GetAssetSignaturesRpcResponse = {
464516
*/
465517
limit: number;
466518

519+
before: string,
520+
after: string,
521+
467522
/**
468523
* The page number of the signatures.
469524
*/
470-
page: number;
525+
page?: number;
471526

472527
/**
473528
* List of individual signatures.
474529
*/
475-
signatures: TransactionSignature[];
530+
items: DasApiTransactionSignature[];
476531
};
Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
import { publicKey } from '@metaplex-foundation/umi';
22
import test from 'ava';
3-
import { GetAssetSignaturesRpcResponse } from '../src';
3+
import {
4+
DasApiTransactionSignature,
5+
} from '../src';
46
import { DAS_API_ENDPOINTS, createUmi } from './_setup';
57

68
DAS_API_ENDPOINTS.forEach((endpoint) => {
7-
test(`it can fetch the proof of a compressed asset by ID (${endpoint.name})`, async (t) => {
9+
test(`it can fetch the signatures of a compressed asset by ID (${endpoint.name})`, async (t) => {
810
// Given a minted NFT on mainnet.
911
const umi = createUmi(endpoint.url);
10-
const assetId = publicKey('5equc6uNZj75zb6yYLUUyy3WnAUmuuwmGZthz2oxUCtx');
12+
const assetId = publicKey('GGRbPQhwmo3dXBkJSAjMFc1QYTKGBt8qc11tTp3LkEKA');
1113

12-
// When we fetch the proof of the asset using its ID.
13-
const signatures = await umi.rpc.getAssetSignatures(assetId);
14+
// When we fetch the Signatures for the asset.
15+
const signatures = await umi.rpc.getAssetSignatures({ assetId });
1416

15-
console.log(signatures);
16-
17-
// Then we expect the following data.
18-
t.like(signatures, <GetAssetSignaturesRpcResponse>{});
17+
// Then we expect to find 2 signatures.
18+
t.is(signatures.total, 2);
19+
t.is(signatures.limit, 1000);
20+
t.is(signatures.items.length, 2);
21+
t.like(signatures.items[0], <DasApiTransactionSignature>{
22+
signature:
23+
'3Ki9QJTC2V1oNhkkhvJAJ4DEBRdMMrvKqctsyPhGL5JGkZz72xAsgTQh4vAEuJNtkxTxdmWg7RhkSXwU2JNRdSVh',
24+
instruction: 'MintToCollectionV1',
25+
slot: 356098299,
26+
});
27+
t.like(signatures.items[1], <DasApiTransactionSignature>{
28+
signature:
29+
'4rNhZukEBfuGxWxesRgStu1PqvStycu1fhNiftXVUcCygazXLpz6BubNCMywBW9eQLKtLa58FSqgyjDxHSTuFYy8',
30+
instruction: 'CreateTree',
31+
slot: 356098214,
32+
});
1933
});
2034
});

0 commit comments

Comments
 (0)