-
Notifications
You must be signed in to change notification settings - Fork 210
/
Copy pathgetApplicationBoxByName.ts
49 lines (46 loc) · 1.39 KB
/
getApplicationBoxByName.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
import JSONRequest from '../jsonrequest';
import HTTPClient from '../../client';
import IntDecoding from '../../../types/intDecoding';
import { Box } from './models/types';
/**
* Given an application ID and the box name (key), return the value stored in the box.
*
* #### Example
* ```typescript
* const index = 60553466;
* const boxName = Buffer.from("foo");
* const boxResponse = await algodClient.getApplicationBoxByName(index, boxName).do();
* const boxValue = boxResponse.value;
* ```
*
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/v2/#get-v2applicationsapplication-idbox)
* @param index - The application ID to look up.
* @category GET
*/
export default class GetApplicationBoxByName extends JSONRequest<
Box,
Record<string, any>
> {
constructor(
c: HTTPClient,
intDecoding: IntDecoding,
private index: number,
name: Uint8Array
) {
super(c, intDecoding);
this.index = index;
// Encode name in base64 format and append the encoding prefix.
const encodedName = Buffer.from(name).toString('base64');
this.query.name = encodeURI(`b64:${encodedName}`);
}
/**
* @returns `/v2/applications/${index}/box`
*/
path() {
return `/v2/applications/${this.index}/box`;
}
// eslint-disable-next-line class-methods-use-this
prepare(body: Record<string, any>): Box {
return Box.from_obj_for_encoding(body);
}
}