@algorandfoundation/algokit-utils 7.0.0-beta.1 → 7.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -25
- package/account/account.d.ts +8 -9
- package/account/account.js +7 -7
- package/account/account.js.map +1 -1
- package/account/account.mjs +7 -7
- 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 +1 -2
- 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 +14 -5
- package/amount.js +6 -0
- package/amount.js.map +1 -1
- package/amount.mjs +6 -0
- package/amount.mjs.map +1 -1
- package/app-client.d.ts +15 -1
- package/app-client.js +15 -0
- package/app-client.js.map +1 -1
- package/app-client.mjs +15 -0
- package/app-client.mjs.map +1 -1
- package/app-deploy.d.ts +18 -2
- package/app-deploy.js +140 -333
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +143 -336
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +39 -3
- package/app.js +116 -369
- package/app.js.map +1 -1
- package/app.mjs +117 -370
- 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 +4 -4
- package/index.js +31 -26
- package/index.js.map +1 -1
- package/index.mjs +4 -4
- package/indexer-lookup.d.ts +0 -1
- package/indexer-lookup.js.map +1 -1
- 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 +2 -3
- package/network-client.js +2 -2
- package/network-client.js.map +1 -1
- package/network-client.mjs +2 -2
- package/network-client.mjs.map +1 -1
- package/package.json +1 -1
- package/testing/_asset.d.ts +0 -1
- package/testing/account.d.ts +0 -1
- package/testing/account.js.map +1 -1
- 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 +12 -12
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +12 -12
- 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 +1 -3
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs +1 -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 +100 -6
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +99 -8
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts +0 -1
- package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +41 -6
- package/transaction/transaction.js +108 -45
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +108 -46
- 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 +3 -3
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs +3 -3
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +14 -6
- package/types/account-manager.js +18 -4
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +18 -4
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +0 -1
- package/types/account.js.map +1 -1
- package/types/account.mjs.map +1 -1
- package/types/algo-http-client-with-retry.d.ts +0 -1
- package/types/algo-http-client-with-retry.js.map +1 -1
- 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 +450 -21
- package/types/algorand-client-transaction-creator.js +406 -22
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +406 -22
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +758 -33
- package/types/algorand-client-transaction-sender.js +444 -14
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +444 -14
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +18 -10
- package/types/algorand-client.js +23 -10
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +23 -10
- 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 +348 -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 +1496 -9
- package/types/app-client.js +903 -21
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +904 -23
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +126 -0
- package/types/app-deployer.js +354 -0
- package/types/app-deployer.js.map +1 -0
- package/types/app-deployer.mjs +352 -0
- package/types/app-deployer.mjs.map +1 -0
- package/types/app-factory.d.ts +846 -0
- package/types/app-factory.js +411 -0
- package/types/app-factory.js.map +1 -0
- package/types/app-factory.mjs +409 -0
- package/types/app-factory.mjs.map +1 -0
- package/types/app-manager.d.ts +244 -0
- package/types/app-manager.js +334 -0
- package/types/app-manager.js.map +1 -0
- package/types/app-manager.mjs +332 -0
- package/types/app-manager.mjs.map +1 -0
- package/types/app-spec.d.ts +2 -1
- package/types/app-spec.js +121 -0
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +120 -0
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +53 -13
- 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 +4 -4
- package/types/asset-manager.js +3 -4
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +3 -4
- package/types/asset-manager.mjs.map +1 -1
- package/types/asset.d.ts +0 -1
- package/types/async-event-emitter.d.ts +23 -0
- package/types/async-event-emitter.js +55 -0
- package/types/async-event-emitter.js.map +1 -0
- package/types/async-event-emitter.mjs +53 -0
- package/types/async-event-emitter.mjs.map +1 -0
- package/types/client-manager.d.ts +133 -51
- package/types/client-manager.js +147 -23
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +148 -24
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +232 -49
- package/types/composer.js +320 -65
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +321 -66
- 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 +1 -2
- package/types/dispenser-client.js +6 -5
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs +6 -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 +0 -1
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs.map +1 -1
- package/types/kmd-account-manager.d.ts +0 -1
- package/types/kmd-account-manager.js +2 -2
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +2 -2
- package/types/kmd-account-manager.mjs.map +1 -1
- 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 +0 -1
- package/types/logic-error.js.map +1 -1
- package/types/logic-error.mjs.map +1 -1
- package/types/network-client.d.ts +13 -1
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +3 -4
- package/types/transaction.d.ts +17 -4
- package/types/transfer.d.ts +0 -1
- package/types/urlTokenBaseHTTPClient.d.ts +0 -1
- package/types/urlTokenBaseHTTPClient.js +1 -1
- package/types/urlTokenBaseHTTPClient.js.map +1 -1
- package/types/urlTokenBaseHTTPClient.mjs +1 -1
- package/types/urlTokenBaseHTTPClient.mjs.map +1 -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.map +0 -1
- package/util.d.ts.map +0 -1
package/types/composer.js
CHANGED
|
@@ -3,11 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var algosdk = require('algosdk');
|
|
6
|
+
var config = require('../config.js');
|
|
6
7
|
var transaction = require('../transaction/transaction.js');
|
|
8
|
+
var types_app = require('./app.js');
|
|
9
|
+
var types_appManager = require('./app-manager.js');
|
|
10
|
+
var types_asyncEventEmitter = require('./async-event-emitter.js');
|
|
7
11
|
var types_networkClient = require('./network-client.js');
|
|
8
12
|
|
|
13
|
+
var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
|
|
9
14
|
var isTransactionWithSigner = algosdk.isTransactionWithSigner;
|
|
10
15
|
var encodeAddress = algosdk.encodeAddress;
|
|
16
|
+
var modelsv2 = algosdk.modelsv2;
|
|
11
17
|
const MAX_TRANSACTION_GROUP_SIZE = 16;
|
|
12
18
|
/** AlgoKit Composer helps you compose and execute transactions as a transaction group. */
|
|
13
19
|
class AlgoKitComposer {
|
|
@@ -32,6 +38,21 @@ class AlgoKitComposer {
|
|
|
32
38
|
this.getSigner = params.getSigner;
|
|
33
39
|
this.defaultValidityWindow = params.defaultValidityWindow ?? this.defaultValidityWindow;
|
|
34
40
|
this.defaultValidityWindowIsExplicit = params.defaultValidityWindow !== undefined;
|
|
41
|
+
this.appManager = params.appManager ?? new types_appManager.AppManager(params.algod);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Add a pre-built transaction to the transaction group.
|
|
45
|
+
* @param transaction The pre-built transaction
|
|
46
|
+
* @param signer Optional signer override for the transaction
|
|
47
|
+
* @returns The composer so you can chain method calls
|
|
48
|
+
*/
|
|
49
|
+
addTransaction(transaction, signer) {
|
|
50
|
+
this.txns.push({
|
|
51
|
+
txn: transaction,
|
|
52
|
+
signer: signer ?? this.getSigner(algosdk.encodeAddress(transaction.from.publicKey)),
|
|
53
|
+
type: 'txnWithSigner',
|
|
54
|
+
});
|
|
55
|
+
return this;
|
|
35
56
|
}
|
|
36
57
|
/**
|
|
37
58
|
* Add a payment transaction to the transaction group.
|
|
@@ -105,9 +126,44 @@ class AlgoKitComposer {
|
|
|
105
126
|
this.txns.push({ ...params, type: 'assetOptOut' });
|
|
106
127
|
return this;
|
|
107
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Add an application create transaction to the transaction group.
|
|
131
|
+
*
|
|
132
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
133
|
+
* @param params The application create transaction parameters
|
|
134
|
+
* @returns The composer so you can chain method calls
|
|
135
|
+
*/
|
|
136
|
+
addAppCreate(params) {
|
|
137
|
+
this.txns.push({ ...params, type: 'appCall' });
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Add an application update transaction to the transaction group.
|
|
142
|
+
*
|
|
143
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
144
|
+
* @param params The application update transaction parameters
|
|
145
|
+
* @returns The composer so you can chain method calls
|
|
146
|
+
*/
|
|
147
|
+
addAppUpdate(params) {
|
|
148
|
+
this.txns.push({ ...params, type: 'appCall', onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC });
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Add an application delete transaction to the transaction group.
|
|
153
|
+
*
|
|
154
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
155
|
+
* @param params The application delete transaction parameters
|
|
156
|
+
* @returns The composer so you can chain method calls
|
|
157
|
+
*/
|
|
158
|
+
addAppDelete(params) {
|
|
159
|
+
this.txns.push({ ...params, type: 'appCall', onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC });
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
108
162
|
/**
|
|
109
163
|
* Add an application call transaction to the transaction group.
|
|
110
164
|
*
|
|
165
|
+
* If you want to create or update an app use `addAppCreate` or `addAppUpdate`.
|
|
166
|
+
*
|
|
111
167
|
* Note: we recommend using app clients to make it easier to make app calls.
|
|
112
168
|
* @param params The application call transaction parameters
|
|
113
169
|
* @returns The composer so you can chain method calls
|
|
@@ -117,13 +173,46 @@ class AlgoKitComposer {
|
|
|
117
173
|
return this;
|
|
118
174
|
}
|
|
119
175
|
/**
|
|
120
|
-
* Add an ABI method application call transaction to the transaction group.
|
|
176
|
+
* Add an ABI method create application call transaction to the transaction group.
|
|
177
|
+
*
|
|
178
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
179
|
+
* @param params The ABI create method application call transaction parameters
|
|
180
|
+
* @returns The composer so you can chain method calls
|
|
181
|
+
*/
|
|
182
|
+
addAppCreateMethodCall(params) {
|
|
183
|
+
this.txns.push({ ...params, type: 'methodCall' });
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Add an ABI method update application call transaction to the transaction group.
|
|
188
|
+
*
|
|
189
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
190
|
+
* @param params The ABI update method application call transaction parameters
|
|
191
|
+
* @returns The composer so you can chain method calls
|
|
192
|
+
*/
|
|
193
|
+
addAppUpdateMethodCall(params) {
|
|
194
|
+
this.txns.push({ ...params, type: 'methodCall', onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC });
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Add an ABI method delete application call transaction to the transaction group.
|
|
199
|
+
*
|
|
200
|
+
* Note: we recommend using app clients to make it easier to make app calls.
|
|
201
|
+
* @param params The ABI delete method application call transaction parameters
|
|
202
|
+
* @returns The composer so you can chain method calls
|
|
203
|
+
*/
|
|
204
|
+
addAppDeleteMethodCall(params) {
|
|
205
|
+
this.txns.push({ ...params, type: 'methodCall', onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC });
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Add a non-create/non-update ABI method application call transaction to the transaction group.
|
|
121
210
|
*
|
|
122
211
|
* Note: we recommend using app clients to make it easier to make app calls.
|
|
123
212
|
* @param params The ABI method application call transaction parameters
|
|
124
213
|
* @returns The composer so you can chain method calls
|
|
125
214
|
*/
|
|
126
|
-
|
|
215
|
+
addAppCallMethodCall(params) {
|
|
127
216
|
this.txns.push({ ...params, type: 'methodCall' });
|
|
128
217
|
return this;
|
|
129
218
|
}
|
|
@@ -145,15 +234,20 @@ class AlgoKitComposer {
|
|
|
145
234
|
this.txns.push({ atc, type: 'atc' });
|
|
146
235
|
return this;
|
|
147
236
|
}
|
|
148
|
-
|
|
237
|
+
/** Build an ATC and return transactions ready to be incorporated into a broader set of transactions this composer is composing */
|
|
238
|
+
buildAtc(atc, processTransaction) {
|
|
149
239
|
const group = atc.buildGroup();
|
|
150
|
-
const txnWithSigners = group.map((ts) => {
|
|
240
|
+
const txnWithSigners = group.map((ts, idx) => {
|
|
241
|
+
// Remove underlying group ID from the transaction since it will be re-grouped when this AlgoKitComposer is built
|
|
151
242
|
ts.txn.group = undefined;
|
|
243
|
+
// Process transaction if a function is provided
|
|
244
|
+
ts.txn = processTransaction?.(ts.txn, idx) ?? ts.txn;
|
|
245
|
+
// If this was a method call stash the ABIMethod for later
|
|
246
|
+
if (atc['methodCalls'].get(idx)) {
|
|
247
|
+
this.txnMethodMap.set(ts.txn.txID(), atc['methodCalls'].get(idx));
|
|
248
|
+
}
|
|
152
249
|
return ts;
|
|
153
250
|
});
|
|
154
|
-
const method = atc['methodCalls'].get(group.length - 1);
|
|
155
|
-
if (method)
|
|
156
|
-
this.txnMethodMap.set(txnWithSigners.at(-1).txn.txID(), method);
|
|
157
251
|
return txnWithSigners;
|
|
158
252
|
}
|
|
159
253
|
commonTxnBuildStep(params, txn, suggestedParams) {
|
|
@@ -161,8 +255,9 @@ class AlgoKitComposer {
|
|
|
161
255
|
txn.addLease(transaction.encodeLease(params.lease));
|
|
162
256
|
if (params.rekeyTo)
|
|
163
257
|
txn.addRekey(params.rekeyTo);
|
|
258
|
+
const encoder = new TextEncoder();
|
|
164
259
|
if (params.note)
|
|
165
|
-
txn.note =
|
|
260
|
+
txn.note = typeof params.note === 'string' ? encoder.encode(params.note) : params.note;
|
|
166
261
|
if (params.firstValidRound) {
|
|
167
262
|
txn.firstRound = Number(params.firstValidRound);
|
|
168
263
|
}
|
|
@@ -180,27 +275,36 @@ class AlgoKitComposer {
|
|
|
180
275
|
throw Error('Cannot set both staticFee and extraFee');
|
|
181
276
|
}
|
|
182
277
|
if (params.staticFee !== undefined) {
|
|
183
|
-
txn.fee = params.staticFee.microAlgo;
|
|
278
|
+
txn.fee = Number(params.staticFee.microAlgo);
|
|
184
279
|
}
|
|
185
280
|
else {
|
|
186
281
|
txn.fee = txn.estimateSize() * suggestedParams.fee || algosdk.ALGORAND_MIN_TX_FEE;
|
|
187
282
|
if (params.extraFee)
|
|
188
|
-
txn.fee += params.extraFee.microAlgo;
|
|
283
|
+
txn.fee += Number(params.extraFee.microAlgo);
|
|
189
284
|
}
|
|
190
285
|
txn.flatFee = true;
|
|
191
286
|
if (params.maxFee !== undefined && txn.fee > params.maxFee.microAlgo) {
|
|
192
|
-
throw Error(`Transaction fee ${txn.fee} is greater than maxFee ${params.maxFee}`);
|
|
287
|
+
throw Error(`Transaction fee ${txn.fee} µALGO is greater than maxFee ${params.maxFee}`);
|
|
193
288
|
}
|
|
194
289
|
return txn;
|
|
195
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Builds an ABI method call transaction and any other associated transactions represented in the ABI args.
|
|
293
|
+
* @param includeSigner Whether to include the actual signer for the transactions.
|
|
294
|
+
* If you are just building transactions without signers yet then set this to `false`.
|
|
295
|
+
*/
|
|
196
296
|
async buildMethodCall(params, suggestedParams, includeSigner) {
|
|
197
297
|
const methodArgs = [];
|
|
198
298
|
const isAbiValue = (x) => {
|
|
199
299
|
if (Array.isArray(x))
|
|
200
300
|
return x.length == 0 || x.every(isAbiValue);
|
|
201
|
-
return
|
|
301
|
+
return typeof x === 'bigint' || typeof x === 'boolean' || typeof x === 'number' || typeof x === 'string' || x instanceof Uint8Array;
|
|
202
302
|
};
|
|
203
|
-
for (
|
|
303
|
+
for (let i = 0; i < (params.args ?? []).length; i++) {
|
|
304
|
+
const arg = params.args[i];
|
|
305
|
+
if (arg === undefined) {
|
|
306
|
+
throw Error(`No value provided for argument ${i + 1} within call to ${params.method.name}`);
|
|
307
|
+
}
|
|
204
308
|
if (isAbiValue(arg)) {
|
|
205
309
|
methodArgs.push(arg);
|
|
206
310
|
continue;
|
|
@@ -223,39 +327,60 @@ class AlgoKitComposer {
|
|
|
223
327
|
? params.signer.signer
|
|
224
328
|
: params.signer
|
|
225
329
|
: this.getSigner(encodeAddress(txn.from.publicKey))
|
|
226
|
-
:
|
|
330
|
+
: AlgoKitComposer.NULL_SIGNER,
|
|
227
331
|
});
|
|
228
332
|
}
|
|
229
333
|
const methodAtc = new algosdk.AtomicTransactionComposer();
|
|
230
|
-
const
|
|
334
|
+
const appId = Number('appId' in params ? params.appId : 0n);
|
|
335
|
+
const approvalProgram = 'approvalProgram' in params
|
|
336
|
+
? typeof params.approvalProgram === 'string'
|
|
337
|
+
? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes
|
|
338
|
+
: params.approvalProgram
|
|
339
|
+
: undefined;
|
|
340
|
+
const clearStateProgram = 'clearStateProgram' in params
|
|
341
|
+
? typeof params.clearStateProgram === 'string'
|
|
342
|
+
? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes
|
|
343
|
+
: params.clearStateProgram
|
|
344
|
+
: undefined;
|
|
231
345
|
methodAtc.addMethodCall({
|
|
232
|
-
appID,
|
|
346
|
+
appID: appId,
|
|
233
347
|
sender: params.sender,
|
|
234
348
|
suggestedParams,
|
|
235
|
-
onComplete: params.onComplete,
|
|
349
|
+
onComplete: params.onComplete ?? algosdk.OnApplicationComplete.NoOpOC,
|
|
236
350
|
appAccounts: params.accountReferences,
|
|
237
351
|
appForeignApps: params.appReferences?.map((x) => Number(x)),
|
|
238
352
|
appForeignAssets: params.assetReferences?.map((x) => Number(x)),
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
353
|
+
boxes: params.boxReferences?.map(types_appManager.AppManager.getBoxReference),
|
|
354
|
+
approvalProgram,
|
|
355
|
+
clearProgram: clearStateProgram,
|
|
356
|
+
extraPages: appId === 0
|
|
357
|
+
? 'extraProgramPages' in params && params.extraProgramPages !== undefined
|
|
358
|
+
? params.extraProgramPages
|
|
359
|
+
: approvalProgram
|
|
360
|
+
? Math.floor((approvalProgram.length + (clearStateProgram?.length ?? 0)) / types_app.APP_PAGE_MAX_SIZE)
|
|
361
|
+
: 0
|
|
362
|
+
: undefined,
|
|
363
|
+
numLocalInts: appId === 0 ? ('schema' in params ? params.schema?.localInts ?? 0 : 0) : undefined,
|
|
364
|
+
numLocalByteSlices: appId === 0 ? ('schema' in params ? params.schema?.localByteSlices ?? 0 : 0) : undefined,
|
|
365
|
+
numGlobalInts: appId === 0 ? ('schema' in params ? params.schema?.globalInts ?? 0 : 0) : undefined,
|
|
366
|
+
numGlobalByteSlices: appId === 0 ? ('schema' in params ? params.schema?.globalByteSlices ?? 0 : 0) : undefined,
|
|
246
367
|
method: params.method,
|
|
247
|
-
signer:
|
|
368
|
+
signer: includeSigner
|
|
369
|
+
? params.signer
|
|
370
|
+
? 'signer' in params.signer
|
|
371
|
+
? params.signer.signer
|
|
372
|
+
: params.signer
|
|
373
|
+
: this.getSigner(params.sender)
|
|
374
|
+
: AlgoKitComposer.NULL_SIGNER,
|
|
248
375
|
methodArgs: methodArgs,
|
|
249
376
|
// note, lease, and rekeyTo are set in the common build step
|
|
250
377
|
note: undefined,
|
|
251
378
|
lease: undefined,
|
|
252
379
|
rekeyTo: undefined,
|
|
253
380
|
});
|
|
254
|
-
//
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
group[methodIdx].txn = this.commonTxnBuildStep(params, group[methodIdx].txn, suggestedParams);
|
|
258
|
-
return this.buildAtc(methodAtc);
|
|
381
|
+
// Process the ATC to get a set of transactions ready for broader grouping
|
|
382
|
+
// and with the common build step to set fees and validity rounds
|
|
383
|
+
return this.buildAtc(methodAtc, (txn, idx) => idx === methodAtc.count() - 1 ? this.commonTxnBuildStep(params, txn, suggestedParams) : txn);
|
|
259
384
|
}
|
|
260
385
|
buildPayment(params, suggestedParams) {
|
|
261
386
|
const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
|
|
@@ -328,57 +453,66 @@ class AlgoKitComposer {
|
|
|
328
453
|
});
|
|
329
454
|
return this.commonTxnBuildStep(params, txn, suggestedParams);
|
|
330
455
|
}
|
|
331
|
-
buildAppCall(params, suggestedParams) {
|
|
456
|
+
async buildAppCall(params, suggestedParams) {
|
|
457
|
+
const appId = Number('appId' in params ? params.appId : 0n);
|
|
458
|
+
const approvalProgram = 'approvalProgram' in params
|
|
459
|
+
? typeof params.approvalProgram === 'string'
|
|
460
|
+
? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes
|
|
461
|
+
: params.approvalProgram
|
|
462
|
+
: undefined;
|
|
463
|
+
const clearStateProgram = 'clearStateProgram' in params
|
|
464
|
+
? typeof params.clearStateProgram === 'string'
|
|
465
|
+
? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes
|
|
466
|
+
: params.clearStateProgram
|
|
467
|
+
: undefined;
|
|
332
468
|
const sdkParams = {
|
|
333
469
|
from: params.sender,
|
|
334
470
|
suggestedParams,
|
|
335
|
-
onComplete: params.onComplete,
|
|
336
|
-
approvalProgram: params.approvalProgram,
|
|
337
|
-
clearProgram: params.clearProgram,
|
|
338
471
|
appArgs: params.args,
|
|
472
|
+
onComplete: params.onComplete ?? algosdk.OnApplicationComplete.NoOpOC,
|
|
339
473
|
accounts: params.accountReferences,
|
|
340
474
|
foreignApps: params.appReferences?.map((x) => Number(x)),
|
|
341
475
|
foreignAssets: params.assetReferences?.map((x) => Number(x)),
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
numGlobalInts: params.schema?.globalUints || 0,
|
|
346
|
-
numGlobalByteSlices: params.schema?.globalByteSlices || 0,
|
|
476
|
+
boxes: params.boxReferences?.map(types_appManager.AppManager.getBoxReference),
|
|
477
|
+
approvalProgram,
|
|
478
|
+
clearProgram: clearStateProgram,
|
|
347
479
|
};
|
|
348
480
|
let txn;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
throw new Error('approvalProgram and clearProgram are required for application creation');
|
|
481
|
+
if (appId === 0) {
|
|
482
|
+
if (sdkParams.approvalProgram === undefined || sdkParams.clearProgram === undefined) {
|
|
483
|
+
throw new Error('approvalProgram and clearStateProgram are required for application creation');
|
|
353
484
|
}
|
|
354
485
|
txn = algosdk.makeApplicationCreateTxnFromObject({
|
|
355
486
|
...sdkParams,
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
487
|
+
extraPages: 'extraProgramPages' in params
|
|
488
|
+
? params.extraProgramPages ?? Math.floor((approvalProgram.length + clearStateProgram.length) / types_app.APP_PAGE_MAX_SIZE)
|
|
489
|
+
: 0,
|
|
490
|
+
numLocalInts: 'schema' in params ? params.schema?.localInts ?? 0 : 0,
|
|
491
|
+
numLocalByteSlices: 'schema' in params ? params.schema?.localByteSlices ?? 0 : 0,
|
|
492
|
+
numGlobalInts: 'schema' in params ? params.schema?.globalInts ?? 0 : 0,
|
|
493
|
+
numGlobalByteSlices: 'schema' in params ? params.schema?.globalByteSlices ?? 0 : 0,
|
|
494
|
+
approvalProgram: approvalProgram,
|
|
495
|
+
clearProgram: clearStateProgram,
|
|
359
496
|
});
|
|
360
497
|
}
|
|
361
|
-
|
|
498
|
+
else {
|
|
499
|
+
txn = algosdk.makeApplicationCallTxnFromObject({ ...sdkParams, appIndex: appId });
|
|
500
|
+
}
|
|
362
501
|
return this.commonTxnBuildStep(params, txn, suggestedParams);
|
|
363
502
|
}
|
|
364
503
|
buildKeyReg(params, suggestedParams) {
|
|
365
504
|
const txn = algosdk.makeKeyRegistrationTxnWithSuggestedParams(params.sender, undefined, params.voteKey, params.selectionKey, Number(params.voteFirst), Number(params.voteLast), Number(params.voteKeyDilution), suggestedParams, undefined, false, params.stateProofKey);
|
|
366
505
|
return this.commonTxnBuildStep(params, txn, suggestedParams);
|
|
367
506
|
}
|
|
507
|
+
/** Builds all transaction types apart from `txnWithSigner`, `atc` and `methodCall` since those ones can have custom signers that need to be retrieved. */
|
|
368
508
|
async buildTxn(txn, suggestedParams) {
|
|
369
509
|
switch (txn.type) {
|
|
370
|
-
case 'txnWithSigner':
|
|
371
|
-
return [txn.txn];
|
|
372
|
-
case 'atc':
|
|
373
|
-
return txn.atc.buildGroup().map((ts) => ts.txn);
|
|
374
|
-
case 'methodCall':
|
|
375
|
-
return (await this.buildMethodCall(txn, suggestedParams, false)).map((ts) => ts.txn);
|
|
376
510
|
case 'pay':
|
|
377
511
|
return [this.buildPayment(txn, suggestedParams)];
|
|
378
512
|
case 'assetCreate':
|
|
379
513
|
return [this.buildAssetCreate(txn, suggestedParams)];
|
|
380
514
|
case 'appCall':
|
|
381
|
-
return [this.buildAppCall(txn, suggestedParams)];
|
|
515
|
+
return [await this.buildAppCall(txn, suggestedParams)];
|
|
382
516
|
case 'assetConfig':
|
|
383
517
|
return [this.buildAssetConfig(txn, suggestedParams)];
|
|
384
518
|
case 'assetDestroy':
|
|
@@ -411,43 +545,77 @@ class AlgoKitComposer {
|
|
|
411
545
|
return (await this.buildTxn(txn, suggestedParams)).map((txn) => ({ txn, signer }));
|
|
412
546
|
}
|
|
413
547
|
/**
|
|
414
|
-
* Compose all of the transactions without signers and return the transaction objects directly.
|
|
548
|
+
* Compose all of the transactions without signers and return the transaction objects directly along with any ABI method calls.
|
|
415
549
|
*
|
|
416
|
-
* @returns The array of built transactions
|
|
550
|
+
* @returns The array of built transactions and any corresponding method calls
|
|
417
551
|
*/
|
|
418
552
|
async buildTransactions() {
|
|
419
553
|
const suggestedParams = await this.getSuggestedParams();
|
|
420
554
|
const transactions = [];
|
|
555
|
+
const methodCalls = new Map();
|
|
556
|
+
const signers = new Map();
|
|
421
557
|
for (const txn of this.txns) {
|
|
422
|
-
|
|
558
|
+
if (!['txnWithSigner', 'atc', 'methodCall'].includes(txn.type)) {
|
|
559
|
+
transactions.push(...(await this.buildTxn(txn, suggestedParams)));
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
const transactionsWithSigner = txn.type === 'txnWithSigner'
|
|
563
|
+
? [txn]
|
|
564
|
+
: txn.type === 'atc'
|
|
565
|
+
? this.buildAtc(txn.atc)
|
|
566
|
+
: txn.type === 'methodCall'
|
|
567
|
+
? await this.buildMethodCall(txn, suggestedParams, false)
|
|
568
|
+
: [];
|
|
569
|
+
transactions.push(...transactionsWithSigner.map((ts) => ts.txn));
|
|
570
|
+
transactionsWithSigner.forEach((ts, idx) => {
|
|
571
|
+
if (ts.signer && ts.signer !== AlgoKitComposer.NULL_SIGNER) {
|
|
572
|
+
signers.set(idx, ts.signer);
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
}
|
|
423
576
|
}
|
|
424
|
-
|
|
577
|
+
for (let i = 0; i < transactions.length; i++) {
|
|
578
|
+
const method = this.txnMethodMap.get(transactions[i].txID());
|
|
579
|
+
if (method)
|
|
580
|
+
methodCalls.set(i, method);
|
|
581
|
+
}
|
|
582
|
+
return { transactions, methodCalls, signers };
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Get the number of transactions currently added to this composer.
|
|
586
|
+
*/
|
|
587
|
+
async count() {
|
|
588
|
+
return (await this.buildTransactions()).transactions.length;
|
|
425
589
|
}
|
|
426
590
|
/**
|
|
427
591
|
* Compose all of the transactions in a single atomic transaction group and an atomic transaction composer.
|
|
428
592
|
*
|
|
429
593
|
* You can then use the transactions standalone, or use the composer to execute or simulate the transactions.
|
|
594
|
+
*
|
|
595
|
+
* Once this method is called, no further transactions will be able to be added.
|
|
596
|
+
* You can safely call this method multiple times to get the same result.
|
|
430
597
|
* @returns The built atomic transaction composer and the transactions
|
|
431
598
|
*/
|
|
432
599
|
async build() {
|
|
433
600
|
if (this.atc.getStatus() === algosdk.AtomicTransactionComposerStatus.BUILDING) {
|
|
434
601
|
const suggestedParams = await this.getSuggestedParams();
|
|
602
|
+
// Build all of the transactions
|
|
435
603
|
const txnWithSigners = [];
|
|
436
604
|
for (const txn of this.txns) {
|
|
437
605
|
txnWithSigners.push(...(await this.buildTxnWithSigner(txn, suggestedParams)));
|
|
438
606
|
}
|
|
439
|
-
|
|
440
|
-
this.atc.addTransaction(ts);
|
|
441
|
-
});
|
|
607
|
+
// Add all of the transactions to the underlying ATC
|
|
442
608
|
const methodCalls = new Map();
|
|
443
609
|
txnWithSigners.forEach((ts, idx) => {
|
|
610
|
+
this.atc.addTransaction(ts);
|
|
611
|
+
// Populate consolidated set of all ABI method calls
|
|
444
612
|
const method = this.txnMethodMap.get(ts.txn.txID());
|
|
445
613
|
if (method)
|
|
446
614
|
methodCalls.set(idx, method);
|
|
447
615
|
});
|
|
448
616
|
this.atc['methodCalls'] = methodCalls;
|
|
449
617
|
}
|
|
450
|
-
return { atc: this.atc, transactions: this.atc.buildGroup() };
|
|
618
|
+
return { atc: this.atc, transactions: this.atc.buildGroup(), methodCalls: this.atc['methodCalls'] };
|
|
451
619
|
}
|
|
452
620
|
/**
|
|
453
621
|
* Rebuild the group, discarding any previously built transactions.
|
|
@@ -459,11 +627,11 @@ class AlgoKitComposer {
|
|
|
459
627
|
return await this.build();
|
|
460
628
|
}
|
|
461
629
|
/**
|
|
462
|
-
* Compose the atomic transaction group and send it to the network
|
|
630
|
+
* Compose the atomic transaction group and send it to the network.
|
|
463
631
|
* @param params The parameters to control execution with
|
|
464
632
|
* @returns The execution result
|
|
465
633
|
*/
|
|
466
|
-
async
|
|
634
|
+
async send(params) {
|
|
467
635
|
const group = (await this.build()).transactions;
|
|
468
636
|
let waitRounds = params?.maxRoundsToWaitForConfirmation;
|
|
469
637
|
if (waitRounds === undefined) {
|
|
@@ -473,10 +641,97 @@ class AlgoKitComposer {
|
|
|
473
641
|
}
|
|
474
642
|
return await transaction.sendAtomicTransactionComposer({
|
|
475
643
|
atc: this.atc,
|
|
476
|
-
|
|
644
|
+
suppressLog: params?.suppressLog,
|
|
645
|
+
maxRoundsToWaitForConfirmation: waitRounds,
|
|
646
|
+
populateAppCallResources: params?.populateAppCallResources,
|
|
477
647
|
}, this.algod);
|
|
478
648
|
}
|
|
649
|
+
/**
|
|
650
|
+
* @deprecated Use `send` instead.
|
|
651
|
+
*
|
|
652
|
+
* Compose the atomic transaction group and send it to the network
|
|
653
|
+
*
|
|
654
|
+
* An alias for `composer.send(params)`.
|
|
655
|
+
* @param params The parameters to control execution with
|
|
656
|
+
* @returns The execution result
|
|
657
|
+
*/
|
|
658
|
+
async execute(params) {
|
|
659
|
+
return this.send(params);
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Compose the atomic transaction group and simulate sending it to the network
|
|
663
|
+
* @returns The simulation result
|
|
664
|
+
*/
|
|
665
|
+
async simulate(options) {
|
|
666
|
+
const atc = options?.skipSignatures ? new AtomicTransactionComposer() : this.atc;
|
|
667
|
+
// Build the transactions
|
|
668
|
+
if (options?.skipSignatures) {
|
|
669
|
+
options.allowEmptySignatures = true;
|
|
670
|
+
// Build transactions uses empty signers
|
|
671
|
+
const transactions = await this.buildTransactions();
|
|
672
|
+
for (const txn of transactions.transactions) {
|
|
673
|
+
atc.addTransaction({ txn, signer: AlgoKitComposer.NULL_SIGNER });
|
|
674
|
+
}
|
|
675
|
+
atc['methodCalls'] = transactions.methodCalls;
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
// Build creates real signatures
|
|
679
|
+
await this.build();
|
|
680
|
+
}
|
|
681
|
+
const { methodResults, simulateResponse } = await atc.simulate(this.algod, new modelsv2.SimulateRequest({
|
|
682
|
+
txnGroups: [],
|
|
683
|
+
...options,
|
|
684
|
+
...(config.Config.debug
|
|
685
|
+
? {
|
|
686
|
+
allowEmptySignatures: true,
|
|
687
|
+
allowMoreLogging: true,
|
|
688
|
+
execTraceConfig: new modelsv2.SimulateTraceConfig({
|
|
689
|
+
enable: true,
|
|
690
|
+
scratchChange: true,
|
|
691
|
+
stackChange: true,
|
|
692
|
+
stateChange: true,
|
|
693
|
+
}),
|
|
694
|
+
}
|
|
695
|
+
: undefined),
|
|
696
|
+
}));
|
|
697
|
+
const failedGroup = simulateResponse?.txnGroups[0];
|
|
698
|
+
if (failedGroup?.failureMessage) {
|
|
699
|
+
const errorMessage = `Transaction failed at transaction(s) ${failedGroup.failedAt?.join(', ') || 'unknown'} in the group. ${failedGroup.failureMessage}`;
|
|
700
|
+
const error = new Error(errorMessage);
|
|
701
|
+
if (config.Config.debug) {
|
|
702
|
+
await config.Config.events.emitAsync(types_asyncEventEmitter.EventType.TxnGroupSimulated, { simulateResponse });
|
|
703
|
+
}
|
|
704
|
+
error.simulateResponse = simulateResponse;
|
|
705
|
+
throw error;
|
|
706
|
+
}
|
|
707
|
+
if (config.Config.debug && config.Config.traceAll) {
|
|
708
|
+
await config.Config.events.emitAsync(types_asyncEventEmitter.EventType.TxnGroupSimulated, { simulateResponse });
|
|
709
|
+
}
|
|
710
|
+
const transactions = atc.buildGroup().map((t) => t.txn);
|
|
711
|
+
return {
|
|
712
|
+
confirmations: simulateResponse.txnGroups[0].txnResults.map((t) => t.txnResult),
|
|
713
|
+
transactions: transactions,
|
|
714
|
+
txIds: transactions.map((t) => t.txID()),
|
|
715
|
+
groupId: Buffer.from(transactions[0].group ?? new Uint8Array()).toString('base64'),
|
|
716
|
+
simulateResponse,
|
|
717
|
+
returns: methodResults.map(transaction.getABIReturnValue),
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Create an encoded transaction note that follows the ARC-2 spec.
|
|
722
|
+
*
|
|
723
|
+
* https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md
|
|
724
|
+
* @param note The ARC-2 transaction note data
|
|
725
|
+
* @returns The binary encoded transaction note
|
|
726
|
+
*/
|
|
727
|
+
static arc2Note(note) {
|
|
728
|
+
const arc2Payload = `${note.dAppName}:${note.format}${typeof note.data === 'string' ? note.data : JSON.stringify(note.data)}`;
|
|
729
|
+
const encoder = new TextEncoder();
|
|
730
|
+
return encoder.encode(arc2Payload);
|
|
731
|
+
}
|
|
479
732
|
}
|
|
733
|
+
/** Signer used to represent a lack of signer */
|
|
734
|
+
AlgoKitComposer.NULL_SIGNER = algosdk.makeEmptyTransactionSigner();
|
|
480
735
|
|
|
481
736
|
exports.MAX_TRANSACTION_GROUP_SIZE = MAX_TRANSACTION_GROUP_SIZE;
|
|
482
737
|
exports.default = AlgoKitComposer;
|