@algorandfoundation/algokit-utils 6.3.0-beta.1 → 7.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +22 -26
- package/account/account.d.ts +12 -10
- package/account/account.js +17 -14
- package/account/account.js.map +1 -1
- package/account/account.mjs +18 -15
- package/account/account.mjs.map +1 -1
- package/account/get-account-config-from-environment.d.ts +0 -1
- package/account/get-account-config-from-environment.js.map +1 -1
- package/account/get-account-config-from-environment.mjs.map +1 -1
- package/account/get-account.d.ts +2 -3
- package/account/get-account.js +1 -1
- package/account/get-account.js.map +1 -1
- package/account/get-account.mjs +1 -1
- package/account/get-account.mjs.map +1 -1
- package/account/get-dispenser-account.d.ts +2 -3
- package/account/get-dispenser-account.js +1 -1
- package/account/get-dispenser-account.js.map +1 -1
- package/account/get-dispenser-account.mjs +1 -1
- package/account/get-dispenser-account.mjs.map +1 -1
- package/account/index.d.ts +0 -1
- package/account/mnemonic-account.d.ts +1 -2
- package/account/mnemonic-account.js +1 -1
- package/account/mnemonic-account.js.map +1 -1
- package/account/mnemonic-account.mjs +1 -1
- package/account/mnemonic-account.mjs.map +1 -1
- package/amount.d.ts +15 -5
- package/amount.js +9 -2
- package/amount.js.map +1 -1
- package/amount.mjs +9 -3
- package/amount.mjs.map +1 -1
- package/app-client.d.ts +19 -5
- package/app-client.js +19 -4
- package/app-client.js.map +1 -1
- package/app-client.mjs +19 -4
- package/app-client.mjs.map +1 -1
- package/app-deploy.d.ts +18 -2
- package/app-deploy.js +159 -342
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +163 -346
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +39 -3
- package/app.js +121 -371
- package/app.js.map +1 -1
- package/app.mjs +122 -372
- package/app.mjs.map +1 -1
- package/asset.d.ts +5 -6
- package/asset.js +5 -8
- package/asset.js.map +1 -1
- package/asset.mjs +5 -8
- package/asset.mjs.map +1 -1
- package/config.d.ts +0 -1
- package/config.js.map +1 -1
- package/config.mjs.map +1 -1
- package/debugging/debugging.d.ts +3 -5
- package/debugging/debugging.js +4 -128
- package/debugging/debugging.js.map +1 -1
- package/debugging/debugging.mjs +4 -109
- package/debugging/debugging.mjs.map +1 -1
- package/debugging/index.d.ts +0 -2
- package/dispenser-client.d.ts +0 -1
- package/dispenser-client.js.map +1 -1
- package/dispenser-client.mjs.map +1 -1
- package/index.d.ts +5 -4
- package/index.js +36 -26
- package/index.js.map +1 -1
- package/index.mjs +6 -5
- package/index.mjs.map +1 -1
- package/indexer-lookup.d.ts +10 -9
- package/indexer-lookup.js +14 -10
- package/indexer-lookup.js.map +1 -1
- package/indexer-lookup.mjs +14 -10
- package/indexer-lookup.mjs.map +1 -1
- package/localnet/get-kmd-wallet-account.d.ts +1 -2
- package/localnet/get-kmd-wallet-account.js +1 -1
- package/localnet/get-kmd-wallet-account.js.map +1 -1
- package/localnet/get-kmd-wallet-account.mjs +1 -1
- package/localnet/get-kmd-wallet-account.mjs.map +1 -1
- package/localnet/get-localnet-dispenser-account.d.ts +1 -2
- package/localnet/get-localnet-dispenser-account.js +1 -1
- package/localnet/get-localnet-dispenser-account.js.map +1 -1
- package/localnet/get-localnet-dispenser-account.mjs +1 -1
- package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts +1 -2
- package/localnet/get-or-create-kmd-wallet-account.js +1 -1
- package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
- package/localnet/index.d.ts +0 -1
- package/localnet/is-localnet.d.ts +1 -2
- package/localnet/is-localnet.js +1 -1
- package/localnet/is-localnet.js.map +1 -1
- package/localnet/is-localnet.mjs +1 -1
- package/localnet/is-localnet.mjs.map +1 -1
- package/network-client.d.ts +3 -10
- package/network-client.js +4 -11
- package/network-client.js.map +1 -1
- package/network-client.mjs +4 -11
- package/network-client.mjs.map +1 -1
- package/package.json +3 -4
- package/testing/_asset.d.ts +2 -2
- package/testing/account.d.ts +4 -4
- package/testing/account.js +8 -2
- package/testing/account.js.map +1 -1
- package/testing/account.mjs +9 -3
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +0 -1
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
- package/testing/fixtures/algorand-fixture.d.ts +0 -1
- package/testing/fixtures/algorand-fixture.js +13 -14
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +13 -14
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/fixtures/index.d.ts +0 -1
- package/testing/index.d.ts +0 -1
- package/testing/indexer.d.ts +0 -1
- package/testing/indexer.js.map +1 -1
- package/testing/indexer.mjs.map +1 -1
- package/testing/test-logger.d.ts +0 -1
- package/testing/test-logger.js +7 -3
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs +7 -3
- package/testing/test-logger.mjs.map +1 -1
- package/testing/transaction-logger.d.ts +0 -1
- package/testing/transaction-logger.js.map +1 -1
- package/testing/transaction-logger.mjs.map +1 -1
- package/transaction/index.d.ts +0 -1
- package/transaction/legacy-bridge.d.ts +31 -6
- package/transaction/legacy-bridge.js +101 -7
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +101 -10
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts +4 -2
- package/transaction/perform-atomic-transaction-composer-simulate.js +14 -9
- package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.mjs +15 -10
- package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +38 -19
- package/transaction/transaction.js +217 -137
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +218 -138
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/index.d.ts +0 -1
- package/transfer/transfer-algos.d.ts +1 -2
- package/transfer/transfer-algos.js +1 -1
- package/transfer/transfer-algos.js.map +1 -1
- package/transfer/transfer-algos.mjs +1 -1
- package/transfer/transfer-algos.mjs.map +1 -1
- package/transfer/transfer.d.ts +1 -2
- package/transfer/transfer.js +6 -4
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs +6 -4
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +33 -25
- package/types/account-manager.js +54 -31
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +56 -33
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +17 -9
- package/types/account.js +2 -2
- package/types/account.js.map +1 -1
- package/types/account.mjs +3 -3
- package/types/account.mjs.map +1 -1
- package/types/algo-http-client-with-retry.d.ts +1 -3
- package/types/algo-http-client-with-retry.js +33 -3
- package/types/algo-http-client-with-retry.js.map +1 -1
- package/types/algo-http-client-with-retry.mjs +32 -2
- package/types/algo-http-client-with-retry.mjs.map +1 -1
- package/types/algorand-client-interface.d.ts +28 -0
- package/types/algorand-client-interface.js +3 -0
- package/types/algorand-client-interface.js.map +1 -0
- package/types/algorand-client-interface.mjs +2 -0
- package/types/algorand-client-interface.mjs.map +1 -0
- package/types/algorand-client-transaction-creator.d.ts +452 -23
- package/types/algorand-client-transaction-creator.js +407 -23
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +407 -23
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +772 -47
- package/types/algorand-client-transaction-sender.js +445 -15
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +445 -15
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +24 -17
- package/types/algorand-client.js +26 -16
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +28 -15
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.d.ts +10 -11
- package/types/amount.js +7 -7
- package/types/amount.js.map +1 -1
- package/types/amount.mjs +7 -7
- package/types/amount.mjs.map +1 -1
- package/types/app-arc56.d.ts +359 -0
- package/types/app-arc56.js +184 -0
- package/types/app-arc56.js.map +1 -0
- package/types/app-arc56.mjs +175 -0
- package/types/app-arc56.mjs.map +1 -0
- package/types/app-client.d.ts +1508 -12
- package/types/app-client.js +1018 -29
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +1020 -32
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +126 -0
- package/types/app-deployer.js +353 -0
- package/types/app-deployer.js.map +1 -0
- package/types/app-deployer.mjs +351 -0
- package/types/app-deployer.mjs.map +1 -0
- package/types/app-factory.d.ts +846 -0
- package/types/app-factory.js +410 -0
- package/types/app-factory.js.map +1 -0
- package/types/app-factory.mjs +408 -0
- package/types/app-factory.mjs.map +1 -0
- package/types/app-manager.d.ts +244 -0
- package/types/app-manager.js +423 -0
- package/types/app-manager.js.map +1 -0
- package/types/app-manager.mjs +421 -0
- package/types/app-manager.mjs.map +1 -0
- package/types/app-spec.d.ts +2 -1
- package/types/app-spec.js +127 -0
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +126 -0
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +57 -18
- package/types/app.js +1 -1
- package/types/app.js.map +1 -1
- package/types/app.mjs +1 -1
- package/types/app.mjs.map +1 -1
- package/types/asset-manager.d.ts +10 -10
- package/types/asset-manager.js +13 -17
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +13 -17
- package/types/asset-manager.mjs.map +1 -1
- package/types/asset.d.ts +0 -1
- package/types/async-event-emitter.d.ts +14 -0
- package/types/async-event-emitter.js +50 -0
- package/types/async-event-emitter.js.map +1 -0
- package/types/async-event-emitter.mjs +48 -0
- package/types/async-event-emitter.mjs.map +1 -0
- package/types/client-manager.d.ts +135 -60
- package/types/client-manager.js +158 -44
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +159 -45
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +271 -87
- package/types/composer.js +405 -125
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +407 -125
- package/types/composer.mjs.map +1 -1
- package/types/config.d.ts +3 -6
- package/types/config.js +5 -44
- package/types/config.js.map +1 -1
- package/types/config.mjs +5 -27
- package/types/config.mjs.map +1 -1
- package/types/debugging.d.ts +29 -101
- package/types/debugging.js +16 -109
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs +12 -107
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.d.ts +2 -2
- package/types/dispenser-client.js +10 -5
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs +10 -5
- package/types/dispenser-client.mjs.map +1 -1
- package/types/expand.d.ts +7 -0
- package/types/expand.js +3 -0
- package/types/expand.js.map +1 -0
- package/types/expand.mjs +2 -0
- package/types/expand.mjs.map +1 -0
- package/types/indexer.d.ts +74 -756
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs.map +1 -1
- package/types/kmd-account-manager.d.ts +2 -3
- package/types/kmd-account-manager.js +3 -3
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +4 -4
- package/types/kmd-account-manager.mjs.map +1 -1
- package/types/lifecycle-events.d.ts +10 -0
- package/types/lifecycle-events.js +8 -0
- package/types/lifecycle-events.js.map +1 -0
- package/types/lifecycle-events.mjs +8 -0
- package/types/lifecycle-events.mjs.map +1 -0
- package/types/logging.d.ts +0 -1
- package/types/logging.js.map +1 -1
- package/types/logging.mjs.map +1 -1
- package/types/logic-error.d.ts +2 -4
- package/types/logic-error.js +3 -3
- package/types/logic-error.js.map +1 -1
- package/types/logic-error.mjs +3 -3
- package/types/logic-error.mjs.map +1 -1
- package/types/network-client.d.ts +14 -2
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +8 -10
- package/types/transaction.d.ts +17 -4
- package/types/transfer.d.ts +0 -1
- package/util.d.ts +2 -2
- package/util.js +11 -10
- package/util.js.map +1 -1
- package/util.mjs +11 -10
- package/util.mjs.map +1 -1
- package/account/account.d.ts.map +0 -1
- package/account/get-account-config-from-environment.d.ts.map +0 -1
- package/account/get-account.d.ts.map +0 -1
- package/account/get-dispenser-account.d.ts.map +0 -1
- package/account/index.d.ts.map +0 -1
- package/account/mnemonic-account.d.ts.map +0 -1
- package/amount.d.ts.map +0 -1
- package/app-client.d.ts.map +0 -1
- package/app-deploy.d.ts.map +0 -1
- package/app.d.ts.map +0 -1
- package/asset.d.ts.map +0 -1
- package/config.d.ts.map +0 -1
- package/debugging/debugging.d.ts.map +0 -1
- package/debugging/index.d.ts.map +0 -1
- package/debugging/simulate-and-persist-response.d.ts +0 -20
- package/debugging/simulate-and-persist-response.d.ts.map +0 -1
- package/debugging/simulate-and-persist-response.js +0 -108
- package/debugging/simulate-and-persist-response.js.map +0 -1
- package/debugging/simulate-and-persist-response.mjs +0 -89
- package/debugging/simulate-and-persist-response.mjs.map +0 -1
- package/dispenser-client.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/indexer-lookup.d.ts.map +0 -1
- package/localnet/get-kmd-wallet-account.d.ts.map +0 -1
- package/localnet/get-localnet-dispenser-account.d.ts.map +0 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts.map +0 -1
- package/localnet/index.d.ts.map +0 -1
- package/localnet/is-localnet.d.ts.map +0 -1
- package/network-client.d.ts.map +0 -1
- package/testing/_asset.d.ts.map +0 -1
- package/testing/account.d.ts.map +0 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +0 -1
- package/testing/fixtures/algorand-fixture.d.ts.map +0 -1
- package/testing/fixtures/index.d.ts.map +0 -1
- package/testing/index.d.ts.map +0 -1
- package/testing/indexer.d.ts.map +0 -1
- package/testing/test-logger.d.ts.map +0 -1
- package/testing/transaction-logger.d.ts.map +0 -1
- package/transaction/index.d.ts.map +0 -1
- package/transaction/legacy-bridge.d.ts.map +0 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts.map +0 -1
- package/transaction/transaction.d.ts.map +0 -1
- package/transfer/index.d.ts.map +0 -1
- package/transfer/transfer-algos.d.ts.map +0 -1
- package/transfer/transfer.d.ts.map +0 -1
- package/types/account-manager.d.ts.map +0 -1
- package/types/account.d.ts.map +0 -1
- package/types/algo-http-client-with-retry.d.ts.map +0 -1
- package/types/algorand-client-transaction-creator.d.ts.map +0 -1
- package/types/algorand-client-transaction-sender.d.ts.map +0 -1
- package/types/algorand-client.d.ts.map +0 -1
- package/types/amount.d.ts.map +0 -1
- package/types/app-client.d.ts.map +0 -1
- package/types/app-spec.d.ts.map +0 -1
- package/types/app.d.ts.map +0 -1
- package/types/asset-manager.d.ts.map +0 -1
- package/types/asset.d.ts.map +0 -1
- package/types/client-manager.d.ts.map +0 -1
- package/types/composer.d.ts.map +0 -1
- package/types/config.d.ts.map +0 -1
- package/types/debugging.d.ts.map +0 -1
- package/types/dispenser-client.d.ts.map +0 -1
- package/types/indexer.d.ts.map +0 -1
- package/types/kmd-account-manager.d.ts.map +0 -1
- package/types/logging.d.ts.map +0 -1
- package/types/logic-error.d.ts.map +0 -1
- package/types/network-client.d.ts.map +0 -1
- package/types/testing.d.ts.map +0 -1
- package/types/transaction.d.ts.map +0 -1
- package/types/transfer.d.ts.map +0 -1
- package/types/urlTokenBaseHTTPClient.d.ts +0 -41
- package/types/urlTokenBaseHTTPClient.d.ts.map +0 -1
- package/types/urlTokenBaseHTTPClient.js +0 -153
- package/types/urlTokenBaseHTTPClient.js.map +0 -1
- package/types/urlTokenBaseHTTPClient.mjs +0 -151
- package/types/urlTokenBaseHTTPClient.mjs.map +0 -1
- package/util.d.ts.map +0 -1
package/app.mjs
CHANGED
|
@@ -1,197 +1,80 @@
|
|
|
1
1
|
import algosdk from 'algosdk';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { APP_PAGE_MAX_SIZE } from './types/app.mjs';
|
|
2
|
+
import { legacySendAppTransactionBridge, _getAppArgsForABICall, _getBoxReference } from './transaction/legacy-bridge.mjs';
|
|
3
|
+
import { getSenderAddress, encodeLease } from './transaction/transaction.mjs';
|
|
4
|
+
import { AppManager } from './types/app-manager.mjs';
|
|
6
5
|
import { toNumber } from './util.mjs';
|
|
7
6
|
|
|
8
7
|
var ABIMethod = algosdk.ABIMethod;
|
|
9
|
-
var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
|
|
10
|
-
var modelsv2 = algosdk.modelsv2;
|
|
11
8
|
var OnApplicationComplete = algosdk.OnApplicationComplete;
|
|
12
|
-
var SourceMap = algosdk.SourceMap;
|
|
13
9
|
/**
|
|
10
|
+
* @deprecated Use `algorand.send.appCreate()` / `algorand.createTransaction.appCreate()` / `algorand.send.appCreateMethodCall()`
|
|
11
|
+
* / `algorand.createTransaction.appCreateMethodCall()` instead
|
|
12
|
+
*
|
|
14
13
|
* Creates a smart contract app, returns the details of the created app.
|
|
15
14
|
* @param create The parameters to create the app with
|
|
16
15
|
* @param algod An algod client
|
|
17
16
|
* @returns The details of the created app, or the transaction to create it if `skipSending` and the compilation result
|
|
18
17
|
*/
|
|
19
18
|
async function createApp(create, algod) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const compiledClear = typeof clear === 'string' ? await compileTeal(clear, algod) : undefined;
|
|
24
|
-
const clearProgram = compiledClear ? compiledClear.compiledBase64ToBytes : clear;
|
|
25
|
-
if (args && args.method) {
|
|
26
|
-
const atc = attachATC(sendParams);
|
|
27
|
-
const before = getAtomicTransactionComposerTransactions(atc);
|
|
28
|
-
atc.addMethodCall({
|
|
29
|
-
appID: 0,
|
|
30
|
-
approvalProgram: approvalProgram,
|
|
31
|
-
clearProgram: clearProgram,
|
|
32
|
-
numLocalInts: schema.localInts,
|
|
33
|
-
numLocalByteSlices: schema.localByteSlices,
|
|
34
|
-
numGlobalInts: schema.globalInts,
|
|
35
|
-
numGlobalByteSlices: schema.globalByteSlices,
|
|
36
|
-
extraPages: schema.extraPages ?? Math.floor((approvalProgram.length + clearProgram.length) / APP_PAGE_MAX_SIZE),
|
|
37
|
-
onComplete: getAppOnCompleteAction(onCompleteAction),
|
|
38
|
-
suggestedParams: controlFees(await getTransactionParams(transactionParams, algod), sendParams),
|
|
39
|
-
note: encodeTransactionNote(note),
|
|
40
|
-
...(await getAppArgsForABICall(args, from)),
|
|
41
|
-
});
|
|
42
|
-
if (sendParams.skipSending) {
|
|
43
|
-
const after = atc.clone().buildGroup();
|
|
44
|
-
return {
|
|
45
|
-
transaction: after[after.length - 1].txn,
|
|
46
|
-
transactions: after.slice(before.length).map((t) => t.txn),
|
|
47
|
-
appId: 0,
|
|
48
|
-
appAddress: '',
|
|
49
|
-
compiledApproval,
|
|
50
|
-
compiledClear,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const result = await sendAtomicTransactionComposer({ atc, sendParams }, algod);
|
|
54
|
-
const confirmation = result.confirmations ? result.confirmations[result.confirmations?.length - 1] : undefined;
|
|
55
|
-
if (confirmation) {
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
57
|
-
const appId = confirmation.applicationIndex;
|
|
58
|
-
Config.getLogger(sendParams.suppressLog).debug(`Created app ${appId} from creator ${getSenderAddress(from)}`);
|
|
59
|
-
return {
|
|
60
|
-
transactions: result.transactions,
|
|
61
|
-
confirmations: result.confirmations,
|
|
62
|
-
return: confirmation ? getABIReturn(args, confirmation) : undefined,
|
|
63
|
-
transaction: result.transactions[result.transactions.length - 1],
|
|
64
|
-
confirmation: confirmation,
|
|
65
|
-
appId,
|
|
66
|
-
appAddress: algosdk.getApplicationAddress(appId),
|
|
67
|
-
compiledApproval,
|
|
68
|
-
compiledClear,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
return {
|
|
73
|
-
transactions: result.transactions,
|
|
74
|
-
confirmations: result.confirmations,
|
|
75
|
-
return: confirmation ? getABIReturn(args, confirmation) : undefined,
|
|
76
|
-
transaction: result.transactions[result.transactions.length - 1],
|
|
77
|
-
confirmation: confirmation,
|
|
78
|
-
appId: 0,
|
|
79
|
-
appAddress: '',
|
|
80
|
-
compiledApproval,
|
|
81
|
-
compiledClear,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
const transaction = algosdk.makeApplicationCreateTxnFromObject({
|
|
87
|
-
approvalProgram: approvalProgram,
|
|
88
|
-
clearProgram: clearProgram,
|
|
89
|
-
numLocalInts: schema.localInts,
|
|
90
|
-
numLocalByteSlices: schema.localByteSlices,
|
|
91
|
-
numGlobalInts: schema.globalInts,
|
|
92
|
-
numGlobalByteSlices: schema.globalByteSlices,
|
|
93
|
-
extraPages: schema.extraPages ?? Math.floor((approvalProgram.length + clearProgram.length) / APP_PAGE_MAX_SIZE),
|
|
94
|
-
onComplete: getAppOnCompleteAction(onCompleteAction),
|
|
95
|
-
suggestedParams: await getTransactionParams(transactionParams, algod),
|
|
96
|
-
from: getSenderAddress(from),
|
|
97
|
-
note: encodeTransactionNote(note),
|
|
98
|
-
...getAppArgsForTransaction(args),
|
|
99
|
-
rekeyTo: args?.rekeyTo ? (typeof args.rekeyTo === 'string' ? args.rekeyTo : getSenderAddress(args.rekeyTo)) : undefined,
|
|
100
|
-
});
|
|
101
|
-
const { confirmation } = await sendTransaction({ transaction, from, sendParams }, algod);
|
|
102
|
-
if (confirmation) {
|
|
103
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
104
|
-
const appId = confirmation.applicationIndex;
|
|
105
|
-
Config.getLogger(sendParams.suppressLog).debug(`Created app ${appId} from creator ${getSenderAddress(from)}`);
|
|
106
|
-
return {
|
|
107
|
-
transaction,
|
|
108
|
-
transactions: [transaction],
|
|
109
|
-
confirmation,
|
|
110
|
-
confirmations: confirmation ? [confirmation] : undefined,
|
|
111
|
-
appId,
|
|
112
|
-
appAddress: algosdk.getApplicationAddress(appId),
|
|
113
|
-
return: getABIReturn(args, confirmation),
|
|
114
|
-
compiledApproval,
|
|
115
|
-
compiledClear,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
return { transaction, transactions: [transaction], appId: 0, appAddress: '', compiledApproval, compiledClear };
|
|
120
|
-
}
|
|
19
|
+
const onComplete = getAppOnCompleteAction(create.onCompleteAction);
|
|
20
|
+
if (onComplete === algosdk.OnApplicationComplete.ClearStateOC) {
|
|
21
|
+
throw new Error('Cannot create an app with on-complete action of ClearState');
|
|
121
22
|
}
|
|
23
|
+
const result = create.args?.method
|
|
24
|
+
? await legacySendAppTransactionBridge(algod, create.from, create.args, create, {
|
|
25
|
+
sender: getSenderAddress(create.from),
|
|
26
|
+
onComplete,
|
|
27
|
+
approvalProgram: create.approvalProgram,
|
|
28
|
+
clearStateProgram: create.clearStateProgram,
|
|
29
|
+
method: create.args.method instanceof ABIMethod ? create.args.method : new ABIMethod(create.args.method),
|
|
30
|
+
extraProgramPages: create.schema.extraPages,
|
|
31
|
+
schema: create.schema,
|
|
32
|
+
}, (c) => c.appCreateMethodCall, (c) => c.appCreateMethodCall)
|
|
33
|
+
: await legacySendAppTransactionBridge(algod, create.from, create.args, create, {
|
|
34
|
+
sender: getSenderAddress(create.from),
|
|
35
|
+
onComplete,
|
|
36
|
+
approvalProgram: create.approvalProgram,
|
|
37
|
+
clearStateProgram: create.clearStateProgram,
|
|
38
|
+
extraProgramPages: create.schema.extraPages,
|
|
39
|
+
schema: create.schema,
|
|
40
|
+
}, (c) => c.appCreate, (c) => c.appCreate);
|
|
41
|
+
return {
|
|
42
|
+
...result,
|
|
43
|
+
appId: 'appId' in result ? Number(result.appId) : 0,
|
|
44
|
+
appAddress: 'appAddress' in result ? result.appAddress.toString() : '',
|
|
45
|
+
};
|
|
122
46
|
}
|
|
123
47
|
/**
|
|
48
|
+
* @deprecated Use `algorand.send.appUpdate()` / `algorand.createTransaction.appUpdate()` / `algorand.send.appUpdateMethodCall()`
|
|
49
|
+
* / `algorand.createTransaction.appUpdateMethodCall()` instead
|
|
50
|
+
*
|
|
124
51
|
* Updates a smart contract app.
|
|
125
52
|
* @param update The parameters to update the app with
|
|
126
53
|
* @param algod An algod client
|
|
127
54
|
* @returns The transaction send result and the compilation result
|
|
128
55
|
*/
|
|
129
56
|
async function updateApp(update, algod) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
...(await getAppArgsForABICall(args, from)),
|
|
147
|
-
});
|
|
148
|
-
if (sendParams.skipSending) {
|
|
149
|
-
const after = atc.clone().buildGroup();
|
|
150
|
-
return {
|
|
151
|
-
transaction: after[after.length - 1].txn,
|
|
152
|
-
transactions: after.slice(before.length).map((t) => t.txn),
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
const result = await sendAtomicTransactionComposer({ atc, sendParams }, algod);
|
|
156
|
-
const confirmation = result.confirmations ? result.confirmations[result.confirmations?.length - 1] : undefined;
|
|
157
|
-
return {
|
|
158
|
-
transactions: result.transactions,
|
|
159
|
-
confirmations: result.confirmations,
|
|
160
|
-
return: confirmation ? getABIReturn(args, confirmation) : undefined,
|
|
161
|
-
transaction: result.transactions[result.transactions.length - 1],
|
|
162
|
-
confirmation: confirmation,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
const transaction = algosdk.makeApplicationUpdateTxnFromObject({
|
|
167
|
-
appIndex: toNumber(appId),
|
|
168
|
-
approvalProgram: approvalProgram,
|
|
169
|
-
clearProgram: clearProgram,
|
|
170
|
-
suggestedParams: await getTransactionParams(transactionParams, algod),
|
|
171
|
-
from: getSenderAddress(from),
|
|
172
|
-
note: encodeTransactionNote(note),
|
|
173
|
-
...getAppArgsForTransaction(args),
|
|
174
|
-
rekeyTo: args?.rekeyTo ? (typeof args.rekeyTo === 'string' ? args.rekeyTo : getSenderAddress(args.rekeyTo)) : undefined,
|
|
175
|
-
});
|
|
176
|
-
const result = await sendTransaction({ transaction, from, sendParams }, algod);
|
|
177
|
-
return {
|
|
178
|
-
...result,
|
|
179
|
-
transactions: [result.transaction],
|
|
180
|
-
confirmations: result.confirmation ? [result.confirmation] : undefined,
|
|
181
|
-
return: getABIReturn(args, result.confirmation),
|
|
182
|
-
compiledApproval,
|
|
183
|
-
compiledClear,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function attachATC(sendParams) {
|
|
188
|
-
if (sendParams.atc) {
|
|
189
|
-
sendParams.skipSending = true;
|
|
190
|
-
}
|
|
191
|
-
sendParams.atc = sendParams.atc ?? new AtomicTransactionComposer();
|
|
192
|
-
return sendParams.atc;
|
|
57
|
+
return update.args?.method
|
|
58
|
+
? await legacySendAppTransactionBridge(algod, update.from, update.args, update, {
|
|
59
|
+
appId: BigInt(update.appId),
|
|
60
|
+
sender: getSenderAddress(update.from),
|
|
61
|
+
onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
|
|
62
|
+
approvalProgram: update.approvalProgram,
|
|
63
|
+
clearStateProgram: update.clearStateProgram,
|
|
64
|
+
method: update.args.method instanceof ABIMethod ? update.args.method : new ABIMethod(update.args.method),
|
|
65
|
+
}, (c) => c.appUpdateMethodCall, (c) => c.appUpdateMethodCall)
|
|
66
|
+
: await legacySendAppTransactionBridge(algod, update.from, update.args, update, {
|
|
67
|
+
appId: BigInt(update.appId),
|
|
68
|
+
sender: getSenderAddress(update.from),
|
|
69
|
+
onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
|
|
70
|
+
approvalProgram: update.approvalProgram,
|
|
71
|
+
clearStateProgram: update.clearStateProgram,
|
|
72
|
+
}, (c) => c.appUpdate, (c) => c.appUpdate);
|
|
193
73
|
}
|
|
194
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Use `algosdk.OnApplicationComplete` directly instead.
|
|
76
|
+
*
|
|
77
|
+
* Returns a `algosdk.OnApplicationComplete` for the given onCompleteAction.
|
|
195
78
|
*
|
|
196
79
|
* If given `undefined` will return `OnApplicationComplete.NoOpOC`.
|
|
197
80
|
*
|
|
@@ -224,77 +107,39 @@ function getAppOnCompleteAction(onCompletionAction) {
|
|
|
224
107
|
}
|
|
225
108
|
}
|
|
226
109
|
/**
|
|
110
|
+
* @deprecated Use `algorand.send.appUpdate()` / `algorand.createTransaction.appUpdate()` / `algorand.send.appUpdateMethodCall()`
|
|
111
|
+
* / `algorand.createTransaction.appUpdateMethodCall()` instead
|
|
112
|
+
*
|
|
227
113
|
* Issues a call to a given app.
|
|
228
114
|
* @param call The call details.
|
|
229
115
|
* @param algod An algod client
|
|
230
116
|
* @returns The result of the call
|
|
231
117
|
*/
|
|
232
118
|
async function callApp(call, algod) {
|
|
233
|
-
const
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
const before = getAtomicTransactionComposerTransactions(atc);
|
|
237
|
-
atc.addMethodCall({
|
|
238
|
-
appID: toNumber(appId),
|
|
239
|
-
suggestedParams: controlFees(await getTransactionParams(transactionParams, algod), sendParams),
|
|
240
|
-
note: encodeTransactionNote(note),
|
|
241
|
-
onComplete: getAppOnCompleteAction(callType),
|
|
242
|
-
...(await getAppArgsForABICall(args, from)),
|
|
243
|
-
});
|
|
244
|
-
if (sendParams.skipSending) {
|
|
245
|
-
const after = atc.clone().buildGroup();
|
|
246
|
-
return {
|
|
247
|
-
transaction: after[after.length - 1].txn,
|
|
248
|
-
transactions: after.slice(before.length).map((t) => t.txn),
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
const result = await sendAtomicTransactionComposer({ atc, sendParams }, algod);
|
|
252
|
-
const confirmation = result.confirmations ? result.confirmations[result.confirmations?.length - 1] : undefined;
|
|
253
|
-
return {
|
|
254
|
-
transactions: result.transactions,
|
|
255
|
-
confirmations: result.confirmations,
|
|
256
|
-
return: confirmation ? getABIReturn(args, confirmation) : undefined,
|
|
257
|
-
transaction: result.transactions[result.transactions.length - 1],
|
|
258
|
-
confirmation: confirmation,
|
|
259
|
-
};
|
|
119
|
+
const onComplete = getAppOnCompleteAction(call.callType);
|
|
120
|
+
if (onComplete === algosdk.OnApplicationComplete.UpdateApplicationOC) {
|
|
121
|
+
throw new Error('Cannot execute an app call with on-complete action of Update');
|
|
260
122
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
from: getSenderAddress(from),
|
|
264
|
-
suggestedParams: await getTransactionParams(transactionParams, algod),
|
|
265
|
-
...getAppArgsForTransaction(args),
|
|
266
|
-
note: encodeTransactionNote(note),
|
|
267
|
-
rekeyTo: args?.rekeyTo ? (typeof args.rekeyTo === 'string' ? args.rekeyTo : getSenderAddress(args.rekeyTo)) : undefined,
|
|
268
|
-
};
|
|
269
|
-
let transaction;
|
|
270
|
-
switch (getAppOnCompleteAction(callType)) {
|
|
271
|
-
case OnApplicationComplete.OptInOC:
|
|
272
|
-
transaction = algosdk.makeApplicationOptInTxnFromObject(appCallParams);
|
|
273
|
-
break;
|
|
274
|
-
case OnApplicationComplete.ClearStateOC:
|
|
275
|
-
transaction = algosdk.makeApplicationClearStateTxnFromObject(appCallParams);
|
|
276
|
-
break;
|
|
277
|
-
case OnApplicationComplete.CloseOutOC:
|
|
278
|
-
transaction = algosdk.makeApplicationCloseOutTxnFromObject(appCallParams);
|
|
279
|
-
break;
|
|
280
|
-
case OnApplicationComplete.DeleteApplicationOC:
|
|
281
|
-
transaction = algosdk.makeApplicationDeleteTxnFromObject(appCallParams);
|
|
282
|
-
break;
|
|
283
|
-
case OnApplicationComplete.NoOpOC:
|
|
284
|
-
transaction = algosdk.makeApplicationNoOpTxnFromObject(appCallParams);
|
|
285
|
-
break;
|
|
286
|
-
default:
|
|
287
|
-
throw new Error(`Received unexpected call type ${callType}`);
|
|
123
|
+
if (call.args?.method && onComplete === algosdk.OnApplicationComplete.ClearStateOC) {
|
|
124
|
+
throw new Error('Cannot execute an ABI method call with on-complete action of ClearState');
|
|
288
125
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
126
|
+
return call.args?.method
|
|
127
|
+
? await legacySendAppTransactionBridge(algod, call.from, call.args, call, {
|
|
128
|
+
appId: BigInt(call.appId),
|
|
129
|
+
sender: getSenderAddress(call.from),
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
131
|
+
onComplete: onComplete,
|
|
132
|
+
method: call.args.method instanceof ABIMethod ? call.args.method : new ABIMethod(call.args.method),
|
|
133
|
+
}, (c) => c.appCallMethodCall, (c) => c.appCallMethodCall)
|
|
134
|
+
: await legacySendAppTransactionBridge(algod, call.from, call.args, call, {
|
|
135
|
+
appId: BigInt(call.appId),
|
|
136
|
+
sender: getSenderAddress(call.from),
|
|
137
|
+
onComplete,
|
|
138
|
+
}, (c) => c.appCall, (c) => c.appCall);
|
|
296
139
|
}
|
|
297
140
|
/**
|
|
141
|
+
* @deprecated Use `AppManager.getABIReturn` instead.
|
|
142
|
+
*
|
|
298
143
|
* Returns any ABI return values for the given app call arguments and transaction confirmation.
|
|
299
144
|
* @param args The arguments that were used for the call
|
|
300
145
|
* @param confirmation The transaction confirmation from algod
|
|
@@ -305,43 +150,22 @@ function getABIReturn(args, confirmation) {
|
|
|
305
150
|
return undefined;
|
|
306
151
|
}
|
|
307
152
|
const method = 'txnCount' in args.method ? args.method : new ABIMethod(args.method);
|
|
308
|
-
|
|
309
|
-
// The parseMethodResponse method mutates the second parameter :(
|
|
310
|
-
const resultDummy = {
|
|
311
|
-
txID: '',
|
|
312
|
-
method,
|
|
313
|
-
rawReturnValue: new Uint8Array(),
|
|
314
|
-
};
|
|
315
|
-
const response = AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation);
|
|
316
|
-
return !response.decodeError
|
|
317
|
-
? {
|
|
318
|
-
rawReturnValue: response.rawReturnValue,
|
|
319
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
320
|
-
returnValue: response.returnValue,
|
|
321
|
-
decodeError: undefined,
|
|
322
|
-
}
|
|
323
|
-
: {
|
|
324
|
-
rawReturnValue: undefined,
|
|
325
|
-
returnValue: undefined,
|
|
326
|
-
decodeError: response.decodeError,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
return undefined;
|
|
153
|
+
return AppManager.getABIReturn(confirmation, method);
|
|
330
154
|
}
|
|
331
155
|
/**
|
|
156
|
+
* @deprecated Use `algorand.app.getGlobalState` instead.
|
|
157
|
+
*
|
|
332
158
|
* Returns the current global state values for the given app ID
|
|
333
159
|
* @param appId The ID of the app return global state for
|
|
334
160
|
* @param algod An algod client instance
|
|
335
161
|
* @returns The current global state
|
|
336
162
|
*/
|
|
337
163
|
async function getAppGlobalState(appId, algod) {
|
|
338
|
-
|
|
339
|
-
if (!appInfo.params || !appInfo.params.globalState) {
|
|
340
|
-
throw new Error("Couldn't find global state");
|
|
341
|
-
}
|
|
342
|
-
return decodeAppState(appInfo.params.globalState);
|
|
164
|
+
return await new AppManager(algod).getGlobalState(BigInt(appId));
|
|
343
165
|
}
|
|
344
166
|
/**
|
|
167
|
+
* @deprecated Use `algorand.app.getLocalState` instead.
|
|
168
|
+
*
|
|
345
169
|
* Returns the current global state values for the given app ID and account
|
|
346
170
|
* @param appId The ID of the app return global state for
|
|
347
171
|
* @param account Either the string address of an account or an account object for the account to get local state for the given app
|
|
@@ -349,30 +173,20 @@ async function getAppGlobalState(appId, algod) {
|
|
|
349
173
|
* @returns The current local state for the given (app, account) combination
|
|
350
174
|
*/
|
|
351
175
|
async function getAppLocalState(appId, account, algod) {
|
|
352
|
-
|
|
353
|
-
const appInfo = modelsv2.AccountApplicationResponse.from_obj_for_encoding(await algod.accountApplicationInformation(accountAddress, toNumber(appId)).do());
|
|
354
|
-
if (!appInfo.appLocalState?.keyValue) {
|
|
355
|
-
throw new Error("Couldn't find local state");
|
|
356
|
-
}
|
|
357
|
-
return decodeAppState(appInfo.appLocalState.keyValue);
|
|
176
|
+
return new AppManager(algod).getLocalState(BigInt(appId), getSenderAddress(account));
|
|
358
177
|
}
|
|
359
178
|
/**
|
|
179
|
+
* @deprecated Use `algorand.app.getBoxNames` instead.
|
|
360
180
|
* Returns the names of the boxes for the given app.
|
|
361
181
|
* @param appId The ID of the app return box names for
|
|
362
182
|
* @param algod An algod client instance
|
|
363
183
|
* @returns The current box names
|
|
364
184
|
*/
|
|
365
185
|
async function getAppBoxNames(appId, algod) {
|
|
366
|
-
|
|
367
|
-
return boxResult.boxes.map((b) => {
|
|
368
|
-
return {
|
|
369
|
-
nameRaw: b.name,
|
|
370
|
-
nameBase64: Buffer.from(b.name).toString('base64'),
|
|
371
|
-
name: Buffer.from(b.name).toString('utf-8'),
|
|
372
|
-
};
|
|
373
|
-
});
|
|
186
|
+
return new AppManager(algod).getBoxNames(BigInt(appId));
|
|
374
187
|
}
|
|
375
188
|
/**
|
|
189
|
+
* @deprecated Use `algorand.app.getBoxValue` instead.
|
|
376
190
|
* Returns the value of the given box name for the given app.
|
|
377
191
|
* @param appId The ID of the app return box names for
|
|
378
192
|
* @param boxName The name of the box to return either as a string, binary array or `BoxName`
|
|
@@ -380,11 +194,10 @@ async function getAppBoxNames(appId, algod) {
|
|
|
380
194
|
* @returns The current box value as a byte array
|
|
381
195
|
*/
|
|
382
196
|
async function getAppBoxValue(appId, boxName, algod) {
|
|
383
|
-
|
|
384
|
-
const boxResult = await algod.getApplicationBoxByName(toNumber(appId), name).do();
|
|
385
|
-
return boxResult.value;
|
|
197
|
+
return new AppManager(algod).getBoxValue(BigInt(appId), typeof boxName !== 'string' && 'name' in boxName ? boxName.nameRaw : boxName);
|
|
386
198
|
}
|
|
387
199
|
/**
|
|
200
|
+
* @deprecated Use `algorand.app.getBoxValues` instead.
|
|
388
201
|
* Returns the value of the given box names for the given app.
|
|
389
202
|
* @param appId The ID of the app return box names for
|
|
390
203
|
* @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`
|
|
@@ -392,74 +205,50 @@ async function getAppBoxValue(appId, boxName, algod) {
|
|
|
392
205
|
* @returns The current box values as a byte array in the same order as the passed in box names
|
|
393
206
|
*/
|
|
394
207
|
async function getAppBoxValues(appId, boxNames, algod) {
|
|
395
|
-
return
|
|
208
|
+
return new AppManager(algod).getBoxValues(BigInt(appId), boxNames.map((b) => (typeof b !== 'string' && 'name' in b ? b.nameRaw : b)));
|
|
396
209
|
}
|
|
397
210
|
/**
|
|
211
|
+
* @deprecated Use `algorand.app.getBoxValueFromABIType` instead.
|
|
398
212
|
* Returns the value of the given box name for the given app decoded based on the given ABI type.
|
|
399
213
|
* @param request The parameters for the box value request
|
|
400
214
|
* @param algod An algod client instance
|
|
401
215
|
* @returns The current box value as an ABI value
|
|
402
216
|
*/
|
|
403
217
|
async function getAppBoxValueFromABIType(request, algod) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
218
|
+
return new AppManager(algod).getBoxValueFromABIType({
|
|
219
|
+
appId: BigInt(request.appId),
|
|
220
|
+
boxName: typeof request.boxName !== 'string' && 'name' in request.boxName ? request.boxName.nameRaw : request.boxName,
|
|
221
|
+
type: request.type,
|
|
222
|
+
});
|
|
407
223
|
}
|
|
408
224
|
/**
|
|
225
|
+
* @deprecated Use `algorand.app.getBoxValuesFromABIType` instead.
|
|
409
226
|
* Returns the value of the given box names for the given app decoded based on the given ABI type.
|
|
410
227
|
* @param request The parameters for the box value request
|
|
411
228
|
* @param algod An algod client instance
|
|
412
229
|
* @returns The current box values as an ABI value in the same order as the passed in box names
|
|
413
230
|
*/
|
|
414
231
|
async function getAppBoxValuesFromABIType(request, algod) {
|
|
415
|
-
|
|
416
|
-
|
|
232
|
+
return new AppManager(algod).getBoxValuesFromABIType({
|
|
233
|
+
appId: BigInt(request.appId),
|
|
234
|
+
boxNames: request.boxNames.map((b) => (typeof b !== 'string' && 'name' in b ? b.nameRaw : b)),
|
|
235
|
+
type: request.type,
|
|
236
|
+
});
|
|
417
237
|
}
|
|
418
238
|
/**
|
|
239
|
+
* @deprecated Use `AppManager.decodeAppState` instead.
|
|
240
|
+
*
|
|
419
241
|
* Converts an array of global/local state values from the algod api to a more friendly
|
|
420
242
|
* generic object keyed by the UTF-8 value of the key.
|
|
421
243
|
* @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`
|
|
422
244
|
* @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values
|
|
423
245
|
*/
|
|
424
246
|
function decodeAppState(state) {
|
|
425
|
-
|
|
426
|
-
// Start with empty set
|
|
427
|
-
for (const stateVal of state) {
|
|
428
|
-
const keyBase64 = stateVal.key;
|
|
429
|
-
const keyRaw = Buffer.from(keyBase64, 'base64');
|
|
430
|
-
const key = keyRaw.toString('utf-8');
|
|
431
|
-
const tealValue = stateVal.value;
|
|
432
|
-
const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type;
|
|
433
|
-
let valueBase64;
|
|
434
|
-
let valueRaw;
|
|
435
|
-
switch (dataTypeFlag) {
|
|
436
|
-
case 1:
|
|
437
|
-
valueBase64 = tealValue.bytes ?? '';
|
|
438
|
-
valueRaw = Buffer.from(valueBase64, 'base64');
|
|
439
|
-
stateValues[key] = {
|
|
440
|
-
keyRaw,
|
|
441
|
-
keyBase64,
|
|
442
|
-
valueRaw: new Uint8Array(valueRaw),
|
|
443
|
-
valueBase64: valueBase64,
|
|
444
|
-
value: valueRaw.toString('utf-8'),
|
|
445
|
-
};
|
|
446
|
-
break;
|
|
447
|
-
case 2: {
|
|
448
|
-
const value = tealValue.uint ?? 0;
|
|
449
|
-
stateValues[key] = {
|
|
450
|
-
keyRaw,
|
|
451
|
-
keyBase64,
|
|
452
|
-
value,
|
|
453
|
-
};
|
|
454
|
-
break;
|
|
455
|
-
}
|
|
456
|
-
default:
|
|
457
|
-
throw new Error(`Received unknown state data type of ${dataTypeFlag}`);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return stateValues;
|
|
247
|
+
return AppManager.decodeAppState(state.map(({ key, value }) => ({ key: Buffer.from(key, 'utf-8'), value })));
|
|
461
248
|
}
|
|
462
249
|
/**
|
|
250
|
+
* @deprecated Use `TransactionComposer` methods to construct transactions instead.
|
|
251
|
+
*
|
|
463
252
|
* Returns the app args ready to load onto an app `Transaction` object
|
|
464
253
|
* @param args The app call args
|
|
465
254
|
* @returns The args ready to load into a `Transaction`
|
|
@@ -478,68 +267,32 @@ function getAppArgsForTransaction(args) {
|
|
|
478
267
|
};
|
|
479
268
|
}
|
|
480
269
|
/**
|
|
270
|
+
* @deprecated Use `TransactionComposer` methods to construct transactions instead.
|
|
271
|
+
*
|
|
481
272
|
* Returns the app args ready to load onto an ABI method call in `AtomicTransactionComposer`
|
|
482
273
|
* @param args The ABI app call args
|
|
483
274
|
* @param from The transaction signer
|
|
484
275
|
* @returns The parameters ready to pass into `addMethodCall` within AtomicTransactionComposer
|
|
485
276
|
*/
|
|
486
277
|
async function getAppArgsForABICall(args, from) {
|
|
487
|
-
|
|
488
|
-
const methodArgs = await Promise.all(('methodArgs' in args ? args.methodArgs : args)?.map(async (a, index) => {
|
|
489
|
-
if (a === undefined) {
|
|
490
|
-
throw new Error(`Argument at position ${index} does not have a value`);
|
|
491
|
-
}
|
|
492
|
-
if (typeof a !== 'object') {
|
|
493
|
-
return a;
|
|
494
|
-
}
|
|
495
|
-
// Handle the various forms of transactions to wrangle them for ATC
|
|
496
|
-
return 'txn' in a
|
|
497
|
-
? a
|
|
498
|
-
: a instanceof Promise
|
|
499
|
-
? { txn: (await a).transaction, signer }
|
|
500
|
-
: 'transaction' in a
|
|
501
|
-
? { txn: a.transaction, signer: 'signer' in a ? getSenderTransactionSigner(a.signer) : signer }
|
|
502
|
-
: 'txID' in a
|
|
503
|
-
? { txn: a, signer }
|
|
504
|
-
: a;
|
|
505
|
-
}));
|
|
506
|
-
return {
|
|
507
|
-
method: 'txnCount' in args.method ? args.method : new ABIMethod(args.method),
|
|
508
|
-
sender: getSenderAddress(from),
|
|
509
|
-
signer: signer,
|
|
510
|
-
boxes: args.boxes?.map(getBoxReference),
|
|
511
|
-
lease: encodeLease(args.lease),
|
|
512
|
-
appForeignApps: args.apps,
|
|
513
|
-
appForeignAssets: args.assets,
|
|
514
|
-
appAccounts: args.accounts?.map(_getAccountAddress),
|
|
515
|
-
methodArgs: methodArgs,
|
|
516
|
-
rekeyTo: args?.rekeyTo ? (typeof args.rekeyTo === 'string' ? args.rekeyTo : getSenderAddress(args.rekeyTo)) : undefined,
|
|
517
|
-
};
|
|
278
|
+
return _getAppArgsForABICall(args, from);
|
|
518
279
|
}
|
|
519
280
|
/**
|
|
281
|
+
* @deprecated Use `AppManager.getBoxReference()` instead.
|
|
282
|
+
*
|
|
520
283
|
* Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.
|
|
521
284
|
* @param box The box to return a reference for
|
|
522
285
|
* @returns The box reference ready to pass into a `Transaction`
|
|
523
286
|
*/
|
|
524
287
|
function getBoxReference(box) {
|
|
525
|
-
|
|
526
|
-
if (typeof box === 'object' && 'appIndex' in box) {
|
|
527
|
-
return box;
|
|
528
|
-
}
|
|
529
|
-
const ref = typeof box === 'object' && 'appId' in box ? box : { appId: 0, name: box };
|
|
530
|
-
return {
|
|
531
|
-
appIndex: ref.appId,
|
|
532
|
-
name: typeof ref.name === 'string'
|
|
533
|
-
? encoder.encode(ref.name)
|
|
534
|
-
: 'length' in ref.name
|
|
535
|
-
? ref.name
|
|
536
|
-
: algosdk.decodeAddress(getSenderAddress(ref.name)).publicKey,
|
|
537
|
-
};
|
|
288
|
+
return _getBoxReference(box);
|
|
538
289
|
}
|
|
539
290
|
function _getAccountAddress(account) {
|
|
540
291
|
return typeof account === 'string' ? account : algosdk.encodeAddress(account.publicKey);
|
|
541
292
|
}
|
|
542
293
|
/**
|
|
294
|
+
* @deprecated Use `algorand.app.getById` instead.
|
|
295
|
+
*
|
|
543
296
|
* Gets the current data for the given app from algod.
|
|
544
297
|
*
|
|
545
298
|
* @param appId The id of the app
|
|
@@ -547,9 +300,11 @@ function _getAccountAddress(account) {
|
|
|
547
300
|
* @returns The data about the app
|
|
548
301
|
*/
|
|
549
302
|
async function getAppById(appId, algod) {
|
|
550
|
-
return
|
|
303
|
+
return await algod.getApplicationByID(toNumber(appId)).do();
|
|
551
304
|
}
|
|
552
305
|
/**
|
|
306
|
+
* @deprecated Use `algorand.app.compileTeal` instead.
|
|
307
|
+
*
|
|
553
308
|
* Compiles the given TEAL using algod and returns the result, including source map.
|
|
554
309
|
*
|
|
555
310
|
* @param algod An algod client
|
|
@@ -557,16 +312,11 @@ async function getAppById(appId, algod) {
|
|
|
557
312
|
* @returns The information about the compiled file
|
|
558
313
|
*/
|
|
559
314
|
async function compileTeal(tealCode, algod) {
|
|
560
|
-
|
|
561
|
-
return {
|
|
562
|
-
teal: tealCode,
|
|
563
|
-
compiled: compiled.result,
|
|
564
|
-
compiledHash: compiled.hash,
|
|
565
|
-
compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),
|
|
566
|
-
sourceMap: new SourceMap(compiled['sourcemap']),
|
|
567
|
-
};
|
|
315
|
+
return await new AppManager(algod).compileTeal(tealCode);
|
|
568
316
|
}
|
|
569
317
|
/**
|
|
318
|
+
* @deprecated Use `abiMethod.getSignature()` or `new ABIMethod(abiMethodParams).getSignature()` instead.
|
|
319
|
+
*
|
|
570
320
|
* Returns the encoded ABI spec for a given ABI Method
|
|
571
321
|
* @param method The method to return a signature for
|
|
572
322
|
* @returns The encoded ABI method spec e.g. `method_name(uint64,string)string`
|