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