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