@algorandfoundation/algokit-utils 6.3.0-beta.1 → 7.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +22 -26
- package/account/account.d.ts +12 -10
- package/account/account.js +17 -14
- package/account/account.js.map +1 -1
- package/account/account.mjs +18 -15
- package/account/account.mjs.map +1 -1
- package/account/get-account-config-from-environment.d.ts +0 -1
- package/account/get-account-config-from-environment.js.map +1 -1
- package/account/get-account-config-from-environment.mjs.map +1 -1
- package/account/get-account.d.ts +2 -3
- package/account/get-account.js +1 -1
- package/account/get-account.js.map +1 -1
- package/account/get-account.mjs +1 -1
- package/account/get-account.mjs.map +1 -1
- package/account/get-dispenser-account.d.ts +2 -3
- package/account/get-dispenser-account.js +1 -1
- package/account/get-dispenser-account.js.map +1 -1
- package/account/get-dispenser-account.mjs +1 -1
- package/account/get-dispenser-account.mjs.map +1 -1
- package/account/index.d.ts +0 -1
- package/account/mnemonic-account.d.ts +1 -2
- package/account/mnemonic-account.js +1 -1
- package/account/mnemonic-account.js.map +1 -1
- package/account/mnemonic-account.mjs +1 -1
- package/account/mnemonic-account.mjs.map +1 -1
- package/amount.d.ts +15 -5
- package/amount.js +9 -2
- package/amount.js.map +1 -1
- package/amount.mjs +9 -3
- package/amount.mjs.map +1 -1
- package/app-client.d.ts +19 -5
- package/app-client.js +19 -4
- package/app-client.js.map +1 -1
- package/app-client.mjs +19 -4
- package/app-client.mjs.map +1 -1
- package/app-deploy.d.ts +18 -2
- package/app-deploy.js +159 -342
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +163 -346
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +39 -3
- package/app.js +121 -371
- package/app.js.map +1 -1
- package/app.mjs +122 -372
- package/app.mjs.map +1 -1
- package/asset.d.ts +5 -6
- package/asset.js +5 -8
- package/asset.js.map +1 -1
- package/asset.mjs +5 -8
- package/asset.mjs.map +1 -1
- package/config.d.ts +0 -1
- package/config.js.map +1 -1
- package/config.mjs.map +1 -1
- package/debugging/debugging.d.ts +3 -5
- package/debugging/debugging.js +4 -128
- package/debugging/debugging.js.map +1 -1
- package/debugging/debugging.mjs +4 -109
- package/debugging/debugging.mjs.map +1 -1
- package/debugging/index.d.ts +0 -2
- package/dispenser-client.d.ts +0 -1
- package/dispenser-client.js.map +1 -1
- package/dispenser-client.mjs.map +1 -1
- package/index.d.ts +5 -4
- package/index.js +36 -26
- package/index.js.map +1 -1
- package/index.mjs +6 -5
- package/index.mjs.map +1 -1
- package/indexer-lookup.d.ts +10 -9
- package/indexer-lookup.js +14 -10
- package/indexer-lookup.js.map +1 -1
- package/indexer-lookup.mjs +14 -10
- package/indexer-lookup.mjs.map +1 -1
- package/localnet/get-kmd-wallet-account.d.ts +1 -2
- package/localnet/get-kmd-wallet-account.js +1 -1
- package/localnet/get-kmd-wallet-account.js.map +1 -1
- package/localnet/get-kmd-wallet-account.mjs +1 -1
- package/localnet/get-kmd-wallet-account.mjs.map +1 -1
- package/localnet/get-localnet-dispenser-account.d.ts +1 -2
- package/localnet/get-localnet-dispenser-account.js +1 -1
- package/localnet/get-localnet-dispenser-account.js.map +1 -1
- package/localnet/get-localnet-dispenser-account.mjs +1 -1
- package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts +1 -2
- package/localnet/get-or-create-kmd-wallet-account.js +1 -1
- package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
- package/localnet/index.d.ts +0 -1
- package/localnet/is-localnet.d.ts +1 -2
- package/localnet/is-localnet.js +1 -1
- package/localnet/is-localnet.js.map +1 -1
- package/localnet/is-localnet.mjs +1 -1
- package/localnet/is-localnet.mjs.map +1 -1
- package/network-client.d.ts +3 -10
- package/network-client.js +4 -11
- package/network-client.js.map +1 -1
- package/network-client.mjs +4 -11
- package/network-client.mjs.map +1 -1
- package/package.json +3 -4
- package/testing/_asset.d.ts +2 -2
- package/testing/account.d.ts +4 -4
- package/testing/account.js +8 -2
- package/testing/account.js.map +1 -1
- package/testing/account.mjs +9 -3
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +0 -1
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
- package/testing/fixtures/algorand-fixture.d.ts +0 -1
- package/testing/fixtures/algorand-fixture.js +13 -14
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +13 -14
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/fixtures/index.d.ts +0 -1
- package/testing/index.d.ts +0 -1
- package/testing/indexer.d.ts +0 -1
- package/testing/indexer.js.map +1 -1
- package/testing/indexer.mjs.map +1 -1
- package/testing/test-logger.d.ts +0 -1
- package/testing/test-logger.js +7 -3
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs +7 -3
- package/testing/test-logger.mjs.map +1 -1
- package/testing/transaction-logger.d.ts +0 -1
- package/testing/transaction-logger.js.map +1 -1
- package/testing/transaction-logger.mjs.map +1 -1
- package/transaction/index.d.ts +0 -1
- package/transaction/legacy-bridge.d.ts +31 -6
- package/transaction/legacy-bridge.js +101 -7
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +101 -10
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts +4 -2
- package/transaction/perform-atomic-transaction-composer-simulate.js +14 -9
- package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.mjs +15 -10
- package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +38 -19
- package/transaction/transaction.js +217 -137
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +218 -138
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/index.d.ts +0 -1
- package/transfer/transfer-algos.d.ts +1 -2
- package/transfer/transfer-algos.js +1 -1
- package/transfer/transfer-algos.js.map +1 -1
- package/transfer/transfer-algos.mjs +1 -1
- package/transfer/transfer-algos.mjs.map +1 -1
- package/transfer/transfer.d.ts +1 -2
- package/transfer/transfer.js +6 -4
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs +6 -4
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +33 -25
- package/types/account-manager.js +54 -31
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +56 -33
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +17 -9
- package/types/account.js +2 -2
- package/types/account.js.map +1 -1
- package/types/account.mjs +3 -3
- package/types/account.mjs.map +1 -1
- package/types/algo-http-client-with-retry.d.ts +1 -3
- package/types/algo-http-client-with-retry.js +33 -3
- package/types/algo-http-client-with-retry.js.map +1 -1
- package/types/algo-http-client-with-retry.mjs +32 -2
- package/types/algo-http-client-with-retry.mjs.map +1 -1
- package/types/algorand-client-interface.d.ts +28 -0
- package/types/algorand-client-interface.js +3 -0
- package/types/algorand-client-interface.js.map +1 -0
- package/types/algorand-client-interface.mjs +2 -0
- package/types/algorand-client-interface.mjs.map +1 -0
- package/types/algorand-client-transaction-creator.d.ts +452 -23
- package/types/algorand-client-transaction-creator.js +407 -23
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +407 -23
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +772 -47
- package/types/algorand-client-transaction-sender.js +445 -15
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +445 -15
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +24 -17
- package/types/algorand-client.js +26 -16
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +28 -15
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.d.ts +10 -11
- package/types/amount.js +7 -7
- package/types/amount.js.map +1 -1
- package/types/amount.mjs +7 -7
- package/types/amount.mjs.map +1 -1
- package/types/app-arc56.d.ts +359 -0
- package/types/app-arc56.js +184 -0
- package/types/app-arc56.js.map +1 -0
- package/types/app-arc56.mjs +175 -0
- package/types/app-arc56.mjs.map +1 -0
- package/types/app-client.d.ts +1508 -12
- package/types/app-client.js +1018 -29
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +1020 -32
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +126 -0
- package/types/app-deployer.js +353 -0
- package/types/app-deployer.js.map +1 -0
- package/types/app-deployer.mjs +351 -0
- package/types/app-deployer.mjs.map +1 -0
- package/types/app-factory.d.ts +846 -0
- package/types/app-factory.js +410 -0
- package/types/app-factory.js.map +1 -0
- package/types/app-factory.mjs +408 -0
- package/types/app-factory.mjs.map +1 -0
- package/types/app-manager.d.ts +244 -0
- package/types/app-manager.js +423 -0
- package/types/app-manager.js.map +1 -0
- package/types/app-manager.mjs +421 -0
- package/types/app-manager.mjs.map +1 -0
- package/types/app-spec.d.ts +2 -1
- package/types/app-spec.js +127 -0
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +126 -0
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +57 -18
- package/types/app.js +1 -1
- package/types/app.js.map +1 -1
- package/types/app.mjs +1 -1
- package/types/app.mjs.map +1 -1
- package/types/asset-manager.d.ts +10 -10
- package/types/asset-manager.js +13 -17
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +13 -17
- package/types/asset-manager.mjs.map +1 -1
- package/types/asset.d.ts +0 -1
- package/types/async-event-emitter.d.ts +14 -0
- package/types/async-event-emitter.js +50 -0
- package/types/async-event-emitter.js.map +1 -0
- package/types/async-event-emitter.mjs +48 -0
- package/types/async-event-emitter.mjs.map +1 -0
- package/types/client-manager.d.ts +135 -60
- package/types/client-manager.js +158 -44
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +159 -45
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +271 -87
- package/types/composer.js +405 -125
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +407 -125
- package/types/composer.mjs.map +1 -1
- package/types/config.d.ts +3 -6
- package/types/config.js +5 -44
- package/types/config.js.map +1 -1
- package/types/config.mjs +5 -27
- package/types/config.mjs.map +1 -1
- package/types/debugging.d.ts +29 -101
- package/types/debugging.js +16 -109
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs +12 -107
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.d.ts +2 -2
- package/types/dispenser-client.js +10 -5
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs +10 -5
- package/types/dispenser-client.mjs.map +1 -1
- package/types/expand.d.ts +7 -0
- package/types/expand.js +3 -0
- package/types/expand.js.map +1 -0
- package/types/expand.mjs +2 -0
- package/types/expand.mjs.map +1 -0
- package/types/indexer.d.ts +74 -756
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs.map +1 -1
- package/types/kmd-account-manager.d.ts +2 -3
- package/types/kmd-account-manager.js +3 -3
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +4 -4
- package/types/kmd-account-manager.mjs.map +1 -1
- package/types/lifecycle-events.d.ts +10 -0
- package/types/lifecycle-events.js +8 -0
- package/types/lifecycle-events.js.map +1 -0
- package/types/lifecycle-events.mjs +8 -0
- package/types/lifecycle-events.mjs.map +1 -0
- package/types/logging.d.ts +0 -1
- package/types/logging.js.map +1 -1
- package/types/logging.mjs.map +1 -1
- package/types/logic-error.d.ts +2 -4
- package/types/logic-error.js +3 -3
- package/types/logic-error.js.map +1 -1
- package/types/logic-error.mjs +3 -3
- package/types/logic-error.mjs.map +1 -1
- package/types/network-client.d.ts +14 -2
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +8 -10
- package/types/transaction.d.ts +17 -4
- package/types/transfer.d.ts +0 -1
- package/util.d.ts +2 -2
- package/util.js +11 -10
- package/util.js.map +1 -1
- package/util.mjs +11 -10
- package/util.mjs.map +1 -1
- package/account/account.d.ts.map +0 -1
- package/account/get-account-config-from-environment.d.ts.map +0 -1
- package/account/get-account.d.ts.map +0 -1
- package/account/get-dispenser-account.d.ts.map +0 -1
- package/account/index.d.ts.map +0 -1
- package/account/mnemonic-account.d.ts.map +0 -1
- package/amount.d.ts.map +0 -1
- package/app-client.d.ts.map +0 -1
- package/app-deploy.d.ts.map +0 -1
- package/app.d.ts.map +0 -1
- package/asset.d.ts.map +0 -1
- package/config.d.ts.map +0 -1
- package/debugging/debugging.d.ts.map +0 -1
- package/debugging/index.d.ts.map +0 -1
- package/debugging/simulate-and-persist-response.d.ts +0 -20
- package/debugging/simulate-and-persist-response.d.ts.map +0 -1
- package/debugging/simulate-and-persist-response.js +0 -108
- package/debugging/simulate-and-persist-response.js.map +0 -1
- package/debugging/simulate-and-persist-response.mjs +0 -89
- package/debugging/simulate-and-persist-response.mjs.map +0 -1
- package/dispenser-client.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/indexer-lookup.d.ts.map +0 -1
- package/localnet/get-kmd-wallet-account.d.ts.map +0 -1
- package/localnet/get-localnet-dispenser-account.d.ts.map +0 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts.map +0 -1
- package/localnet/index.d.ts.map +0 -1
- package/localnet/is-localnet.d.ts.map +0 -1
- package/network-client.d.ts.map +0 -1
- package/testing/_asset.d.ts.map +0 -1
- package/testing/account.d.ts.map +0 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +0 -1
- package/testing/fixtures/algorand-fixture.d.ts.map +0 -1
- package/testing/fixtures/index.d.ts.map +0 -1
- package/testing/index.d.ts.map +0 -1
- package/testing/indexer.d.ts.map +0 -1
- package/testing/test-logger.d.ts.map +0 -1
- package/testing/transaction-logger.d.ts.map +0 -1
- package/transaction/index.d.ts.map +0 -1
- package/transaction/legacy-bridge.d.ts.map +0 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts.map +0 -1
- package/transaction/transaction.d.ts.map +0 -1
- package/transfer/index.d.ts.map +0 -1
- package/transfer/transfer-algos.d.ts.map +0 -1
- package/transfer/transfer.d.ts.map +0 -1
- package/types/account-manager.d.ts.map +0 -1
- package/types/account.d.ts.map +0 -1
- package/types/algo-http-client-with-retry.d.ts.map +0 -1
- package/types/algorand-client-transaction-creator.d.ts.map +0 -1
- package/types/algorand-client-transaction-sender.d.ts.map +0 -1
- package/types/algorand-client.d.ts.map +0 -1
- package/types/amount.d.ts.map +0 -1
- package/types/app-client.d.ts.map +0 -1
- package/types/app-spec.d.ts.map +0 -1
- package/types/app.d.ts.map +0 -1
- package/types/asset-manager.d.ts.map +0 -1
- package/types/asset.d.ts.map +0 -1
- package/types/client-manager.d.ts.map +0 -1
- package/types/composer.d.ts.map +0 -1
- package/types/config.d.ts.map +0 -1
- package/types/debugging.d.ts.map +0 -1
- package/types/dispenser-client.d.ts.map +0 -1
- package/types/indexer.d.ts.map +0 -1
- package/types/kmd-account-manager.d.ts.map +0 -1
- package/types/logging.d.ts.map +0 -1
- package/types/logic-error.d.ts.map +0 -1
- package/types/network-client.d.ts.map +0 -1
- package/types/testing.d.ts.map +0 -1
- package/types/transaction.d.ts.map +0 -1
- package/types/transfer.d.ts.map +0 -1
- package/types/urlTokenBaseHTTPClient.d.ts +0 -41
- package/types/urlTokenBaseHTTPClient.d.ts.map +0 -1
- package/types/urlTokenBaseHTTPClient.js +0 -153
- package/types/urlTokenBaseHTTPClient.js.map +0 -1
- package/types/urlTokenBaseHTTPClient.mjs +0 -151
- package/types/urlTokenBaseHTTPClient.mjs.map +0 -1
- package/util.d.ts.map +0 -1
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import algosdk from 'algosdk';
|
|
1
|
+
import algosdk, { TransactionType, stringifyJSON, Address } from 'algosdk';
|
|
2
2
|
import { Buffer } from 'buffer';
|
|
3
3
|
import { Config } from '../config.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { EventType } from '../types/lifecycle-events.mjs';
|
|
5
5
|
import { toNumber } from '../util.mjs';
|
|
6
6
|
import { performAtomicTransactionComposerSimulate } from './perform-atomic-transaction-composer-simulate.mjs';
|
|
7
7
|
|
|
8
8
|
var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
|
|
9
|
-
var modelsv2 = algosdk.modelsv2;
|
|
10
9
|
const MAX_TRANSACTION_GROUP_SIZE = 16;
|
|
11
10
|
const MAX_APP_CALL_FOREIGN_REFERENCES = 8;
|
|
12
11
|
const MAX_APP_CALL_ACCOUNT_REFERENCES = 4;
|
|
13
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Convert your data to a `string` or `Uint8Array`, if using ARC-2 use `TransactionComposer.arc2Note`.
|
|
14
|
+
*
|
|
15
|
+
* Encodes a transaction note into a byte array ready to be included in an Algorand transaction.
|
|
14
16
|
*
|
|
15
17
|
* @param note The transaction note
|
|
16
18
|
* @returns the transaction note ready for inclusion in a transaction
|
|
@@ -76,14 +78,20 @@ function encodeLease(lease) {
|
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
/**
|
|
81
|
+
* @deprecated Use `algorand.client` to interact with accounts, and use `.addr` to get the address
|
|
82
|
+
* and/or move from using `SendTransactionFrom` to `TransactionSignerAccount` and use `.addr` instead.
|
|
83
|
+
*
|
|
79
84
|
* Returns the public address of the given transaction sender.
|
|
80
85
|
* @param sender A transaction sender
|
|
81
86
|
* @returns The public address
|
|
82
87
|
*/
|
|
83
88
|
const getSenderAddress = function (sender) {
|
|
84
|
-
return typeof sender === 'string' ? sender : 'addr' in sender ? sender.addr : sender.address();
|
|
89
|
+
return typeof sender === 'string' ? sender : 'addr' in sender ? sender.addr.toString() : sender.address().toString();
|
|
85
90
|
};
|
|
86
91
|
/**
|
|
92
|
+
* @deprecated Use `AlgorandClient` / `TransactionComposer` to construct transactions instead or
|
|
93
|
+
* construct an `algosdk.TransactionWithSigner` manually instead.
|
|
94
|
+
*
|
|
87
95
|
* Given a transaction in a variety of supported formats, returns a TransactionWithSigner object ready to be passed to an
|
|
88
96
|
* AtomicTransactionComposer's addTransaction method.
|
|
89
97
|
* @param transaction One of: A TransactionWithSigner object (returned as is), a TransactionToSign object (signer is obtained from the
|
|
@@ -122,6 +130,9 @@ const memoize = (fn) => {
|
|
|
122
130
|
return cached;
|
|
123
131
|
};
|
|
124
132
|
/**
|
|
133
|
+
* @deprecated Use `TransactionSignerAccount` instead of `SendTransactionFrom` or use
|
|
134
|
+
* `algosdk.makeBasicAccountTransactionSigner` / `algosdk.makeLogicSigAccountTransactionSigner`.
|
|
135
|
+
*
|
|
125
136
|
* Returns a `TransactionSigner` for the given transaction sender.
|
|
126
137
|
* This function has memoization, so will return the same transaction signer for a given sender.
|
|
127
138
|
* @param sender A transaction sender
|
|
@@ -135,6 +146,10 @@ const getSenderTransactionSigner = memoize(function (sender) {
|
|
|
135
146
|
: algosdk.makeBasicAccountTransactionSigner(sender);
|
|
136
147
|
});
|
|
137
148
|
/**
|
|
149
|
+
* @deprecated Use `AlgorandClient` / `TransactionComposer` to sign transactions
|
|
150
|
+
* or use the relevant underlying `account.signTxn` / `algosdk.signLogicSigTransactionObject`
|
|
151
|
+
* / `multiSigAccount.sign` / `TransactionSigner` methods directly.
|
|
152
|
+
*
|
|
138
153
|
* Signs a single transaction by the given signer.
|
|
139
154
|
* @param transaction The transaction to sign
|
|
140
155
|
* @param signer The signer to sign
|
|
@@ -149,7 +164,10 @@ const signTransaction = async (transaction, signer) => {
|
|
|
149
164
|
? signer.sign(transaction)
|
|
150
165
|
: (await signer.signer([transaction], [0]))[0];
|
|
151
166
|
};
|
|
152
|
-
/**
|
|
167
|
+
/**
|
|
168
|
+
* @deprecated Use `AlgorandClient` / `TransactionComposer` to send transactions.
|
|
169
|
+
*
|
|
170
|
+
* Prepares a transaction for sending and then (if instructed) signs and sends the given transaction to the chain.
|
|
153
171
|
*
|
|
154
172
|
* @param send The details for the transaction to prepare/send, including:
|
|
155
173
|
* * `transaction`: The unsigned transaction
|
|
@@ -197,29 +215,18 @@ const sendTransaction = async function (send, algod) {
|
|
|
197
215
|
* @returns The unnamed resources accessed by the group and by each transaction in the group
|
|
198
216
|
*/
|
|
199
217
|
async function getUnnamedAppCallResourcesAccessed(atc, algod) {
|
|
200
|
-
const
|
|
218
|
+
const simulateRequest = new algosdk.modelsv2.SimulateRequest({
|
|
201
219
|
txnGroups: [],
|
|
202
220
|
allowUnnamedResources: true,
|
|
203
221
|
allowEmptySignatures: true,
|
|
222
|
+
fixSigners: true,
|
|
204
223
|
});
|
|
205
|
-
const
|
|
206
|
-
const stxns = await algosdk.makeEmptyTransactionSigner()(txns, indexes);
|
|
207
|
-
return Promise.all(stxns.map(async (stxn) => {
|
|
208
|
-
const decodedStxn = algosdk.decodeSignedTransaction(stxn);
|
|
209
|
-
const sender = algosdk.encodeAddress(decodedStxn.txn.from.publicKey);
|
|
210
|
-
const authAddr = (await algod.accountInformation(sender).do())['auth-addr'];
|
|
211
|
-
const stxnObj = { txn: decodedStxn.txn.get_obj_for_encoding() };
|
|
212
|
-
if (authAddr !== undefined) {
|
|
213
|
-
stxnObj.sgnr = Buffer.from(algosdk.decodeAddress(authAddr).publicKey);
|
|
214
|
-
}
|
|
215
|
-
return algosdk.encodeObj(stxnObj);
|
|
216
|
-
}));
|
|
217
|
-
};
|
|
224
|
+
const nullSigner = algosdk.makeEmptyTransactionSigner();
|
|
218
225
|
const emptySignerAtc = atc.clone();
|
|
219
226
|
emptySignerAtc['transactions'].forEach((t) => {
|
|
220
|
-
t.signer =
|
|
227
|
+
t.signer = nullSigner;
|
|
221
228
|
});
|
|
222
|
-
const result = await emptySignerAtc.simulate(algod,
|
|
229
|
+
const result = await emptySignerAtc.simulate(algod, simulateRequest);
|
|
223
230
|
const groupResponse = result.simulateResponse.txnGroups[0];
|
|
224
231
|
if (groupResponse.failureMessage) {
|
|
225
232
|
throw Error(`Error during resource population simulation in transaction ${groupResponse.failedAt}: ${groupResponse.failureMessage}`);
|
|
@@ -252,7 +259,7 @@ async function populateAppCallResources(atc, algod) {
|
|
|
252
259
|
const unnamedResourcesAccessed = await getUnnamedAppCallResourcesAccessed(atc, algod);
|
|
253
260
|
const group = atc.buildGroup();
|
|
254
261
|
unnamedResourcesAccessed.txns.forEach((r, i) => {
|
|
255
|
-
if (r === undefined)
|
|
262
|
+
if (r === undefined || group[i].txn.type !== TransactionType.appl)
|
|
256
263
|
return;
|
|
257
264
|
if (r.boxes || r.extraBoxRefs)
|
|
258
265
|
throw Error('Unexpected boxes at the transaction level');
|
|
@@ -260,22 +267,19 @@ async function populateAppCallResources(atc, algod) {
|
|
|
260
267
|
throw Error('Unexpected app local at the transaction level');
|
|
261
268
|
if (r.assetHoldings)
|
|
262
269
|
throw Error('Unexpected asset holding at the transaction level');
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
group[i].txn.appForeignAssets = [...(group[i].txn.appForeignAssets ?? []), Number(a)];
|
|
272
|
-
});
|
|
273
|
-
const accounts = group[i].txn.appAccounts?.length || 0;
|
|
270
|
+
group[i].txn['applicationCall'] = {
|
|
271
|
+
...group[i].txn.applicationCall,
|
|
272
|
+
accounts: [...(group[i].txn?.applicationCall?.accounts ?? []), ...(r.accounts ?? [])],
|
|
273
|
+
foreignApps: [...(group[i].txn?.applicationCall?.foreignApps ?? []), ...(r.apps ?? [])],
|
|
274
|
+
foreignAssets: [...(group[i].txn?.applicationCall?.foreignAssets ?? []), ...(r.assets ?? [])],
|
|
275
|
+
boxes: [...(group[i].txn?.applicationCall?.boxes ?? []), ...(r.boxes ?? [])],
|
|
276
|
+
};
|
|
277
|
+
const accounts = group[i].txn.applicationCall?.accounts?.length ?? 0;
|
|
274
278
|
if (accounts > MAX_APP_CALL_ACCOUNT_REFERENCES)
|
|
275
279
|
throw Error(`Account reference limit of ${MAX_APP_CALL_ACCOUNT_REFERENCES} exceeded in transaction ${i}`);
|
|
276
|
-
const assets = group[i].txn.
|
|
277
|
-
const apps = group[i].txn.
|
|
278
|
-
const boxes = group[i].txn.boxes?.length
|
|
280
|
+
const assets = group[i].txn.applicationCall?.foreignAssets?.length ?? 0;
|
|
281
|
+
const apps = group[i].txn.applicationCall?.foreignApps?.length ?? 0;
|
|
282
|
+
const boxes = group[i].txn.applicationCall?.boxes?.length ?? 0;
|
|
279
283
|
if (accounts + assets + apps + boxes > MAX_APP_CALL_FOREIGN_REFERENCES) {
|
|
280
284
|
throw Error(`Resource reference limit of ${MAX_APP_CALL_FOREIGN_REFERENCES} exceeded in transaction ${i}`);
|
|
281
285
|
}
|
|
@@ -284,10 +288,10 @@ async function populateAppCallResources(atc, algod) {
|
|
|
284
288
|
const isApplBelowLimit = (t) => {
|
|
285
289
|
if (t.txn.type !== algosdk.TransactionType.appl)
|
|
286
290
|
return false;
|
|
287
|
-
const accounts = t.txn.
|
|
288
|
-
const assets = t.txn.
|
|
289
|
-
const apps = t.txn.
|
|
290
|
-
const boxes = t.txn.boxes?.length
|
|
291
|
+
const accounts = t.txn.applicationCall?.accounts?.length ?? 0;
|
|
292
|
+
const assets = t.txn.applicationCall?.foreignAssets?.length ?? 0;
|
|
293
|
+
const apps = t.txn.applicationCall?.foreignApps?.length ?? 0;
|
|
294
|
+
const boxes = t.txn.applicationCall?.boxes?.length ?? 0;
|
|
291
295
|
return accounts + assets + apps + boxes < MAX_APP_CALL_FOREIGN_REFERENCES;
|
|
292
296
|
};
|
|
293
297
|
// If this is a asset holding or app local, first try to find a transaction that already has the account available
|
|
@@ -298,22 +302,26 @@ async function populateAppCallResources(atc, algod) {
|
|
|
298
302
|
return false;
|
|
299
303
|
return (
|
|
300
304
|
// account is in the foreign accounts array
|
|
301
|
-
t.txn.
|
|
305
|
+
t.txn.applicationCall?.accounts?.map((a) => a.toString()).includes(account.toString()) ||
|
|
302
306
|
// account is available as an app account
|
|
303
|
-
t.txn.
|
|
307
|
+
t.txn.applicationCall?.foreignApps?.map((a) => algosdk.getApplicationAddress(a).toString()).includes(account.toString()) ||
|
|
304
308
|
// account is available since it's in one of the fields
|
|
305
|
-
Object.values(t.txn)
|
|
306
|
-
.map((f) => JSON.stringify(f))
|
|
307
|
-
.includes(JSON.stringify(algosdk.decodeAddress(account))));
|
|
309
|
+
Object.values(t.txn).some((f) => stringifyJSON(f, (_, v) => (v instanceof Address ? v.toString() : v))?.includes(account.toString())));
|
|
308
310
|
});
|
|
309
311
|
if (txnIndex > -1) {
|
|
310
312
|
if (type === 'assetHolding') {
|
|
311
313
|
const { asset } = reference;
|
|
312
|
-
txns[txnIndex].txn
|
|
314
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
315
|
+
...txns[txnIndex].txn.applicationCall,
|
|
316
|
+
foreignAssets: [...(txns[txnIndex].txn?.applicationCall?.foreignAssets ?? []), ...[asset]],
|
|
317
|
+
};
|
|
313
318
|
}
|
|
314
319
|
else {
|
|
315
320
|
const { app } = reference;
|
|
316
|
-
txns[txnIndex].txn
|
|
321
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
322
|
+
...txns[txnIndex].txn.applicationCall,
|
|
323
|
+
foreignApps: [...(txns[txnIndex].txn?.applicationCall?.foreignApps ?? []), ...[app]],
|
|
324
|
+
};
|
|
317
325
|
}
|
|
318
326
|
return;
|
|
319
327
|
}
|
|
@@ -322,20 +330,23 @@ async function populateAppCallResources(atc, algod) {
|
|
|
322
330
|
if (!isApplBelowLimit(t))
|
|
323
331
|
return false;
|
|
324
332
|
// check if there is space in the accounts array
|
|
325
|
-
if ((t.txn.
|
|
333
|
+
if ((t.txn.applicationCall?.accounts?.length ?? 0) >= MAX_APP_CALL_ACCOUNT_REFERENCES)
|
|
326
334
|
return false;
|
|
327
335
|
if (type === 'assetHolding') {
|
|
328
336
|
const { asset } = reference;
|
|
329
|
-
return t.txn.
|
|
337
|
+
return t.txn.applicationCall?.foreignAssets?.includes(asset);
|
|
330
338
|
}
|
|
331
339
|
else {
|
|
332
340
|
const { app } = reference;
|
|
333
|
-
return t.txn.
|
|
341
|
+
return t.txn.applicationCall?.foreignApps?.includes(app) || t.txn.applicationCall?.appIndex === app;
|
|
334
342
|
}
|
|
335
343
|
});
|
|
336
344
|
if (txnIndex > -1) {
|
|
337
345
|
const { account } = reference;
|
|
338
|
-
txns[txnIndex].txn
|
|
346
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
347
|
+
...txns[txnIndex].txn.applicationCall,
|
|
348
|
+
accounts: [...(txns[txnIndex].txn?.applicationCall?.accounts ?? []), ...[account]],
|
|
349
|
+
};
|
|
339
350
|
return;
|
|
340
351
|
}
|
|
341
352
|
}
|
|
@@ -346,10 +357,13 @@ async function populateAppCallResources(atc, algod) {
|
|
|
346
357
|
if (!isApplBelowLimit(t))
|
|
347
358
|
return false;
|
|
348
359
|
// If the app is in the foreign array OR the app being called, then we know it's available
|
|
349
|
-
return t.txn.
|
|
360
|
+
return t.txn.applicationCall?.foreignApps?.includes(app) || t.txn.applicationCall?.appIndex === app;
|
|
350
361
|
});
|
|
351
362
|
if (txnIndex > -1) {
|
|
352
|
-
txns[txnIndex].txn
|
|
363
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
364
|
+
...txns[txnIndex].txn.applicationCall,
|
|
365
|
+
boxes: [...(txns[txnIndex].txn?.applicationCall?.boxes ?? []), ...[{ appIndex: app, name }]],
|
|
366
|
+
};
|
|
353
367
|
return;
|
|
354
368
|
}
|
|
355
369
|
}
|
|
@@ -357,12 +371,12 @@ async function populateAppCallResources(atc, algod) {
|
|
|
357
371
|
const txnIndex = txns.findIndex((t) => {
|
|
358
372
|
if (t.txn.type !== algosdk.TransactionType.appl)
|
|
359
373
|
return false;
|
|
360
|
-
const accounts = t.txn.
|
|
374
|
+
const accounts = t.txn.applicationCall?.accounts?.length ?? 0;
|
|
361
375
|
if (type === 'account')
|
|
362
376
|
return accounts < MAX_APP_CALL_ACCOUNT_REFERENCES;
|
|
363
|
-
const assets = t.txn.
|
|
364
|
-
const apps = t.txn.
|
|
365
|
-
const boxes = t.txn.boxes?.length
|
|
377
|
+
const assets = t.txn.applicationCall?.foreignAssets?.length ?? 0;
|
|
378
|
+
const apps = t.txn.applicationCall?.foreignApps?.length ?? 0;
|
|
379
|
+
const boxes = t.txn.applicationCall?.boxes?.length ?? 0;
|
|
366
380
|
// If we're adding local state or asset holding, we need space for the acocunt and the other reference
|
|
367
381
|
if (type === 'assetHolding' || type === 'appLocal') {
|
|
368
382
|
return accounts + assets + apps + boxes < MAX_APP_CALL_FOREIGN_REFERENCES - 1 && accounts < MAX_APP_CALL_ACCOUNT_REFERENCES;
|
|
@@ -377,30 +391,57 @@ async function populateAppCallResources(atc, algod) {
|
|
|
377
391
|
throw Error('No more transactions below reference limit. Add another app call to the group.');
|
|
378
392
|
}
|
|
379
393
|
if (type === 'account') {
|
|
380
|
-
txns[txnIndex].txn
|
|
394
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
395
|
+
...txns[txnIndex].txn.applicationCall,
|
|
396
|
+
accounts: [...(txns[txnIndex].txn?.applicationCall?.accounts ?? []), ...[reference]],
|
|
397
|
+
};
|
|
381
398
|
}
|
|
382
399
|
else if (type === 'app') {
|
|
383
|
-
txns[txnIndex].txn
|
|
400
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
401
|
+
...txns[txnIndex].txn.applicationCall,
|
|
402
|
+
foreignApps: [
|
|
403
|
+
...(txns[txnIndex].txn?.applicationCall?.foreignApps ?? []),
|
|
404
|
+
...[typeof reference === 'bigint' ? reference : BigInt(reference)],
|
|
405
|
+
],
|
|
406
|
+
};
|
|
384
407
|
}
|
|
385
408
|
else if (type === 'box') {
|
|
386
409
|
const { app, name } = reference;
|
|
387
|
-
txns[txnIndex].txn
|
|
410
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
411
|
+
...txns[txnIndex].txn.applicationCall,
|
|
412
|
+
boxes: [...(txns[txnIndex].txn?.applicationCall?.boxes ?? []), ...[{ appIndex: app, name }]],
|
|
413
|
+
};
|
|
388
414
|
if (app.toString() !== '0') {
|
|
389
|
-
txns[txnIndex].txn
|
|
415
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
416
|
+
...txns[txnIndex].txn.applicationCall,
|
|
417
|
+
foreignApps: [...(txns[txnIndex].txn?.applicationCall?.foreignApps ?? []), ...[app]],
|
|
418
|
+
};
|
|
390
419
|
}
|
|
391
420
|
}
|
|
392
421
|
else if (type === 'assetHolding') {
|
|
393
422
|
const { asset, account } = reference;
|
|
394
|
-
txns[txnIndex].txn
|
|
395
|
-
|
|
423
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
424
|
+
...txns[txnIndex].txn.applicationCall,
|
|
425
|
+
foreignAssets: [...(txns[txnIndex].txn?.applicationCall?.foreignAssets ?? []), ...[asset]],
|
|
426
|
+
accounts: [...(txns[txnIndex].txn?.applicationCall?.accounts ?? []), ...[account]],
|
|
427
|
+
};
|
|
396
428
|
}
|
|
397
429
|
else if (type === 'appLocal') {
|
|
398
430
|
const { app, account } = reference;
|
|
399
|
-
txns[txnIndex].txn
|
|
400
|
-
|
|
431
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
432
|
+
...txns[txnIndex].txn.applicationCall,
|
|
433
|
+
foreignApps: [...(txns[txnIndex].txn?.applicationCall?.foreignApps ?? []), ...[app]],
|
|
434
|
+
accounts: [...(txns[txnIndex].txn?.applicationCall?.accounts ?? []), ...[account]],
|
|
435
|
+
};
|
|
401
436
|
}
|
|
402
437
|
else if (type === 'asset') {
|
|
403
|
-
txns[txnIndex].txn
|
|
438
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
439
|
+
...txns[txnIndex].txn.applicationCall,
|
|
440
|
+
foreignAssets: [
|
|
441
|
+
...(txns[txnIndex].txn?.applicationCall?.foreignAssets ?? []),
|
|
442
|
+
...[typeof reference === 'bigint' ? reference : BigInt(reference)],
|
|
443
|
+
],
|
|
444
|
+
};
|
|
404
445
|
}
|
|
405
446
|
};
|
|
406
447
|
const g = unnamedResourcesAccessed.group;
|
|
@@ -452,98 +493,87 @@ async function populateAppCallResources(atc, algod) {
|
|
|
452
493
|
}
|
|
453
494
|
/**
|
|
454
495
|
* Signs and sends transactions that have been collected by an `AtomicTransactionComposer`.
|
|
455
|
-
* @param atcSend The parameters controlling the send, including
|
|
456
|
-
* * `atc` The `AtomicTransactionComposer`
|
|
457
|
-
* * `sendParams` The parameters to control the send behaviour
|
|
496
|
+
* @param atcSend The parameters controlling the send, including `atc` The `AtomicTransactionComposer` and params to control send behaviour
|
|
458
497
|
* @param algod An algod client
|
|
459
498
|
* @returns An object with transaction IDs, transactions, group transaction ID (`groupTransactionId`) if more than 1 transaction sent, and (if `skipWaiting` is `false` or unset) confirmation (`confirmation`)
|
|
460
499
|
*/
|
|
461
500
|
const sendAtomicTransactionComposer = async function (atcSend, algod) {
|
|
462
|
-
const { atc: givenAtc, sendParams } = atcSend;
|
|
501
|
+
const { atc: givenAtc, sendParams, ...executeParams } = atcSend;
|
|
463
502
|
let atc;
|
|
464
|
-
// const hasAppCalls = () =>
|
|
465
|
-
// givenAtc
|
|
466
|
-
// .buildGroup()
|
|
467
|
-
// .map((t) => t.txn.type)
|
|
468
|
-
// .includes(algosdk.TransactionType.appl)
|
|
469
503
|
atc = givenAtc;
|
|
470
504
|
try {
|
|
505
|
+
const transactionsWithSigner = atc.buildGroup();
|
|
471
506
|
// If populateAppCallResources is true OR if populateAppCallResources is undefined and there are app calls, then populate resources
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
if (populateResources) {
|
|
507
|
+
const populateResources = executeParams?.populateAppCallResources ?? sendParams?.populateAppCallResources ?? Config.populateAppCallResources;
|
|
508
|
+
if (populateResources && transactionsWithSigner.map((t) => t.txn.type).includes(algosdk.TransactionType.appl)) {
|
|
475
509
|
atc = await populateAppCallResources(givenAtc, algod);
|
|
476
510
|
}
|
|
477
|
-
const transactionsWithSigner = atc.buildGroup();
|
|
478
511
|
const transactionsToSend = transactionsWithSigner.map((t) => {
|
|
479
512
|
return t.txn;
|
|
480
513
|
});
|
|
481
514
|
let groupId = undefined;
|
|
482
515
|
if (transactionsToSend.length > 1) {
|
|
483
516
|
groupId = transactionsToSend[0].group ? Buffer.from(transactionsToSend[0].group).toString('base64') : '';
|
|
484
|
-
Config.getLogger(sendParams?.suppressLog).verbose(`Sending group of ${transactionsToSend.length} transactions (${groupId})`, {
|
|
517
|
+
Config.getLogger(executeParams?.suppressLog ?? sendParams?.suppressLog).verbose(`Sending group of ${transactionsToSend.length} transactions (${groupId})`, {
|
|
485
518
|
transactionsToSend,
|
|
486
519
|
});
|
|
487
|
-
Config.getLogger(sendParams?.suppressLog).debug(`Transaction IDs (${groupId})`, transactionsToSend.map((t) => t.txID()));
|
|
520
|
+
Config.getLogger(executeParams?.suppressLog ?? sendParams?.suppressLog).debug(`Transaction IDs (${groupId})`, transactionsToSend.map((t) => t.txID()));
|
|
488
521
|
}
|
|
489
|
-
if (Config.debug && Config.
|
|
522
|
+
if (Config.debug && Config.traceAll) {
|
|
490
523
|
// Dump the traces to a file for use with AlgoKit AVM debugger
|
|
491
|
-
await
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
algod,
|
|
495
|
-
bufferSizeMb: Config.traceBufferSizeMb,
|
|
524
|
+
const simulateResponse = await performAtomicTransactionComposerSimulate(atc, algod);
|
|
525
|
+
await Config.events.emitAsync(EventType.TxnGroupSimulated, {
|
|
526
|
+
simulateResponse,
|
|
496
527
|
});
|
|
497
528
|
}
|
|
498
|
-
const result = await atc.execute(algod, sendParams?.maxRoundsToWaitForConfirmation ?? 5);
|
|
529
|
+
const result = await atc.execute(algod, executeParams?.maxRoundsToWaitForConfirmation ?? sendParams?.maxRoundsToWaitForConfirmation ?? 5);
|
|
499
530
|
if (transactionsToSend.length > 1) {
|
|
500
|
-
Config.getLogger(sendParams?.suppressLog).verbose(`Group transaction (${groupId}) sent with ${transactionsToSend.length} transactions`);
|
|
531
|
+
Config.getLogger(executeParams?.suppressLog ?? sendParams?.suppressLog).verbose(`Group transaction (${groupId}) sent with ${transactionsToSend.length} transactions`);
|
|
501
532
|
}
|
|
502
533
|
else {
|
|
503
|
-
Config.getLogger(sendParams?.suppressLog).verbose(`Sent transaction ID ${transactionsToSend[0].txID()} ${transactionsToSend[0].type} from ${
|
|
534
|
+
Config.getLogger(executeParams?.suppressLog ?? sendParams?.suppressLog).verbose(`Sent transaction ID ${transactionsToSend[0].txID()} ${transactionsToSend[0].type} from ${transactionsToSend[0].sender.toString()}`);
|
|
504
535
|
}
|
|
505
536
|
let confirmations = undefined;
|
|
506
537
|
if (!sendParams?.skipWaiting) {
|
|
507
|
-
confirmations = await Promise.all(transactionsToSend.map(async (t) =>
|
|
538
|
+
confirmations = await Promise.all(transactionsToSend.map(async (t) => await algod.pendingTransactionInformation(t.txID()).do()));
|
|
508
539
|
}
|
|
509
540
|
return {
|
|
510
541
|
groupId,
|
|
511
542
|
confirmations,
|
|
512
543
|
txIds: transactionsToSend.map((t) => t.txID()),
|
|
513
544
|
transactions: transactionsToSend,
|
|
514
|
-
returns: result.methodResults.map(
|
|
515
|
-
decodeError: r.decodeError,
|
|
516
|
-
returnValue: r.returnValue,
|
|
517
|
-
rawReturnValue: r.rawReturnValue,
|
|
518
|
-
})),
|
|
545
|
+
returns: result.methodResults.map(getABIReturnValue),
|
|
519
546
|
};
|
|
520
547
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
521
548
|
}
|
|
522
549
|
catch (e) {
|
|
523
|
-
//
|
|
524
|
-
|
|
550
|
+
// Create a new error object so the stack trace is correct (algosdk throws an error with a more limited stack trace)
|
|
551
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
552
|
+
const err = new Error(typeof e === 'object' ? e?.message : 'Received error executing Atomic Transaction Composer');
|
|
553
|
+
err.cause = e;
|
|
554
|
+
if (typeof e === 'object') {
|
|
555
|
+
// Remove headers as it doesn't have anything useful.
|
|
556
|
+
delete e.response?.headers;
|
|
557
|
+
err.response = e.response;
|
|
558
|
+
// body property very noisy
|
|
559
|
+
if (e.response && 'body' in e.response)
|
|
560
|
+
delete err.response.body;
|
|
561
|
+
err.name = e.name;
|
|
562
|
+
}
|
|
525
563
|
if (Config.debug && typeof e === 'object') {
|
|
526
|
-
|
|
527
|
-
Config.logger.error('Received error executing Atomic Transaction Composer and debug flag enabled; attempting simulation to get more information',
|
|
528
|
-
|
|
529
|
-
if (Config.debug &&
|
|
530
|
-
//
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
simulate = await simulateAndPersistResponse({
|
|
534
|
-
atc,
|
|
535
|
-
projectRoot: Config.projectRoot,
|
|
536
|
-
algod,
|
|
537
|
-
bufferSizeMb: Config.traceBufferSizeMb,
|
|
564
|
+
err.traces = [];
|
|
565
|
+
Config.logger.error('Received error executing Atomic Transaction Composer and debug flag enabled; attempting simulation to get more information', err);
|
|
566
|
+
const simulate = await performAtomicTransactionComposerSimulate(atc, algod);
|
|
567
|
+
if (Config.debug && !Config.traceAll) {
|
|
568
|
+
// Emit the event only if traceAll: false, as it should have already been emitted above
|
|
569
|
+
await Config.events.emitAsync(EventType.TxnGroupSimulated, {
|
|
570
|
+
simulateResponse: simulate,
|
|
538
571
|
});
|
|
539
572
|
}
|
|
540
|
-
else {
|
|
541
|
-
simulate = await performAtomicTransactionComposerSimulate(atc, algod);
|
|
542
|
-
}
|
|
543
573
|
if (simulate && simulate.txnGroups[0].failedAt) {
|
|
544
574
|
for (const txn of simulate.txnGroups[0].txnResults) {
|
|
545
|
-
|
|
546
|
-
trace: txn.execTrace?.
|
|
575
|
+
err.traces.push({
|
|
576
|
+
trace: txn.execTrace?.toEncodingData(),
|
|
547
577
|
appBudget: txn.appBudgetConsumed,
|
|
548
578
|
logicSigBudget: txn.logicSigBudgetConsumed,
|
|
549
579
|
logs: txn.txnResult.logs,
|
|
@@ -553,26 +583,53 @@ const sendAtomicTransactionComposer = async function (atcSend, algod) {
|
|
|
553
583
|
}
|
|
554
584
|
}
|
|
555
585
|
else {
|
|
556
|
-
Config.logger.error('Received error executing Atomic Transaction Composer, for more information enable the debug flag',
|
|
586
|
+
Config.logger.error('Received error executing Atomic Transaction Composer, for more information enable the debug flag', err);
|
|
557
587
|
}
|
|
558
|
-
throw
|
|
588
|
+
throw err;
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
const convertABIDecodedBigIntToNumber = (value, type) => {
|
|
592
|
+
if (typeof value === 'bigint') {
|
|
593
|
+
if (type instanceof algosdk.ABIUintType) {
|
|
594
|
+
return type.bitSize < 53 ? Number(value) : value;
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
return value;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
else if (Array.isArray(value) && (type instanceof algosdk.ABIArrayStaticType || type instanceof algosdk.ABIArrayDynamicType)) {
|
|
601
|
+
return value.map((v) => convertABIDecodedBigIntToNumber(v, type.childType));
|
|
602
|
+
}
|
|
603
|
+
else if (Array.isArray(value) && type instanceof algosdk.ABITupleType) {
|
|
604
|
+
return value.map((v, i) => convertABIDecodedBigIntToNumber(v, type.childTypes[i]));
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
return value;
|
|
559
608
|
}
|
|
560
609
|
};
|
|
561
610
|
/**
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
* @param
|
|
565
|
-
* @returns The dryrun result
|
|
611
|
+
* Takes an algosdk `ABIResult` and converts it to an `ABIReturn`.
|
|
612
|
+
* Converts `bigint`'s for Uint's < 64 to `number` for easier use.
|
|
613
|
+
* @param result The `ABIReturn`
|
|
566
614
|
*/
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
return
|
|
615
|
+
function getABIReturnValue(result) {
|
|
616
|
+
if (result.decodeError) {
|
|
617
|
+
return {
|
|
618
|
+
decodeError: result.decodeError,
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
return {
|
|
622
|
+
method: result.method,
|
|
623
|
+
rawReturnValue: result.rawReturnValue,
|
|
624
|
+
decodeError: undefined,
|
|
625
|
+
returnValue: result.returnValue !== undefined && result.method.returns.type !== 'void'
|
|
626
|
+
? convertABIDecodedBigIntToNumber(result.returnValue, result.method.returns.type)
|
|
627
|
+
: result.returnValue,
|
|
628
|
+
};
|
|
574
629
|
}
|
|
575
630
|
/**
|
|
631
|
+
* @deprecated Use `TransactionComposer` (`algorand.newGroup()`) or `AtomicTransactionComposer` to construct and send group transactions instead.
|
|
632
|
+
*
|
|
576
633
|
* Signs and sends a group of [up to 16](https://developer.algorand.org/docs/get-details/atomic_transfers/#create-transactions) transactions to the chain
|
|
577
634
|
*
|
|
578
635
|
* @param groupSend The group details to send, with:
|
|
@@ -622,7 +679,7 @@ const waitForConfirmation = async function (transactionId, maxRoundsToWait, algo
|
|
|
622
679
|
throw new Error(`Invalid timeout, received ${maxRoundsToWait}, expected > 0`);
|
|
623
680
|
}
|
|
624
681
|
// Get current round
|
|
625
|
-
const status =
|
|
682
|
+
const status = await algod.status().do();
|
|
626
683
|
if (status === undefined) {
|
|
627
684
|
throw new Error('Unable to get node status');
|
|
628
685
|
}
|
|
@@ -631,7 +688,7 @@ const waitForConfirmation = async function (transactionId, maxRoundsToWait, algo
|
|
|
631
688
|
let currentRound = startRound;
|
|
632
689
|
while (currentRound < startRound + BigInt(maxRoundsToWait)) {
|
|
633
690
|
try {
|
|
634
|
-
const pendingInfo =
|
|
691
|
+
const pendingInfo = await algod.pendingTransactionInformation(transactionId).do();
|
|
635
692
|
if (pendingInfo !== undefined) {
|
|
636
693
|
const confirmedRound = pendingInfo.confirmedRound;
|
|
637
694
|
if (confirmedRound && confirmedRound > 0) {
|
|
@@ -659,6 +716,8 @@ const waitForConfirmation = async function (transactionId, maxRoundsToWait, algo
|
|
|
659
716
|
throw new Error(`Transaction ${transactionId} not confirmed after ${maxRoundsToWait} rounds`);
|
|
660
717
|
};
|
|
661
718
|
/**
|
|
719
|
+
* @deprecated Use `TransactionComposer` and the `maxFee` field in the transaction params instead.
|
|
720
|
+
*
|
|
662
721
|
* Limit the acceptable fee to a defined amount of µAlgo.
|
|
663
722
|
* This also sets the transaction to be flatFee to ensure the transaction only succeeds at
|
|
664
723
|
* the estimated rate.
|
|
@@ -667,20 +726,24 @@ const waitForConfirmation = async function (transactionId, maxRoundsToWait, algo
|
|
|
667
726
|
*/
|
|
668
727
|
function capTransactionFee(transaction, maxAcceptableFee) {
|
|
669
728
|
// If a flat fee hasn't already been defined
|
|
670
|
-
if (!transaction.flatFee) {
|
|
729
|
+
if (!('flatFee' in transaction) || !transaction.flatFee) {
|
|
671
730
|
// Once a transaction has been constructed by algosdk, transaction.fee indicates what the total transaction fee
|
|
672
731
|
// Will be based on the current suggested fee-per-byte value.
|
|
673
732
|
if (transaction.fee > maxAcceptableFee.microAlgo) {
|
|
674
733
|
throw new Error(`Cancelled transaction due to high network congestion fees. Algorand suggested fees would cause this transaction to cost ${transaction.fee} µALGO. Cap for this transaction is ${maxAcceptableFee.microAlgo} µALGO.`);
|
|
675
734
|
}
|
|
676
|
-
else if (transaction.fee >
|
|
735
|
+
else if (transaction.fee > 1000000) {
|
|
677
736
|
Config.logger.warn(`Algorand network congestion fees are in effect. This transaction will incur a fee of ${transaction.fee} µALGO.`);
|
|
678
737
|
}
|
|
679
738
|
// Now set the flat on the transaction. Otherwise the network may increase the fee above our cap and perform the transaction.
|
|
680
|
-
|
|
739
|
+
if ('flatFee' in transaction) {
|
|
740
|
+
transaction.flatFee = true;
|
|
741
|
+
}
|
|
681
742
|
}
|
|
682
743
|
}
|
|
683
744
|
/**
|
|
745
|
+
* @deprecated Use `TransactionComposer` and the `maxFee` and `staticFee` fields in the transaction params instead.
|
|
746
|
+
*
|
|
684
747
|
* Allows for control of fees on a `Transaction` or `SuggestedParams` object
|
|
685
748
|
* @param transaction The transaction or suggested params
|
|
686
749
|
* @param feeControl The fee control parameters
|
|
@@ -688,8 +751,10 @@ function capTransactionFee(transaction, maxAcceptableFee) {
|
|
|
688
751
|
function controlFees(transaction, feeControl) {
|
|
689
752
|
const { fee, maxFee } = feeControl;
|
|
690
753
|
if (fee) {
|
|
691
|
-
transaction.fee = fee.microAlgo;
|
|
692
|
-
|
|
754
|
+
transaction.fee = Number(fee.microAlgo);
|
|
755
|
+
if ('flatFee' in transaction) {
|
|
756
|
+
transaction.flatFee = true;
|
|
757
|
+
}
|
|
693
758
|
}
|
|
694
759
|
if (maxFee !== undefined) {
|
|
695
760
|
capTransactionFee(transaction, maxFee);
|
|
@@ -697,15 +762,30 @@ function controlFees(transaction, feeControl) {
|
|
|
697
762
|
return transaction;
|
|
698
763
|
}
|
|
699
764
|
/**
|
|
765
|
+
* @deprecated Use `suggestedParams ? { ...suggestedParams } : await algod.getTransactionParams().do()` instead
|
|
766
|
+
*
|
|
700
767
|
* Returns suggested transaction parameters from algod unless some are already provided.
|
|
701
768
|
* @param params Optionally provide parameters to use
|
|
702
769
|
* @param algod Algod algod
|
|
703
770
|
* @returns The suggested transaction parameters
|
|
704
771
|
*/
|
|
705
772
|
async function getTransactionParams(params, algod) {
|
|
706
|
-
|
|
773
|
+
if (params) {
|
|
774
|
+
return { ...params };
|
|
775
|
+
}
|
|
776
|
+
const p = await algod.getTransactionParams().do();
|
|
777
|
+
return {
|
|
778
|
+
fee: p.fee,
|
|
779
|
+
firstValid: p.firstValid,
|
|
780
|
+
lastValid: p.lastValid,
|
|
781
|
+
genesisID: p.genesisID,
|
|
782
|
+
genesisHash: p.genesisHash,
|
|
783
|
+
minFee: p.minFee,
|
|
784
|
+
};
|
|
707
785
|
}
|
|
708
786
|
/**
|
|
787
|
+
* @deprecated Use `atc.clone().buildGroup()` instead.
|
|
788
|
+
*
|
|
709
789
|
* Returns the array of transactions currently present in the given `AtomicTransactionComposer`
|
|
710
790
|
* @param atc The atomic transaction composer
|
|
711
791
|
* @returns The array of transactions with signers
|
|
@@ -719,5 +799,5 @@ function getAtomicTransactionComposerTransactions(atc) {
|
|
|
719
799
|
}
|
|
720
800
|
}
|
|
721
801
|
|
|
722
|
-
export { MAX_APP_CALL_ACCOUNT_REFERENCES, MAX_APP_CALL_FOREIGN_REFERENCES, MAX_TRANSACTION_GROUP_SIZE, capTransactionFee, controlFees, encodeLease, encodeTransactionNote, getAtomicTransactionComposerTransactions, getSenderAddress, getSenderTransactionSigner, getTransactionParams, getTransactionWithSigner,
|
|
802
|
+
export { MAX_APP_CALL_ACCOUNT_REFERENCES, MAX_APP_CALL_FOREIGN_REFERENCES, MAX_TRANSACTION_GROUP_SIZE, capTransactionFee, controlFees, encodeLease, encodeTransactionNote, getABIReturnValue, getAtomicTransactionComposerTransactions, getSenderAddress, getSenderTransactionSigner, getTransactionParams, getTransactionWithSigner, populateAppCallResources, sendAtomicTransactionComposer, sendGroupOfTransactions, sendTransaction, signTransaction, waitForConfirmation };
|
|
723
803
|
//# sourceMappingURL=transaction.mjs.map
|