@algorandfoundation/algokit-utils 2.3.3-beta.3 → 2.3.3-beta.5
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/cjs/account.d.ts.map +1 -0
- package/cjs/account.js.map +1 -0
- package/cjs/amount.d.ts.map +1 -0
- package/cjs/amount.js.map +1 -0
- package/cjs/app-client.d.ts.map +1 -0
- package/cjs/app-client.js.map +1 -0
- package/cjs/app-deploy.d.ts.map +1 -0
- package/cjs/app-deploy.js.map +1 -0
- package/cjs/app.d.ts.map +1 -0
- package/cjs/app.js.map +1 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js.map +1 -0
- package/cjs/indexer-lookup.d.ts.map +1 -0
- package/cjs/indexer-lookup.js.map +1 -0
- package/cjs/localnet.d.ts.map +1 -0
- package/{localnet.js → cjs/localnet.js} +1 -1
- package/cjs/localnet.js.map +1 -0
- package/cjs/network-client.d.ts.map +1 -0
- package/cjs/network-client.js.map +1 -0
- package/cjs/testing/account.d.ts.map +1 -0
- package/cjs/testing/account.js.map +1 -0
- package/cjs/testing/fixtures/algokit-log-capture-fixture.d.ts.map +1 -0
- package/cjs/testing/fixtures/algokit-log-capture-fixture.js.map +1 -0
- package/cjs/testing/fixtures/algorand-fixture.d.ts.map +1 -0
- package/cjs/testing/fixtures/algorand-fixture.js.map +1 -0
- package/cjs/testing/fixtures/index.d.ts.map +1 -0
- package/cjs/testing/fixtures/index.js.map +1 -0
- package/cjs/testing/index.d.ts.map +1 -0
- package/cjs/testing/index.js.map +1 -0
- package/cjs/testing/indexer.d.ts.map +1 -0
- package/cjs/testing/indexer.js.map +1 -0
- package/cjs/testing/test-logger.d.ts.map +1 -0
- package/{testing → cjs/testing}/test-logger.js +2 -0
- package/cjs/testing/test-logger.js.map +1 -0
- package/cjs/testing/transaction-logger.d.ts.map +1 -0
- package/{testing → cjs/testing}/transaction-logger.js +2 -3
- package/cjs/testing/transaction-logger.js.map +1 -0
- package/cjs/transaction.d.ts.map +1 -0
- package/cjs/transaction.js.map +1 -0
- package/cjs/transfer.d.ts.map +1 -0
- package/cjs/transfer.js.map +1 -0
- package/cjs/types/account.d.ts +66 -0
- package/cjs/types/account.d.ts.map +1 -0
- package/{types → cjs/types}/account.js +7 -0
- package/cjs/types/account.js.map +1 -0
- package/cjs/types/algo-http-client-with-retry.d.ts.map +1 -0
- package/{types → cjs/types}/algo-http-client-with-retry.js +16 -16
- package/cjs/types/algo-http-client-with-retry.js.map +1 -0
- package/cjs/types/amount.d.ts +24 -0
- package/cjs/types/amount.d.ts.map +1 -0
- package/{types → cjs/types}/amount.js +1 -0
- package/cjs/types/amount.js.map +1 -0
- package/cjs/types/app-client.d.ts +408 -0
- package/cjs/types/app-client.d.ts.map +1 -0
- package/{types → cjs/types}/app-client.js +13 -0
- package/cjs/types/app-client.js.map +1 -0
- package/cjs/types/app-spec.d.ts.map +1 -0
- package/{types → cjs/types}/app-spec.js.map +1 -1
- package/cjs/types/app.d.ts +308 -0
- package/cjs/types/app.d.ts.map +1 -0
- package/cjs/types/app.js.map +1 -0
- package/cjs/types/config.d.ts.map +1 -0
- package/{types → cjs/types}/config.js +1 -0
- package/cjs/types/config.js.map +1 -0
- package/cjs/types/indexer.d.ts.map +1 -0
- package/cjs/types/indexer.js.map +1 -0
- package/cjs/types/logging.d.ts.map +1 -0
- package/cjs/types/logging.js.map +1 -0
- package/cjs/types/logic-error.d.ts.map +1 -0
- package/{types → cjs/types}/logic-error.js +5 -2
- package/cjs/types/logic-error.js.map +1 -0
- package/cjs/types/network-client.d.ts +20 -0
- package/cjs/types/network-client.d.ts.map +1 -0
- package/cjs/types/network-client.js.map +1 -0
- package/cjs/types/testing.d.ts.map +1 -0
- package/{types → cjs/types}/testing.js.map +1 -1
- package/cjs/types/transaction.d.ts +111 -0
- package/cjs/types/transaction.d.ts.map +1 -0
- package/{types → cjs/types}/transaction.js.map +1 -1
- package/cjs/types/transfer.d.ts +32 -0
- package/cjs/types/transfer.d.ts.map +1 -0
- package/{types → cjs/types}/transfer.js.map +1 -1
- package/cjs/types/urlTokenBaseHTTPClient.d.ts.map +1 -0
- package/{types → cjs/types}/urlTokenBaseHTTPClient.js +4 -0
- package/cjs/types/urlTokenBaseHTTPClient.js.map +1 -0
- package/cjs/util.d.ts.map +1 -0
- package/cjs/util.js.map +1 -0
- package/esm/account.js +170 -0
- package/esm/account.js.map +1 -0
- package/esm/amount.js +27 -0
- package/esm/amount.js.map +1 -0
- package/esm/app-client.js +76 -0
- package/esm/app-client.js.map +1 -0
- package/esm/app-deploy.js +446 -0
- package/esm/app-deploy.js.map +1 -0
- package/esm/app.js +572 -0
- package/esm/app.js.map +1 -0
- package/esm/index.js +14 -0
- package/esm/index.js.map +1 -0
- package/esm/indexer-lookup.js +98 -0
- package/esm/indexer-lookup.js.map +1 -0
- package/esm/localnet.js +111 -0
- package/esm/localnet.js.map +1 -0
- package/esm/network-client.js +179 -0
- package/esm/network-client.js.map +1 -0
- package/esm/testing/account.js +24 -0
- package/esm/testing/account.js.map +1 -0
- package/esm/testing/fixtures/algokit-log-capture-fixture.js +39 -0
- package/esm/testing/fixtures/algokit-log-capture-fixture.js.map +1 -0
- package/esm/testing/fixtures/algorand-fixture.js +53 -0
- package/esm/testing/fixtures/algorand-fixture.js.map +1 -0
- package/esm/testing/fixtures/index.js +3 -0
- package/esm/testing/fixtures/index.js.map +1 -0
- package/esm/testing/index.js +6 -0
- package/esm/testing/index.js.map +1 -0
- package/esm/testing/indexer.js +36 -0
- package/esm/testing/indexer.js.map +1 -0
- package/esm/testing/test-logger.js +69 -0
- package/esm/testing/test-logger.js.map +1 -0
- package/esm/testing/transaction-logger.js +66 -0
- package/esm/testing/transaction-logger.js.map +1 -0
- package/esm/transaction.js +365 -0
- package/esm/transaction.js.map +1 -0
- package/esm/transfer.js +59 -0
- package/esm/transfer.js.map +1 -0
- package/esm/types/account.js +90 -0
- package/esm/types/account.js.map +1 -0
- package/esm/types/algo-http-client-with-retry.js +58 -0
- package/esm/types/algo-http-client-with-retry.js.map +1 -0
- package/esm/types/amount.js +35 -0
- package/esm/types/amount.js.map +1 -0
- package/esm/types/app-client.js +624 -0
- package/esm/types/app-client.js.map +1 -0
- package/esm/types/app-spec.js +2 -0
- package/esm/types/app-spec.js.map +1 -0
- package/esm/types/app.js +33 -0
- package/esm/types/app.js.map +1 -0
- package/esm/types/config.js +50 -0
- package/esm/types/config.js.map +1 -0
- package/esm/types/indexer.js +31 -0
- package/esm/types/indexer.js.map +1 -0
- package/esm/types/logging.js +24 -0
- package/esm/types/logging.js.map +1 -0
- package/esm/types/logic-error.js +49 -0
- package/esm/types/logic-error.js.map +1 -0
- package/esm/types/network-client.js +2 -0
- package/esm/types/network-client.js.map +1 -0
- package/esm/types/testing.js +2 -0
- package/esm/types/testing.js.map +1 -0
- package/esm/types/transaction.js +2 -0
- package/esm/types/transaction.js.map +1 -0
- package/esm/types/transfer.js +2 -0
- package/esm/types/transfer.js.map +1 -0
- package/esm/types/urlTokenBaseHTTPClient.js +151 -0
- package/esm/types/urlTokenBaseHTTPClient.js.map +1 -0
- package/esm/util.js +20 -0
- package/esm/util.js.map +1 -0
- package/package.json +42 -6
- package/types/account.d.ts +125 -63
- package/types/account.d.ts.map +1 -1
- package/types/amount.d.ts +18 -22
- package/types/amount.d.ts.map +1 -1
- package/types/app-client.d.ts +70 -407
- package/types/app-client.d.ts.map +1 -1
- package/types/app-deploy.d.ts +101 -0
- package/types/app-deploy.d.ts.map +1 -0
- package/types/app.d.ts +145 -290
- package/types/app.d.ts.map +1 -1
- package/types/index.d.ts +14 -0
- package/types/index.d.ts.map +1 -0
- package/types/indexer-lookup.d.ts +38 -0
- package/types/indexer-lookup.d.ts.map +1 -0
- package/types/localnet.d.ts +54 -0
- package/types/localnet.d.ts.map +1 -0
- package/types/network-client.d.ts +96 -19
- package/types/network-client.d.ts.map +1 -1
- package/types/testing/account.d.ts +14 -0
- package/types/testing/account.d.ts.map +1 -0
- package/types/testing/fixtures/algokit-log-capture-fixture.d.ts +19 -0
- package/types/testing/fixtures/algokit-log-capture-fixture.d.ts.map +1 -0
- package/types/testing/fixtures/algorand-fixture.d.ts +48 -0
- package/types/testing/fixtures/algorand-fixture.d.ts.map +1 -0
- package/types/testing/fixtures/index.d.ts +3 -0
- package/types/testing/fixtures/index.d.ts.map +1 -0
- package/types/testing/index.d.ts +6 -0
- package/types/testing/index.d.ts.map +1 -0
- package/types/testing/indexer.d.ts +12 -0
- package/types/testing/indexer.d.ts.map +1 -0
- package/types/testing/test-logger.d.ts +41 -0
- package/types/testing/test-logger.d.ts.map +1 -0
- package/types/testing/transaction-logger.d.ts +29 -0
- package/types/testing/transaction-logger.d.ts.map +1 -0
- package/types/transaction.d.ts +133 -106
- package/types/transaction.d.ts.map +1 -1
- package/types/transfer.d.ts +21 -31
- package/types/transfer.d.ts.map +1 -1
- package/types/types/account.d.ts +66 -0
- package/types/types/account.d.ts.map +1 -0
- package/types/types/algo-http-client-with-retry.d.ts +14 -0
- package/types/types/algo-http-client-with-retry.d.ts.map +1 -0
- package/types/types/amount.d.ts +24 -0
- package/types/types/amount.d.ts.map +1 -0
- package/types/types/app-client.d.ts +408 -0
- package/types/types/app-client.d.ts.map +1 -0
- package/types/types/app-spec.d.ts +154 -0
- package/types/types/app-spec.d.ts.map +1 -0
- package/types/types/app.d.ts +308 -0
- package/types/types/app.d.ts.map +1 -0
- package/types/types/config.d.ts +32 -0
- package/types/types/config.d.ts.map +1 -0
- package/types/types/indexer.d.ts +623 -0
- package/types/types/indexer.d.ts.map +1 -0
- package/types/types/logging.d.ts +13 -0
- package/types/types/logging.d.ts.map +1 -0
- package/types/types/logic-error.d.ts +37 -0
- package/types/types/logic-error.d.ts.map +1 -0
- package/types/types/network-client.d.ts +20 -0
- package/types/types/network-client.d.ts.map +1 -0
- package/types/types/testing.d.ts +89 -0
- package/types/types/testing.d.ts.map +1 -0
- package/types/types/transaction.d.ts +111 -0
- package/types/types/transaction.d.ts.map +1 -0
- package/types/types/transfer.d.ts +32 -0
- package/types/types/transfer.d.ts.map +1 -0
- package/types/types/urlTokenBaseHTTPClient.d.ts +41 -0
- package/types/types/urlTokenBaseHTTPClient.d.ts.map +1 -0
- package/types/util.d.ts +10 -0
- package/types/util.d.ts.map +1 -0
- package/account.d.ts.map +0 -1
- package/account.js.map +0 -1
- package/amount.d.ts.map +0 -1
- package/amount.js.map +0 -1
- package/app-client.d.ts.map +0 -1
- package/app-client.js.map +0 -1
- package/app-deploy.d.ts.map +0 -1
- package/app-deploy.js.map +0 -1
- package/app.d.ts.map +0 -1
- package/app.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/indexer-lookup.d.ts.map +0 -1
- package/indexer-lookup.js.map +0 -1
- package/localnet.d.ts.map +0 -1
- package/localnet.js.map +0 -1
- package/network-client.d.ts.map +0 -1
- package/network-client.js.map +0 -1
- package/testing/account.d.ts.map +0 -1
- package/testing/account.js.map +0 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +0 -1
- package/testing/fixtures/algokit-log-capture-fixture.js.map +0 -1
- package/testing/fixtures/algorand-fixture.d.ts.map +0 -1
- package/testing/fixtures/algorand-fixture.js.map +0 -1
- package/testing/fixtures/index.d.ts.map +0 -1
- package/testing/fixtures/index.js.map +0 -1
- package/testing/index.d.ts.map +0 -1
- package/testing/index.js.map +0 -1
- package/testing/indexer.d.ts.map +0 -1
- package/testing/indexer.js.map +0 -1
- package/testing/test-logger.d.ts.map +0 -1
- package/testing/test-logger.js.map +0 -1
- package/testing/transaction-logger.d.ts.map +0 -1
- package/testing/transaction-logger.js.map +0 -1
- package/transaction.d.ts.map +0 -1
- package/transaction.js.map +0 -1
- package/transfer.d.ts.map +0 -1
- package/transfer.js.map +0 -1
- package/types/account.js.map +0 -1
- package/types/algo-http-client-with-retry.d.ts.map +0 -1
- package/types/algo-http-client-with-retry.js.map +0 -1
- package/types/amount.js.map +0 -1
- package/types/app-client.js.map +0 -1
- package/types/app-spec.d.ts.map +0 -1
- package/types/app.js.map +0 -1
- package/types/config.d.ts.map +0 -1
- package/types/config.js.map +0 -1
- package/types/indexer.d.ts.map +0 -1
- package/types/indexer.js.map +0 -1
- package/types/logging.d.ts.map +0 -1
- package/types/logging.js.map +0 -1
- package/types/logic-error.d.ts.map +0 -1
- package/types/logic-error.js.map +0 -1
- package/types/network-client.js.map +0 -1
- package/types/testing.d.ts.map +0 -1
- package/types/urlTokenBaseHTTPClient.d.ts.map +0 -1
- package/types/urlTokenBaseHTTPClient.js.map +0 -1
- package/util.d.ts.map +0 -1
- package/util.js.map +0 -1
- /package/{account.d.ts → cjs/account.d.ts} +0 -0
- /package/{account.js → cjs/account.js} +0 -0
- /package/{amount.d.ts → cjs/amount.d.ts} +0 -0
- /package/{amount.js → cjs/amount.js} +0 -0
- /package/{app-client.d.ts → cjs/app-client.d.ts} +0 -0
- /package/{app-client.js → cjs/app-client.js} +0 -0
- /package/{app-deploy.d.ts → cjs/app-deploy.d.ts} +0 -0
- /package/{app-deploy.js → cjs/app-deploy.js} +0 -0
- /package/{app.d.ts → cjs/app.d.ts} +0 -0
- /package/{app.js → cjs/app.js} +0 -0
- /package/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/{index.js → cjs/index.js} +0 -0
- /package/{indexer-lookup.d.ts → cjs/indexer-lookup.d.ts} +0 -0
- /package/{indexer-lookup.js → cjs/indexer-lookup.js} +0 -0
- /package/{localnet.d.ts → cjs/localnet.d.ts} +0 -0
- /package/{network-client.d.ts → cjs/network-client.d.ts} +0 -0
- /package/{network-client.js → cjs/network-client.js} +0 -0
- /package/{testing → cjs/testing}/account.d.ts +0 -0
- /package/{testing → cjs/testing}/account.js +0 -0
- /package/{testing → cjs/testing}/fixtures/algokit-log-capture-fixture.d.ts +0 -0
- /package/{testing → cjs/testing}/fixtures/algokit-log-capture-fixture.js +0 -0
- /package/{testing → cjs/testing}/fixtures/algorand-fixture.d.ts +0 -0
- /package/{testing → cjs/testing}/fixtures/algorand-fixture.js +0 -0
- /package/{testing → cjs/testing}/fixtures/index.d.ts +0 -0
- /package/{testing → cjs/testing}/fixtures/index.js +0 -0
- /package/{testing → cjs/testing}/index.d.ts +0 -0
- /package/{testing → cjs/testing}/index.js +0 -0
- /package/{testing → cjs/testing}/indexer.d.ts +0 -0
- /package/{testing → cjs/testing}/indexer.js +0 -0
- /package/{testing → cjs/testing}/test-logger.d.ts +0 -0
- /package/{testing → cjs/testing}/transaction-logger.d.ts +0 -0
- /package/{transaction.d.ts → cjs/transaction.d.ts} +0 -0
- /package/{transaction.js → cjs/transaction.js} +0 -0
- /package/{transfer.d.ts → cjs/transfer.d.ts} +0 -0
- /package/{transfer.js → cjs/transfer.js} +0 -0
- /package/{types → cjs/types}/algo-http-client-with-retry.d.ts +0 -0
- /package/{types → cjs/types}/app-spec.d.ts +0 -0
- /package/{types → cjs/types}/app-spec.js +0 -0
- /package/{types → cjs/types}/app.js +0 -0
- /package/{types → cjs/types}/config.d.ts +0 -0
- /package/{types → cjs/types}/indexer.d.ts +0 -0
- /package/{types → cjs/types}/indexer.js +0 -0
- /package/{types → cjs/types}/logging.d.ts +0 -0
- /package/{types → cjs/types}/logging.js +0 -0
- /package/{types → cjs/types}/logic-error.d.ts +0 -0
- /package/{types → cjs/types}/network-client.js +0 -0
- /package/{types → cjs/types}/testing.d.ts +0 -0
- /package/{types → cjs/types}/testing.js +0 -0
- /package/{types → cjs/types}/transaction.js +0 -0
- /package/{types → cjs/types}/transfer.js +0 -0
- /package/{types → cjs/types}/urlTokenBaseHTTPClient.d.ts +0 -0
- /package/{util.d.ts → cjs/util.d.ts} +0 -0
- /package/{util.js → cjs/util.js} +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const DEFAULT_INDEXER_MAX_API_RESOURCES_PER_ACCOUNT = 1000; //MaxAPIResourcesPerAccount: This is the default maximum, though may be provider specific
|
|
2
|
+
/**
|
|
3
|
+
* Looks up a transaction by ID using Indexer.
|
|
4
|
+
* @param transactionId The ID of the transaction to look up
|
|
5
|
+
* @param indexer An indexer client
|
|
6
|
+
* @returns The result of the look-up
|
|
7
|
+
*/
|
|
8
|
+
export async function lookupTransactionById(transactionId, indexer) {
|
|
9
|
+
return (await indexer.lookupTransactionByID(transactionId).do());
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Looks up an account by address using Indexer.
|
|
13
|
+
* @param transactionId The address of the account to look up
|
|
14
|
+
* @param indexer An indexer client
|
|
15
|
+
* @returns The result of the look-up
|
|
16
|
+
*/
|
|
17
|
+
export async function lookupAccountByAddress(accountAddress, indexer) {
|
|
18
|
+
return (await indexer.lookupAccountByID(accountAddress).do());
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Looks up applications that were created by the given address.
|
|
22
|
+
* @param indexer An indexer instance
|
|
23
|
+
* @param address The address of the creator to look up
|
|
24
|
+
* @param getAll Whether or not to include deleted applications
|
|
25
|
+
* @param paginationLimit The number of records to return per paginated request, default 1000
|
|
26
|
+
* @returns The list of application results
|
|
27
|
+
*/
|
|
28
|
+
export async function lookupAccountCreatedApplicationByAddress(indexer, address, getAll = undefined, paginationLimit) {
|
|
29
|
+
return await executePaginatedRequest((response) => {
|
|
30
|
+
if ('message' in response) {
|
|
31
|
+
throw { status: 404, ...response };
|
|
32
|
+
}
|
|
33
|
+
return response.applications;
|
|
34
|
+
}, (nextToken) => {
|
|
35
|
+
let s = indexer
|
|
36
|
+
.lookupAccountCreatedApplications(address)
|
|
37
|
+
.includeAll(getAll)
|
|
38
|
+
.limit(paginationLimit ?? DEFAULT_INDEXER_MAX_API_RESOURCES_PER_ACCOUNT);
|
|
39
|
+
if (nextToken) {
|
|
40
|
+
s = s.nextToken(nextToken);
|
|
41
|
+
}
|
|
42
|
+
return s;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Allows transactions to be searched for the given criteria.
|
|
47
|
+
* @param indexer An indexer client
|
|
48
|
+
* @param searchCriteria The criteria to search for
|
|
49
|
+
* @param paginationLimit The number of records to return per paginated request, default 1000
|
|
50
|
+
* @returns The search results
|
|
51
|
+
*/
|
|
52
|
+
export async function searchTransactions(indexer, searchCriteria, paginationLimit) {
|
|
53
|
+
let currentRound = 0;
|
|
54
|
+
const transactions = await executePaginatedRequest((response) => {
|
|
55
|
+
if ('message' in response) {
|
|
56
|
+
throw { status: 404, ...response };
|
|
57
|
+
}
|
|
58
|
+
if (response['current-round'] > currentRound) {
|
|
59
|
+
currentRound = response['current-round'];
|
|
60
|
+
}
|
|
61
|
+
return response.transactions;
|
|
62
|
+
}, (nextToken) => {
|
|
63
|
+
let s = searchCriteria(indexer.searchForTransactions()).limit(paginationLimit ?? DEFAULT_INDEXER_MAX_API_RESOURCES_PER_ACCOUNT);
|
|
64
|
+
if (nextToken) {
|
|
65
|
+
s = s.nextToken(nextToken);
|
|
66
|
+
}
|
|
67
|
+
return s;
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
'current-round': currentRound,
|
|
71
|
+
'next-token': '',
|
|
72
|
+
transactions: transactions,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// https://developer.algorand.org/docs/get-details/indexer/#paginated-results
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
+
export async function executePaginatedRequest(
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
extractItems, buildRequest) {
|
|
80
|
+
const results = [];
|
|
81
|
+
let nextToken = undefined;
|
|
82
|
+
// eslint-disable-next-line no-constant-condition
|
|
83
|
+
while (true) {
|
|
84
|
+
const request = buildRequest(nextToken);
|
|
85
|
+
const response = await request.do();
|
|
86
|
+
const items = extractItems(response);
|
|
87
|
+
if (items == null || items.length === 0) {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
results.push(...items);
|
|
91
|
+
nextToken = response['next-token'];
|
|
92
|
+
if (!nextToken) {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return results;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=indexer-lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer-lookup.js","sourceRoot":"","sources":["../../src/indexer-lookup.ts"],"names":[],"mappings":"AAUA,MAAM,6CAA6C,GAAG,IAAI,CAAA,CAAC,yFAAyF;AAEpJ;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,aAAqB,EAAE,OAAgB;IACjF,OAAO,CAAC,MAAM,OAAO,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC,EAAE,EAAE,CAA4B,CAAA;AAC7F,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,cAAsB,EAAE,OAAgB;IACnF,OAAO,CAAC,MAAM,OAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,CAAwB,CAAA;AACtF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,wCAAwC,CAC5D,OAAgB,EAChB,OAAe,EACf,SAA8B,SAAS,EACvC,eAAwB;IAExB,OAAO,MAAM,uBAAuB,CAClC,CAAC,QAA8D,EAAE,EAAE;QACjE,IAAI,SAAS,IAAI,QAAQ,EAAE;YACzB,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAA;SACnC;QACD,OAAO,QAAQ,CAAC,YAAY,CAAA;IAC9B,CAAC,EACD,CAAC,SAAS,EAAE,EAAE;QACZ,IAAI,CAAC,GAAG,OAAO;aACZ,gCAAgC,CAAC,OAAO,CAAC;aACzC,UAAU,CAAC,MAAM,CAAC;aAClB,KAAK,CAAC,eAAe,IAAI,6CAA6C,CAAC,CAAA;QAC1E,IAAI,SAAS,EAAE;YACb,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;SAC3B;QACD,OAAO,CAAC,CAAA;IACV,CAAC,C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AAM,KAAK,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;QACpC,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACvC,MAAK;SACN;QACD,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;QACtB,SAAS,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAA;QAClC,IAAI,CAAC,SAAS,EAAE;YACd,MAAK;SACN;KACF;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
package/esm/localnet.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import algosdk from 'algosdk';
|
|
2
|
+
import { Config } from './';
|
|
3
|
+
import { getDispenserAccount, mnemonicAccount } from './account';
|
|
4
|
+
import { getAlgoKmdClient } from './network-client';
|
|
5
|
+
import { transferAlgos } from './transfer';
|
|
6
|
+
import { AlgoAmount } from './types/amount';
|
|
7
|
+
/** Returns true if the algod client is pointing to a LocalNet Algorand network */
|
|
8
|
+
export async function isLocalNet(algod) {
|
|
9
|
+
const params = await algod.getTransactionParams().do();
|
|
10
|
+
return params.genesisID === 'devnet-v1' || params.genesisID === 'sandnet-v1' || params.genesisID === 'dockernet-v1';
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Gets an account with private key loaded from a KMD wallet of the given name, or alternatively creates one with funds in it via a KMD wallet of the given name.
|
|
14
|
+
*
|
|
15
|
+
* This is useful to get idempotent accounts from LocalNet without having to specify the private key (which will change when resetting the LocalNet).
|
|
16
|
+
*
|
|
17
|
+
* This significantly speeds up local dev time and improves experience since you can write code that *just works* first go without manual config in a fresh LocalNet.
|
|
18
|
+
*
|
|
19
|
+
* If this is used via `getAccount`, then you can even use the same code that runs on production without changes for local development!
|
|
20
|
+
*
|
|
21
|
+
* @param walletAccount The wallet details with:
|
|
22
|
+
* * `name`: The name of the wallet to retrieve / create
|
|
23
|
+
* * `fundWith`: The number of Algos to fund the account with when it gets created, if not specified then 1000 Algos will be funded from the dispenser account
|
|
24
|
+
* @param algod An algod client
|
|
25
|
+
* @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables
|
|
26
|
+
*
|
|
27
|
+
* @returns An Algorand account with private key loaded - either one that already existed in the given KMD wallet, or a new one that is funded for you
|
|
28
|
+
*/
|
|
29
|
+
export async function getOrCreateKmdWalletAccount(walletAccount, algod, kmdClient) {
|
|
30
|
+
const kmd = kmdClient ?? getAlgoKmdClient();
|
|
31
|
+
// Get an existing account from the KMD wallet
|
|
32
|
+
const existing = await getKmdWalletAccount(walletAccount, algod, kmd);
|
|
33
|
+
if (existing) {
|
|
34
|
+
return existing;
|
|
35
|
+
}
|
|
36
|
+
// None existed: create the KMD wallet instead
|
|
37
|
+
const walletId = (await kmd.createWallet(walletAccount.name, '')).wallet.id;
|
|
38
|
+
const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token;
|
|
39
|
+
await kmd.generateKey(walletHandle);
|
|
40
|
+
// Get the account from the new KMD wallet
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
42
|
+
const account = (await getKmdWalletAccount(walletAccount, algod, kmd));
|
|
43
|
+
Config.logger.info(`LocalNet account '${walletAccount.name}' doesn't yet exist; created account ${account.addr} with keys stored in KMD and funding with ${walletAccount.fundWith?.algos ?? 1000} ALGOs`);
|
|
44
|
+
// Fund the account from the dispenser
|
|
45
|
+
await transferAlgos({
|
|
46
|
+
amount: walletAccount.fundWith ?? AlgoAmount.Algos(1000),
|
|
47
|
+
from: await getDispenserAccount(algod, kmd),
|
|
48
|
+
to: account.addr,
|
|
49
|
+
}, algod);
|
|
50
|
+
return account;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
|
|
54
|
+
*
|
|
55
|
+
* @param walletAccount The details of the wallet, with:
|
|
56
|
+
* * `name`: The name of the wallet to retrieve an account from
|
|
57
|
+
* * `predicate`: An optional filter to use to find the account (otherwise it will return a random account from the wallet)
|
|
58
|
+
* @param algod An algod client
|
|
59
|
+
* @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables
|
|
60
|
+
* @example Get default funded account in a LocalNet
|
|
61
|
+
*
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const defaultDispenserAccount = await getKmdWalletAccount(algod,
|
|
64
|
+
* 'unencrypted-default-wallet',
|
|
65
|
+
* a => a.status !== 'Offline' && a.amount > 1_000_000_000
|
|
66
|
+
* )
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export async function getKmdWalletAccount(walletAccount, algod, kmdClient) {
|
|
70
|
+
const { name, predicate } = walletAccount;
|
|
71
|
+
const kmd = kmdClient ?? getAlgoKmdClient();
|
|
72
|
+
const wallets = await kmd.listWallets();
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
|
+
const wallet = wallets.wallets.filter((w) => w.name === name);
|
|
75
|
+
if (wallet.length === 0) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
const walletId = wallet[0].id;
|
|
79
|
+
const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token;
|
|
80
|
+
const keyIds = (await kmd.listKeys(walletHandle)).addresses;
|
|
81
|
+
let i = 0;
|
|
82
|
+
if (predicate) {
|
|
83
|
+
for (i = 0; i < keyIds.length; i++) {
|
|
84
|
+
const key = keyIds[i];
|
|
85
|
+
const account = await algod.accountInformation(key).do();
|
|
86
|
+
if (predicate(account)) {
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (i >= keyIds.length) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const accountKey = (await kmd.exportKey(walletHandle, '', keyIds[i])).private_key;
|
|
95
|
+
const accountMnemonic = algosdk.secretKeyToMnemonic(accountKey);
|
|
96
|
+
return mnemonicAccount(accountMnemonic);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts)
|
|
100
|
+
*
|
|
101
|
+
* @param algod An algod client
|
|
102
|
+
* @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables
|
|
103
|
+
*/
|
|
104
|
+
export async function getLocalNetDispenserAccount(algod, kmd) {
|
|
105
|
+
if (!(await isLocalNet(algod))) {
|
|
106
|
+
throw "Can't get default account from non LocalNet network";
|
|
107
|
+
}
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
109
|
+
return (await getKmdWalletAccount({ name: 'unencrypted-default-wallet', predicate: (a) => a.status !== 'Offline' && a.amount > 1_000_000_000 }, algod, kmd));
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=localnet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localnet.js","sourceRoot":"","sources":["../../src/localnet.ts"],"names":[],"mappings":"AAAA,OAAO,OAAkC,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAA;AAC3B,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,kFAAkF;AAClF,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,KAAc;IAC7C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,oBAAoB,EAAE,CAAC,EAAE,EAAE,CAAA;IAEtD,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW,IAAI,MAAM,CAAC,SAAS,KAAK,YAAY,IAAI,MAAM,CAAC,SAAS,KAAK,cAAc,CAAA;AACrH,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,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,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;IAEjF,MAAM,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAA;IAC/D,OAAO,eAAe,CAAC,eAAe,CAAC,CAAA;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,KAAc,EAAE,GAAS;IACzE,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE;QAC9B,MAAM,qDAAqD,CAAA;KAC5D;IAED,oEAAoE;IACpE,OAAO,CAAC,MAAM,mBAAmB,CAC/B,EAAE,IAAI,EAAE,4BAA4B,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,GAAG,aAAa,EAAE,EAC5G,KAAK,EACL,GAAG,CACJ,CAAE,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import algosdk, { Indexer, Kmd } from 'algosdk';
|
|
2
|
+
import { AlgoHttpClientWithRetry } from './types/algo-http-client-with-retry';
|
|
3
|
+
/** Retrieve configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment not algod-side) */
|
|
4
|
+
export function getConfigFromEnvOrDefaults() {
|
|
5
|
+
if (!process || !process.env) {
|
|
6
|
+
throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead');
|
|
7
|
+
}
|
|
8
|
+
const algodConfig = !process.env.ALGOD_SERVER
|
|
9
|
+
? getDefaultLocalNetConfig('algod')
|
|
10
|
+
: { server: process.env.ALGOD_SERVER, port: process.env.ALGOD_PORT, token: process.env.ALGOD_TOKEN };
|
|
11
|
+
const indexerConfig = !process.env.INDEXER_SERVER
|
|
12
|
+
? getDefaultLocalNetConfig('indexer')
|
|
13
|
+
: {
|
|
14
|
+
server: process.env.INDEXER_SERVER,
|
|
15
|
+
port: process.env.INDEXER_PORT,
|
|
16
|
+
token: process.env.INDEXER_TOKEN,
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
algodConfig,
|
|
20
|
+
indexerConfig,
|
|
21
|
+
kmdConfig: process && process.env && process.env.ALGOD_SERVER
|
|
22
|
+
? { ...algodConfig, port: process?.env?.KMD_PORT ?? '4002' }
|
|
23
|
+
: getDefaultLocalNetConfig('kmd'),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
|
|
27
|
+
export function getAlgodConfigFromEnvironment() {
|
|
28
|
+
if (!process || !process.env) {
|
|
29
|
+
throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead');
|
|
30
|
+
}
|
|
31
|
+
if (!process.env.ALGOD_SERVER) {
|
|
32
|
+
throw new Error('Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables');
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
server: process.env.ALGOD_SERVER,
|
|
36
|
+
port: process.env.ALGOD_PORT,
|
|
37
|
+
token: process.env.ALGOD_TOKEN,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
|
|
41
|
+
export function getIndexerConfigFromEnvironment() {
|
|
42
|
+
if (!process || !process.env) {
|
|
43
|
+
throw new Error('Attempt to get default indexer configuration from a non Node.js context; supply the config instead');
|
|
44
|
+
}
|
|
45
|
+
if (!process.env.INDEXER_SERVER) {
|
|
46
|
+
throw new Error('Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables');
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
server: process.env.INDEXER_SERVER,
|
|
50
|
+
port: process.env.INDEXER_PORT,
|
|
51
|
+
token: process.env.INDEXER_TOKEN,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Returns the Algorand configuration to point to the AlgoNode service
|
|
55
|
+
*
|
|
56
|
+
* @param network Which network to connect to - TestNet or MainNet
|
|
57
|
+
* @param config Which algod config to return - Algod or Indexer
|
|
58
|
+
*/
|
|
59
|
+
export function getAlgoNodeConfig(network, config) {
|
|
60
|
+
return {
|
|
61
|
+
server: `https://${network}-${config === 'algod' ? 'api' : 'idx'}.algonode.cloud/`,
|
|
62
|
+
port: 443,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Returns the Algorand configuration to point to the default LocalNet
|
|
66
|
+
*
|
|
67
|
+
* @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number
|
|
68
|
+
*/
|
|
69
|
+
export function getDefaultLocalNetConfig(configOrPort) {
|
|
70
|
+
return {
|
|
71
|
+
server: `http://localhost`,
|
|
72
|
+
port: configOrPort === 'algod' ? 4001 : configOrPort === 'indexer' ? 8980 : configOrPort === 'kmd' ? 4002 : configOrPort,
|
|
73
|
+
token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function getAlgoTokenHeader(server, token, defaultHeader) {
|
|
77
|
+
// Purestake uses a slightly different API key header than the default
|
|
78
|
+
if (server.includes('purestake.io') && typeof token === 'string')
|
|
79
|
+
return { 'X-API-Key': token };
|
|
80
|
+
// Because we override the default HTTP Client construction (to get retries) we need to put a string token into the standard header ourselves
|
|
81
|
+
return typeof token === 'string' ? { [defaultHeader ?? 'X-Algo-API-Token']: token } : token ?? {};
|
|
82
|
+
}
|
|
83
|
+
/** Returns an algod SDK client that automatically retries on idempotent calls
|
|
84
|
+
*
|
|
85
|
+
* @param config The config if you want to override the default (getting config from process.env)
|
|
86
|
+
* @example Default (load from environment variables)
|
|
87
|
+
*
|
|
88
|
+
* ```typescript
|
|
89
|
+
* // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN
|
|
90
|
+
* // Automatically detects if you are using PureStake to switch in the right header name for ALGOD_TOKEN
|
|
91
|
+
* const algod = getAlgoClient()
|
|
92
|
+
* await algod.healthCheck().do()
|
|
93
|
+
* ```
|
|
94
|
+
* @example AlgoNode (testnet)
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const algod = getAlgoClient(getAlgoNodeConfig('testnet', 'algod'))
|
|
97
|
+
* await algod.healthCheck().do()
|
|
98
|
+
* ```
|
|
99
|
+
* @example AlgoNode (mainnet)
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const algod = getAlgoClient(getAlgoNodeConfig('mainnet', 'algod'))
|
|
102
|
+
* await algod.healthCheck().do()
|
|
103
|
+
* ```
|
|
104
|
+
* @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const algod = getAlgoClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
|
|
107
|
+
* await algod.healthCheck().do()
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export function getAlgoClient(config) {
|
|
111
|
+
const { token, server, port } = config ?? getAlgodConfigFromEnvironment();
|
|
112
|
+
const httpClientWithRetry = new AlgoHttpClientWithRetry(getAlgoTokenHeader(server, token), server, port);
|
|
113
|
+
return new algosdk.Algodv2(httpClientWithRetry, server);
|
|
114
|
+
}
|
|
115
|
+
/** Returns an indexer SDK client that automatically retries on idempotent calls
|
|
116
|
+
*
|
|
117
|
+
* @param config The config if you want to override the default (getting config from process.env)
|
|
118
|
+
* @example Default (load from environment variables)
|
|
119
|
+
*
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN
|
|
122
|
+
* // Automatically detects if you are using PureStake to switch in the right header name for INDEXER_TOKEN
|
|
123
|
+
* const indexer = getAlgoIndexerClient()
|
|
124
|
+
* await indexer.makeHealthCheck().do()
|
|
125
|
+
* ```
|
|
126
|
+
* @example AlgoNode (testnet)
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const indexer = getAlgoIndexerClient(getAlgoNodeConfig('testnet', 'indexer'))
|
|
129
|
+
* await indexer.makeHealthCheck().do()
|
|
130
|
+
* ```
|
|
131
|
+
* @example AlgoNode (mainnet)
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const indexer = getAlgoIndexerClient(getAlgoNodeConfig('mainnet', 'indexer'))
|
|
134
|
+
* await indexer.makeHealthCheck().do()
|
|
135
|
+
* ```
|
|
136
|
+
* @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const indexer = getAlgoIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
|
|
139
|
+
* await indexer.makeHealthCheck().do()
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export function getAlgoIndexerClient(config) {
|
|
143
|
+
const { token, server, port } = config ?? getIndexerConfigFromEnvironment();
|
|
144
|
+
const httpClientWithRetry = new AlgoHttpClientWithRetry(getAlgoTokenHeader(server, token, 'X-Indexer-API-Token'), server, port);
|
|
145
|
+
return new Indexer(httpClientWithRetry);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Returns a KMD SDK client that automatically retries on idempotent calls
|
|
149
|
+
*
|
|
150
|
+
* KMD client allows you to export private keys, which is useful to get the default account in a LocalNet network.
|
|
151
|
+
*
|
|
152
|
+
* @param config The config if you want to override the default (getting config from process.env)
|
|
153
|
+
* @example Default (load from environment variables)
|
|
154
|
+
*
|
|
155
|
+
* ```typescript
|
|
156
|
+
* // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN
|
|
157
|
+
* const kmd = getAlgoKmdClient()
|
|
158
|
+
* ```
|
|
159
|
+
* @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const kmd = getAlgoKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export function getAlgoKmdClient(config) {
|
|
165
|
+
const { token, server } = config ?? getAlgodConfigFromEnvironment();
|
|
166
|
+
// We can only use Kmd on the LocalNet otherwise it's not exposed so this makes some assumptions
|
|
167
|
+
// (e.g. same token and server as algod and port 4002 by default)
|
|
168
|
+
return new Kmd(token, server, process?.env?.KMD_PORT ?? '4002');
|
|
169
|
+
}
|
|
170
|
+
export async function isTestNet(algod) {
|
|
171
|
+
const params = await algod.getTransactionParams().do();
|
|
172
|
+
return params.genesisID === 'testnet-v1';
|
|
173
|
+
}
|
|
174
|
+
export async function isMainNet(algod) {
|
|
175
|
+
const params = await algod.getTransactionParams().do();
|
|
176
|
+
return params.genesisID === 'mainnet-v1';
|
|
177
|
+
}
|
|
178
|
+
export { isLocalNet } from './localnet';
|
|
179
|
+
//# sourceMappingURL=network-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-client.js","sourceRoot":"","sources":["../../src/network-client.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAW,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAG7E,uJAAuJ;AACvJ,MAAM,UAAU,0BAA0B;IACxC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,kGAAkG,CAAC,CAAA;KACpH;IACD,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,GAAG,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AAC,CAAA;AAC3E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAc;IAC5C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,oBAAoB,EAAE,CAAC,EAAE,EAAE,CAAA;IACtD,OAAO,MAAM,CAAC,SAAS,KAAK,YAAY,CAAA;AAC1C,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAc;IAC5C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,oBAAoB,EAAE,CAAC,EAAE,EAAE,CAAA;IACtD,OAAO,MAAM,CAAC,SAAS,KAAK,YAAY,CAAA;AAC1C,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import algosdk from 'algosdk';
|
|
2
|
+
import { Config } from '../';
|
|
3
|
+
import { getDispenserAccount } from '../account';
|
|
4
|
+
import { transferAlgos } from '../transfer';
|
|
5
|
+
/**
|
|
6
|
+
* Creates an ephemeral Algorand account for the purposes of testing.
|
|
7
|
+
* Returns a newly created random test account that is funded from the dispenser
|
|
8
|
+
* DO NOT USE THIS TO CREATE A MAINNET ACCOUNT!
|
|
9
|
+
* Note: By default this will log the mnemonic of the account.
|
|
10
|
+
* @param param0 The config for the test account to generate
|
|
11
|
+
* @param algod An algod client
|
|
12
|
+
* @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables
|
|
13
|
+
* @returns The account, with private key loaded
|
|
14
|
+
*/
|
|
15
|
+
export async function getTestAccount({ suppressLog, initialFunds }, algod, kmd) {
|
|
16
|
+
const account = algosdk.generateAccount();
|
|
17
|
+
Config.getLogger(suppressLog).info(`New test account created with address '${account.addr}' and mnemonic '${algosdk.secretKeyToMnemonic(account.sk)}'.`);
|
|
18
|
+
const dispenser = await getDispenserAccount(algod, kmd);
|
|
19
|
+
await transferAlgos({ from: dispenser, to: account.addr, amount: initialFunds, note: 'Funding test account', suppressLog }, algod);
|
|
20
|
+
const accountInfo = await algod.accountInformation(account.addr).do();
|
|
21
|
+
Config.getLogger(suppressLog).info('Test account funded; account balance: %d µAlgos', accountInfo.amount);
|
|
22
|
+
return account;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/testing/account.ts"],"names":[],"mappings":"AAAA,OAAO,OAAkC,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAG3C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EAAE,WAAW,EAAE,YAAY,EAAwB,EAAE,KAAc,EAAE,GAAS;IACjH,MAAM,OAAO,GAAG,OAAO,CAAC,eAAe,EAAE,CAAA;IAEzC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAChC,0CAA0C,OAAO,CAAC,IAAI,mBAAmB,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CACrH,CAAA;IAED,MAAM,SAAS,GAAG,MAAM,mBAAmB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IAEvD,MAAM,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,sBAAsB,EAAE,WAAW,EAAE,EAAE,KAAK,CAAC,CAAA;IAElI,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,CAAA;IAErE,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,iDAAiD,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAEzG,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Config } from '../../';
|
|
2
|
+
import { TestLogger } from '../test-logger';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a test fixture for capturing AlgoKit logs.
|
|
5
|
+
*
|
|
6
|
+
* @example ```typescript
|
|
7
|
+
* const logs = algoKitLogCaptureFixture()
|
|
8
|
+
*
|
|
9
|
+
* beforeEach(logs.beforeEach)
|
|
10
|
+
* afterEach(logs.afterEach)
|
|
11
|
+
*
|
|
12
|
+
* test('My test', () => {
|
|
13
|
+
* const capturedLogs = logs.testLogger.capturedLogs
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @returns The fixture
|
|
18
|
+
*/
|
|
19
|
+
export const algoKitLogCaptureFixture = () => {
|
|
20
|
+
const originalLogger = Config.logger;
|
|
21
|
+
let hybridLogger;
|
|
22
|
+
return {
|
|
23
|
+
get testLogger() {
|
|
24
|
+
return hybridLogger;
|
|
25
|
+
},
|
|
26
|
+
beforeEach: () => {
|
|
27
|
+
hybridLogger = new TestLogger(originalLogger);
|
|
28
|
+
Config.configure({
|
|
29
|
+
logger: hybridLogger,
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
afterEach: () => {
|
|
33
|
+
Config.configure({
|
|
34
|
+
logger: originalLogger,
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=algokit-log-capture-fixture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"algokit-log-capture-fixture.js","sourceRoot":"","sources":["../../../../src/testing/fixtures/algokit-log-capture-fixture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAmC,GAAG,EAAE;IAC3E,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAA;IAEpC,IAAI,YAAwB,CAAA;IAE5B,OAAO;QACL,IAAI,UAAU;YACZ,OAAO,YAAY,CAAA;QACrB,CAAC;QACD,UAAU,EAAE,GAAG,EAAE;YACf,YAAY,GAAG,IAAI,UAAU,CAAC,cAAc,CAAC,CAAA;YAC7C,MAAM,CAAC,SAAS,CAAC;gBACf,MAAM,EAAE,YAAY;aACrB,CAAC,CAAA;QACJ,CAAC;QACD,SAAS,EAAE,GAAG,EAAE;YACd,MAAM,CAAC,SAAS,CAAC;gBACf,MAAM,EAAE,cAAc;aACvB,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { getTestAccount, runWhenIndexerCaughtUp, TransactionLogger } from '../';
|
|
2
|
+
import { algos, Config, getAlgoClient, getAlgoIndexerClient, getAlgoKmdClient, getConfigFromEnvOrDefaults, lookupTransactionById, } from '../../';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a test fixture for automated testing against Algorand.
|
|
5
|
+
* By default it tests against an environment variable specified client
|
|
6
|
+
* if the standard environment variables are specified, otherwise against
|
|
7
|
+
* a default LocalNet instance, but you can pass in an algod, indexer
|
|
8
|
+
* and/or kmd if you want to test against an explicitly defined network.
|
|
9
|
+
*
|
|
10
|
+
* @example ```typescript
|
|
11
|
+
* const algorand = algorandFixture(undefined, getConfigFromEnvOrDefaults())
|
|
12
|
+
*
|
|
13
|
+
* beforeEach(algorand.beforeEach, 10_000)
|
|
14
|
+
*
|
|
15
|
+
* test('My test', async () => {
|
|
16
|
+
* const {algod, indexer, testAccount, ...} = algorand.context
|
|
17
|
+
* // test things...
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param fixtureConfig The fixture configuration
|
|
22
|
+
* @param config The algo configuration
|
|
23
|
+
* @returns The fixture
|
|
24
|
+
*/
|
|
25
|
+
export function algorandFixture(fixtureConfig, config) {
|
|
26
|
+
config = config || getConfigFromEnvOrDefaults();
|
|
27
|
+
const algod = fixtureConfig?.algod ?? getAlgoClient(config.algodConfig);
|
|
28
|
+
const indexer = fixtureConfig?.indexer ?? getAlgoIndexerClient(config.indexerConfig);
|
|
29
|
+
const kmd = fixtureConfig?.kmd ?? getAlgoKmdClient(config.kmdConfig);
|
|
30
|
+
let context;
|
|
31
|
+
const beforeEach = async () => {
|
|
32
|
+
Config.configure({ debug: true });
|
|
33
|
+
const transactionLogger = new TransactionLogger();
|
|
34
|
+
const transactionLoggerAlgod = transactionLogger.capture(algod);
|
|
35
|
+
context = {
|
|
36
|
+
algod: transactionLoggerAlgod,
|
|
37
|
+
indexer: indexer,
|
|
38
|
+
kmd: kmd,
|
|
39
|
+
testAccount: await getTestAccount({ initialFunds: fixtureConfig?.testAccountFunding ?? algos(10), suppressLog: true }, transactionLoggerAlgod, kmd),
|
|
40
|
+
generateAccount: (params) => getTestAccount(params, transactionLoggerAlgod, kmd),
|
|
41
|
+
transactionLogger: transactionLogger,
|
|
42
|
+
waitForIndexer: () => transactionLogger.waitForIndexer(indexer),
|
|
43
|
+
waitForIndexerTransaction: (transactionId) => runWhenIndexerCaughtUp(() => lookupTransactionById(transactionId, indexer)),
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
get context() {
|
|
48
|
+
return context;
|
|
49
|
+
},
|
|
50
|
+
beforeEach,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=algorand-fixture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"algorand-fixture.js","sourceRoot":"","sources":["../../../../src/testing/fixtures/algorand-fixture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,KAAK,CAA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AAC,iBAAiB,CAAC,cAAc,CAAC,OAAO,CAAC;YAC/D,yBAAyB,EAAE,CAAC,aAAqB,EAAE,EAAE,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;SAClI,CAAA;IACH,CAAC,CAAA;IAED,OAAO;QACL,IAAI,OAAO;YACT,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,UAAU;KACX,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/testing/fixtures/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the given indexer call until a 404 error is no longer returned.
|
|
3
|
+
* Tried every 200ms up to 20 times.
|
|
4
|
+
* Very rudimentary implementation designed for automated testing.
|
|
5
|
+
* @example ```typescript
|
|
6
|
+
* const transaction = await runWhenIndexerCaughtUp(() => indexer.lookupTransactionByID(txnId).do())
|
|
7
|
+
* ```
|
|
8
|
+
* @param run The code to run
|
|
9
|
+
* @returns The result (as a promise), or throws if the indexer didn't catch up in time
|
|
10
|
+
*/
|
|
11
|
+
export async function runWhenIndexerCaughtUp(run) {
|
|
12
|
+
let result = null;
|
|
13
|
+
let ok = false;
|
|
14
|
+
let tries = 0;
|
|
15
|
+
while (!ok) {
|
|
16
|
+
try {
|
|
17
|
+
result = await run();
|
|
18
|
+
ok = true;
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
if (e?.status === 404) {
|
|
23
|
+
tries++;
|
|
24
|
+
if (tries > 20) {
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=indexer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer.js","sourceRoot":"","sources":["../../../src/testing/indexer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAI,GAAqB;IACnE,IAAI,MAAM,GAAa,IAAI,CAAA;IAC3B,IAAI,EAAE,GAAG,KAAK,CAAA;IACd,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,OAAO,CAAC,EAAE,EAAE;QACV,IAAI;YACF,MAAM,GAAG,MAAM,GAAG,EAAE,CAAA;YACpB,EAAE,GAAG,IAAI,CAAA;YACT,8DAA8D;SAC/D;QAAC,OAAO,CAAM,EAAE;YACf,IAAI,CAAC,EAAE,MAAM,KAAK,GAAG,EAAE;gBACrB,KAAK,EAAE,CAAA;gBACP,IAAI,KAAK,GAAG,EAAE,EAAE;oBACd,MAAM,CAAC,CAAA;iBACR;gBACD,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;aAC/D;iBAAM;gBACL,MAAM,CAAC,CAAA;aACR;SACF;KACF;IAED,OAAO,MAAW,CAAA;AACpB,CAAC"}
|