/
lookupAssetTransactions.ts
396 lines (377 loc) · 9.37 KB
/
lookupAssetTransactions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import IntDecoding from '../../../types/intDecoding';
import { base64StringFunnel } from './lookupAccountTransactions';
export default class LookupAssetTransactions extends JSONRequest {
/**
* Returns transactions relating to the given asset.
*
* #### Example
* ```typescript
* const assetId = 163650;
* const assetTxns = await indexerClient.lookupAssetTransactions(assetId).do();
* ```
*
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/indexer/#get-v2assetsasset-idtransactions)
* @param index - The asset ID to look up.
*/
constructor(c: HTTPClient, intDecoding: IntDecoding, private index: number) {
super(c, intDecoding);
this.index = index;
}
/**
* @returns `/v2/assets/${index}/transactions`
*/
path() {
return `/v2/assets/${this.index}/transactions`;
}
/**
* Specifies a prefix which must be contained in the note field.
*
* #### Example
* ```typescript
* const notePrefixBase64Encoded = "Y3JlYXRl";
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .notePrefix(notePrefixBase64Encoded)
* .do();
* ```
*
* @param prefix - base64 string or uint8array
* @category query
*/
notePrefix(prefix: Uint8Array | string) {
this.query['note-prefix'] = base64StringFunnel(prefix);
return this;
}
/**
* Type of transaction to filter with.
*
* #### Example
* ```typescript
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .txType("axfer")
* .do();
* ```
*
* @param type - one of `pay`, `keyreg`, `acfg`, `axfer`, `afrz`, `appl`
* @category query
*/
txType(type: string) {
this.query['tx-type'] = type;
return this;
}
/**
* Type of signature to filter with.
* - sig: Standard
* - msig: MultiSig
* - lsig: LogicSig
*
* #### Example
* ```typescript
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .sigType("lsig")
* .do();
* ```
*
* @param type - one of `sig`, `msig`, `lsig`
* @category query
*/
sigType(type: string) {
this.query['sig-type'] = type;
return this;
}
/**
* Lookup the specific transaction by ID.
*
* #### Example
* ```typescript
* const txId = "MEUOC4RQJB23CQZRFRKYEI6WBO73VTTPST5A7B3S5OKBUY6LFUDA";
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .txid(txId)
* .do();
* ```
*
* @param txid
* @category query
*/
txid(txid: string) {
this.query.txid = txid;
return this;
}
/**
* Include results for the specified round.
*
* #### Example
* ```typescript
* const targetBlock = 18309917;
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .round(targetBlock)
* .do();
* ```
*
* @param round
* @category query
*/
round(round: number) {
this.query.round = round;
return this;
}
/**
* Include results at or after the specified min-round.
*
* #### Example
* ```typescript
* const minRound = 18309917;
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .minRound(minRound)
* .do();
* ```
*
* @param round
* @category query
*/
minRound(round: number) {
this.query['min-round'] = round;
return this;
}
/**
* Include results at or before the specified max-round.
*
* #### Example
* ```typescript
* const maxRound = 18309917;
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .maxRound(maxRound)
* .do();
* ```
*
* @param round
* @category query
*/
maxRound(round: number) {
this.query['max-round'] = round;
return this;
}
/**
* Maximum number of results to return.
*
* #### Example
* ```typescript
* const maxResults = 25;
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .limit(maxResults)
* .do();
* ```
*
* @param limit
* @category query
*/
limit(limit: number) {
this.query.limit = limit;
return this;
}
/**
* Include results before the given time.
*
* #### Example
* ```typescript
* const beforeTime = "2022-02-02T20:20:22.02Z";
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .beforeTime(beforeTime)
* .do();
* ```
*
* @param before - rfc3339 string
* @category query
*/
beforeTime(before: string) {
this.query['before-time'] = before;
return this;
}
/**
* Include results after the given time.
*
* #### Example
* ```typescript
* const afterTime = "2022-10-21T00:00:11.55Z";
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .afterTime(afterTime)
* .do();
* ```
*
* @param after - rfc3339 string
* @category query
*/
afterTime(after: string) {
this.query['after-time'] = after;
return this;
}
/**
* Filtered results should have an amount greater than this value, as int, representing asset units.
*
* #### Example
* ```typescript
* const minBalance = 300000;
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .currencyGreaterThan(minBalance - 1)
* .do();
* ```
*
* @param greater
* @category query
*/
currencyGreaterThan(greater: number) {
// We convert the following to a string for now to correctly include zero values in request parameters.
this.query['currency-greater-than'] = greater.toString();
return this;
}
/**
* Filtered results should have an amount less than this value, as int, representing asset units.
*
* #### Example
* ```typescript
* const maxBalance = 500000;
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .currencyLessThan(maxBalance + 1)
* .do();
* ```
*
* @param lesser
* @category query
*/
currencyLessThan(lesser: number) {
this.query['currency-less-than'] = lesser;
return this;
}
/**
* Combined with address, defines what address to filter on, as string.
*
* #### Example
* ```typescript
* const assetId = 163650;
* const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
* const role = "sender";
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .address(address)
* .addressRole(role)
* .do();
* ```
*
* @param role - one of `sender`, `receiver`, `freeze-target`
* @category query
*/
addressRole(role: string) {
this.query['address-role'] = role;
return this;
}
/**
* Only include transactions with this address in one of the transaction fields.
*
* #### Example
* ```typescript
* const assetId = 163650;
* const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .address(address)
* .do();
* ```
*
* @param address
* @category query
*/
address(address: string) {
this.query.address = address;
return this;
}
/**
* Whether or not to consider the `close-to` field as a receiver when filtering transactions, as bool. Set to `true` to ignore `close-to`.
*
* #### Example
* ```typescript
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .excludeCloseTo(true)
* .do();
* ```
*
* @param exclude
* @category query
*/
excludeCloseTo(exclude: boolean) {
this.query['exclude-close-to'] = exclude;
return this;
}
/**
* The next page of results.
*
* #### Example
* ```typescript
* const maxResults = 25;
* const assetId = 163650;
*
* const assetTxnsPage1 = await indexerClient
* .lookupAssetTransactions(assetId)
* .limit(maxResults)
* .do();
*
* const assetTxnsPage2 = await indexerClient
* .lookupAssetTransactions(assetId)
* .limit(maxResults)
* .nextToken(assetTxnsPage1["next-token"])
* .do();
* ```
*
* @param nextToken - provided by the previous results.
* @category query
*/
nextToken(nextToken: string) {
this.query.next = nextToken;
return this;
}
/**
* Whether or not to include rekeying transactions.
*
* #### Example
* ```typescript
* const assetId = 163650;
* const assetTxns = await indexerClient
* .lookupAssetTransactions(assetId)
* .rekeyTo(false)
* .do();
* ```
*
* @param rekeyTo
* @category query
*/
rekeyTo(rekeyTo: boolean) {
this.query['rekey-to'] = rekeyTo;
return this;
}
}