Skip to content

Commit 6427fa2

Browse files
added jsdoc comments to record provider/scanner types
1 parent 9d8c501 commit 6427fa2

File tree

9 files changed

+178
-68
lines changed

9 files changed

+178
-68
lines changed

sdk/src/models/record-provider/encryptedRecord.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/**
2+
* EncryptedRecord is a type that represents information about an encrypted record.
3+
*
4+
* @example
5+
* const encryptedRecord: EncryptedRecord = {
6+
* commitment: "...",
7+
* checksum: "...",
8+
* blockHeight: 123456,
9+
* programName: "...",
10+
* functionName: "...",
11+
* outputIndex: 0,
12+
* owner: "...",
13+
* recordCiphertext: "...",
14+
* recordName: "...",
15+
* recordNonce: "...",
16+
* transactionId: "...",
17+
* transitionId: "...",
18+
* transactionIndex: 0,
19+
* transitionIndex: 0,
20+
* }
21+
*/
122
export type EncryptedRecord = {
223
commitment: string;
324
checksum?: string;

sdk/src/models/record-provider/ownedRecord.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* OwnedRecord is a type that represents information about an owned record that is found on chain.
3+
*
4+
* @example
5+
* const ownedRecord: OwnedRecord = {
6+
* blockHeight: 123456,
7+
* commitment: "...",
8+
* functionName: "...",
9+
* outputIndex: 0,
10+
* owner: "...",
11+
* programName: "...",
12+
* recordCiphertext: "...",
13+
* recordPlaintext: "...",
14+
* recordName: "...",
15+
* spent: true,
16+
* tag: "...",
17+
* transactionId: "...",
18+
* transitionId: "...",
19+
* transactionIndex: 0,
20+
* transitionIndex: 0,
21+
* }
22+
*/
123
export type OwnedRecord = {
224
blockHeight?: number;
325
commitment?: string;

sdk/src/models/record-provider/recordSearchParams.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
/**
22
* Interface for record search parameters. This allows for arbitrary search parameters to be passed to record provider
33
* implementations.
4+
*
5+
* @example
6+
* const recordSearchParams: RecordSearchParams = {
7+
* // Declared fields
8+
* unspent: true,
9+
* nonces: ["..."],
10+
* // Arbitrary fields
11+
* startHeight: 123456,
12+
* programName: "..."
13+
* }
414
*/
515
export interface RecordSearchParams {
616
unspent: boolean;

sdk/src/models/record-provider/recordsResponseFilter.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* RecordsResponseFilter is a type that represents a filter for the response from a record provider.
3+
* A `true` value for a field in the filter will include that field in the response.
4+
*
5+
* @example
6+
* const recordsResponseFilter: RecordsResponseFilter = {
7+
* program: true,
8+
* record: true,
9+
* function: true,
10+
* transition: true,
11+
* blockHeight: true,
12+
* transactionId: true,
13+
* transitionId: true,
14+
* ioIndex: true,
15+
* }
16+
*/
117
export type RecordsResponseFilter = {
218
program: boolean;
319
record: boolean;

sdk/src/models/record-scanner/ownedFilter.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ import { RecordSearchParams } from "../record-provider/recordSearchParams";
22
import { RecordsFilter } from "./recordsFilter";
33
import { RecordsResponseFilter } from "../record-provider/recordsResponseFilter";
44

5+
/**
6+
* OwnedFilter is an extension of RecordSearchParams that represents a filter for scanning owned records.
7+
*
8+
* @example
9+
* const ownedFilter: OwnedFilter = {
10+
* unspent: true,
11+
* nonces: ["..."],
12+
* decrypt: true,
13+
* filter: {
14+
* program: "...",
15+
* record: "...",
16+
* },
17+
* }
18+
*/
519
export interface OwnedFilter extends RecordSearchParams {
620
decrypt?: boolean;
721
filter?: RecordsFilter;

sdk/src/models/record-scanner/recordsFilter.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import { RecordSearchParams } from "../record-provider/recordSearchParams";
22

3+
/**
4+
* RecordsFilter is an extension of RecordSearchParams that represents a filter for scanning encrypted or owned records.
5+
*
6+
* @example
7+
* const recordsFilter: RecordsFilter = {
8+
* start: 0,
9+
* end: 100,
10+
* program: "...",
11+
* record: "...",
12+
* }
13+
*/
314
export interface RecordsFilter extends RecordSearchParams {
415
start: number;
516
end?: number;

sdk/src/models/record-scanner/registrationRequest.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* RegistrationRequest is a type that represents a request to register an account's view key with a record scanning service.
3+
*
4+
* @example
5+
* const registrationRequest: RegistrationRequest = {
6+
* viewKey: "...",
7+
* start: 123456,
8+
* }
9+
*/
110
export type RegistrationRequest = {
211
viewKey: string;
312
start: number;

sdk/src/record-provider.ts

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { logAndThrow } from "./utils.js";
21
import { Account } from "./account.js";
32
import { AleoNetworkClient } from "./network-client.js";
4-
import { RecordsResponseFilter } from "./models/record-provider/recordsResponseFilter.js";
53
import { EncryptedRecord } from "./models/record-provider/encryptedRecord.js";
4+
import { logAndThrow } from "./utils.js";
65
import { OwnedRecord } from "./models/record-provider/ownedRecord.js";
76
import { RecordSearchParams } from "./models/record-provider/recordSearchParams.js";
7+
import { RecordsResponseFilter } from "./models/record-provider/recordsResponseFilter.js";
88

99
/**
1010
* Interface for a record provider. A record provider is used to find records for use in deployment and execution
@@ -14,36 +14,41 @@ import { RecordSearchParams } from "./models/record-provider/recordSearchParams.
1414
*/
1515
interface RecordProvider {
1616
/**
17-
* Find encrypted records from the chosen provider
17+
* The account used to search for records.
18+
*/
19+
account?: Account;
20+
21+
/**
22+
* Find encrypted records from the chosen provider.
1823
*
19-
* @param {RecordSearchParams} recordsFilter The filter to use to find the records
20-
* @param {RecordsResponseFilter} responseFilter The filter to use to filter the response
21-
* @returns {Promise<EncryptedRecord[]>} The encrypted records
24+
* @param {RecordSearchParams} recordsFilter The filter used to find the records.
25+
* @param {RecordsResponseFilter} responseFilter The filter used to filter the response.
26+
* @returns {Promise<EncryptedRecord[]>} The encrypted records.
2227
*/
2328
encryptedRecords(recordsFilter: RecordSearchParams, responseFilter: RecordsResponseFilter): Promise<EncryptedRecord[]>;
2429

2530
/**
2631
* Check if a list of serial numbers exist in the chosen provider
2732
*
28-
* @param {string[]} serialNumbers The serial numbers to check
29-
* @returns {Promise<Record<string, boolean>>} A record of serial numbers and whether they exist
33+
* @param {string[]} serialNumbers The serial numbers to check.
34+
* @returns {Promise<Record<string, boolean>>} Map of Aleo Record serial numbers and whether they appeared in any inputs on chain. If boolean corresponding to the Serial Number has a true value, that Record is considered spent by the Aleo Network.
3035
*/
3136
checkSerialNumbers(serialNumbers: string[]): Promise<Record<string, boolean>>;
3237

3338
/**
3439
* Check if a list of tags exist in the chosen provider
3540
*
36-
* @param {string[]} tags The tags to check
37-
* @returns {Promise<Record<string, boolean>>} A record of tags and whether they exist
41+
* @param {string[]} tags The tags to check.
42+
* @returns {Promise<Record<string, boolean>>} Map of Aleo Record tags and whether they appeared in any inputs on chain. If boolean corresponding to the tag has a true value, that Record is considered spent by the Aleo Network.
3843
*/
3944
checkTags(tags: string[]): Promise<Record<string, boolean>>;
4045

4146
/**
4247
* Find a credits.aleo record with a given number of microcredits from the chosen provider
4348
*
44-
* @param {number} microcredits The number of microcredits to search for
45-
* @param {RecordSearchParams} searchParameters Additional parameters to search for
46-
* @returns {Promise<OwnedRecord>} The record if one is found
49+
* @param {number} microcredits The number of microcredits to search for.
50+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
51+
* @returns {Promise<OwnedRecord>} The record if one is found.
4752
*
4853
* @example
4954
* // A class implementing record provider can be used to find a record with a given number of microcredits
@@ -63,9 +68,9 @@ interface RecordProvider {
6368
/**
6469
* Find a list of credit.aleo records with a given number of microcredits from the chosen provider
6570
*
66-
* @param {number[]} microcreditAmounts A list of separate microcredit amounts to search for (e.g. [5000, 100000])
67-
* @param {RecordSearchParams} searchParameters Additional parameters to search for
68-
* @returns {Promise<OwnedRecord[]>} A list of records with a value greater or equal to the amounts specified if such records exist, otherwise an error
71+
* @param {number[]} microcreditAmounts A list of separate microcredit amounts to search for (e.g. [5000, 100000]).
72+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
73+
* @returns {Promise<OwnedRecord[]>} A list of records with a value greater or equal to the amounts specified if such records exist, otherwise an error.
6974
*
7075
* @example
7176
* // A class implementing record provider can be used to find a record with a given number of microcredits
@@ -86,8 +91,8 @@ interface RecordProvider {
8691

8792
/**
8893
* Find an arbitrary record
89-
* @param {RecordSearchParams} searchParameters Additional parameters to search for
90-
* @returns {Promise<OwnedRecord>} The record if found, otherwise an error
94+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
95+
* @returns {Promise<OwnedRecord>} The record if found, otherwise an error.
9196
*
9297
* @example
9398
* // The RecordSearchParams interface can be used to create parameters for custom record searches which can then
@@ -131,8 +136,8 @@ interface RecordProvider {
131136
/**
132137
* Find multiple records from arbitrary programs
133138
*
134-
* @param {RecordSearchParams} searchParameters Additional parameters to search for
135-
* @returns {Promise<OwnedRecord[]>} The records if found, otherwise an error
139+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
140+
* @returns {Promise<OwnedRecord[]>} The records if found, otherwise an error.
136141
*
137142
* @example
138143
* // The RecordSearchParams interface can be used to create parameters for custom record searches which can then
@@ -188,7 +193,7 @@ class NetworkRecordProvider implements RecordProvider {
188193
/**
189194
* Set the account used to search for records
190195
*
191-
* @param {Account} account The account to use for searching for records
196+
* @param {Account} account The account used to use for searching for records.
192197
*/
193198
setAccount(account: Account) {
194199
this.account = account;
@@ -197,9 +202,9 @@ class NetworkRecordProvider implements RecordProvider {
197202
/**
198203
* Find a list of credit records with a given number of microcredits by via the official Aleo API
199204
*
200-
* @param {number[]} microcredits The number of microcredits to search for
201-
* @param {RecordSearchParams} searchParameters Additional parameters to search for
202-
* @returns {Promise<OwnedRecord[]>} The records if found, otherwise an error
205+
* @param {number[]} microcredits The number of microcredits to search for.
206+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
207+
* @returns {Promise<OwnedRecord[]>} The records if found, otherwise an error.
203208
*
204209
* @example
205210
* // Create a new NetworkRecordProvider
@@ -268,9 +273,9 @@ class NetworkRecordProvider implements RecordProvider {
268273
/**
269274
* Find a credit record with a given number of microcredits by via the official Aleo API
270275
*
271-
* @param {number} microcredits The number of microcredits to search for
272-
* @param {RecordSearchParams} searchParameters Additional parameters to search for
273-
* @returns {Promise<OwnedRecord>} The record if found, otherwise an error
276+
* @param {number} microcredits The number of microcredits to search for.
277+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
278+
* @returns {Promise<OwnedRecord>} The record if found, otherwise an error.
274279
*
275280
* @example
276281
* // Create a new NetworkRecordProvider
@@ -363,13 +368,13 @@ class NetworkRecordProvider implements RecordProvider {
363368
}
364369
}
365370

366-
// If the end height is not specified, use the current block height
371+
// If the end height is not specified, use the current block height.
367372
if (endHeight == 0) {
368373
const end = await this.networkClient.getLatestHeight();
369374
endHeight = end;
370375
}
371376

372-
// If the start height is greater than the end height, throw an error
377+
// If the start height is greater than the end height, throw an error.
373378
if (startHeight >= endHeight) {
374379
logAndThrow("Start height must be less than end height");
375380
}
@@ -425,11 +430,8 @@ class BlockHeightSearch implements RecordSearchParams {
425430
}
426431
}
427432

428-
export {
433+
export {
429434
BlockHeightSearch,
430-
EncryptedRecord,
431-
OwnedRecord,
435+
NetworkRecordProvider,
432436
RecordProvider,
433-
RecordSearchParams,
434-
RecordsResponseFilter,
435-
};
437+
};

0 commit comments

Comments
 (0)