@algorandfoundation/algokit-utils 1.0.0-beta.2 → 1.0.0-beta.20
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/{dist/account.d.ts → account.d.ts} +29 -31
- package/account.d.ts.map +1 -0
- package/{dist/account.js → account.js} +43 -43
- package/account.js.map +1 -0
- package/amount.d.ts +8 -0
- package/amount.d.ts.map +1 -0
- package/amount.js +24 -0
- package/amount.js.map +1 -0
- package/app.d.ts +51 -0
- package/app.d.ts.map +1 -0
- package/app.js +288 -0
- package/app.js.map +1 -0
- package/application-client.d.ts +10 -0
- package/application-client.d.ts.map +1 -0
- package/application-client.js +15 -0
- package/application-client.js.map +1 -0
- package/deploy-app.d.ts +93 -0
- package/deploy-app.d.ts.map +1 -0
- package/{dist/deploy-app.js → deploy-app.js} +129 -137
- package/deploy-app.js.map +1 -0
- package/index.d.ts +14 -0
- package/index.d.ts.map +1 -0
- package/{dist/index.js → index.js} +6 -4
- package/index.js.map +1 -0
- package/{dist/indexer-lookup.d.ts → indexer-lookup.d.ts} +1 -1
- package/{dist/indexer-lookup.d.ts.map → indexer-lookup.d.ts.map} +1 -1
- package/{dist/localnet.d.ts → localnet.d.ts} +4 -4
- package/localnet.d.ts.map +1 -0
- package/{dist/localnet.js → localnet.js} +10 -10
- package/localnet.js.map +1 -0
- package/{dist/network-client.d.ts → network-client.d.ts} +11 -20
- package/network-client.d.ts.map +1 -0
- package/{dist/network-client.js → network-client.js} +11 -11
- package/{dist/network-client.js.map → network-client.js.map} +1 -1
- package/package.json +4 -92
- package/testing/account.d.ts +14 -0
- package/testing/account.d.ts.map +1 -0
- package/testing/account.js +31 -0
- package/testing/account.js.map +1 -0
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +19 -0
- package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +1 -0
- package/testing/fixtures/algokit-log-capture-fixture.js +43 -0
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -0
- package/testing/fixtures/algorand-fixture.d.ts +20 -0
- package/testing/fixtures/algorand-fixture.d.ts.map +1 -0
- package/testing/fixtures/algorand-fixture.js +49 -0
- package/testing/fixtures/algorand-fixture.js.map +1 -0
- package/testing/fixtures/index.d.ts +3 -0
- package/testing/fixtures/index.d.ts.map +1 -0
- package/testing/fixtures/index.js +19 -0
- package/testing/fixtures/index.js.map +1 -0
- package/testing/index.d.ts +6 -0
- package/testing/index.d.ts.map +1 -0
- package/testing/index.js +22 -0
- package/testing/index.js.map +1 -0
- package/testing/indexer.d.ts +12 -0
- package/testing/indexer.d.ts.map +1 -0
- package/testing/indexer.js +39 -0
- package/testing/indexer.js.map +1 -0
- package/testing/test-logger.d.ts +39 -0
- package/testing/test-logger.d.ts.map +1 -0
- package/testing/test-logger.js +69 -0
- package/testing/test-logger.js.map +1 -0
- package/testing/transaction-logger.d.ts +29 -0
- package/testing/transaction-logger.d.ts.map +1 -0
- package/testing/transaction-logger.js +71 -0
- package/testing/transaction-logger.js.map +1 -0
- package/transaction.d.ts +80 -0
- package/transaction.d.ts.map +1 -0
- package/{dist/transaction.js → transaction.js} +88 -106
- package/transaction.js.map +1 -0
- package/transfer.d.ts +21 -0
- package/transfer.d.ts.map +1 -0
- package/transfer.js +65 -0
- package/transfer.js.map +1 -0
- package/types/account.d.ts +52 -0
- package/types/account.d.ts.map +1 -0
- package/types/account.js +86 -0
- package/types/account.js.map +1 -0
- package/types/algo-http-client-with-retry.d.ts.map +1 -0
- package/{dist → types}/algo-http-client-with-retry.js +2 -2
- package/types/algo-http-client-with-retry.js.map +1 -0
- package/{dist/algod-type.d.ts → types/algod.d.ts} +6 -7
- package/types/algod.d.ts.map +1 -0
- package/{dist/algod-type.js → types/algod.js} +1 -1
- package/types/algod.js.map +1 -0
- package/{dist/algo-amount.d.ts → types/amount.d.ts} +3 -1
- package/types/amount.d.ts.map +1 -0
- package/{dist/algo-amount.js → types/amount.js} +7 -1
- package/types/amount.js.map +1 -0
- package/types/app.d.ts +234 -0
- package/types/app.d.ts.map +1 -0
- package/types/app.js +32 -0
- package/types/app.js.map +1 -0
- package/types/application-client.d.ts +147 -0
- package/types/application-client.d.ts.map +1 -0
- package/types/application-client.js +340 -0
- package/types/application-client.js.map +1 -0
- package/types/appspec.d.ts +77 -0
- package/types/appspec.d.ts.map +1 -0
- package/types/appspec.js +15 -0
- package/types/appspec.js.map +1 -0
- package/types/config.d.ts +15 -0
- package/types/config.d.ts.map +1 -0
- package/types/config.js +27 -0
- package/types/config.js.map +1 -0
- package/{dist/indexer-type.d.ts → types/indexer.d.ts} +9 -10
- package/types/indexer.d.ts.map +1 -0
- package/{dist/indexer-type.js → types/indexer.js} +1 -1
- package/types/indexer.js.map +1 -0
- package/{dist/config.d.ts → types/logging.d.ts} +3 -15
- package/types/logging.d.ts.map +1 -0
- package/types/logging.js +27 -0
- package/types/logging.js.map +1 -0
- package/types/logic-error.d.ts +16 -0
- package/types/logic-error.d.ts.map +1 -0
- package/types/logic-error.js +35 -0
- package/types/logic-error.js.map +1 -0
- package/types/network-client.d.ts +11 -0
- package/types/network-client.d.ts.map +1 -0
- package/types/network-client.js +3 -0
- package/types/network-client.js.map +1 -0
- package/types/testing.d.ts +89 -0
- package/types/testing.d.ts.map +1 -0
- package/types/testing.js +3 -0
- package/types/testing.js.map +1 -0
- package/types/transaction.d.ts +67 -0
- package/types/transaction.d.ts.map +1 -0
- package/types/transaction.js +3 -0
- package/types/transaction.js.map +1 -0
- package/types/transfer.d.ts +32 -0
- package/types/transfer.d.ts.map +1 -0
- package/types/transfer.js +3 -0
- package/types/transfer.js.map +1 -0
- package/types/urlTokenBaseHTTPClient.d.ts.map +1 -0
- package/types/urlTokenBaseHTTPClient.js.map +1 -0
- package/LICENSE +0 -21
- package/README.md +0 -31
- package/dist/account.d.ts.map +0 -1
- package/dist/account.js.map +0 -1
- package/dist/algo-amount.d.ts.map +0 -1
- package/dist/algo-amount.js.map +0 -1
- package/dist/algo-http-client-with-retry.d.ts.map +0 -1
- package/dist/algo-http-client-with-retry.js.map +0 -1
- package/dist/algod-type.d.ts.map +0 -1
- package/dist/algod-type.js.map +0 -1
- package/dist/app.d.ts +0 -150
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js +0 -160
- package/dist/app.js.map +0 -1
- package/dist/application-client.d.ts +0 -1
- package/dist/application-client.d.ts.map +0 -1
- package/dist/application-client.js +0 -69
- package/dist/application-client.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -28
- package/dist/config.js.map +0 -1
- package/dist/deploy-app.d.ts +0 -149
- package/dist/deploy-app.d.ts.map +0 -1
- package/dist/deploy-app.js.map +0 -1
- package/dist/index.d.ts +0 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/indexer-type.d.ts.map +0 -1
- package/dist/indexer-type.js.map +0 -1
- package/dist/localnet.d.ts.map +0 -1
- package/dist/localnet.js.map +0 -1
- package/dist/network-client.d.ts.map +0 -1
- package/dist/package.json +0 -20
- package/dist/transaction.d.ts +0 -147
- package/dist/transaction.d.ts.map +0 -1
- package/dist/transaction.js.map +0 -1
- package/dist/transfer.d.ts +0 -24
- package/dist/transfer.d.ts.map +0 -1
- package/dist/transfer.js +0 -33
- package/dist/transfer.js.map +0 -1
- package/dist/urlTokenBaseHTTPClient.d.ts.map +0 -1
- package/dist/urlTokenBaseHTTPClient.js.map +0 -1
- /package/{dist/indexer-lookup.js → indexer-lookup.js} +0 -0
- /package/{dist/indexer-lookup.js.map → indexer-lookup.js.map} +0 -0
- /package/{dist → types}/algo-http-client-with-retry.d.ts +0 -0
- /package/{dist → types}/urlTokenBaseHTTPClient.d.ts +0 -0
- /package/{dist → types}/urlTokenBaseHTTPClient.js +0 -0
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import algosdk, { Account, Algodv2, Kmd } from 'algosdk';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import algosdk, { Account, Algodv2, Kmd, MultisigMetadata, TransactionSigner } from 'algosdk';
|
|
2
|
+
import { MultisigAccount, SigningAccount, TransactionSignerAccount } from './types/account';
|
|
3
|
+
import { AlgoAmount } from './types/amount';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Returns an account wrapper that supports partial or full multisig signing.
|
|
6
|
+
* @param multisigParams The parameters that define the multisig account
|
|
7
|
+
* @param signingAccounts The signers that are currently present
|
|
8
|
+
* @returns A multisig account wrapper
|
|
6
9
|
*/
|
|
7
|
-
export declare
|
|
10
|
+
export declare function multisigAccount(multisigParams: MultisigMetadata, signingAccounts: (Account | SigningAccount)[]): MultisigAccount;
|
|
11
|
+
/**
|
|
12
|
+
* Returns an account wrapper that supports a rekeyed account.
|
|
13
|
+
* @param account The account, with private key loaded, that is signing
|
|
14
|
+
* @param sender The address of the rekeyed account that will act as a sender
|
|
15
|
+
* @returns The @see SigningAccount wrapper
|
|
16
|
+
*/
|
|
17
|
+
export declare function rekeyedAccount(account: Account, sender: string): SigningAccount;
|
|
18
|
+
/**
|
|
19
|
+
* Returns an account wrapper that supports a transaction signer with associated sender address.
|
|
20
|
+
* @param signer The transaction signer
|
|
21
|
+
* @param sender The address of sender account
|
|
22
|
+
* @returns The @see SigningAccount wrapper
|
|
23
|
+
*/
|
|
24
|
+
export declare function transactionSignerAccount(signer: TransactionSigner, sender: string): TransactionSignerAccount;
|
|
8
25
|
/** Returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
|
|
9
26
|
*
|
|
10
27
|
* This is a wrapper around algosdk.mnemonicToSecretKey to provide a more friendly/obvious name.
|
|
@@ -12,24 +29,24 @@ export declare const DISPENSER_ACCOUNT = "DISPENSER";
|
|
|
12
29
|
* @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
|
|
13
30
|
* never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
|
|
14
31
|
*/
|
|
15
|
-
export declare function
|
|
32
|
+
export declare function mnemonicAccount(mnemonicSecret: string): Account;
|
|
16
33
|
/**
|
|
17
34
|
* Returns an Algorand account with private key loaded by convention based on the given name identifier.
|
|
18
35
|
*
|
|
19
36
|
* Note: This function expects to run in a Node.js environment.
|
|
20
37
|
*
|
|
21
38
|
* ## Convention:
|
|
22
|
-
* * **Non-LocalNet:** will load process.env['{NAME}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
|
|
39
|
+
* * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
|
|
23
40
|
* never commit it into source control and ideally load it via a secret storage service rather than the file system.
|
|
24
|
-
* If process.env['{NAME}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
|
|
25
|
-
* * **LocalNet:** will load the account from a KMD wallet called {NAME} and if that wallet doesn't exist it will create it and fund the account for you
|
|
41
|
+
* If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
|
|
42
|
+
* * **LocalNet:** will load the account from a KMD wallet called \{NAME\} and if that wallet doesn't exist it will create it and fund the account for you
|
|
26
43
|
*
|
|
27
44
|
* This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).
|
|
28
45
|
*
|
|
29
46
|
* @example Default
|
|
30
47
|
*
|
|
31
48
|
* If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
|
|
32
|
-
* ```
|
|
49
|
+
* ```typescript
|
|
33
50
|
* const account = await getAccount('ACCOUNT', algod)
|
|
34
51
|
* ```
|
|
35
52
|
*
|
|
@@ -46,25 +63,6 @@ export declare function getAccount(account: {
|
|
|
46
63
|
name: string;
|
|
47
64
|
fundWith?: AlgoAmount;
|
|
48
65
|
} | string, algod: Algodv2, kmdClient?: Kmd): Promise<Account | SigningAccount>;
|
|
49
|
-
/**
|
|
50
|
-
* Parameters for the getTestAccount function.
|
|
51
|
-
*/
|
|
52
|
-
interface GetTestAccountParams {
|
|
53
|
-
/** Initial funds to ensure the account has */
|
|
54
|
-
initialFunds: AlgoAmount;
|
|
55
|
-
/** Whether to suppress the log (which includes a mnemonic) or not (default: do not supress the log) */
|
|
56
|
-
suppressLog?: boolean;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Creates an ephemeral Algorand account for the purposes of testing.
|
|
60
|
-
* Returns a newly created random test account that is funded from the dispenser @see {getDispenserAccount}
|
|
61
|
-
* DO NOT USE THIS TO CREATE A MAINNET ACCOUNT!
|
|
62
|
-
* Note: By default this will log the mnemonic of the account.
|
|
63
|
-
* @param param0 The config for the test account to generate
|
|
64
|
-
* @param algod An algod client
|
|
65
|
-
* @returns The account, with private key loaded
|
|
66
|
-
*/
|
|
67
|
-
export declare function getTestAccount({ suppressLog, initialFunds }: GetTestAccountParams, algod: Algodv2): Promise<Account>;
|
|
68
66
|
/** Returns an account's address as a byte array
|
|
69
67
|
*
|
|
70
68
|
* @param account Either an account (with private key loaded) or the string address of an account
|
|
@@ -81,7 +79,7 @@ export declare function getAccountAddressAsString(addressEncodedInB64: string):
|
|
|
81
79
|
* otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC @see {getAccount}
|
|
82
80
|
*
|
|
83
81
|
* @param algod An algod client
|
|
82
|
+
* @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
|
|
84
83
|
*/
|
|
85
|
-
export declare function getDispenserAccount(algod: Algodv2): Promise<algosdk.Account | SigningAccount>;
|
|
86
|
-
export {};
|
|
84
|
+
export declare function getDispenserAccount(algod: Algodv2, kmd?: Kmd): Promise<algosdk.Account | SigningAccount>;
|
|
87
85
|
//# sourceMappingURL=account.d.ts.map
|
package/account.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EA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od };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getDispenserAccount = exports.getAccountAddressAsString = exports.getAccountAddressAsUint8Array = exports.
|
|
6
|
+
exports.getDispenserAccount = exports.getAccountAddressAsString = exports.getAccountAddressAsUint8Array = exports.getAccount = exports.mnemonicAccount = exports.transactionSignerAccount = exports.rekeyedAccount = exports.multisigAccount = void 0;
|
|
7
7
|
const algosdk_1 = __importDefault(require("algosdk"));
|
|
8
|
-
const
|
|
8
|
+
const _1 = require("./");
|
|
9
9
|
const localnet_1 = require("./localnet");
|
|
10
10
|
const network_client_1 = require("./network-client");
|
|
11
|
-
const
|
|
12
|
-
const transfer_1 = require("./transfer");
|
|
11
|
+
const account_1 = require("./types/account");
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
13
|
+
* Returns an account wrapper that supports partial or full multisig signing.
|
|
14
|
+
* @param multisigParams The parameters that define the multisig account
|
|
15
|
+
* @param signingAccounts The signers that are currently present
|
|
16
|
+
* @returns A multisig account wrapper
|
|
15
17
|
*/
|
|
16
|
-
|
|
18
|
+
function multisigAccount(multisigParams, signingAccounts) {
|
|
19
|
+
return new account_1.MultisigAccount(multisigParams, signingAccounts);
|
|
20
|
+
}
|
|
21
|
+
exports.multisigAccount = multisigAccount;
|
|
22
|
+
/**
|
|
23
|
+
* Returns an account wrapper that supports a rekeyed account.
|
|
24
|
+
* @param account The account, with private key loaded, that is signing
|
|
25
|
+
* @param sender The address of the rekeyed account that will act as a sender
|
|
26
|
+
* @returns The @see SigningAccount wrapper
|
|
27
|
+
*/
|
|
28
|
+
function rekeyedAccount(account, sender) {
|
|
29
|
+
return new account_1.SigningAccount(account, sender);
|
|
30
|
+
}
|
|
31
|
+
exports.rekeyedAccount = rekeyedAccount;
|
|
32
|
+
/**
|
|
33
|
+
* Returns an account wrapper that supports a transaction signer with associated sender address.
|
|
34
|
+
* @param signer The transaction signer
|
|
35
|
+
* @param sender The address of sender account
|
|
36
|
+
* @returns The @see SigningAccount wrapper
|
|
37
|
+
*/
|
|
38
|
+
function transactionSignerAccount(signer, sender) {
|
|
39
|
+
return { addr: sender, signer };
|
|
40
|
+
}
|
|
41
|
+
exports.transactionSignerAccount = transactionSignerAccount;
|
|
17
42
|
/** Returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
|
|
18
43
|
*
|
|
19
44
|
* This is a wrapper around algosdk.mnemonicToSecretKey to provide a more friendly/obvious name.
|
|
@@ -21,28 +46,28 @@ exports.DISPENSER_ACCOUNT = 'DISPENSER';
|
|
|
21
46
|
* @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
|
|
22
47
|
* never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
|
|
23
48
|
*/
|
|
24
|
-
function
|
|
49
|
+
function mnemonicAccount(mnemonicSecret) {
|
|
25
50
|
// This method is confusingly named, so this function provides a more dev friendly "wrapper" name
|
|
26
51
|
return algosdk_1.default.mnemonicToSecretKey(mnemonicSecret);
|
|
27
52
|
}
|
|
28
|
-
exports.
|
|
53
|
+
exports.mnemonicAccount = mnemonicAccount;
|
|
29
54
|
/**
|
|
30
55
|
* Returns an Algorand account with private key loaded by convention based on the given name identifier.
|
|
31
56
|
*
|
|
32
57
|
* Note: This function expects to run in a Node.js environment.
|
|
33
58
|
*
|
|
34
59
|
* ## Convention:
|
|
35
|
-
* * **Non-LocalNet:** will load process.env['{NAME}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
|
|
60
|
+
* * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
|
|
36
61
|
* never commit it into source control and ideally load it via a secret storage service rather than the file system.
|
|
37
|
-
* If process.env['{NAME}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
|
|
38
|
-
* * **LocalNet:** will load the account from a KMD wallet called {NAME} and if that wallet doesn't exist it will create it and fund the account for you
|
|
62
|
+
* If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
|
|
63
|
+
* * **LocalNet:** will load the account from a KMD wallet called \{NAME\} and if that wallet doesn't exist it will create it and fund the account for you
|
|
39
64
|
*
|
|
40
65
|
* This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).
|
|
41
66
|
*
|
|
42
67
|
* @example Default
|
|
43
68
|
*
|
|
44
69
|
* If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
|
|
45
|
-
* ```
|
|
70
|
+
* ```typescript
|
|
46
71
|
* const account = await getAccount('ACCOUNT', algod)
|
|
47
72
|
* ```
|
|
48
73
|
*
|
|
@@ -71,12 +96,12 @@ async function getAccount(account, algod, kmdClient) {
|
|
|
71
96
|
const envKey = `${name.toUpperCase()}_MNEMONIC`;
|
|
72
97
|
if (process.env[envKey]) {
|
|
73
98
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
74
|
-
const signer =
|
|
99
|
+
const signer = mnemonicAccount(process.env[envKey]);
|
|
75
100
|
const senderKey = `${name.toUpperCase()}_SENDER`;
|
|
76
101
|
if (process.env[senderKey]) {
|
|
77
|
-
|
|
102
|
+
_1.Config.logger.debug(`Using rekeyed account ${signer.addr} for sender ${process.env[senderKey]} for ${name} account`);
|
|
78
103
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
79
|
-
return new
|
|
104
|
+
return new account_1.SigningAccount(signer, process.env[senderKey]);
|
|
80
105
|
}
|
|
81
106
|
else {
|
|
82
107
|
return signer;
|
|
@@ -90,32 +115,6 @@ async function getAccount(account, algod, kmdClient) {
|
|
|
90
115
|
throw `Missing environment variable ${envKey} when looking for account ${name}`;
|
|
91
116
|
}
|
|
92
117
|
exports.getAccount = getAccount;
|
|
93
|
-
/**
|
|
94
|
-
* Creates an ephemeral Algorand account for the purposes of testing.
|
|
95
|
-
* Returns a newly created random test account that is funded from the dispenser @see {getDispenserAccount}
|
|
96
|
-
* DO NOT USE THIS TO CREATE A MAINNET ACCOUNT!
|
|
97
|
-
* Note: By default this will log the mnemonic of the account.
|
|
98
|
-
* @param param0 The config for the test account to generate
|
|
99
|
-
* @param algod An algod client
|
|
100
|
-
* @returns The account, with private key loaded
|
|
101
|
-
*/
|
|
102
|
-
async function getTestAccount({ suppressLog, initialFunds }, algod) {
|
|
103
|
-
const account = algosdk_1.default.generateAccount();
|
|
104
|
-
if (!suppressLog) {
|
|
105
|
-
config_1.AlgoKitConfig.logger.info(`New test account created with address '${account.addr}' and mnemonic '${algosdk_1.default.secretKeyToMnemonic(account.sk)}'.`);
|
|
106
|
-
}
|
|
107
|
-
// If we are running against LocalNet we can use the default account within it
|
|
108
|
-
// otherwise use an automation account specified via environment variables and ensure it's populated with ALGOs
|
|
109
|
-
const canFundFromDefaultAccount = await (0, network_client_1.isLocalNet)(algod);
|
|
110
|
-
const dispenser = canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod) : await getAccount(exports.DISPENSER_ACCOUNT, algod);
|
|
111
|
-
await (0, transfer_1.transferAlgos)({ from: dispenser, to: account.addr, amount: initialFunds, note: 'Funding test account', suppressLog }, algod);
|
|
112
|
-
const accountInfo = await algod.accountInformation(account.addr).do();
|
|
113
|
-
if (!suppressLog) {
|
|
114
|
-
config_1.AlgoKitConfig.logger.info('Test account funded; account balance: %d µAlgos', accountInfo.amount);
|
|
115
|
-
}
|
|
116
|
-
return account;
|
|
117
|
-
}
|
|
118
|
-
exports.getTestAccount = getTestAccount;
|
|
119
118
|
/** Returns an account's address as a byte array
|
|
120
119
|
*
|
|
121
120
|
* @param account Either an account (with private key loaded) or the string address of an account
|
|
@@ -138,11 +137,12 @@ exports.getAccountAddressAsString = getAccountAddressAsString;
|
|
|
138
137
|
* otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC @see {getAccount}
|
|
139
138
|
*
|
|
140
139
|
* @param algod An algod client
|
|
140
|
+
* @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
|
|
141
141
|
*/
|
|
142
|
-
async function getDispenserAccount(algod) {
|
|
142
|
+
async function getDispenserAccount(algod, kmd) {
|
|
143
143
|
// If we are running against a sandbox we can use the default account within it, otherwise use an automation account specified via environment variables and ensure it's populated with ALGOs
|
|
144
144
|
const canFundFromDefaultAccount = await (0, network_client_1.isLocalNet)(algod);
|
|
145
|
-
return canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod) : await getAccount(
|
|
145
|
+
return canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod, kmd) : await getAccount(account_1.DISPENSER_ACCOUNT, algod);
|
|
146
146
|
}
|
|
147
147
|
exports.getDispenserAccount = getDispenserAccount;
|
|
148
148
|
//# sourceMappingURL=account.js.map
|
package/account.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6F;AAC7F,yBAA2B;AAC3B,yCAAqF;AACrF,qDAA6C;AAC7C,6CAA8G;AAG9G;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,cAAgC,EAAE,eAA6C;IAC7G,OAAO,IAAI,yBAAe,CAAC,cAAc,EAAE,eAAe,CAAC,CAAA;AAC7D,CAAC;AAFD,0CAEC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,OAAgB,EAAE,MAAc;IAC7D,OAAO,IAAI,wBAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;AAC5C,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,MAAyB,EAAE,MAAc;IAChF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;AACjC,CAAC;AAFD,4DAEC;AAED;;;;;;GAMG;AACH,SAAgB,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
+
export declare const algos: (algos: number) => AlgoAmount;
|
|
4
|
+
/** Returns an amount of µAlgos using @see AlgoAmount */
|
|
5
|
+
export declare const microAlgos: (microAlgos: number) => AlgoAmount;
|
|
6
|
+
/** Returns an amount of µAlgos to cover standard fees for the given number of transactions using @see AlgoAmount */
|
|
7
|
+
export declare const transactionFees: (numberOfTransactions: number) => AlgoAmount;
|
|
8
|
+
//# sourceMappingURL=amount.d.ts.map
|
package/amount.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../src/amount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,uDAAuD;AACvD,eAAO,MAAM,KAAK,UAAW,MAAM,eAElC,CAAA;AAED,wDAAwD;AACxD,eAAO,MAAM,UAAU,eAAgB,MAAM,eAE5C,CAAA;AAED,oHAAoH;AACpH,eAAO,MAAM,eAAe,yBAA0B,MAAM,eAE3D,CAAA"}
|
package/amount.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.transactionFees = exports.microAlgos = exports.algos = void 0;
|
|
7
|
+
const algosdk_1 = __importDefault(require("algosdk"));
|
|
8
|
+
const amount_1 = require("./types/amount");
|
|
9
|
+
/** Returns an amount of Algos using @see AlgoAmount */
|
|
10
|
+
const algos = (algos) => {
|
|
11
|
+
return amount_1.AlgoAmount.Algos(algos);
|
|
12
|
+
};
|
|
13
|
+
exports.algos = algos;
|
|
14
|
+
/** Returns an amount of µAlgos using @see AlgoAmount */
|
|
15
|
+
const microAlgos = (microAlgos) => {
|
|
16
|
+
return amount_1.AlgoAmount.MicroAlgos(microAlgos);
|
|
17
|
+
};
|
|
18
|
+
exports.microAlgos = microAlgos;
|
|
19
|
+
/** Returns an amount of µAlgos to cover standard fees for the given number of transactions using @see AlgoAmount */
|
|
20
|
+
const transactionFees = (numberOfTransactions) => {
|
|
21
|
+
return amount_1.AlgoAmount.MicroAlgos(numberOfTransactions * algosdk_1.default.ALGORAND_MIN_TX_FEE);
|
|
22
|
+
};
|
|
23
|
+
exports.transactionFees = transactionFees;
|
|
24
|
+
//# sourceMappingURL=amount.js.map
|
package/amount.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../src/amount.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAC7B,2CAA2C;AAE3C,uDAAuD;AAChD,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE;IACrC,OAAO,mBAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC,CAAA;AAFY,QAAA,KAAK,SAEjB;AAED,wDAAwD;AACjD,MAAM,UAAU,GAAG,CAAC,UAAkB,EAAE,EAAE;IAC/C,OAAO,mBAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;AAC1C,CAAC,CAAA;AAFY,QAAA,UAAU,cAEtB;AAED,oHAAoH;AAC7G,MAAM,eAAe,GAAG,CAAC,oBAA4B,EAAE,EAAE;IAC9D,OAAO,mBAAU,CAAC,UAAU,CAAC,oBAAoB,GAAG,iBAAO,CAAC,mBAAmB,CAAC,CAAA;AAClF,CAAC,CAAA;AAFY,QAAA,eAAe,mBAE3B"}
|
package/app.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import algosdk, { Algodv2 } from 'algosdk';
|
|
2
|
+
import { ApplicationResponse, PendingTransactionResponse } from './types/algod';
|
|
3
|
+
import { ABIReturn, AppCallArgs, AppCallParams, AppCallTransactionResult, AppCompilationResult, AppReference, CompiledTeal, CreateAppParams, UpdateAppParams } from './types/app';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a smart contract app, returns the details of the created app.
|
|
6
|
+
* @param create The parameters to create the app with
|
|
7
|
+
* @param algod An algod client
|
|
8
|
+
* @returns The details of the created app, or the transaction to create it if `skipSending`
|
|
9
|
+
*/
|
|
10
|
+
export declare function createApp(create: CreateAppParams, algod: Algodv2): Promise<Partial<AppCompilationResult> & AppCallTransactionResult & AppReference>;
|
|
11
|
+
/**
|
|
12
|
+
* Updates a smart contract app.
|
|
13
|
+
* @param update The parameters to update the app with
|
|
14
|
+
* @param algod An algod client
|
|
15
|
+
* @returns The transaction
|
|
16
|
+
*/
|
|
17
|
+
export declare function updateApp(update: UpdateAppParams, algod: Algodv2): Promise<Partial<AppCompilationResult> & AppCallTransactionResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Issues a call to a given app.
|
|
20
|
+
* @param call The call details.
|
|
21
|
+
* @param algod An algod client
|
|
22
|
+
* @returns The result of the call
|
|
23
|
+
*/
|
|
24
|
+
export declare function callApp(call: AppCallParams, algod: Algodv2): Promise<AppCallTransactionResult>;
|
|
25
|
+
export declare function getABIReturn(args?: AppCallArgs, confirmation?: PendingTransactionResponse): ABIReturn | undefined;
|
|
26
|
+
/** Returns the app args ready to load onto an app @see {Transaction} object */
|
|
27
|
+
export declare function getAppArgsForTransaction(args?: AppCallArgs): {
|
|
28
|
+
accounts: string[] | undefined;
|
|
29
|
+
appArgs: Uint8Array[] | undefined;
|
|
30
|
+
boxes: algosdk.BoxReference[] | undefined;
|
|
31
|
+
foreignApps: number[] | undefined;
|
|
32
|
+
foreignAssets: number[] | undefined;
|
|
33
|
+
lease: Uint8Array | undefined;
|
|
34
|
+
} | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Gets the current data for the given app from algod.
|
|
37
|
+
*
|
|
38
|
+
* @param appId The id of the app
|
|
39
|
+
* @param algod An algod client
|
|
40
|
+
* @returns The data about the app
|
|
41
|
+
*/
|
|
42
|
+
export declare function getAppByIndex(appId: number, algod: Algodv2): Promise<ApplicationResponse>;
|
|
43
|
+
/**
|
|
44
|
+
* Compiles the given TEAL using algod and returns the result.
|
|
45
|
+
*
|
|
46
|
+
* @param algod An algod client
|
|
47
|
+
* @param tealCode The TEAL code
|
|
48
|
+
* @returns The information about the compiled file
|
|
49
|
+
*/
|
|
50
|
+
export declare function compileTeal(tealCode: string, algod: Algodv2): Promise<CompiledTeal>;
|
|
51
|
+
//# sourceMappingURL=app.d.ts.map
|
package/app.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAEd,OAAO,EAMR,MAAM,SAAS,CAAA;AAIhB,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAA;AAC/E,OAAO,EACL,SAAS,EAET,WAAW,EACX,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,YAAY,EAEZ,YAAY,EACZ,eAAe,EACf,eAAe,EAChB,MAAM,aAAa,CAAA;AAEpB;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,wBAAwB,GAAG,YAAY,CAAC,CA2ClF;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,wBAAwB,CAAC,CA6BnE;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAqCpG;AAED,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,YAAY,CAAC,EAAE,0BAA0B,GAAG,SAAS,GAAG,SAAS,CA6BjH;AAED,+EAA+E;AAC/E,wBAAgB,wBAAwB,CAAC,IAAI,CAAC,EAAE,WAAW;;;;;;;cA4E1D;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,gCAEhE;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CASzF"}
|
package/app.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.compileTeal = exports.getAppByIndex = exports.getAppArgsForTransaction = exports.getABIReturn = exports.callApp = exports.updateApp = exports.createApp = void 0;
|
|
27
|
+
const algosdk_1 = __importStar(require("algosdk"));
|
|
28
|
+
const buffer_1 = require("buffer");
|
|
29
|
+
const _1 = require("./");
|
|
30
|
+
const transaction_1 = require("./transaction");
|
|
31
|
+
const app_1 = require("./types/app");
|
|
32
|
+
/**
|
|
33
|
+
* Creates a smart contract app, returns the details of the created app.
|
|
34
|
+
* @param create The parameters to create the app with
|
|
35
|
+
* @param algod An algod client
|
|
36
|
+
* @returns The details of the created app, or the transaction to create it if `skipSending`
|
|
37
|
+
*/
|
|
38
|
+
async function createApp(create, algod) {
|
|
39
|
+
const { from, approvalProgram: approval, clearStateProgram: clear, schema, note, transactionParams, args, ...sendParams } = create;
|
|
40
|
+
const compiledApproval = typeof approval === 'string' ? await compileTeal(approval, algod) : undefined;
|
|
41
|
+
const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : approval;
|
|
42
|
+
const compiledClear = typeof clear === 'string' ? await compileTeal(clear, algod) : undefined;
|
|
43
|
+
const clearProgram = compiledClear ? compiledClear.compiledBase64ToBytes : clear;
|
|
44
|
+
const transaction = algosdk_1.default.makeApplicationCreateTxnFromObject({
|
|
45
|
+
approvalProgram: approvalProgram,
|
|
46
|
+
clearProgram: clearProgram,
|
|
47
|
+
numLocalInts: schema.localInts,
|
|
48
|
+
numLocalByteSlices: schema.localByteSlices,
|
|
49
|
+
numGlobalInts: schema.globalInts,
|
|
50
|
+
numGlobalByteSlices: schema.globalByteSlices,
|
|
51
|
+
extraPages: schema.extraPages ?? Math.floor((approvalProgram.length + clearProgram.length) / app_1.APP_PAGE_MAX_SIZE),
|
|
52
|
+
onComplete: algosdk_1.default.OnApplicationComplete.NoOpOC,
|
|
53
|
+
suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
|
|
54
|
+
from: (0, transaction_1.getSenderAddress)(from),
|
|
55
|
+
note: (0, transaction_1.encodeTransactionNote)(note),
|
|
56
|
+
...getAppArgsForTransaction(args),
|
|
57
|
+
rekeyTo: undefined,
|
|
58
|
+
});
|
|
59
|
+
const { confirmation } = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
|
|
60
|
+
if (confirmation) {
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
62
|
+
const appId = confirmation['application-index'];
|
|
63
|
+
_1.Config.getLogger(sendParams.suppressLog).debug(`Created app ${appId} from creator ${(0, transaction_1.getSenderAddress)(from)}`);
|
|
64
|
+
return {
|
|
65
|
+
transaction,
|
|
66
|
+
confirmation,
|
|
67
|
+
appId,
|
|
68
|
+
appAddress: algosdk_1.default.getApplicationAddress(appId),
|
|
69
|
+
return: getABIReturn(args, confirmation),
|
|
70
|
+
compiledApproval,
|
|
71
|
+
compiledClear,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return { transaction, appId: 0, appAddress: '', compiledApproval, compiledClear };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.createApp = createApp;
|
|
79
|
+
/**
|
|
80
|
+
* Updates a smart contract app.
|
|
81
|
+
* @param update The parameters to update the app with
|
|
82
|
+
* @param algod An algod client
|
|
83
|
+
* @returns The transaction
|
|
84
|
+
*/
|
|
85
|
+
async function updateApp(update, algod) {
|
|
86
|
+
const { appId, from, approvalProgram: approval, clearStateProgram: clear, note, transactionParams, args, ...sendParams } = update;
|
|
87
|
+
const compiledApproval = typeof approval === 'string' ? await compileTeal(approval, algod) : undefined;
|
|
88
|
+
const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : approval;
|
|
89
|
+
const compiledClear = typeof clear === 'string' ? await compileTeal(clear, algod) : undefined;
|
|
90
|
+
const clearProgram = compiledClear ? compiledClear.compiledBase64ToBytes : clear;
|
|
91
|
+
const transaction = algosdk_1.default.makeApplicationUpdateTxnFromObject({
|
|
92
|
+
appIndex: appId,
|
|
93
|
+
approvalProgram: approvalProgram,
|
|
94
|
+
clearProgram: clearProgram,
|
|
95
|
+
suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
|
|
96
|
+
from: (0, transaction_1.getSenderAddress)(from),
|
|
97
|
+
note: (0, transaction_1.encodeTransactionNote)(note),
|
|
98
|
+
...getAppArgsForTransaction(args),
|
|
99
|
+
rekeyTo: undefined,
|
|
100
|
+
});
|
|
101
|
+
_1.Config.getLogger(sendParams.suppressLog).debug(`Updating app ${appId}`);
|
|
102
|
+
const result = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
|
|
103
|
+
return {
|
|
104
|
+
...result,
|
|
105
|
+
return: getABIReturn(args, result.confirmation),
|
|
106
|
+
compiledApproval,
|
|
107
|
+
compiledClear,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
exports.updateApp = updateApp;
|
|
111
|
+
/**
|
|
112
|
+
* Issues a call to a given app.
|
|
113
|
+
* @param call The call details.
|
|
114
|
+
* @param algod An algod client
|
|
115
|
+
* @returns The result of the call
|
|
116
|
+
*/
|
|
117
|
+
async function callApp(call, algod) {
|
|
118
|
+
const { appId, callType, from, args, note, transactionParams, ...sendParams } = call;
|
|
119
|
+
const appCallParameters = {
|
|
120
|
+
appIndex: appId,
|
|
121
|
+
from: (0, transaction_1.getSenderAddress)(from),
|
|
122
|
+
suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
|
|
123
|
+
...getAppArgsForTransaction(args),
|
|
124
|
+
note: (0, transaction_1.encodeTransactionNote)(note),
|
|
125
|
+
rekeyTo: undefined,
|
|
126
|
+
};
|
|
127
|
+
let transaction;
|
|
128
|
+
switch (callType) {
|
|
129
|
+
case 'optin':
|
|
130
|
+
transaction = algosdk_1.default.makeApplicationOptInTxnFromObject(appCallParameters);
|
|
131
|
+
break;
|
|
132
|
+
case 'clearstate':
|
|
133
|
+
transaction = algosdk_1.default.makeApplicationClearStateTxnFromObject(appCallParameters);
|
|
134
|
+
break;
|
|
135
|
+
case 'closeout':
|
|
136
|
+
transaction = algosdk_1.default.makeApplicationCloseOutTxnFromObject(appCallParameters);
|
|
137
|
+
break;
|
|
138
|
+
case 'delete':
|
|
139
|
+
transaction = algosdk_1.default.makeApplicationDeleteTxnFromObject(appCallParameters);
|
|
140
|
+
break;
|
|
141
|
+
case 'normal':
|
|
142
|
+
transaction = algosdk_1.default.makeApplicationNoOpTxnFromObject(appCallParameters);
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
const result = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
|
|
146
|
+
return {
|
|
147
|
+
...result,
|
|
148
|
+
return: getABIReturn(args, result.confirmation),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
exports.callApp = callApp;
|
|
152
|
+
function getABIReturn(args, confirmation) {
|
|
153
|
+
try {
|
|
154
|
+
if (!args || !('method' in args)) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
const method = 'txnCount' in args.method ? args.method : new algosdk_1.ABIMethod(args.method);
|
|
158
|
+
if (method.returns.type !== 'void' && confirmation) {
|
|
159
|
+
const logs = confirmation.logs || [];
|
|
160
|
+
if (logs.length === 0) {
|
|
161
|
+
throw new Error('App call transaction did not log a return value');
|
|
162
|
+
}
|
|
163
|
+
const lastLog = logs[logs.length - 1];
|
|
164
|
+
if (lastLog.byteLength < 4 || lastLog.slice(0, 4).toString() !== app_1.ABI_RETURN_PREFIX.toString()) {
|
|
165
|
+
throw new Error('App call transaction did not log a return value (ABI_RETURN_PREFIX not found)');
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
rawReturnValue: new Uint8Array(lastLog.slice(4)),
|
|
169
|
+
returnValue: method.returns.type.decode(new Uint8Array(lastLog.slice(4))),
|
|
170
|
+
decodeError: undefined,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
return {
|
|
176
|
+
rawReturnValue: undefined,
|
|
177
|
+
returnValue: undefined,
|
|
178
|
+
decodeError: e,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
exports.getABIReturn = getABIReturn;
|
|
184
|
+
/** Returns the app args ready to load onto an app @see {Transaction} object */
|
|
185
|
+
function getAppArgsForTransaction(args) {
|
|
186
|
+
if (!args)
|
|
187
|
+
return undefined;
|
|
188
|
+
let actualArgs;
|
|
189
|
+
if ('method' in args) {
|
|
190
|
+
// todo: Land a change to algosdk that extract the logic from ATC, because (fair warning) this is a HACK
|
|
191
|
+
// I don't want to have to rewrite all of the ABI resolution logic so using an ATC temporarily here
|
|
192
|
+
// and passing stuff in to keep it happy like a randomly generated account :O
|
|
193
|
+
// Most of these values aren't being used since the transaction is discarded
|
|
194
|
+
const dummyAtc = new algosdk_1.AtomicTransactionComposer();
|
|
195
|
+
const dummyAccount = algosdk_1.default.generateAccount();
|
|
196
|
+
const dummySigner = (0, algosdk_1.makeBasicAccountTransactionSigner)(dummyAccount);
|
|
197
|
+
const dummyAppId = 1;
|
|
198
|
+
const dummyParams = {
|
|
199
|
+
fee: 1,
|
|
200
|
+
firstRound: 1,
|
|
201
|
+
genesisHash: buffer_1.Buffer.from('abcd', 'utf-8').toString('base64'),
|
|
202
|
+
genesisID: 'a',
|
|
203
|
+
lastRound: 1,
|
|
204
|
+
};
|
|
205
|
+
const methodArgs = args.args?.map((a) => {
|
|
206
|
+
if (typeof a !== 'object') {
|
|
207
|
+
return a;
|
|
208
|
+
}
|
|
209
|
+
// Handle the various forms of transactions to wrangle them for ATC
|
|
210
|
+
return 'txn' in a
|
|
211
|
+
? a
|
|
212
|
+
: 'transaction' in a
|
|
213
|
+
? { txn: a.transaction, signer: dummySigner }
|
|
214
|
+
: 'txID' in a
|
|
215
|
+
? { txn: a, signer: dummySigner }
|
|
216
|
+
: a;
|
|
217
|
+
});
|
|
218
|
+
const dummyOnComplete = algosdk_1.OnApplicationComplete.NoOpOC;
|
|
219
|
+
dummyAtc.addMethodCall({
|
|
220
|
+
method: 'txnCount' in args.method ? args.method : new algosdk_1.ABIMethod(args.method),
|
|
221
|
+
methodArgs,
|
|
222
|
+
// Rest are dummy values
|
|
223
|
+
appID: dummyAppId,
|
|
224
|
+
sender: dummyAccount.addr,
|
|
225
|
+
signer: dummySigner,
|
|
226
|
+
suggestedParams: dummyParams,
|
|
227
|
+
onComplete: dummyOnComplete,
|
|
228
|
+
});
|
|
229
|
+
const txn = dummyAtc.buildGroup()[0];
|
|
230
|
+
actualArgs = {
|
|
231
|
+
accounts: txn.txn.appAccounts,
|
|
232
|
+
appArgs: txn.txn.appArgs,
|
|
233
|
+
apps: txn.txn.appForeignApps,
|
|
234
|
+
assets: txn.txn.appForeignAssets,
|
|
235
|
+
boxes: txn.txn.boxes?.map((b) => ({
|
|
236
|
+
appId: b.appIndex,
|
|
237
|
+
name: b.name,
|
|
238
|
+
})),
|
|
239
|
+
lease: args.lease,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
actualArgs = args;
|
|
244
|
+
}
|
|
245
|
+
const encoder = new TextEncoder();
|
|
246
|
+
return {
|
|
247
|
+
accounts: actualArgs?.accounts?.map((a) => (typeof a === 'string' ? a : algosdk_1.default.encodeAddress(a.publicKey))),
|
|
248
|
+
appArgs: actualArgs?.appArgs?.map((a) => (typeof a === 'string' ? encoder.encode(a) : a)),
|
|
249
|
+
boxes: actualArgs?.boxes?.map((ref) => ({
|
|
250
|
+
appIndex: ref.appId,
|
|
251
|
+
name: typeof ref.name === 'string' ? encoder.encode(ref.name) : ref.name,
|
|
252
|
+
})),
|
|
253
|
+
foreignApps: actualArgs?.apps,
|
|
254
|
+
foreignAssets: actualArgs?.assets,
|
|
255
|
+
lease: typeof actualArgs?.lease === 'string' ? encoder.encode(actualArgs?.lease) : actualArgs?.lease,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
exports.getAppArgsForTransaction = getAppArgsForTransaction;
|
|
259
|
+
/**
|
|
260
|
+
* Gets the current data for the given app from algod.
|
|
261
|
+
*
|
|
262
|
+
* @param appId The id of the app
|
|
263
|
+
* @param algod An algod client
|
|
264
|
+
* @returns The data about the app
|
|
265
|
+
*/
|
|
266
|
+
async function getAppByIndex(appId, algod) {
|
|
267
|
+
return (await algod.getApplicationByID(appId).do());
|
|
268
|
+
}
|
|
269
|
+
exports.getAppByIndex = getAppByIndex;
|
|
270
|
+
/**
|
|
271
|
+
* Compiles the given TEAL using algod and returns the result.
|
|
272
|
+
*
|
|
273
|
+
* @param algod An algod client
|
|
274
|
+
* @param tealCode The TEAL code
|
|
275
|
+
* @returns The information about the compiled file
|
|
276
|
+
*/
|
|
277
|
+
async function compileTeal(tealCode, algod) {
|
|
278
|
+
const compiled = await algod.compile(tealCode).sourcemap(true).do();
|
|
279
|
+
return {
|
|
280
|
+
teal: tealCode,
|
|
281
|
+
compiled: compiled.result,
|
|
282
|
+
compiledHash: compiled.hash,
|
|
283
|
+
compiledBase64ToBytes: new Uint8Array(buffer_1.Buffer.from(compiled.result, 'base64')),
|
|
284
|
+
sourceMap: new algosdk_1.SourceMap(compiled['sourcemap']),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
exports.compileTeal = compileTeal;
|
|
288
|
+
//# sourceMappingURL=app.js.map
|