@algorandfoundation/algokit-utils 6.1.0-beta.1 → 6.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/account/account.d.ts +24 -3
- package/account/account.d.ts.map +1 -1
- package/account/account.js +29 -53
- package/account/account.js.map +1 -1
- package/account/account.mjs +29 -53
- package/account/account.mjs.map +1 -1
- package/account/get-account.d.ts +2 -2
- package/account/get-account.d.ts.map +1 -1
- package/account/get-account.js +9 -29
- package/account/get-account.js.map +1 -1
- package/account/get-account.mjs +4 -24
- package/account/get-account.mjs.map +1 -1
- package/account/get-dispenser-account.d.ts +7 -2
- package/account/get-dispenser-account.d.ts.map +1 -1
- package/account/get-dispenser-account.js +7 -8
- package/account/get-dispenser-account.js.map +1 -1
- package/account/get-dispenser-account.mjs +7 -8
- package/account/get-dispenser-account.mjs.map +1 -1
- package/account/mnemonic-account.d.ts +4 -1
- package/account/mnemonic-account.d.ts.map +1 -1
- package/account/mnemonic-account.js +4 -1
- package/account/mnemonic-account.js.map +1 -1
- package/account/mnemonic-account.mjs +4 -1
- package/account/mnemonic-account.mjs.map +1 -1
- package/dispenser-client.d.ts +2 -0
- package/dispenser-client.d.ts.map +1 -1
- package/dispenser-client.js +2 -0
- package/dispenser-client.js.map +1 -1
- package/dispenser-client.mjs +2 -0
- package/dispenser-client.mjs.map +1 -1
- package/index.d.ts +7 -7
- package/index.d.ts.map +1 -1
- package/index.js +31 -31
- package/index.mjs +9 -9
- package/localnet/get-kmd-wallet-account.d.ts +2 -0
- package/localnet/get-kmd-wallet-account.d.ts.map +1 -1
- package/localnet/get-kmd-wallet-account.js +5 -30
- package/localnet/get-kmd-wallet-account.js.map +1 -1
- package/localnet/get-kmd-wallet-account.mjs +5 -30
- package/localnet/get-kmd-wallet-account.mjs.map +1 -1
- package/localnet/get-localnet-dispenser-account.d.ts +2 -0
- package/localnet/get-localnet-dispenser-account.d.ts.map +1 -1
- package/localnet/get-localnet-dispenser-account.js +5 -7
- package/localnet/get-localnet-dispenser-account.js.map +1 -1
- package/localnet/get-localnet-dispenser-account.mjs +5 -7
- package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts +2 -0
- package/localnet/get-or-create-kmd-wallet-account.d.ts.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.js +5 -27
- package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs +5 -27
- package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
- package/localnet/is-localnet.d.ts +4 -1
- package/localnet/is-localnet.d.ts.map +1 -1
- package/localnet/is-localnet.js +7 -3
- package/localnet/is-localnet.js.map +1 -1
- package/localnet/is-localnet.mjs +7 -3
- package/localnet/is-localnet.mjs.map +1 -1
- package/network-client.d.ts +36 -8
- package/network-client.d.ts.map +1 -1
- package/network-client.js +49 -88
- package/network-client.js.map +1 -1
- package/network-client.mjs +49 -88
- package/network-client.mjs.map +1 -1
- package/package.json +3 -2
- package/testing/account.d.ts +3 -5
- package/testing/account.d.ts.map +1 -1
- package/testing/account.js +6 -9
- package/testing/account.js.map +1 -1
- package/testing/account.mjs +6 -9
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algorand-fixture.d.ts +20 -2
- package/testing/fixtures/algorand-fixture.d.ts.map +1 -1
- package/testing/fixtures/algorand-fixture.js +11 -30
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +11 -30
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/transaction/transaction.d.ts.map +1 -1
- package/transaction/transaction.js +8 -8
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +8 -8
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/transfer.js +4 -4
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs +4 -4
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +108 -24
- package/types/account-manager.d.ts.map +1 -1
- package/types/account-manager.js +167 -34
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +166 -34
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +13 -11
- package/types/account.d.ts.map +1 -1
- package/types/algorand-client.d.ts +12 -6
- package/types/algorand-client.d.ts.map +1 -1
- package/types/algorand-client.js +20 -15
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +20 -15
- package/types/algorand-client.mjs.map +1 -1
- package/types/client-manager.d.ts +197 -4
- package/types/client-manager.d.ts.map +1 -1
- package/types/client-manager.js +284 -7
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +284 -7
- package/types/client-manager.mjs.map +1 -1
- package/types/kmd-account-manager.d.ts +70 -0
- package/types/kmd-account-manager.d.ts.map +1 -0
- package/types/kmd-account-manager.js +144 -0
- package/types/kmd-account-manager.js.map +1 -0
- package/types/kmd-account-manager.mjs +142 -0
- package/types/kmd-account-manager.mjs.map +1 -0
- package/types/network-client.d.ts +2 -2
- package/types/network-client.d.ts.map +1 -1
- package/types/testing.d.ts +9 -6
- package/types/testing.d.ts.map +1 -1
package/types/client-manager.js
CHANGED
|
@@ -1,22 +1,42 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var algosdk = require('algosdk');
|
|
4
|
+
var types_algoHttpClientWithRetry = require('./algo-http-client-with-retry.js');
|
|
5
5
|
var types_appClient = require('./app-client.js');
|
|
6
|
+
var types_dispenserClient = require('./dispenser-client.js');
|
|
6
7
|
|
|
8
|
+
var Kmd = algosdk.Kmd;
|
|
9
|
+
var Indexer = algosdk.Indexer;
|
|
10
|
+
var IntDecoding = algosdk.IntDecoding;
|
|
7
11
|
/** Exposes access to various API clients. */
|
|
8
12
|
class ClientManager {
|
|
9
13
|
/**
|
|
10
14
|
* algosdk clients or config for interacting with the official Algorand APIs.
|
|
11
15
|
* @param clientsOrConfig The clients or config to use
|
|
16
|
+
* @example Algod client only
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const clientManager = new ClientManager({ algod: algodClient })
|
|
19
|
+
* ```
|
|
20
|
+
* @example All clients
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const clientManager = new ClientManager({ algod: algodClient, indexer: indexerClient, kmd: kmdClient })
|
|
23
|
+
* ```
|
|
24
|
+
* @example Algod config only
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const clientManager = new ClientManager({ algodConfig })
|
|
27
|
+
* ```
|
|
28
|
+
* @example All client configs
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const clientManager = new ClientManager({ algodConfig, indexerConfig, kmdConfig })
|
|
31
|
+
* ```
|
|
12
32
|
*/
|
|
13
33
|
constructor(clientsOrConfig) {
|
|
14
34
|
const _clients = 'algod' in clientsOrConfig
|
|
15
35
|
? clientsOrConfig
|
|
16
36
|
: {
|
|
17
|
-
algod:
|
|
18
|
-
indexer: clientsOrConfig.indexerConfig ?
|
|
19
|
-
kmd: clientsOrConfig.kmdConfig ?
|
|
37
|
+
algod: ClientManager.getAlgodClient(clientsOrConfig.algodConfig),
|
|
38
|
+
indexer: clientsOrConfig.indexerConfig ? ClientManager.getIndexerClient(clientsOrConfig.indexerConfig) : undefined,
|
|
39
|
+
kmd: clientsOrConfig.kmdConfig ? ClientManager.getKmdClient(clientsOrConfig.kmdConfig) : undefined,
|
|
20
40
|
};
|
|
21
41
|
this._algod = _clients.algod;
|
|
22
42
|
this._indexer = _clients.indexer;
|
|
@@ -38,6 +58,49 @@ class ClientManager {
|
|
|
38
58
|
throw new Error('Attempt to use Kmd client in AlgoKit instance with no Kmd configured');
|
|
39
59
|
return this._kmd;
|
|
40
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Get details about the current network.
|
|
63
|
+
* @example Getting genesis ID
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const network = await networkClient.network()
|
|
66
|
+
* const genesisId = network.genesisId
|
|
67
|
+
* ```
|
|
68
|
+
* @returns The current network details
|
|
69
|
+
*/
|
|
70
|
+
async network() {
|
|
71
|
+
if (!this._getNetworkPromise) {
|
|
72
|
+
this._getNetworkPromise = this._algod.getTransactionParams().do();
|
|
73
|
+
}
|
|
74
|
+
const params = await this._getNetworkPromise;
|
|
75
|
+
return {
|
|
76
|
+
isTestNet: ['testnet-v1.0', 'testnet-v1', 'testnet'].includes(params.genesisID),
|
|
77
|
+
isMainNet: ['mainnet-v1.0', 'mainnet-v1', 'mainnet'].includes(params.genesisID),
|
|
78
|
+
isLocalNet: params.genesisID === 'devnet-v1' || params.genesisID === 'sandnet-v1' || params.genesisID === 'dockernet-v1',
|
|
79
|
+
genesisId: params.genesisID,
|
|
80
|
+
genesisHash: params.genesisHash,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns true if the current network is LocalNet.
|
|
85
|
+
* @returns True if the current network is LocalNet.
|
|
86
|
+
*/
|
|
87
|
+
async isLocalNet() {
|
|
88
|
+
return (await this.network()).isLocalNet;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Returns true if the current network is TestNet.
|
|
92
|
+
* @returns True if the current network is TestNet.
|
|
93
|
+
*/
|
|
94
|
+
async isTestNet() {
|
|
95
|
+
return (await this.network()).isTestNet;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns true if the current network is MainNet.
|
|
99
|
+
* @returns True if the current network is MainNet.
|
|
100
|
+
*/
|
|
101
|
+
async isMainNet() {
|
|
102
|
+
return (await this.network()).isMainNet;
|
|
103
|
+
}
|
|
41
104
|
/**
|
|
42
105
|
* Returns a TestNet Dispenser API client.
|
|
43
106
|
* Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.
|
|
@@ -45,7 +108,7 @@ class ClientManager {
|
|
|
45
108
|
* @param params An object containing parameters for the TestNetDispenserApiClient class.
|
|
46
109
|
* Or null if you want the client to load the access token from the environment variable `ALGOKIT_DISPENSER_ACCESS_TOKEN`.
|
|
47
110
|
* @example
|
|
48
|
-
* const client =
|
|
111
|
+
* const client = clientManager.getTestNetDispenser(
|
|
49
112
|
* {
|
|
50
113
|
* authToken: 'your_auth_token',
|
|
51
114
|
* requestTimeout: 15,
|
|
@@ -55,7 +118,7 @@ class ClientManager {
|
|
|
55
118
|
* @returns An instance of the TestNetDispenserApiClient class.
|
|
56
119
|
*/
|
|
57
120
|
getTestNetDispenser(params = null) {
|
|
58
|
-
return
|
|
121
|
+
return new types_dispenserClient.TestNetDispenserApiClient(params);
|
|
59
122
|
}
|
|
60
123
|
/**
|
|
61
124
|
* Returns a new `ApplicationClient` client, resolving the app by creator address and name.
|
|
@@ -93,6 +156,220 @@ class ClientManager {
|
|
|
93
156
|
getTypedAppClientById(typedClient, details) {
|
|
94
157
|
return new typedClient({ ...details, resolveBy: 'id' }, this._algod);
|
|
95
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Retrieve client configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment)
|
|
161
|
+
*
|
|
162
|
+
* If `process.env.ALGOD_SERVER` is defined it will use that along with optional `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.
|
|
163
|
+
*
|
|
164
|
+
* If `process.env.INDEXER_SERVER` is defined it will use that along with optional `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.
|
|
165
|
+
*
|
|
166
|
+
* If either aren't defined it will use the default LocalNet config, noting if `process.env.ALGOD_SERVER` is specified, but
|
|
167
|
+
* `process.env.INDEXER_SERVER` isn't then it will leave indexer as `undefined`.
|
|
168
|
+
*
|
|
169
|
+
* It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,
|
|
170
|
+
* otherwise it will use the default LocalNet config unless it detects testnet or mainnet.
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const config = ClientManager.getConfigFromEnvironmentOrLocalNet()
|
|
174
|
+
* ```
|
|
175
|
+
* @returns The config for algod, indexer and kmd
|
|
176
|
+
*/
|
|
177
|
+
static getConfigFromEnvironmentOrLocalNet() {
|
|
178
|
+
if (!process || !process.env) {
|
|
179
|
+
throw new Error('Attempt to get default client configuration from a non Node.js context; supply the config instead');
|
|
180
|
+
}
|
|
181
|
+
const algodConfig = !process.env.ALGOD_SERVER
|
|
182
|
+
? ClientManager.getDefaultLocalNetConfig('algod')
|
|
183
|
+
: ClientManager.getAlgodConfigFromEnvironment();
|
|
184
|
+
const indexerConfig = !process.env.INDEXER_SERVER
|
|
185
|
+
? ClientManager.getDefaultLocalNetConfig('indexer')
|
|
186
|
+
: !process.env.ALGOD_SERVER
|
|
187
|
+
? ClientManager.getIndexerConfigFromEnvironment()
|
|
188
|
+
: undefined;
|
|
189
|
+
return {
|
|
190
|
+
algodConfig,
|
|
191
|
+
indexerConfig,
|
|
192
|
+
kmdConfig: process.env.ALGOD_SERVER
|
|
193
|
+
? process.env.ALGOD_SERVER.includes('mainnet') || process.env.ALGOD_SERVER.includes('testnet')
|
|
194
|
+
? undefined
|
|
195
|
+
: { ...algodConfig, port: process?.env?.KMD_PORT ?? '4002' }
|
|
196
|
+
: ClientManager.getDefaultLocalNetConfig('kmd'),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/** Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment)
|
|
200
|
+
*
|
|
201
|
+
* Expects `process.env.ALGOD_SERVER` to be defined, and you can also specify `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.
|
|
202
|
+
*/
|
|
203
|
+
static getAlgodConfigFromEnvironment() {
|
|
204
|
+
if (!process || !process.env) {
|
|
205
|
+
throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead');
|
|
206
|
+
}
|
|
207
|
+
if (!process.env.ALGOD_SERVER) {
|
|
208
|
+
throw new Error('Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables');
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
server: process.env.ALGOD_SERVER,
|
|
212
|
+
port: process.env.ALGOD_PORT,
|
|
213
|
+
token: process.env.ALGOD_TOKEN,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment).
|
|
218
|
+
*
|
|
219
|
+
* Expects `process.env.INDEXER_SERVER` to be defined, and you can also specify `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.
|
|
220
|
+
*/
|
|
221
|
+
static getIndexerConfigFromEnvironment() {
|
|
222
|
+
if (!process || !process.env) {
|
|
223
|
+
throw new Error('Attempt to get default indexer configuration from a non Node.js context; supply the config instead');
|
|
224
|
+
}
|
|
225
|
+
if (!process.env.INDEXER_SERVER) {
|
|
226
|
+
throw new Error('Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables');
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
server: process.env.INDEXER_SERVER,
|
|
230
|
+
port: process.env.INDEXER_PORT,
|
|
231
|
+
token: process.env.INDEXER_TOKEN,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/** Returns the Algorand configuration to point to the free tier of the AlgoNode service.
|
|
235
|
+
*
|
|
236
|
+
* @param network Which network to connect to - TestNet or MainNet
|
|
237
|
+
* @param config Which algod config to return - Algod or Indexer
|
|
238
|
+
*/
|
|
239
|
+
static getAlgoNodeConfig(network, config) {
|
|
240
|
+
return {
|
|
241
|
+
server: `https://${network}-${config === 'algod' ? 'api' : 'idx'}.algonode.cloud/`,
|
|
242
|
+
port: 443,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/** Returns the Algorand configuration to point to the default LocalNet.
|
|
246
|
+
*
|
|
247
|
+
* @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number
|
|
248
|
+
*/
|
|
249
|
+
static getDefaultLocalNetConfig(configOrPort) {
|
|
250
|
+
return {
|
|
251
|
+
server: `http://localhost`,
|
|
252
|
+
port: configOrPort === 'algod' ? 4001 : configOrPort === 'indexer' ? 8980 : configOrPort === 'kmd' ? 4002 : configOrPort,
|
|
253
|
+
token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Returns an algod SDK client that automatically retries on idempotent calls.
|
|
258
|
+
*
|
|
259
|
+
* @param config The config of the client
|
|
260
|
+
* @example AlgoNode (testnet)
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod'))
|
|
263
|
+
* await algod.healthCheck().do()
|
|
264
|
+
* ```
|
|
265
|
+
* @example AlgoNode (mainnet)
|
|
266
|
+
* ```typescript
|
|
267
|
+
* const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('mainnet', 'algod'))
|
|
268
|
+
* await algod.healthCheck().do()
|
|
269
|
+
* ```
|
|
270
|
+
* @example Custom (e.g. default LocalNet)
|
|
271
|
+
* ```typescript
|
|
272
|
+
* const algod = ClientManager.getAlgodClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
|
|
273
|
+
* await algod.healthCheck().do()
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
static getAlgodClient(config) {
|
|
277
|
+
const { token, server, port } = config;
|
|
278
|
+
const tokenHeader = typeof token === 'string' ? { 'X-Algo-API-Token': token } : token ?? {};
|
|
279
|
+
const httpClientWithRetry = new types_algoHttpClientWithRetry.AlgoHttpClientWithRetry(tokenHeader, server, port);
|
|
280
|
+
return new algosdk.Algodv2(httpClientWithRetry, server);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Returns an algod SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN
|
|
288
|
+
* const algod = ClientManager.getAlgodClientFromEnvironment()
|
|
289
|
+
* await algod.healthCheck().do()
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
static getAlgodClientFromEnvironment() {
|
|
293
|
+
return ClientManager.getAlgodClient(ClientManager.getAlgodConfigFromEnvironment());
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Returns an indexer SDK client that automatically retries on idempotent calls
|
|
297
|
+
*
|
|
298
|
+
* @param config The config of the client
|
|
299
|
+
* @param overrideIntDecoding Override the default int decoding for responses, uses MIXED by default to avoid lost precision for big integers
|
|
300
|
+
* @example AlgoNode (testnet)
|
|
301
|
+
* ```typescript
|
|
302
|
+
* const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('testnet', 'indexer'))
|
|
303
|
+
* await indexer.makeHealthCheck().do()
|
|
304
|
+
* ```
|
|
305
|
+
* @example AlgoNode (mainnet)
|
|
306
|
+
* ```typescript
|
|
307
|
+
* const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('mainnet', 'indexer'))
|
|
308
|
+
* await indexer.makeHealthCheck().do()
|
|
309
|
+
* ```
|
|
310
|
+
* @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)
|
|
311
|
+
* ```typescript
|
|
312
|
+
* const indexer = ClientManager.getIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
|
|
313
|
+
* await indexer.makeHealthCheck().do()
|
|
314
|
+
* ```
|
|
315
|
+
* @example Override int decoding for responses
|
|
316
|
+
* ```typescript
|
|
317
|
+
* const indexer = ClientManager.getIndexerClient(config, IntDecoding.BIGINT)
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
static getIndexerClient(config, overrideIntDecoding) {
|
|
321
|
+
const { token, server, port } = config;
|
|
322
|
+
const tokenHeader = typeof token === 'string' ? { 'X-Indexer-API-Token': token } : token ?? {};
|
|
323
|
+
const httpClientWithRetry = new types_algoHttpClientWithRetry.AlgoHttpClientWithRetry(tokenHeader, server, port);
|
|
324
|
+
const indexer = new Indexer(httpClientWithRetry);
|
|
325
|
+
// Use mixed int decoding by default so bigints don't have lost precision
|
|
326
|
+
indexer.setIntEncoding(overrideIntDecoding ?? IntDecoding.MIXED);
|
|
327
|
+
return indexer;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Returns an indexer SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).
|
|
331
|
+
*
|
|
332
|
+
* @param overrideIntDecoding Override the default int decoding for responses, uses MIXED by default to avoid lost precision for big integers
|
|
333
|
+
* @example
|
|
334
|
+
*
|
|
335
|
+
* ```typescript
|
|
336
|
+
* // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN
|
|
337
|
+
* const indexer = ClientManager.getIndexerClientFromEnvironment()
|
|
338
|
+
* await indexer.makeHealthCheck().do()
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
static getIndexerClientFromEnvironment(overrideIntDecoding) {
|
|
342
|
+
return ClientManager.getIndexerClient(ClientManager.getIndexerConfigFromEnvironment(), overrideIntDecoding);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Returns a KMD SDK client.
|
|
346
|
+
*
|
|
347
|
+
* KMD client allows you to export private keys, which is useful to (for instance) get the default account in a LocalNet network.
|
|
348
|
+
*
|
|
349
|
+
* @param config The config for the client
|
|
350
|
+
* @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)
|
|
351
|
+
* ```typescript
|
|
352
|
+
* const kmd = ClientManager.getKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
static getKmdClient(config) {
|
|
356
|
+
const { token, server, port } = config;
|
|
357
|
+
return new Kmd(token, server, port);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Returns a KMD SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN
|
|
365
|
+
* const kmd = ClientManager.getKmdClientFromEnvironment()
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
static getKmdClientFromEnvironment() {
|
|
369
|
+
// We can only use Kmd on the LocalNet otherwise it's not exposed so this makes some assumptions
|
|
370
|
+
// (e.g. same token and server as algod and port 4002 by default)
|
|
371
|
+
return ClientManager.getKmdClient({ ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' });
|
|
372
|
+
}
|
|
96
373
|
}
|
|
97
374
|
|
|
98
375
|
exports.ClientManager = ClientManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-manager.js","sources":["../../src/types/client-manager.ts"],"sourcesContent":[null],"names":["
|
|
1
|
+
{"version":3,"file":"client-manager.js","sources":["../../src/types/client-manager.ts"],"sourcesContent":[null],"names":["TestNetDispenserApiClient","ApplicationClient","AlgoHttpClientWithRetry"],"mappings":";;;;;;;AAcA,IAAO,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;AACxB,IAAO,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;AAEhC,IAAO,WAAW,GAAG,OAAO,CAAC,WAAW,CAAA;AA0BxC;MACa,aAAa,CAAA;AAKxB;;;;;;;;;;;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