@algorandfoundation/algokit-utils 6.3.0-beta.1 → 7.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +22 -26
- package/account/account.d.ts +12 -10
- package/account/account.js +17 -14
- package/account/account.js.map +1 -1
- package/account/account.mjs +18 -15
- package/account/account.mjs.map +1 -1
- package/account/get-account-config-from-environment.d.ts +0 -1
- package/account/get-account-config-from-environment.js.map +1 -1
- package/account/get-account-config-from-environment.mjs.map +1 -1
- package/account/get-account.d.ts +2 -3
- package/account/get-account.js +1 -1
- package/account/get-account.js.map +1 -1
- package/account/get-account.mjs +1 -1
- package/account/get-account.mjs.map +1 -1
- package/account/get-dispenser-account.d.ts +2 -3
- package/account/get-dispenser-account.js +1 -1
- package/account/get-dispenser-account.js.map +1 -1
- package/account/get-dispenser-account.mjs +1 -1
- package/account/get-dispenser-account.mjs.map +1 -1
- package/account/index.d.ts +0 -1
- package/account/mnemonic-account.d.ts +1 -2
- package/account/mnemonic-account.js +1 -1
- package/account/mnemonic-account.js.map +1 -1
- package/account/mnemonic-account.mjs +1 -1
- package/account/mnemonic-account.mjs.map +1 -1
- package/amount.d.ts +15 -5
- package/amount.js +9 -2
- package/amount.js.map +1 -1
- package/amount.mjs +9 -3
- package/amount.mjs.map +1 -1
- package/app-client.d.ts +19 -5
- package/app-client.js +19 -4
- package/app-client.js.map +1 -1
- package/app-client.mjs +19 -4
- package/app-client.mjs.map +1 -1
- package/app-deploy.d.ts +18 -2
- package/app-deploy.js +159 -342
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +163 -346
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +39 -3
- package/app.js +121 -371
- package/app.js.map +1 -1
- package/app.mjs +122 -372
- package/app.mjs.map +1 -1
- package/asset.d.ts +5 -6
- package/asset.js +5 -8
- package/asset.js.map +1 -1
- package/asset.mjs +5 -8
- package/asset.mjs.map +1 -1
- package/config.d.ts +0 -1
- package/config.js.map +1 -1
- package/config.mjs.map +1 -1
- package/debugging/debugging.d.ts +3 -5
- package/debugging/debugging.js +4 -128
- package/debugging/debugging.js.map +1 -1
- package/debugging/debugging.mjs +4 -109
- package/debugging/debugging.mjs.map +1 -1
- package/debugging/index.d.ts +0 -2
- package/dispenser-client.d.ts +0 -1
- package/dispenser-client.js.map +1 -1
- package/dispenser-client.mjs.map +1 -1
- package/index.d.ts +5 -4
- package/index.js +36 -26
- package/index.js.map +1 -1
- package/index.mjs +6 -5
- package/index.mjs.map +1 -1
- package/indexer-lookup.d.ts +10 -9
- package/indexer-lookup.js +14 -10
- package/indexer-lookup.js.map +1 -1
- package/indexer-lookup.mjs +14 -10
- package/indexer-lookup.mjs.map +1 -1
- package/localnet/get-kmd-wallet-account.d.ts +1 -2
- package/localnet/get-kmd-wallet-account.js +1 -1
- package/localnet/get-kmd-wallet-account.js.map +1 -1
- package/localnet/get-kmd-wallet-account.mjs +1 -1
- package/localnet/get-kmd-wallet-account.mjs.map +1 -1
- package/localnet/get-localnet-dispenser-account.d.ts +1 -2
- package/localnet/get-localnet-dispenser-account.js +1 -1
- package/localnet/get-localnet-dispenser-account.js.map +1 -1
- package/localnet/get-localnet-dispenser-account.mjs +1 -1
- package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts +1 -2
- package/localnet/get-or-create-kmd-wallet-account.js +1 -1
- package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
- package/localnet/index.d.ts +0 -1
- package/localnet/is-localnet.d.ts +1 -2
- package/localnet/is-localnet.js +1 -1
- package/localnet/is-localnet.js.map +1 -1
- package/localnet/is-localnet.mjs +1 -1
- package/localnet/is-localnet.mjs.map +1 -1
- package/network-client.d.ts +3 -10
- package/network-client.js +4 -11
- package/network-client.js.map +1 -1
- package/network-client.mjs +4 -11
- package/network-client.mjs.map +1 -1
- package/package.json +3 -4
- package/testing/_asset.d.ts +2 -2
- package/testing/account.d.ts +4 -4
- package/testing/account.js +8 -2
- package/testing/account.js.map +1 -1
- package/testing/account.mjs +9 -3
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +0 -1
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
- package/testing/fixtures/algorand-fixture.d.ts +0 -1
- package/testing/fixtures/algorand-fixture.js +13 -14
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +13 -14
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/fixtures/index.d.ts +0 -1
- package/testing/index.d.ts +0 -1
- package/testing/indexer.d.ts +0 -1
- package/testing/indexer.js.map +1 -1
- package/testing/indexer.mjs.map +1 -1
- package/testing/test-logger.d.ts +0 -1
- package/testing/test-logger.js +7 -3
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs +7 -3
- package/testing/test-logger.mjs.map +1 -1
- package/testing/transaction-logger.d.ts +0 -1
- package/testing/transaction-logger.js.map +1 -1
- package/testing/transaction-logger.mjs.map +1 -1
- package/transaction/index.d.ts +0 -1
- package/transaction/legacy-bridge.d.ts +31 -6
- package/transaction/legacy-bridge.js +101 -7
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +101 -10
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts +4 -2
- package/transaction/perform-atomic-transaction-composer-simulate.js +14 -9
- package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.mjs +15 -10
- package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +38 -19
- package/transaction/transaction.js +217 -137
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +218 -138
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/index.d.ts +0 -1
- package/transfer/transfer-algos.d.ts +1 -2
- package/transfer/transfer-algos.js +1 -1
- package/transfer/transfer-algos.js.map +1 -1
- package/transfer/transfer-algos.mjs +1 -1
- package/transfer/transfer-algos.mjs.map +1 -1
- package/transfer/transfer.d.ts +1 -2
- package/transfer/transfer.js +6 -4
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs +6 -4
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +33 -25
- package/types/account-manager.js +54 -31
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +56 -33
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +17 -9
- package/types/account.js +2 -2
- package/types/account.js.map +1 -1
- package/types/account.mjs +3 -3
- package/types/account.mjs.map +1 -1
- package/types/algo-http-client-with-retry.d.ts +1 -3
- package/types/algo-http-client-with-retry.js +33 -3
- package/types/algo-http-client-with-retry.js.map +1 -1
- package/types/algo-http-client-with-retry.mjs +32 -2
- package/types/algo-http-client-with-retry.mjs.map +1 -1
- package/types/algorand-client-interface.d.ts +28 -0
- package/types/algorand-client-interface.js +3 -0
- package/types/algorand-client-interface.js.map +1 -0
- package/types/algorand-client-interface.mjs +2 -0
- package/types/algorand-client-interface.mjs.map +1 -0
- package/types/algorand-client-transaction-creator.d.ts +452 -23
- package/types/algorand-client-transaction-creator.js +407 -23
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +407 -23
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +772 -47
- package/types/algorand-client-transaction-sender.js +445 -15
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +445 -15
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +24 -17
- package/types/algorand-client.js +26 -16
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +28 -15
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.d.ts +10 -11
- package/types/amount.js +7 -7
- package/types/amount.js.map +1 -1
- package/types/amount.mjs +7 -7
- package/types/amount.mjs.map +1 -1
- package/types/app-arc56.d.ts +359 -0
- package/types/app-arc56.js +184 -0
- package/types/app-arc56.js.map +1 -0
- package/types/app-arc56.mjs +175 -0
- package/types/app-arc56.mjs.map +1 -0
- package/types/app-client.d.ts +1508 -12
- package/types/app-client.js +1018 -29
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +1020 -32
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +126 -0
- package/types/app-deployer.js +353 -0
- package/types/app-deployer.js.map +1 -0
- package/types/app-deployer.mjs +351 -0
- package/types/app-deployer.mjs.map +1 -0
- package/types/app-factory.d.ts +846 -0
- package/types/app-factory.js +410 -0
- package/types/app-factory.js.map +1 -0
- package/types/app-factory.mjs +408 -0
- package/types/app-factory.mjs.map +1 -0
- package/types/app-manager.d.ts +244 -0
- package/types/app-manager.js +423 -0
- package/types/app-manager.js.map +1 -0
- package/types/app-manager.mjs +421 -0
- package/types/app-manager.mjs.map +1 -0
- package/types/app-spec.d.ts +2 -1
- package/types/app-spec.js +127 -0
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +126 -0
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +57 -18
- package/types/app.js +1 -1
- package/types/app.js.map +1 -1
- package/types/app.mjs +1 -1
- package/types/app.mjs.map +1 -1
- package/types/asset-manager.d.ts +10 -10
- package/types/asset-manager.js +13 -17
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +13 -17
- package/types/asset-manager.mjs.map +1 -1
- package/types/asset.d.ts +0 -1
- package/types/async-event-emitter.d.ts +14 -0
- package/types/async-event-emitter.js +50 -0
- package/types/async-event-emitter.js.map +1 -0
- package/types/async-event-emitter.mjs +48 -0
- package/types/async-event-emitter.mjs.map +1 -0
- package/types/client-manager.d.ts +135 -60
- package/types/client-manager.js +158 -44
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +159 -45
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +271 -87
- package/types/composer.js +405 -125
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +407 -125
- package/types/composer.mjs.map +1 -1
- package/types/config.d.ts +3 -6
- package/types/config.js +5 -44
- package/types/config.js.map +1 -1
- package/types/config.mjs +5 -27
- package/types/config.mjs.map +1 -1
- package/types/debugging.d.ts +29 -101
- package/types/debugging.js +16 -109
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs +12 -107
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.d.ts +2 -2
- package/types/dispenser-client.js +10 -5
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs +10 -5
- package/types/dispenser-client.mjs.map +1 -1
- package/types/expand.d.ts +7 -0
- package/types/expand.js +3 -0
- package/types/expand.js.map +1 -0
- package/types/expand.mjs +2 -0
- package/types/expand.mjs.map +1 -0
- package/types/indexer.d.ts +74 -756
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs.map +1 -1
- package/types/kmd-account-manager.d.ts +2 -3
- package/types/kmd-account-manager.js +3 -3
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +4 -4
- package/types/kmd-account-manager.mjs.map +1 -1
- package/types/lifecycle-events.d.ts +10 -0
- package/types/lifecycle-events.js +8 -0
- package/types/lifecycle-events.js.map +1 -0
- package/types/lifecycle-events.mjs +8 -0
- package/types/lifecycle-events.mjs.map +1 -0
- package/types/logging.d.ts +0 -1
- package/types/logging.js.map +1 -1
- package/types/logging.mjs.map +1 -1
- package/types/logic-error.d.ts +2 -4
- package/types/logic-error.js +3 -3
- package/types/logic-error.js.map +1 -1
- package/types/logic-error.mjs +3 -3
- package/types/logic-error.mjs.map +1 -1
- package/types/network-client.d.ts +14 -2
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +8 -10
- package/types/transaction.d.ts +17 -4
- package/types/transfer.d.ts +0 -1
- package/util.d.ts +2 -2
- package/util.js +11 -10
- package/util.js.map +1 -1
- package/util.mjs +11 -10
- package/util.mjs.map +1 -1
- package/account/account.d.ts.map +0 -1
- package/account/get-account-config-from-environment.d.ts.map +0 -1
- package/account/get-account.d.ts.map +0 -1
- package/account/get-dispenser-account.d.ts.map +0 -1
- package/account/index.d.ts.map +0 -1
- package/account/mnemonic-account.d.ts.map +0 -1
- package/amount.d.ts.map +0 -1
- package/app-client.d.ts.map +0 -1
- package/app-deploy.d.ts.map +0 -1
- package/app.d.ts.map +0 -1
- package/asset.d.ts.map +0 -1
- package/config.d.ts.map +0 -1
- package/debugging/debugging.d.ts.map +0 -1
- package/debugging/index.d.ts.map +0 -1
- package/debugging/simulate-and-persist-response.d.ts +0 -20
- package/debugging/simulate-and-persist-response.d.ts.map +0 -1
- package/debugging/simulate-and-persist-response.js +0 -108
- package/debugging/simulate-and-persist-response.js.map +0 -1
- package/debugging/simulate-and-persist-response.mjs +0 -89
- package/debugging/simulate-and-persist-response.mjs.map +0 -1
- package/dispenser-client.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/indexer-lookup.d.ts.map +0 -1
- package/localnet/get-kmd-wallet-account.d.ts.map +0 -1
- package/localnet/get-localnet-dispenser-account.d.ts.map +0 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts.map +0 -1
- package/localnet/index.d.ts.map +0 -1
- package/localnet/is-localnet.d.ts.map +0 -1
- package/network-client.d.ts.map +0 -1
- package/testing/_asset.d.ts.map +0 -1
- package/testing/account.d.ts.map +0 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +0 -1
- package/testing/fixtures/algorand-fixture.d.ts.map +0 -1
- package/testing/fixtures/index.d.ts.map +0 -1
- package/testing/index.d.ts.map +0 -1
- package/testing/indexer.d.ts.map +0 -1
- package/testing/test-logger.d.ts.map +0 -1
- package/testing/transaction-logger.d.ts.map +0 -1
- package/transaction/index.d.ts.map +0 -1
- package/transaction/legacy-bridge.d.ts.map +0 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts.map +0 -1
- package/transaction/transaction.d.ts.map +0 -1
- package/transfer/index.d.ts.map +0 -1
- package/transfer/transfer-algos.d.ts.map +0 -1
- package/transfer/transfer.d.ts.map +0 -1
- package/types/account-manager.d.ts.map +0 -1
- package/types/account.d.ts.map +0 -1
- package/types/algo-http-client-with-retry.d.ts.map +0 -1
- package/types/algorand-client-transaction-creator.d.ts.map +0 -1
- package/types/algorand-client-transaction-sender.d.ts.map +0 -1
- package/types/algorand-client.d.ts.map +0 -1
- package/types/amount.d.ts.map +0 -1
- package/types/app-client.d.ts.map +0 -1
- package/types/app-spec.d.ts.map +0 -1
- package/types/app.d.ts.map +0 -1
- package/types/asset-manager.d.ts.map +0 -1
- package/types/asset.d.ts.map +0 -1
- package/types/client-manager.d.ts.map +0 -1
- package/types/composer.d.ts.map +0 -1
- package/types/config.d.ts.map +0 -1
- package/types/debugging.d.ts.map +0 -1
- package/types/dispenser-client.d.ts.map +0 -1
- package/types/indexer.d.ts.map +0 -1
- package/types/kmd-account-manager.d.ts.map +0 -1
- package/types/logging.d.ts.map +0 -1
- package/types/logic-error.d.ts.map +0 -1
- package/types/network-client.d.ts.map +0 -1
- package/types/testing.d.ts.map +0 -1
- package/types/transaction.d.ts.map +0 -1
- package/types/transfer.d.ts.map +0 -1
- package/types/urlTokenBaseHTTPClient.d.ts +0 -41
- package/types/urlTokenBaseHTTPClient.d.ts.map +0 -1
- package/types/urlTokenBaseHTTPClient.js +0 -153
- package/types/urlTokenBaseHTTPClient.js.map +0 -1
- package/types/urlTokenBaseHTTPClient.mjs +0 -151
- package/types/urlTokenBaseHTTPClient.mjs.map +0 -1
- package/util.d.ts.map +0 -1
package/types/composer.mjs
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import algosdk from 'algosdk';
|
|
2
|
-
import {
|
|
1
|
+
import algosdk, { Address } from 'algosdk';
|
|
2
|
+
import { Config } from '../config.mjs';
|
|
3
|
+
import { encodeLease, sendAtomicTransactionComposer, getABIReturnValue } from '../transaction/transaction.mjs';
|
|
4
|
+
import { APP_PAGE_MAX_SIZE } from './app.mjs';
|
|
5
|
+
import { AppManager } from './app-manager.mjs';
|
|
6
|
+
import { EventType } from './lifecycle-events.mjs';
|
|
3
7
|
import { genesisIdIsLocalNet } from './network-client.mjs';
|
|
4
8
|
|
|
9
|
+
var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
|
|
5
10
|
var isTransactionWithSigner = algosdk.isTransactionWithSigner;
|
|
6
|
-
var
|
|
11
|
+
var modelsv2 = algosdk.modelsv2;
|
|
12
|
+
const address = (address) => {
|
|
13
|
+
return typeof address === 'string' ? Address.fromString(address) : address;
|
|
14
|
+
};
|
|
7
15
|
const MAX_TRANSACTION_GROUP_SIZE = 16;
|
|
8
|
-
/**
|
|
9
|
-
class
|
|
16
|
+
/** TransactionComposer helps you compose and execute transactions as a transaction group. */
|
|
17
|
+
class TransactionComposer {
|
|
10
18
|
/**
|
|
11
|
-
* Create
|
|
19
|
+
* Create a `TransactionComposer`.
|
|
12
20
|
* @param params The configuration for this composer
|
|
13
21
|
*/
|
|
14
22
|
constructor(params) {
|
|
@@ -19,7 +27,7 @@ class AlgoKitComposer {
|
|
|
19
27
|
/** Transactions that have not yet been composed */
|
|
20
28
|
this.txns = [];
|
|
21
29
|
/** The default transaction validity window */
|
|
22
|
-
this.defaultValidityWindow =
|
|
30
|
+
this.defaultValidityWindow = 10n;
|
|
23
31
|
/** Whether the validity window was explicitly set on construction */
|
|
24
32
|
this.defaultValidityWindowIsExplicit = false;
|
|
25
33
|
this.algod = params.algod;
|
|
@@ -28,6 +36,21 @@ class AlgoKitComposer {
|
|
|
28
36
|
this.getSigner = params.getSigner;
|
|
29
37
|
this.defaultValidityWindow = params.defaultValidityWindow ?? this.defaultValidityWindow;
|
|
30
38
|
this.defaultValidityWindowIsExplicit = params.defaultValidityWindow !== undefined;
|
|
39
|
+
this.appManager = params.appManager ?? new AppManager(params.algod);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Add a pre-built transaction to the transaction group.
|
|
43
|
+
* @param transaction The pre-built transaction
|
|
44
|
+
* @param signer Optional signer override for the transaction
|
|
45
|
+
* @returns The composer so you can chain method calls
|
|
46
|
+
*/
|
|
47
|
+
addTransaction(transaction, signer) {
|
|
48
|
+
this.txns.push({
|
|
49
|
+
txn: transaction,
|
|
50
|
+
signer: signer ?? this.getSigner(transaction.sender),
|
|
51
|
+
type: 'txnWithSigner',
|
|
52
|
+
});
|
|
53
|
+
return this;
|
|
31
54
|
}
|
|
32
55
|
/**
|
|
33
56
|
* Add a payment transaction to the transaction group.
|
|
@@ -101,9 +124,44 @@ class AlgoKitComposer {
|
|
|
101
124
|
this.txns.push({ ...params, type: 'assetOptOut' });
|
|
102
125
|
return this;
|
|
103
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Add an application create transaction to the transaction group.
|
|
129
|
+
*
|
|
130
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
131
|
+
* @param params The application create transaction parameters
|
|
132
|
+
* @returns The composer so you can chain method calls
|
|
133
|
+
*/
|
|
134
|
+
addAppCreate(params) {
|
|
135
|
+
this.txns.push({ ...params, type: 'appCall' });
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Add an application update transaction to the transaction group.
|
|
140
|
+
*
|
|
141
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
142
|
+
* @param params The application update transaction parameters
|
|
143
|
+
* @returns The composer so you can chain method calls
|
|
144
|
+
*/
|
|
145
|
+
addAppUpdate(params) {
|
|
146
|
+
this.txns.push({ ...params, type: 'appCall', onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC });
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Add an application delete transaction to the transaction group.
|
|
151
|
+
*
|
|
152
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
153
|
+
* @param params The application delete transaction parameters
|
|
154
|
+
* @returns The composer so you can chain method calls
|
|
155
|
+
*/
|
|
156
|
+
addAppDelete(params) {
|
|
157
|
+
this.txns.push({ ...params, type: 'appCall', onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC });
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
104
160
|
/**
|
|
105
161
|
* Add an application call transaction to the transaction group.
|
|
106
162
|
*
|
|
163
|
+
* If you want to create or update an app use `addAppCreate` or `addAppUpdate`.
|
|
164
|
+
*
|
|
107
165
|
* Note: we recommend using app clients to make it easier to make app calls.
|
|
108
166
|
* @param params The application call transaction parameters
|
|
109
167
|
* @returns The composer so you can chain method calls
|
|
@@ -113,13 +171,46 @@ class AlgoKitComposer {
|
|
|
113
171
|
return this;
|
|
114
172
|
}
|
|
115
173
|
/**
|
|
116
|
-
* Add an ABI method application call transaction to the transaction group.
|
|
174
|
+
* Add an ABI method create application call transaction to the transaction group.
|
|
175
|
+
*
|
|
176
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
177
|
+
* @param params The ABI create method application call transaction parameters
|
|
178
|
+
* @returns The composer so you can chain method calls
|
|
179
|
+
*/
|
|
180
|
+
addAppCreateMethodCall(params) {
|
|
181
|
+
this.txns.push({ ...params, type: 'methodCall' });
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Add an ABI method update application call transaction to the transaction group.
|
|
186
|
+
*
|
|
187
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
188
|
+
* @param params The ABI update method application call transaction parameters
|
|
189
|
+
* @returns The composer so you can chain method calls
|
|
190
|
+
*/
|
|
191
|
+
addAppUpdateMethodCall(params) {
|
|
192
|
+
this.txns.push({ ...params, type: 'methodCall', onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC });
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Add an ABI method delete application call transaction to the transaction group.
|
|
197
|
+
*
|
|
198
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
199
|
+
* @param params The ABI delete method application call transaction parameters
|
|
200
|
+
* @returns The composer so you can chain method calls
|
|
201
|
+
*/
|
|
202
|
+
addAppDeleteMethodCall(params) {
|
|
203
|
+
this.txns.push({ ...params, type: 'methodCall', onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC });
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Add a non-create/non-update ABI method application call transaction to the transaction group.
|
|
117
208
|
*
|
|
118
209
|
* Note: we recommend using app clients to make it easier to make app calls.
|
|
119
210
|
* @param params The ABI method application call transaction parameters
|
|
120
211
|
* @returns The composer so you can chain method calls
|
|
121
212
|
*/
|
|
122
|
-
|
|
213
|
+
addAppCallMethodCall(params) {
|
|
123
214
|
this.txns.push({ ...params, type: 'methodCall' });
|
|
124
215
|
return this;
|
|
125
216
|
}
|
|
@@ -141,73 +232,105 @@ class AlgoKitComposer {
|
|
|
141
232
|
this.txns.push({ atc, type: 'atc' });
|
|
142
233
|
return this;
|
|
143
234
|
}
|
|
235
|
+
/** Build an ATC and return transactions ready to be incorporated into a broader set of transactions this composer is composing */
|
|
144
236
|
buildAtc(atc) {
|
|
145
237
|
const group = atc.buildGroup();
|
|
146
|
-
const txnWithSigners = group.map((ts) => {
|
|
238
|
+
const txnWithSigners = group.map((ts, idx) => {
|
|
239
|
+
// Remove underlying group ID from the transaction since it will be re-grouped when this TransactionComposer is built
|
|
147
240
|
ts.txn.group = undefined;
|
|
241
|
+
// If this was a method call stash the ABIMethod for later
|
|
242
|
+
if (atc['methodCalls'].get(idx)) {
|
|
243
|
+
this.txnMethodMap.set(ts.txn.txID(), atc['methodCalls'].get(idx));
|
|
244
|
+
}
|
|
148
245
|
return ts;
|
|
149
246
|
});
|
|
150
|
-
const method = atc['methodCalls'].get(group.length - 1);
|
|
151
|
-
if (method)
|
|
152
|
-
this.txnMethodMap.set(txnWithSigners.at(-1).txn.txID(), method);
|
|
153
247
|
return txnWithSigners;
|
|
154
248
|
}
|
|
155
|
-
commonTxnBuildStep(
|
|
249
|
+
commonTxnBuildStep(buildTxn, params, txnParams) {
|
|
250
|
+
// We are going to mutate suggested params, let's create a clone first
|
|
251
|
+
txnParams.suggestedParams = { ...txnParams.suggestedParams };
|
|
156
252
|
if (params.lease)
|
|
157
|
-
|
|
253
|
+
txnParams.lease = encodeLease(params.lease);
|
|
158
254
|
if (params.rekeyTo)
|
|
159
|
-
|
|
255
|
+
txnParams.rekeyTo = address(params.rekeyTo);
|
|
256
|
+
const encoder = new TextEncoder();
|
|
160
257
|
if (params.note)
|
|
161
|
-
|
|
258
|
+
txnParams.note = (typeof params.note === 'string' ? encoder.encode(params.note) : params.note);
|
|
162
259
|
if (params.firstValidRound) {
|
|
163
|
-
|
|
260
|
+
txnParams.suggestedParams.firstValid = params.firstValidRound;
|
|
164
261
|
}
|
|
165
262
|
if (params.lastValidRound) {
|
|
166
|
-
|
|
263
|
+
txnParams.suggestedParams.lastValid = params.lastValidRound;
|
|
167
264
|
}
|
|
168
265
|
else {
|
|
169
266
|
// If the validity window isn't set in this transaction or by default and we are pointing at
|
|
170
267
|
// LocalNet set a bigger window to avoid dead transactions
|
|
171
|
-
const window = params.validityWindow
|
|
172
|
-
|
|
173
|
-
|
|
268
|
+
const window = params.validityWindow
|
|
269
|
+
? BigInt(params.validityWindow)
|
|
270
|
+
: !this.defaultValidityWindowIsExplicit && genesisIdIsLocalNet(txnParams.suggestedParams.genesisID ?? 'unknown')
|
|
271
|
+
? 1000n
|
|
272
|
+
: this.defaultValidityWindow;
|
|
273
|
+
txnParams.suggestedParams.lastValid = BigInt(txnParams.suggestedParams.firstValid) + window;
|
|
174
274
|
}
|
|
175
275
|
if (params.staticFee !== undefined && params.extraFee !== undefined) {
|
|
176
276
|
throw Error('Cannot set both staticFee and extraFee');
|
|
177
277
|
}
|
|
178
278
|
if (params.staticFee !== undefined) {
|
|
179
|
-
|
|
279
|
+
txnParams.suggestedParams.fee = params.staticFee.microAlgo;
|
|
280
|
+
txnParams.suggestedParams.flatFee = true;
|
|
180
281
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
txn.fee += params.extraFee.microAlgo;
|
|
185
|
-
}
|
|
186
|
-
txn.flatFee = true;
|
|
282
|
+
const txn = buildTxn(txnParams);
|
|
283
|
+
if (params.extraFee)
|
|
284
|
+
txn.fee += params.extraFee.microAlgo;
|
|
187
285
|
if (params.maxFee !== undefined && txn.fee > params.maxFee.microAlgo) {
|
|
188
|
-
throw Error(`Transaction fee ${txn.fee} is greater than maxFee ${params.maxFee}`);
|
|
286
|
+
throw Error(`Transaction fee ${txn.fee} µALGO is greater than maxFee ${params.maxFee}`);
|
|
189
287
|
}
|
|
190
288
|
return txn;
|
|
191
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Builds an ABI method call transaction and any other associated transactions represented in the ABI args.
|
|
292
|
+
* @param includeSigner Whether to include the actual signer for the transactions.
|
|
293
|
+
* If you are just building transactions without signers yet then set this to `false`.
|
|
294
|
+
*/
|
|
192
295
|
async buildMethodCall(params, suggestedParams, includeSigner) {
|
|
193
296
|
const methodArgs = [];
|
|
297
|
+
const transactionsForGroup = [];
|
|
194
298
|
const isAbiValue = (x) => {
|
|
195
299
|
if (Array.isArray(x))
|
|
196
300
|
return x.length == 0 || x.every(isAbiValue);
|
|
197
|
-
return
|
|
301
|
+
return typeof x === 'bigint' || typeof x === 'boolean' || typeof x === 'number' || typeof x === 'string' || x instanceof Uint8Array;
|
|
198
302
|
};
|
|
199
|
-
for (
|
|
303
|
+
for (let i = (params.args ?? []).length - 1; i >= 0; i--) {
|
|
304
|
+
const arg = params.args[i];
|
|
305
|
+
if (arg === undefined) {
|
|
306
|
+
// An undefined transaction argument signals that the value will be supplied by a method call argument
|
|
307
|
+
if (algosdk.abiTypeIsTransaction(params.method.args[i].type) && transactionsForGroup.length > 0) {
|
|
308
|
+
// Move the last transaction from the group to the method call arguments to appease algosdk
|
|
309
|
+
const placeholderTransaction = transactionsForGroup.splice(-1, 1)[0];
|
|
310
|
+
methodArgs.push(placeholderTransaction);
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
throw Error(`No value provided for argument ${i + 1} within call to ${params.method.name}`);
|
|
314
|
+
}
|
|
200
315
|
if (isAbiValue(arg)) {
|
|
201
316
|
methodArgs.push(arg);
|
|
202
317
|
continue;
|
|
203
318
|
}
|
|
319
|
+
// Underlying ATC only supports addresses as strings
|
|
320
|
+
if (arg instanceof Address) {
|
|
321
|
+
methodArgs.push(arg.toString());
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
204
324
|
if (isTransactionWithSigner(arg)) {
|
|
205
325
|
methodArgs.push(arg);
|
|
206
326
|
continue;
|
|
207
327
|
}
|
|
208
328
|
if ('method' in arg) {
|
|
209
329
|
const tempTxnWithSigners = await this.buildMethodCall(arg, suggestedParams, includeSigner);
|
|
210
|
-
|
|
330
|
+
// If there is any transaction args, add to the atc
|
|
331
|
+
// Everything else should be added as method args
|
|
332
|
+
methodArgs.push(...tempTxnWithSigners.slice(-1)); // Add the method call itself as a method arg
|
|
333
|
+
transactionsForGroup.push(...tempTxnWithSigners.slice(0, -1).reverse()); // Add any transaction arguments to the atc
|
|
211
334
|
continue;
|
|
212
335
|
}
|
|
213
336
|
const txn = await arg;
|
|
@@ -218,73 +341,97 @@ class AlgoKitComposer {
|
|
|
218
341
|
? 'signer' in params.signer
|
|
219
342
|
? params.signer.signer
|
|
220
343
|
: params.signer
|
|
221
|
-
: this.getSigner(
|
|
222
|
-
:
|
|
344
|
+
: this.getSigner(txn.sender)
|
|
345
|
+
: TransactionComposer.NULL_SIGNER,
|
|
223
346
|
});
|
|
224
347
|
}
|
|
225
348
|
const methodAtc = new algosdk.AtomicTransactionComposer();
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
349
|
+
transactionsForGroup.reverse().forEach((txn) => methodAtc.addTransaction(txn));
|
|
350
|
+
const appId = Number('appId' in params ? params.appId : 0n);
|
|
351
|
+
const approvalProgram = 'approvalProgram' in params
|
|
352
|
+
? typeof params.approvalProgram === 'string'
|
|
353
|
+
? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes
|
|
354
|
+
: params.approvalProgram
|
|
355
|
+
: undefined;
|
|
356
|
+
const clearStateProgram = 'clearStateProgram' in params
|
|
357
|
+
? typeof params.clearStateProgram === 'string'
|
|
358
|
+
? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes
|
|
359
|
+
: params.clearStateProgram
|
|
360
|
+
: undefined;
|
|
361
|
+
const txnParams = {
|
|
362
|
+
appID: appId,
|
|
229
363
|
sender: params.sender,
|
|
230
364
|
suggestedParams,
|
|
231
|
-
onComplete: params.onComplete,
|
|
365
|
+
onComplete: params.onComplete ?? algosdk.OnApplicationComplete.NoOpOC,
|
|
232
366
|
appAccounts: params.accountReferences,
|
|
233
367
|
appForeignApps: params.appReferences?.map((x) => Number(x)),
|
|
234
368
|
appForeignAssets: params.assetReferences?.map((x) => Number(x)),
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
369
|
+
boxes: params.boxReferences?.map(AppManager.getBoxReference),
|
|
370
|
+
approvalProgram,
|
|
371
|
+
clearProgram: clearStateProgram,
|
|
372
|
+
extraPages: appId === 0
|
|
373
|
+
? 'extraProgramPages' in params && params.extraProgramPages !== undefined
|
|
374
|
+
? params.extraProgramPages
|
|
375
|
+
: approvalProgram
|
|
376
|
+
? Math.floor((approvalProgram.length + (clearStateProgram?.length ?? 0)) / APP_PAGE_MAX_SIZE)
|
|
377
|
+
: 0
|
|
378
|
+
: undefined,
|
|
379
|
+
numLocalInts: appId === 0 ? ('schema' in params ? (params.schema?.localInts ?? 0) : 0) : undefined,
|
|
380
|
+
numLocalByteSlices: appId === 0 ? ('schema' in params ? (params.schema?.localByteSlices ?? 0) : 0) : undefined,
|
|
381
|
+
numGlobalInts: appId === 0 ? ('schema' in params ? (params.schema?.globalInts ?? 0) : 0) : undefined,
|
|
382
|
+
numGlobalByteSlices: appId === 0 ? ('schema' in params ? (params.schema?.globalByteSlices ?? 0) : 0) : undefined,
|
|
242
383
|
method: params.method,
|
|
243
|
-
signer:
|
|
244
|
-
|
|
384
|
+
signer: includeSigner
|
|
385
|
+
? params.signer
|
|
386
|
+
? 'signer' in params.signer
|
|
387
|
+
? params.signer.signer
|
|
388
|
+
: params.signer
|
|
389
|
+
: this.getSigner(params.sender)
|
|
390
|
+
: TransactionComposer.NULL_SIGNER,
|
|
391
|
+
methodArgs: methodArgs.reverse(),
|
|
245
392
|
// note, lease, and rekeyTo are set in the common build step
|
|
246
393
|
note: undefined,
|
|
247
394
|
lease: undefined,
|
|
248
395
|
rekeyTo: undefined,
|
|
249
|
-
}
|
|
250
|
-
//
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
396
|
+
};
|
|
397
|
+
// Build the transaction
|
|
398
|
+
this.commonTxnBuildStep((txnParams) => {
|
|
399
|
+
methodAtc.addMethodCall(txnParams);
|
|
400
|
+
return methodAtc.buildGroup()[methodAtc.count() - 1].txn;
|
|
401
|
+
}, params, txnParams);
|
|
402
|
+
// Process the ATC to get a set of transactions ready for broader grouping
|
|
254
403
|
return this.buildAtc(methodAtc);
|
|
255
404
|
}
|
|
256
405
|
buildPayment(params, suggestedParams) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
406
|
+
return this.commonTxnBuildStep(algosdk.makePaymentTxnWithSuggestedParamsFromObject, params, {
|
|
407
|
+
sender: params.sender,
|
|
408
|
+
receiver: params.receiver,
|
|
260
409
|
amount: params.amount.microAlgo,
|
|
261
410
|
closeRemainderTo: params.closeRemainderTo,
|
|
262
411
|
suggestedParams,
|
|
263
412
|
});
|
|
264
|
-
return this.commonTxnBuildStep(params, txn, suggestedParams);
|
|
265
413
|
}
|
|
266
414
|
buildAssetCreate(params, suggestedParams) {
|
|
267
|
-
|
|
268
|
-
|
|
415
|
+
return this.commonTxnBuildStep(algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject, params, {
|
|
416
|
+
sender: params.sender,
|
|
269
417
|
total: params.total,
|
|
270
418
|
decimals: params.decimals ?? 0,
|
|
271
419
|
assetName: params.assetName,
|
|
272
420
|
unitName: params.unitName,
|
|
273
421
|
assetURL: params.url,
|
|
274
422
|
defaultFrozen: params.defaultFrozen ?? false,
|
|
275
|
-
assetMetadataHash: params.metadataHash,
|
|
423
|
+
assetMetadataHash: typeof params.metadataHash === 'string' ? Buffer.from(params.metadataHash, 'utf-8') : params.metadataHash,
|
|
276
424
|
manager: params.manager,
|
|
277
425
|
reserve: params.reserve,
|
|
278
426
|
freeze: params.freeze,
|
|
279
427
|
clawback: params.clawback,
|
|
280
428
|
suggestedParams,
|
|
281
429
|
});
|
|
282
|
-
return this.commonTxnBuildStep(params, txn, suggestedParams);
|
|
283
430
|
}
|
|
284
431
|
buildAssetConfig(params, suggestedParams) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
assetIndex:
|
|
432
|
+
return this.commonTxnBuildStep(algosdk.makeAssetConfigTxnWithSuggestedParamsFromObject, params, {
|
|
433
|
+
sender: params.sender,
|
|
434
|
+
assetIndex: params.assetId,
|
|
288
435
|
suggestedParams,
|
|
289
436
|
manager: params.manager,
|
|
290
437
|
reserve: params.reserve,
|
|
@@ -292,89 +439,101 @@ class AlgoKitComposer {
|
|
|
292
439
|
clawback: params.clawback,
|
|
293
440
|
strictEmptyAddressChecking: false,
|
|
294
441
|
});
|
|
295
|
-
return this.commonTxnBuildStep(params, txn, suggestedParams);
|
|
296
442
|
}
|
|
297
443
|
buildAssetDestroy(params, suggestedParams) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
assetIndex:
|
|
444
|
+
return this.commonTxnBuildStep(algosdk.makeAssetDestroyTxnWithSuggestedParamsFromObject, params, {
|
|
445
|
+
sender: params.sender,
|
|
446
|
+
assetIndex: params.assetId,
|
|
301
447
|
suggestedParams,
|
|
302
448
|
});
|
|
303
|
-
return this.commonTxnBuildStep(params, txn, suggestedParams);
|
|
304
449
|
}
|
|
305
450
|
buildAssetFreeze(params, suggestedParams) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
assetIndex:
|
|
451
|
+
return this.commonTxnBuildStep(algosdk.makeAssetFreezeTxnWithSuggestedParamsFromObject, params, {
|
|
452
|
+
sender: params.sender,
|
|
453
|
+
assetIndex: params.assetId,
|
|
309
454
|
freezeTarget: params.account,
|
|
310
|
-
|
|
455
|
+
frozen: params.frozen,
|
|
311
456
|
suggestedParams,
|
|
312
457
|
});
|
|
313
|
-
return this.commonTxnBuildStep(params, txn, suggestedParams);
|
|
314
458
|
}
|
|
315
459
|
buildAssetTransfer(params, suggestedParams) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
assetIndex:
|
|
460
|
+
return this.commonTxnBuildStep(algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject, params, {
|
|
461
|
+
sender: params.sender,
|
|
462
|
+
receiver: params.receiver,
|
|
463
|
+
assetIndex: params.assetId,
|
|
320
464
|
amount: params.amount,
|
|
321
465
|
suggestedParams,
|
|
322
466
|
closeRemainderTo: params.closeAssetTo,
|
|
323
|
-
|
|
467
|
+
assetSender: params.clawbackTarget,
|
|
324
468
|
});
|
|
325
|
-
return this.commonTxnBuildStep(params, txn, suggestedParams);
|
|
326
469
|
}
|
|
327
|
-
buildAppCall(params, suggestedParams) {
|
|
470
|
+
async buildAppCall(params, suggestedParams) {
|
|
471
|
+
const appId = 'appId' in params ? params.appId : 0n;
|
|
472
|
+
const approvalProgram = 'approvalProgram' in params
|
|
473
|
+
? typeof params.approvalProgram === 'string'
|
|
474
|
+
? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes
|
|
475
|
+
: params.approvalProgram
|
|
476
|
+
: undefined;
|
|
477
|
+
const clearStateProgram = 'clearStateProgram' in params
|
|
478
|
+
? typeof params.clearStateProgram === 'string'
|
|
479
|
+
? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes
|
|
480
|
+
: params.clearStateProgram
|
|
481
|
+
: undefined;
|
|
328
482
|
const sdkParams = {
|
|
329
|
-
|
|
483
|
+
sender: params.sender,
|
|
330
484
|
suggestedParams,
|
|
331
|
-
onComplete: params.onComplete,
|
|
332
|
-
approvalProgram: params.approvalProgram,
|
|
333
|
-
clearProgram: params.clearProgram,
|
|
334
485
|
appArgs: params.args,
|
|
486
|
+
onComplete: params.onComplete ?? algosdk.OnApplicationComplete.NoOpOC,
|
|
335
487
|
accounts: params.accountReferences,
|
|
336
488
|
foreignApps: params.appReferences?.map((x) => Number(x)),
|
|
337
489
|
foreignAssets: params.assetReferences?.map((x) => Number(x)),
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
numGlobalInts: params.schema?.globalUints || 0,
|
|
342
|
-
numGlobalByteSlices: params.schema?.globalByteSlices || 0,
|
|
490
|
+
boxes: params.boxReferences?.map(AppManager.getBoxReference),
|
|
491
|
+
approvalProgram,
|
|
492
|
+
clearProgram: clearStateProgram,
|
|
343
493
|
};
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (params.approvalProgram === undefined || params.clearProgram === undefined) {
|
|
348
|
-
throw new Error('approvalProgram and clearProgram are required for application creation');
|
|
494
|
+
if (appId === 0n) {
|
|
495
|
+
if (sdkParams.approvalProgram === undefined || sdkParams.clearProgram === undefined) {
|
|
496
|
+
throw new Error('approvalProgram and clearStateProgram are required for application creation');
|
|
349
497
|
}
|
|
350
|
-
|
|
498
|
+
return this.commonTxnBuildStep(algosdk.makeApplicationCreateTxnFromObject, params, {
|
|
351
499
|
...sdkParams,
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
500
|
+
extraPages: 'extraProgramPages' in params
|
|
501
|
+
? (params.extraProgramPages ?? Math.floor((approvalProgram.length + clearStateProgram.length) / APP_PAGE_MAX_SIZE))
|
|
502
|
+
: 0,
|
|
503
|
+
numLocalInts: 'schema' in params ? (params.schema?.localInts ?? 0) : 0,
|
|
504
|
+
numLocalByteSlices: 'schema' in params ? (params.schema?.localByteSlices ?? 0) : 0,
|
|
505
|
+
numGlobalInts: 'schema' in params ? (params.schema?.globalInts ?? 0) : 0,
|
|
506
|
+
numGlobalByteSlices: 'schema' in params ? (params.schema?.globalByteSlices ?? 0) : 0,
|
|
507
|
+
approvalProgram: approvalProgram,
|
|
508
|
+
clearProgram: clearStateProgram,
|
|
355
509
|
});
|
|
356
510
|
}
|
|
357
|
-
|
|
358
|
-
|
|
511
|
+
else {
|
|
512
|
+
return this.commonTxnBuildStep(algosdk.makeApplicationCallTxnFromObject, params, { ...sdkParams, appIndex: appId });
|
|
513
|
+
}
|
|
359
514
|
}
|
|
360
515
|
buildKeyReg(params, suggestedParams) {
|
|
361
|
-
|
|
362
|
-
|
|
516
|
+
return this.commonTxnBuildStep(algosdk.makeKeyRegistrationTxnWithSuggestedParamsFromObject, params, {
|
|
517
|
+
sender: params.sender,
|
|
518
|
+
voteKey: params.voteKey,
|
|
519
|
+
selectionKey: params.selectionKey,
|
|
520
|
+
voteFirst: params.voteFirst,
|
|
521
|
+
voteLast: params.voteLast,
|
|
522
|
+
voteKeyDilution: params.voteKeyDilution,
|
|
523
|
+
stateProofKey: params.stateProofKey,
|
|
524
|
+
nonParticipation: false,
|
|
525
|
+
suggestedParams,
|
|
526
|
+
});
|
|
363
527
|
}
|
|
528
|
+
/** Builds all transaction types apart from `txnWithSigner`, `atc` and `methodCall` since those ones can have custom signers that need to be retrieved. */
|
|
364
529
|
async buildTxn(txn, suggestedParams) {
|
|
365
530
|
switch (txn.type) {
|
|
366
|
-
case 'txnWithSigner':
|
|
367
|
-
return [txn.txn];
|
|
368
|
-
case 'atc':
|
|
369
|
-
return txn.atc.buildGroup().map((ts) => ts.txn);
|
|
370
|
-
case 'methodCall':
|
|
371
|
-
return (await this.buildMethodCall(txn, suggestedParams, false)).map((ts) => ts.txn);
|
|
372
531
|
case 'pay':
|
|
373
532
|
return [this.buildPayment(txn, suggestedParams)];
|
|
374
533
|
case 'assetCreate':
|
|
375
534
|
return [this.buildAssetCreate(txn, suggestedParams)];
|
|
376
535
|
case 'appCall':
|
|
377
|
-
return [this.buildAppCall(txn, suggestedParams)];
|
|
536
|
+
return [await this.buildAppCall(txn, suggestedParams)];
|
|
378
537
|
case 'assetConfig':
|
|
379
538
|
return [this.buildAssetConfig(txn, suggestedParams)];
|
|
380
539
|
case 'assetDestroy':
|
|
@@ -407,43 +566,77 @@ class AlgoKitComposer {
|
|
|
407
566
|
return (await this.buildTxn(txn, suggestedParams)).map((txn) => ({ txn, signer }));
|
|
408
567
|
}
|
|
409
568
|
/**
|
|
410
|
-
* Compose all of the transactions without signers and return the transaction objects directly.
|
|
569
|
+
* Compose all of the transactions without signers and return the transaction objects directly along with any ABI method calls.
|
|
411
570
|
*
|
|
412
|
-
* @returns The array of built transactions
|
|
571
|
+
* @returns The array of built transactions and any corresponding method calls
|
|
413
572
|
*/
|
|
414
573
|
async buildTransactions() {
|
|
415
574
|
const suggestedParams = await this.getSuggestedParams();
|
|
416
575
|
const transactions = [];
|
|
576
|
+
const methodCalls = new Map();
|
|
577
|
+
const signers = new Map();
|
|
417
578
|
for (const txn of this.txns) {
|
|
418
|
-
|
|
579
|
+
if (!['txnWithSigner', 'atc', 'methodCall'].includes(txn.type)) {
|
|
580
|
+
transactions.push(...(await this.buildTxn(txn, suggestedParams)));
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
const transactionsWithSigner = txn.type === 'txnWithSigner'
|
|
584
|
+
? [txn]
|
|
585
|
+
: txn.type === 'atc'
|
|
586
|
+
? this.buildAtc(txn.atc)
|
|
587
|
+
: txn.type === 'methodCall'
|
|
588
|
+
? await this.buildMethodCall(txn, suggestedParams, false)
|
|
589
|
+
: [];
|
|
590
|
+
transactions.push(...transactionsWithSigner.map((ts) => ts.txn));
|
|
591
|
+
transactionsWithSigner.forEach((ts, idx) => {
|
|
592
|
+
if (ts.signer && ts.signer !== TransactionComposer.NULL_SIGNER) {
|
|
593
|
+
signers.set(idx, ts.signer);
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
for (let i = 0; i < transactions.length; i++) {
|
|
599
|
+
const method = this.txnMethodMap.get(transactions[i].txID());
|
|
600
|
+
if (method)
|
|
601
|
+
methodCalls.set(i, method);
|
|
419
602
|
}
|
|
420
|
-
return transactions;
|
|
603
|
+
return { transactions, methodCalls, signers };
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Get the number of transactions currently added to this composer.
|
|
607
|
+
*/
|
|
608
|
+
async count() {
|
|
609
|
+
return (await this.buildTransactions()).transactions.length;
|
|
421
610
|
}
|
|
422
611
|
/**
|
|
423
612
|
* Compose all of the transactions in a single atomic transaction group and an atomic transaction composer.
|
|
424
613
|
*
|
|
425
614
|
* You can then use the transactions standalone, or use the composer to execute or simulate the transactions.
|
|
615
|
+
*
|
|
616
|
+
* Once this method is called, no further transactions will be able to be added.
|
|
617
|
+
* You can safely call this method multiple times to get the same result.
|
|
426
618
|
* @returns The built atomic transaction composer and the transactions
|
|
427
619
|
*/
|
|
428
620
|
async build() {
|
|
429
621
|
if (this.atc.getStatus() === algosdk.AtomicTransactionComposerStatus.BUILDING) {
|
|
430
622
|
const suggestedParams = await this.getSuggestedParams();
|
|
623
|
+
// Build all of the transactions
|
|
431
624
|
const txnWithSigners = [];
|
|
432
625
|
for (const txn of this.txns) {
|
|
433
626
|
txnWithSigners.push(...(await this.buildTxnWithSigner(txn, suggestedParams)));
|
|
434
627
|
}
|
|
435
|
-
|
|
436
|
-
this.atc.addTransaction(ts);
|
|
437
|
-
});
|
|
628
|
+
// Add all of the transactions to the underlying ATC
|
|
438
629
|
const methodCalls = new Map();
|
|
439
630
|
txnWithSigners.forEach((ts, idx) => {
|
|
631
|
+
this.atc.addTransaction(ts);
|
|
632
|
+
// Populate consolidated set of all ABI method calls
|
|
440
633
|
const method = this.txnMethodMap.get(ts.txn.txID());
|
|
441
634
|
if (method)
|
|
442
635
|
methodCalls.set(idx, method);
|
|
443
636
|
});
|
|
444
637
|
this.atc['methodCalls'] = methodCalls;
|
|
445
638
|
}
|
|
446
|
-
return { atc: this.atc, transactions: this.atc.buildGroup() };
|
|
639
|
+
return { atc: this.atc, transactions: this.atc.buildGroup(), methodCalls: this.atc['methodCalls'] };
|
|
447
640
|
}
|
|
448
641
|
/**
|
|
449
642
|
* Rebuild the group, discarding any previously built transactions.
|
|
@@ -455,24 +648,113 @@ class AlgoKitComposer {
|
|
|
455
648
|
return await this.build();
|
|
456
649
|
}
|
|
457
650
|
/**
|
|
458
|
-
* Compose the atomic transaction group and send it to the network
|
|
651
|
+
* Compose the atomic transaction group and send it to the network.
|
|
459
652
|
* @param params The parameters to control execution with
|
|
460
653
|
* @returns The execution result
|
|
461
654
|
*/
|
|
462
|
-
async
|
|
655
|
+
async send(params) {
|
|
463
656
|
const group = (await this.build()).transactions;
|
|
464
657
|
let waitRounds = params?.maxRoundsToWaitForConfirmation;
|
|
465
658
|
if (waitRounds === undefined) {
|
|
466
|
-
const lastRound = group.reduce((max, txn) =>
|
|
467
|
-
const { firstRound } = await this.getSuggestedParams();
|
|
468
|
-
waitRounds = lastRound - firstRound + 1;
|
|
659
|
+
const lastRound = group.reduce((max, txn) => (txn.txn.lastValid > max ? txn.txn.lastValid : BigInt(max)), 0n);
|
|
660
|
+
const { firstValid: firstRound } = await this.getSuggestedParams();
|
|
661
|
+
waitRounds = Number(BigInt(lastRound) - BigInt(firstRound)) + 1;
|
|
469
662
|
}
|
|
470
663
|
return await sendAtomicTransactionComposer({
|
|
471
664
|
atc: this.atc,
|
|
472
|
-
|
|
665
|
+
suppressLog: params?.suppressLog,
|
|
666
|
+
maxRoundsToWaitForConfirmation: waitRounds,
|
|
667
|
+
populateAppCallResources: params?.populateAppCallResources,
|
|
473
668
|
}, this.algod);
|
|
474
669
|
}
|
|
670
|
+
/**
|
|
671
|
+
* @deprecated Use `send` instead.
|
|
672
|
+
*
|
|
673
|
+
* Compose the atomic transaction group and send it to the network
|
|
674
|
+
*
|
|
675
|
+
* An alias for `composer.send(params)`.
|
|
676
|
+
* @param params The parameters to control execution with
|
|
677
|
+
* @returns The execution result
|
|
678
|
+
*/
|
|
679
|
+
async execute(params) {
|
|
680
|
+
return this.send(params);
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Compose the atomic transaction group and simulate sending it to the network
|
|
684
|
+
* @returns The simulation result
|
|
685
|
+
*/
|
|
686
|
+
async simulate(options) {
|
|
687
|
+
const atc = options?.skipSignatures ? new AtomicTransactionComposer() : this.atc;
|
|
688
|
+
// Build the transactions
|
|
689
|
+
if (options?.skipSignatures) {
|
|
690
|
+
options.allowEmptySignatures = true;
|
|
691
|
+
options.fixSigners = true;
|
|
692
|
+
// Build transactions uses empty signers
|
|
693
|
+
const transactions = await this.buildTransactions();
|
|
694
|
+
for (const txn of transactions.transactions) {
|
|
695
|
+
atc.addTransaction({ txn, signer: TransactionComposer.NULL_SIGNER });
|
|
696
|
+
}
|
|
697
|
+
atc['methodCalls'] = transactions.methodCalls;
|
|
698
|
+
}
|
|
699
|
+
else {
|
|
700
|
+
// Build creates real signatures
|
|
701
|
+
await this.build();
|
|
702
|
+
}
|
|
703
|
+
const { methodResults, simulateResponse } = await atc.simulate(this.algod, new modelsv2.SimulateRequest({
|
|
704
|
+
txnGroups: [],
|
|
705
|
+
...options,
|
|
706
|
+
...(Config.debug
|
|
707
|
+
? {
|
|
708
|
+
allowEmptySignatures: true,
|
|
709
|
+
fixSigners: true,
|
|
710
|
+
allowMoreLogging: true,
|
|
711
|
+
execTraceConfig: new modelsv2.SimulateTraceConfig({
|
|
712
|
+
enable: true,
|
|
713
|
+
scratchChange: true,
|
|
714
|
+
stackChange: true,
|
|
715
|
+
stateChange: true,
|
|
716
|
+
}),
|
|
717
|
+
}
|
|
718
|
+
: undefined),
|
|
719
|
+
}));
|
|
720
|
+
const failedGroup = simulateResponse?.txnGroups[0];
|
|
721
|
+
if (failedGroup?.failureMessage) {
|
|
722
|
+
const errorMessage = `Transaction failed at transaction(s) ${failedGroup.failedAt?.join(', ') || 'unknown'} in the group. ${failedGroup.failureMessage}`;
|
|
723
|
+
const error = new Error(errorMessage);
|
|
724
|
+
if (Config.debug) {
|
|
725
|
+
await Config.events.emitAsync(EventType.TxnGroupSimulated, { simulateResponse });
|
|
726
|
+
}
|
|
727
|
+
error.simulateResponse = simulateResponse;
|
|
728
|
+
throw error;
|
|
729
|
+
}
|
|
730
|
+
if (Config.debug && Config.traceAll) {
|
|
731
|
+
await Config.events.emitAsync(EventType.TxnGroupSimulated, { simulateResponse });
|
|
732
|
+
}
|
|
733
|
+
const transactions = atc.buildGroup().map((t) => t.txn);
|
|
734
|
+
return {
|
|
735
|
+
confirmations: simulateResponse.txnGroups[0].txnResults.map((t) => t.txnResult),
|
|
736
|
+
transactions: transactions,
|
|
737
|
+
txIds: transactions.map((t) => t.txID()),
|
|
738
|
+
groupId: Buffer.from(transactions[0].group ?? new Uint8Array()).toString('base64'),
|
|
739
|
+
simulateResponse,
|
|
740
|
+
returns: methodResults.map(getABIReturnValue),
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Create an encoded transaction note that follows the ARC-2 spec.
|
|
745
|
+
*
|
|
746
|
+
* https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md
|
|
747
|
+
* @param note The ARC-2 transaction note data
|
|
748
|
+
* @returns The binary encoded transaction note
|
|
749
|
+
*/
|
|
750
|
+
static arc2Note(note) {
|
|
751
|
+
const arc2Payload = `${note.dAppName}:${note.format}${typeof note.data === 'string' ? note.data : JSON.stringify(note.data)}`;
|
|
752
|
+
const encoder = new TextEncoder();
|
|
753
|
+
return encoder.encode(arc2Payload);
|
|
754
|
+
}
|
|
475
755
|
}
|
|
756
|
+
/** Signer used to represent a lack of signer */
|
|
757
|
+
TransactionComposer.NULL_SIGNER = algosdk.makeEmptyTransactionSigner();
|
|
476
758
|
|
|
477
|
-
export { MAX_TRANSACTION_GROUP_SIZE,
|
|
759
|
+
export { MAX_TRANSACTION_GROUP_SIZE, TransactionComposer };
|
|
478
760
|
//# sourceMappingURL=composer.mjs.map
|