@algorandfoundation/algokit-utils 7.0.0-beta.2 → 7.0.0-beta.21
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 +3 -25
- package/account/account.d.ts +1 -2
- package/account/account.js +6 -4
- package/account/account.js.map +1 -1
- package/account/account.mjs +6 -4
- 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 +0 -1
- package/account/get-account.js.map +1 -1
- package/account/get-account.mjs.map +1 -1
- package/account/get-dispenser-account.d.ts +0 -1
- package/account/get-dispenser-account.js.map +1 -1
- package/account/get-dispenser-account.mjs.map +1 -1
- package/account/index.d.ts +0 -1
- package/account/mnemonic-account.d.ts +0 -1
- package/account/mnemonic-account.js.map +1 -1
- package/account/mnemonic-account.mjs.map +1 -1
- package/amount.d.ts +14 -5
- package/amount.js +6 -0
- package/amount.js.map +1 -1
- package/amount.mjs +6 -0
- package/amount.mjs.map +1 -1
- package/app-client.d.ts +15 -1
- package/app-client.js +15 -0
- package/app-client.js.map +1 -1
- package/app-client.mjs +15 -0
- package/app-client.mjs.map +1 -1
- package/app-deploy.d.ts +0 -1
- package/app-deploy.js +4 -6
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +7 -9
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +10 -11
- package/app.js +15 -11
- package/app.js.map +1 -1
- package/app.mjs +15 -11
- package/app.mjs.map +1 -1
- package/asset.d.ts +3 -4
- package/asset.js +3 -6
- package/asset.js.map +1 -1
- package/asset.mjs +3 -6
- 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 +6 -5
- package/index.js +48 -38
- package/index.js.map +1 -1
- package/index.mjs +6 -5
- package/index.mjs.map +1 -1
- package/indexer-lookup.d.ts +0 -1
- package/indexer-lookup.js.map +1 -1
- package/indexer-lookup.mjs.map +1 -1
- package/localnet/get-kmd-wallet-account.d.ts +0 -1
- package/localnet/get-kmd-wallet-account.js.map +1 -1
- package/localnet/get-kmd-wallet-account.mjs.map +1 -1
- package/localnet/get-localnet-dispenser-account.d.ts +0 -1
- package/localnet/get-localnet-dispenser-account.js.map +1 -1
- package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts +0 -1
- package/localnet/get-or-create-kmd-wallet-account.js.map +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 +0 -1
- package/localnet/is-localnet.js.map +1 -1
- package/localnet/is-localnet.mjs.map +1 -1
- package/network-client.d.ts +0 -1
- package/network-client.js.map +1 -1
- package/network-client.mjs.map +1 -1
- package/package.json +2 -2
- package/testing/_asset.d.ts +0 -1
- package/testing/account.d.ts +0 -1
- package/testing/account.js.map +1 -1
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +0 -1
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
- package/testing/fixtures/algorand-fixture.d.ts +0 -1
- package/testing/fixtures/algorand-fixture.js +1 -1
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +1 -1
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/fixtures/index.d.ts +0 -1
- package/testing/index.d.ts +0 -1
- package/testing/indexer.d.ts +0 -1
- package/testing/indexer.js.map +1 -1
- package/testing/indexer.mjs.map +1 -1
- package/testing/test-logger.d.ts +0 -1
- package/testing/test-logger.js +1 -3
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs +1 -3
- package/testing/test-logger.mjs.map +1 -1
- package/testing/transaction-logger.d.ts +0 -1
- package/testing/transaction-logger.js.map +1 -1
- package/testing/transaction-logger.mjs.map +1 -1
- package/transaction/index.d.ts +0 -1
- package/transaction/legacy-bridge.d.ts +5 -6
- package/transaction/legacy-bridge.js +1 -1
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +4 -4
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts +0 -1
- package/transaction/perform-atomic-transaction-composer-simulate.js +1 -0
- package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.mjs +1 -0
- package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +41 -6
- package/transaction/transaction.js +113 -61
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +113 -62
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/index.d.ts +0 -1
- package/transfer/transfer-algos.d.ts +1 -2
- package/transfer/transfer-algos.js +1 -1
- package/transfer/transfer-algos.js.map +1 -1
- package/transfer/transfer-algos.mjs +1 -1
- package/transfer/transfer-algos.mjs.map +1 -1
- package/transfer/transfer.d.ts +1 -2
- package/transfer/transfer.js +3 -3
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs +3 -3
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +15 -7
- package/types/account-manager.js +27 -11
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +29 -13
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +9 -1
- package/types/account.js.map +1 -1
- package/types/account.mjs.map +1 -1
- package/types/algo-http-client-with-retry.d.ts +0 -1
- package/types/algo-http-client-with-retry.js.map +1 -1
- package/types/algo-http-client-with-retry.mjs.map +1 -1
- package/types/algorand-client-interface.d.ts +28 -0
- package/types/algorand-client-interface.js +3 -0
- package/types/algorand-client-interface.js.map +1 -0
- package/types/algorand-client-interface.mjs +2 -0
- package/types/algorand-client-interface.mjs.map +1 -0
- package/types/algorand-client-transaction-creator.d.ts +33 -34
- package/types/algorand-client-transaction-creator.js +31 -31
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +31 -31
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +31 -32
- package/types/algorand-client-transaction-sender.js +25 -9
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +25 -9
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +13 -13
- package/types/algorand-client.js +10 -10
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +12 -12
- 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 +1494 -8
- package/types/app-client.js +1009 -19
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +1009 -20
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +19 -14
- package/types/app-deployer.js +25 -25
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +27 -27
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +846 -0
- package/types/app-factory.js +409 -0
- package/types/app-factory.js.map +1 -0
- package/types/app-factory.mjs +407 -0
- package/types/app-factory.mjs.map +1 -0
- package/types/app-manager.d.ts +12 -3
- package/types/app-manager.js +13 -15
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +13 -15
- package/types/app-manager.mjs.map +1 -1
- 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 +14 -9
- package/types/app.js.map +1 -1
- package/types/app.mjs.map +1 -1
- package/types/asset-manager.d.ts +7 -7
- package/types/asset-manager.js +5 -6
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +5 -6
- 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 +131 -51
- package/types/client-manager.js +143 -23
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +144 -24
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +110 -37
- package/types/composer.js +139 -26
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +140 -27
- package/types/composer.mjs.map +1 -1
- package/types/config.d.ts +3 -6
- package/types/config.js +5 -44
- package/types/config.js.map +1 -1
- package/types/config.mjs +5 -27
- package/types/config.mjs.map +1 -1
- package/types/debugging.d.ts +29 -101
- package/types/debugging.js +16 -109
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs +12 -107
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.d.ts +1 -2
- package/types/dispenser-client.js +6 -5
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs +6 -5
- package/types/dispenser-client.mjs.map +1 -1
- package/types/expand.d.ts +0 -1
- package/types/indexer.d.ts +0 -1
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs.map +1 -1
- package/types/kmd-account-manager.d.ts +0 -1
- package/types/kmd-account-manager.js +2 -2
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +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 +13 -1
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +3 -4
- package/types/transaction.d.ts +14 -4
- package/types/transfer.d.ts +0 -1
- package/types/urlTokenBaseHTTPClient.d.ts +0 -1
- package/types/urlTokenBaseHTTPClient.js +1 -1
- package/types/urlTokenBaseHTTPClient.js.map +1 -1
- package/types/urlTokenBaseHTTPClient.mjs +1 -1
- package/types/urlTokenBaseHTTPClient.mjs.map +1 -1
- package/util.d.ts +2 -2
- package/util.js +11 -10
- package/util.js.map +1 -1
- package/util.mjs +11 -10
- package/util.mjs.map +1 -1
- package/account/account.d.ts.map +0 -1
- package/account/get-account-config-from-environment.d.ts.map +0 -1
- package/account/get-account.d.ts.map +0 -1
- package/account/get-dispenser-account.d.ts.map +0 -1
- package/account/index.d.ts.map +0 -1
- package/account/mnemonic-account.d.ts.map +0 -1
- package/amount.d.ts.map +0 -1
- package/app-client.d.ts.map +0 -1
- package/app-deploy.d.ts.map +0 -1
- package/app.d.ts.map +0 -1
- package/asset.d.ts.map +0 -1
- package/config.d.ts.map +0 -1
- package/debugging/debugging.d.ts.map +0 -1
- package/debugging/index.d.ts.map +0 -1
- package/debugging/simulate-and-persist-response.d.ts +0 -20
- package/debugging/simulate-and-persist-response.d.ts.map +0 -1
- package/debugging/simulate-and-persist-response.js +0 -108
- package/debugging/simulate-and-persist-response.js.map +0 -1
- package/debugging/simulate-and-persist-response.mjs +0 -89
- package/debugging/simulate-and-persist-response.mjs.map +0 -1
- package/dispenser-client.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/indexer-lookup.d.ts.map +0 -1
- package/localnet/get-kmd-wallet-account.d.ts.map +0 -1
- package/localnet/get-localnet-dispenser-account.d.ts.map +0 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts.map +0 -1
- package/localnet/index.d.ts.map +0 -1
- package/localnet/is-localnet.d.ts.map +0 -1
- package/network-client.d.ts.map +0 -1
- package/testing/_asset.d.ts.map +0 -1
- package/testing/account.d.ts.map +0 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +0 -1
- package/testing/fixtures/algorand-fixture.d.ts.map +0 -1
- package/testing/fixtures/index.d.ts.map +0 -1
- package/testing/index.d.ts.map +0 -1
- package/testing/indexer.d.ts.map +0 -1
- package/testing/test-logger.d.ts.map +0 -1
- package/testing/transaction-logger.d.ts.map +0 -1
- package/transaction/index.d.ts.map +0 -1
- package/transaction/legacy-bridge.d.ts.map +0 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts.map +0 -1
- package/transaction/transaction.d.ts.map +0 -1
- package/transfer/index.d.ts.map +0 -1
- package/transfer/transfer-algos.d.ts.map +0 -1
- package/transfer/transfer.d.ts.map +0 -1
- package/types/account-manager.d.ts.map +0 -1
- package/types/account.d.ts.map +0 -1
- package/types/algo-http-client-with-retry.d.ts.map +0 -1
- package/types/algorand-client-transaction-creator.d.ts.map +0 -1
- package/types/algorand-client-transaction-sender.d.ts.map +0 -1
- package/types/algorand-client.d.ts.map +0 -1
- package/types/amount.d.ts.map +0 -1
- package/types/app-client.d.ts.map +0 -1
- package/types/app-deployer.d.ts.map +0 -1
- package/types/app-manager.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/expand.d.ts.map +0 -1
- package/types/indexer.d.ts.map +0 -1
- package/types/kmd-account-manager.d.ts.map +0 -1
- package/types/logging.d.ts.map +0 -1
- package/types/logic-error.d.ts.map +0 -1
- package/types/network-client.d.ts.map +0 -1
- package/types/testing.d.ts.map +0 -1
- package/types/transaction.d.ts.map +0 -1
- package/types/transfer.d.ts.map +0 -1
- package/types/urlTokenBaseHTTPClient.d.ts.map +0 -1
- package/util.d.ts.map +0 -1
package/types/app-client.js
CHANGED
|
@@ -5,17 +5,20 @@ var buffer = require('buffer');
|
|
|
5
5
|
var app = require('../app.js');
|
|
6
6
|
var appDeploy = require('../app-deploy.js');
|
|
7
7
|
var config = require('../config.js');
|
|
8
|
-
var debugging = require('../debugging/debugging.js');
|
|
9
8
|
var legacyBridge = require('../transaction/legacy-bridge.js');
|
|
10
9
|
var transaction = require('../transaction/transaction.js');
|
|
10
|
+
var util = require('../util.js');
|
|
11
11
|
var types_app = require('./app.js');
|
|
12
|
-
var
|
|
12
|
+
var types_appArc56 = require('./app-arc56.js');
|
|
13
|
+
var types_appSpec = require('./app-spec.js');
|
|
14
|
+
var types_lifecycleEvents = require('./lifecycle-events.js');
|
|
13
15
|
var types_logicError = require('./logic-error.js');
|
|
14
16
|
|
|
15
17
|
var ABIMethod = algosdk.ABIMethod;
|
|
16
18
|
var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
|
|
17
19
|
var getApplicationAddress = algosdk.getApplicationAddress;
|
|
18
20
|
var Indexer = algosdk.Indexer;
|
|
21
|
+
var OnApplicationComplete = algosdk.OnApplicationComplete;
|
|
19
22
|
var SourceMap = algosdk.SourceMap;
|
|
20
23
|
/**
|
|
21
24
|
* Determines deploy time control (UPDATABLE, DELETABLE) value by inspecting application specification
|
|
@@ -39,13 +42,976 @@ function getDeployTimeControl(approval, appSpec, templateVariableName, callConfi
|
|
|
39
42
|
return !!abiCallConfig && abiCallConfig !== 'NEVER';
|
|
40
43
|
});
|
|
41
44
|
}
|
|
42
|
-
|
|
45
|
+
const BYTE_CBLOCK = 38;
|
|
46
|
+
const INT_CBLOCK = 32;
|
|
47
|
+
/**
|
|
48
|
+
* Get the offset of the last constant block at the beginning of the program
|
|
49
|
+
* This value is used to calculate the program counter for an ARC56 program that has a pcOffsetMethod of "cblocks"
|
|
50
|
+
*
|
|
51
|
+
* @param program The program to parse
|
|
52
|
+
* @returns The PC value of the opcode after the last constant block
|
|
53
|
+
*/
|
|
54
|
+
function getConstantBlockOffset(program) {
|
|
55
|
+
const bytes = [...program];
|
|
56
|
+
const programSize = bytes.length;
|
|
57
|
+
bytes.shift(); // remove version
|
|
58
|
+
/** The PC of the opcode after the bytecblock */
|
|
59
|
+
let bytecblockOffset;
|
|
60
|
+
/** The PC of the opcode after the intcblock */
|
|
61
|
+
let intcblockOffset;
|
|
62
|
+
while (bytes.length > 0) {
|
|
63
|
+
/** The current byte from the beginning of the byte array */
|
|
64
|
+
const byte = bytes.shift();
|
|
65
|
+
// If the byte is a constant block...
|
|
66
|
+
if (byte === BYTE_CBLOCK || byte === INT_CBLOCK) {
|
|
67
|
+
const isBytecblock = byte === BYTE_CBLOCK;
|
|
68
|
+
/** The byte following the opcode is the number of values in the constant block */
|
|
69
|
+
const valuesRemaining = bytes.shift();
|
|
70
|
+
// Iterate over all the values in the constant block
|
|
71
|
+
for (let i = 0; i < valuesRemaining; i++) {
|
|
72
|
+
if (isBytecblock) {
|
|
73
|
+
/** The byte following the opcode is the length of the next element */
|
|
74
|
+
const length = bytes.shift();
|
|
75
|
+
bytes.splice(0, length);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// intcblock is a uvarint, so we need to keep reading until we find the end (MSB is not set)
|
|
79
|
+
while ((bytes.shift() & 0x80) !== 0) {
|
|
80
|
+
// Do nothing...
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (isBytecblock)
|
|
85
|
+
bytecblockOffset = programSize - bytes.length - 1;
|
|
86
|
+
else
|
|
87
|
+
intcblockOffset = programSize - bytes.length - 1;
|
|
88
|
+
if (bytes[0] !== BYTE_CBLOCK && bytes[0] !== INT_CBLOCK) {
|
|
89
|
+
// if the next opcode isn't a constant block, we're done
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return Math.max(bytecblockOffset ?? 0, intcblockOffset ?? 0);
|
|
95
|
+
}
|
|
96
|
+
/** ARC-56/ARC-32 application client that allows you to manage calls and
|
|
97
|
+
* state for a specific deployed instance of an app (with a known app ID). */
|
|
98
|
+
class AppClient {
|
|
99
|
+
constructor(params) {
|
|
100
|
+
this._appId = params.appId;
|
|
101
|
+
this._appAddress = algosdk.getApplicationAddress(this._appId);
|
|
102
|
+
this._appSpec = AppClient.normaliseAppSpec(params.appSpec);
|
|
103
|
+
this._appName = params.appName ?? this._appSpec.name;
|
|
104
|
+
this._algorand = params.algorand;
|
|
105
|
+
this._defaultSender = params.defaultSender;
|
|
106
|
+
this._defaultSigner = params.defaultSigner;
|
|
107
|
+
this._approvalSourceMap = params.approvalSourceMap;
|
|
108
|
+
this._clearSourceMap = params.clearSourceMap;
|
|
109
|
+
this._localStateMethods = (address) => this.getStateMethods(() => this.getLocalState(address), () => this._appSpec.state.keys.local, () => this._appSpec.state.maps.local);
|
|
110
|
+
this._globalStateMethods = this.getStateMethods(() => this.getGlobalState(), () => this._appSpec.state.keys.global, () => this._appSpec.state.maps.global);
|
|
111
|
+
this._boxStateMethods = this.getBoxMethods();
|
|
112
|
+
this._paramsMethods = {
|
|
113
|
+
...this.getMethodCallParamsMethods(),
|
|
114
|
+
/** Get parameters to define bare (raw) transactions to the current app */
|
|
115
|
+
bare: this.getBareParamsMethods(),
|
|
116
|
+
};
|
|
117
|
+
this._createTransactionsMethods = {
|
|
118
|
+
...this.getMethodCallCreateTransactionMethods(),
|
|
119
|
+
/** Get transactions for bare (raw) calls to the current app */
|
|
120
|
+
bare: this.getBareCreateTransactionMethods(),
|
|
121
|
+
};
|
|
122
|
+
this._sendMethods = {
|
|
123
|
+
...this.getMethodCallSendMethods(),
|
|
124
|
+
/** Send bare (raw) transactions to the current app */
|
|
125
|
+
bare: this.getBareSendMethods(),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Clone this app client with different params
|
|
130
|
+
*
|
|
131
|
+
* @param params The params to use for the the cloned app client. Omit a param to keep the original value. Set a param to override the original value. Setting to undefined will clear the original value.
|
|
132
|
+
* @returns A new app client with the altered params
|
|
133
|
+
*/
|
|
134
|
+
clone(params) {
|
|
135
|
+
return new AppClient({
|
|
136
|
+
appId: this._appId,
|
|
137
|
+
appSpec: this._appSpec,
|
|
138
|
+
algorand: this._algorand,
|
|
139
|
+
appName: this._appName,
|
|
140
|
+
defaultSender: this._defaultSender,
|
|
141
|
+
defaultSigner: this._defaultSigner,
|
|
142
|
+
approvalSourceMap: this._approvalSourceMap,
|
|
143
|
+
clearSourceMap: this._clearSourceMap,
|
|
144
|
+
...params,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** Start a new `TransactionComposer` transaction group */
|
|
148
|
+
newGroup() {
|
|
149
|
+
return this._algorand.newGroup();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Returns a new `AppClient` client, resolving the app by creator address and name
|
|
153
|
+
* using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
|
|
154
|
+
* @param params The parameters to create the app client
|
|
155
|
+
*/
|
|
156
|
+
static async fromCreatorAndName(params) {
|
|
157
|
+
const appSpec = AppClient.normaliseAppSpec(params.appSpec);
|
|
158
|
+
const appLookup = params.appLookupCache ?? (await params.algorand.appDeployer.getCreatorAppsByName(params.creatorAddress, params.ignoreCache));
|
|
159
|
+
const appMetadata = appLookup.apps[params.appName ?? appSpec.name];
|
|
160
|
+
if (!appMetadata) {
|
|
161
|
+
throw new Error(`App not found for creator ${params.creatorAddress} and name ${params.appName ?? appSpec.name}`);
|
|
162
|
+
}
|
|
163
|
+
return new AppClient({
|
|
164
|
+
...params,
|
|
165
|
+
algorand: params.algorand,
|
|
166
|
+
appId: appMetadata.appId,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Returns an `AppClient` instance for the current network based on
|
|
171
|
+
* pre-determined network-specific app IDs specified in the ARC-56 app spec.
|
|
172
|
+
*
|
|
173
|
+
* If no IDs are in the app spec or the network isn't recognised, an error is thrown.
|
|
174
|
+
* @param params The parameters to create the app client
|
|
175
|
+
*/
|
|
176
|
+
static async fromNetwork(params) {
|
|
177
|
+
const network = await params.algorand.client.network();
|
|
178
|
+
const appSpec = AppClient.normaliseAppSpec(params.appSpec);
|
|
179
|
+
const networkNames = [network.genesisHash];
|
|
180
|
+
if (network.isLocalNet)
|
|
181
|
+
networkNames.push('localnet');
|
|
182
|
+
if (network.isTestNet)
|
|
183
|
+
networkNames.push('testnet');
|
|
184
|
+
if (network.isMainNet)
|
|
185
|
+
networkNames.push('mainnet');
|
|
186
|
+
const availableAppSpecNetworks = Object.keys(appSpec.networks ?? {});
|
|
187
|
+
const networkIndex = availableAppSpecNetworks.findIndex((n) => networkNames.includes(n));
|
|
188
|
+
if (networkIndex === -1) {
|
|
189
|
+
throw new Error(`No app ID found for network ${JSON.stringify(networkNames)} in the app spec`);
|
|
190
|
+
}
|
|
191
|
+
const appId = BigInt(appSpec.networks[networkIndex].appID);
|
|
192
|
+
return new AppClient({ ...params, appId, appSpec });
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Takes a string or parsed JSON object that could be ARC-32 or ARC-56 format and
|
|
196
|
+
* normalises it into a parsed ARC-56 contract object.
|
|
197
|
+
* @param spec The spec to normalise
|
|
198
|
+
* @returns The normalised ARC-56 contract object
|
|
199
|
+
*/
|
|
200
|
+
static normaliseAppSpec(spec) {
|
|
201
|
+
const parsedSpec = typeof spec === 'string' ? JSON.parse(spec) : spec;
|
|
202
|
+
const appSpec = 'hints' in parsedSpec ? types_appSpec.arc32ToArc56(parsedSpec) : parsedSpec;
|
|
203
|
+
return appSpec;
|
|
204
|
+
}
|
|
205
|
+
/** The ID of the app instance this client is linked to. */
|
|
206
|
+
get appId() {
|
|
207
|
+
return this._appId;
|
|
208
|
+
}
|
|
209
|
+
/** The app address of the app instance this client is linked to. */
|
|
210
|
+
get appAddress() {
|
|
211
|
+
return this._appAddress;
|
|
212
|
+
}
|
|
213
|
+
/** The name of the app (from the ARC-32 / ARC-56 app spec). */
|
|
214
|
+
get appName() {
|
|
215
|
+
return this._appName;
|
|
216
|
+
}
|
|
217
|
+
/** The ARC-56 app spec being used */
|
|
218
|
+
get appSpec() {
|
|
219
|
+
return this._appSpec;
|
|
220
|
+
}
|
|
221
|
+
/** A reference to the underlying `AlgorandClient` this app client is using. */
|
|
222
|
+
get algorand() {
|
|
223
|
+
return this._algorand;
|
|
224
|
+
}
|
|
225
|
+
/** Get parameters to create transactions for the current app.
|
|
226
|
+
*
|
|
227
|
+
* A good mental model for this is that these parameters represent a deferred transaction creation.
|
|
228
|
+
* @example Create a transaction in the future using Algorand Client
|
|
229
|
+
* ```typescript
|
|
230
|
+
* const myMethodCall = appClient.params.call({method: 'my_method', args: [123, 'hello']})
|
|
231
|
+
* // ...
|
|
232
|
+
* await algorand.send.AppMethodCall(myMethodCall)
|
|
233
|
+
* ```
|
|
234
|
+
* @example Define a nested transaction as an ABI argument
|
|
235
|
+
* ```typescript
|
|
236
|
+
* const myMethodCall = appClient.params.call({method: 'my_method', args: [123, 'hello']})
|
|
237
|
+
* await appClient.send.call({method: 'my_method2', args: [myMethodCall]})
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
get params() {
|
|
241
|
+
return this._paramsMethods;
|
|
242
|
+
}
|
|
243
|
+
/** Create transactions for the current app */
|
|
244
|
+
get createTransaction() {
|
|
245
|
+
return this._createTransactionsMethods;
|
|
246
|
+
}
|
|
247
|
+
/** Send transactions to the current app */
|
|
248
|
+
get send() {
|
|
249
|
+
return this._sendMethods;
|
|
250
|
+
}
|
|
251
|
+
/** Get state (local, global, box) from the current app */
|
|
252
|
+
get state() {
|
|
253
|
+
return {
|
|
254
|
+
/**
|
|
255
|
+
* Methods to access local state for the current app
|
|
256
|
+
* @param address The address of the account to get the local state for
|
|
257
|
+
*/
|
|
258
|
+
local: this._localStateMethods,
|
|
259
|
+
/**
|
|
260
|
+
* Methods to access global state for the current app
|
|
261
|
+
*/
|
|
262
|
+
global: this._globalStateMethods,
|
|
263
|
+
/**
|
|
264
|
+
* Methods to access box storage for the current app
|
|
265
|
+
*/
|
|
266
|
+
box: this._boxStateMethods,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Funds Algo into the app account for this app.
|
|
271
|
+
*
|
|
272
|
+
* An alias for `appClient.send.fundAppAccount(params)`.
|
|
273
|
+
* @param params The parameters for the funding transaction
|
|
274
|
+
* @returns The result of the funding
|
|
275
|
+
*/
|
|
276
|
+
async fundAppAccount(params) {
|
|
277
|
+
return this.send.fundAppAccount(params);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Returns raw global state for the current app.
|
|
281
|
+
* @returns The global state
|
|
282
|
+
*/
|
|
283
|
+
async getGlobalState() {
|
|
284
|
+
return await this._algorand.app.getGlobalState(this.appId);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Returns raw local state for the given account address.
|
|
288
|
+
* @param address The address of the account to get the local state for
|
|
289
|
+
* @returns The local state
|
|
290
|
+
*/
|
|
291
|
+
async getLocalState(address) {
|
|
292
|
+
return await this._algorand.app.getLocalState(this.appId, address);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Returns the names of all current boxes for the current app.
|
|
296
|
+
* @returns The names of the boxes
|
|
297
|
+
*/
|
|
298
|
+
async getBoxNames() {
|
|
299
|
+
return await this._algorand.app.getBoxNames(this.appId);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Returns the value of the given box for the current app.
|
|
303
|
+
* @param name The identifier of the box to return
|
|
304
|
+
* @returns The current box value as a byte array
|
|
305
|
+
*/
|
|
306
|
+
async getBoxValue(name) {
|
|
307
|
+
return await this._algorand.app.getBoxValue(this.appId, name);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Returns the value of the given box for the current app.
|
|
311
|
+
* @param name The identifier of the box to return
|
|
312
|
+
* @param type
|
|
313
|
+
* @returns The current box value as a byte array
|
|
314
|
+
*/
|
|
315
|
+
async getBoxValueFromABIType(name, type) {
|
|
316
|
+
return await this._algorand.app.getBoxValueFromABIType({
|
|
317
|
+
appId: this.appId,
|
|
318
|
+
boxName: name,
|
|
319
|
+
type,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Returns the values of all current boxes for the current app.
|
|
324
|
+
* Note: This will issue multiple HTTP requests (one per box) and it's not an atomic operation so values may be out of sync.
|
|
325
|
+
* @param filter Optional filter to filter which boxes' values are returned
|
|
326
|
+
* @returns The (name, value) pair of the boxes with values as raw byte arrays
|
|
327
|
+
*/
|
|
328
|
+
async getBoxValues(filter) {
|
|
329
|
+
const names = (await this.getBoxNames()).filter(filter ?? ((_) => true));
|
|
330
|
+
const values = await this._algorand.app.getBoxValues(this.appId, names.map((name) => name.nameRaw));
|
|
331
|
+
return names.map((name, i) => ({ name, value: values[i] }));
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Returns the values of all current boxes for the current app decoded using an ABI Type.
|
|
335
|
+
* Note: This will issue multiple HTTP requests (one per box) and it's not an atomic operation so values may be out of sync.
|
|
336
|
+
* @param type The ABI type to decode the values with
|
|
337
|
+
* @param filter Optional filter to filter which boxes' values are returned
|
|
338
|
+
* @returns The (name, value) pair of the boxes with values as the ABI Value
|
|
339
|
+
*/
|
|
340
|
+
async getBoxValuesFromABIType(type, filter) {
|
|
341
|
+
const names = (await this.getBoxNames()).filter(filter ?? ((_) => true));
|
|
342
|
+
const values = await this._algorand.app.getBoxValuesFromABIType({
|
|
343
|
+
appId: this.appId,
|
|
344
|
+
boxNames: names.map((name) => name.nameRaw),
|
|
345
|
+
type,
|
|
346
|
+
});
|
|
347
|
+
return names.map((name, i) => ({ name, value: values[i] }));
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Takes an error that may include a logic error from a call to the current app and re-exposes the
|
|
351
|
+
* error to include source code information via the source map and ARC-56 spec.
|
|
352
|
+
* @param e The error to parse
|
|
353
|
+
* @param isClearStateProgram Whether or not the code was running the clear state program (defaults to approval program)
|
|
354
|
+
* @returns The new error, or if there was no logic error or source map then the wrapped error with source details
|
|
355
|
+
*/
|
|
356
|
+
async exposeLogicError(e, isClearStateProgram) {
|
|
357
|
+
const pcOffsetMethod = this._appSpec.sourceInfo?.[isClearStateProgram ? 'clear' : 'approval']?.pcOffsetMethod;
|
|
358
|
+
let program;
|
|
359
|
+
if (pcOffsetMethod === 'cblocks') {
|
|
360
|
+
// TODO: Cache this if we deploy the app and it's not updateable
|
|
361
|
+
const appInfo = await this._algorand.app.getById(this.appId);
|
|
362
|
+
program = isClearStateProgram ? appInfo.clearStateProgram : appInfo.approvalProgram;
|
|
363
|
+
}
|
|
364
|
+
return AppClient.exposeLogicError(e, this._appSpec, {
|
|
365
|
+
isClearStateProgram,
|
|
366
|
+
approvalSourceMap: this._approvalSourceMap,
|
|
367
|
+
clearSourceMap: this._clearSourceMap,
|
|
368
|
+
program,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Export the current source maps for the app.
|
|
373
|
+
* @returns The source maps
|
|
374
|
+
*/
|
|
375
|
+
exportSourceMaps() {
|
|
376
|
+
if (!this._approvalSourceMap || !this._clearSourceMap) {
|
|
377
|
+
throw new Error("Unable to export source maps; they haven't been loaded into this client - you need to call create, update, or deploy first");
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
approvalSourceMap: this._approvalSourceMap,
|
|
381
|
+
clearSourceMap: this._clearSourceMap,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Import source maps for the app.
|
|
386
|
+
* @param sourceMaps The source maps to import
|
|
387
|
+
*/
|
|
388
|
+
importSourceMaps(sourceMaps) {
|
|
389
|
+
this._approvalSourceMap = new SourceMap(sourceMaps.approvalSourceMap);
|
|
390
|
+
this._clearSourceMap = new SourceMap(sourceMaps.clearSourceMap);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Returns the ABI Method spec for the given method string for the app represented by this application client instance
|
|
394
|
+
* @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.
|
|
395
|
+
* e.g. `my_method` or `my_method(unit64,string)bytes`
|
|
396
|
+
* @returns A tuple with: [ARC-56 `Method`, algosdk `ABIMethod`]
|
|
397
|
+
*/
|
|
398
|
+
getABIMethod(methodNameOrSignature) {
|
|
399
|
+
return types_appArc56.getArc56Method(methodNameOrSignature, this._appSpec);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Checks for decode errors on the SendAppTransactionResult and maps the return value to the specified type
|
|
403
|
+
* on the ARC-56 method, replacing the `return` property with the decoded type.
|
|
404
|
+
*
|
|
405
|
+
* If the return type is an ARC-56 struct then the struct will be returned.
|
|
406
|
+
*
|
|
407
|
+
* @param result The SendAppTransactionResult to be mapped
|
|
408
|
+
* @param method The method that was called
|
|
409
|
+
* @returns The smart contract response with an updated return value
|
|
410
|
+
*/
|
|
411
|
+
async processMethodCallReturn(result, method) {
|
|
412
|
+
const resultValue = await result;
|
|
413
|
+
return { ...resultValue, return: types_appArc56.getArc56ReturnValue(resultValue.return, method, this._appSpec.structs) };
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Compiles the approval and clear state programs (if TEAL templates provided),
|
|
417
|
+
* performing any provided deploy-time parameter replacement and stores
|
|
418
|
+
* the source maps.
|
|
419
|
+
*
|
|
420
|
+
* If no TEAL templates provided it will use any byte code provided in the app spec.
|
|
421
|
+
*
|
|
422
|
+
* Will store any generated source maps for later use in debugging.
|
|
423
|
+
*/
|
|
424
|
+
async compile(compilation) {
|
|
425
|
+
const result = await AppClient.compile(this._appSpec, this._algorand.app, compilation);
|
|
426
|
+
if (result.compiledApproval) {
|
|
427
|
+
this._approvalSourceMap = result.compiledApproval.sourceMap;
|
|
428
|
+
}
|
|
429
|
+
if (result.compiledClear) {
|
|
430
|
+
this._clearSourceMap = result.compiledClear.sourceMap;
|
|
431
|
+
}
|
|
432
|
+
return result;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Takes an error that may include a logic error from a call to the current app and re-exposes the
|
|
436
|
+
* error to include source code information via the source map and ARC-56 spec.
|
|
437
|
+
* @param e The error to parse
|
|
438
|
+
* @param appSpec The app spec for the app
|
|
439
|
+
* @param details Additional information to inform the error
|
|
440
|
+
* @returns The new error, or if there was no logic error or source map then the wrapped error with source details
|
|
441
|
+
*/
|
|
442
|
+
static exposeLogicError(e, appSpec, details) {
|
|
443
|
+
const { isClearStateProgram, approvalSourceMap, clearSourceMap, program } = details;
|
|
444
|
+
const sourceMap = isClearStateProgram ? clearSourceMap : approvalSourceMap;
|
|
445
|
+
const errorDetails = types_logicError.LogicError.parseLogicError(e);
|
|
446
|
+
// Return the error if we don't have a PC
|
|
447
|
+
if (errorDetails === undefined || errorDetails?.pc === undefined)
|
|
448
|
+
return e;
|
|
449
|
+
/** The PC value to find in the ARC56 SourceInfo */
|
|
450
|
+
let arc56Pc = errorDetails?.pc;
|
|
451
|
+
const programSourceInfo = isClearStateProgram ? appSpec.sourceInfo?.clear : appSpec.sourceInfo?.approval;
|
|
452
|
+
/** The offset to apply to the PC if using the cblocks pc offset method */
|
|
453
|
+
let cblocksOffset = 0;
|
|
454
|
+
// If the program uses cblocks offset, then we need to adjust the PC accordingly
|
|
455
|
+
if (programSourceInfo?.pcOffsetMethod === 'cblocks') {
|
|
456
|
+
if (program === undefined)
|
|
457
|
+
throw new Error('Program bytes are required to calculate the ARC56 cblocks PC offset');
|
|
458
|
+
cblocksOffset = getConstantBlockOffset(program);
|
|
459
|
+
arc56Pc = errorDetails.pc - cblocksOffset;
|
|
460
|
+
}
|
|
461
|
+
// Find the source info for this PC and get the error message
|
|
462
|
+
const sourceInfo = programSourceInfo?.sourceInfo.find((s) => s.pc.includes(arc56Pc));
|
|
463
|
+
const errorMessage = sourceInfo?.errorMessage;
|
|
464
|
+
// If we have the source we can display the TEAL in the error message
|
|
465
|
+
if (appSpec.source) {
|
|
466
|
+
let getLineForPc = (inputPc) => sourceMap?.getLineForPc?.(inputPc);
|
|
467
|
+
// If the SourceMap is not defined, we need to provide our own function for going from a PC to TEAL based on ARC56 SourceInfo[]
|
|
468
|
+
if (sourceMap === undefined) {
|
|
469
|
+
getLineForPc = (inputPc) => {
|
|
470
|
+
const teal = programSourceInfo?.sourceInfo.find((s) => s.pc.includes(inputPc - cblocksOffset))?.teal;
|
|
471
|
+
if (teal === undefined)
|
|
472
|
+
return undefined;
|
|
473
|
+
return teal - 1;
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
e = new types_logicError.LogicError(errorDetails, buffer.Buffer.from(isClearStateProgram ? appSpec.source.clear : appSpec.source.approval, 'base64')
|
|
477
|
+
.toString()
|
|
478
|
+
.split('\n'),
|
|
479
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
480
|
+
getLineForPc);
|
|
481
|
+
}
|
|
482
|
+
if (errorMessage) {
|
|
483
|
+
const appId = JSON.stringify(e).match(/(?<=app=)\d+/)?.[0] || '';
|
|
484
|
+
const txId = JSON.stringify(e).match(/(?<=transaction )\S+(?=:)/)?.[0];
|
|
485
|
+
const error = new Error(`Runtime error when executing ${appSpec.name} (appId: ${appId}) in transaction ${txId}: ${errorMessage}`);
|
|
486
|
+
error.cause = e;
|
|
487
|
+
return error;
|
|
488
|
+
}
|
|
489
|
+
return e;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Compiles the approval and clear state programs (if TEAL templates provided),
|
|
493
|
+
* performing any provided deploy-time parameter replacement and returns
|
|
494
|
+
* the compiled code and any compilation results (including source maps).
|
|
495
|
+
*
|
|
496
|
+
* If no TEAL templates provided it will use any byte code provided in the app spec.
|
|
497
|
+
*
|
|
498
|
+
* Will store any generated source maps for later use in debugging.
|
|
499
|
+
* @param appSpec The app spec for the app
|
|
500
|
+
* @param compilation Any compilation parameters to use
|
|
501
|
+
*/
|
|
502
|
+
static async compile(appSpec, appManager, compilation) {
|
|
503
|
+
const { deployTimeParams, updatable, deletable } = compilation ?? {};
|
|
504
|
+
if (!appSpec.source) {
|
|
505
|
+
if (!appSpec.byteCode?.approval || !appSpec.byteCode?.clear) {
|
|
506
|
+
throw new Error(`Attempt to compile app ${appSpec.name} without source or byteCode`);
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
approvalProgram: buffer.Buffer.from(appSpec.byteCode.approval, 'base64'),
|
|
510
|
+
clearStateProgram: buffer.Buffer.from(appSpec.byteCode.clear, 'base64'),
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
const approvalTemplate = buffer.Buffer.from(appSpec.source.approval, 'base64').toString('utf-8');
|
|
514
|
+
const compiledApproval = await appManager.compileTealTemplate(approvalTemplate, deployTimeParams, {
|
|
515
|
+
updatable,
|
|
516
|
+
deletable,
|
|
517
|
+
});
|
|
518
|
+
const clearTemplate = buffer.Buffer.from(appSpec.source.clear, 'base64').toString('utf-8');
|
|
519
|
+
const compiledClear = await appManager.compileTealTemplate(clearTemplate, deployTimeParams);
|
|
520
|
+
if (config.Config.debug) {
|
|
521
|
+
await config.Config.events.emitAsync(types_lifecycleEvents.EventType.AppCompiled, {
|
|
522
|
+
sources: [
|
|
523
|
+
{ compiledTeal: compiledApproval, appName: appSpec.name, fileName: 'approval' },
|
|
524
|
+
{ compiledTeal: compiledClear, appName: appSpec.name, fileName: 'clear' },
|
|
525
|
+
],
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
return {
|
|
529
|
+
approvalProgram: compiledApproval.compiledBase64ToBytes,
|
|
530
|
+
compiledApproval,
|
|
531
|
+
clearStateProgram: compiledClear.compiledBase64ToBytes,
|
|
532
|
+
compiledClear,
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Returns ABI method arguments ready for a method call params object with default values populated
|
|
537
|
+
* and structs replaced with tuples.
|
|
538
|
+
*
|
|
539
|
+
* It does this by replacing any `undefined` values with the equivalent default value from the given ARC-56 app spec.
|
|
540
|
+
* @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.
|
|
541
|
+
* e.g. `my_method` or `my_method(unit64,string)bytes`
|
|
542
|
+
* @param args The arguments to the method with `undefined` for any that should be populated with a default value
|
|
543
|
+
*/
|
|
544
|
+
async getABIArgsWithDefaultValues(methodNameOrSignature, args, sender) {
|
|
545
|
+
const m = types_appArc56.getArc56Method(methodNameOrSignature, this._appSpec);
|
|
546
|
+
return await Promise.all(args?.map(async (a, i) => {
|
|
547
|
+
const arg = m.args[i];
|
|
548
|
+
if (a !== undefined) {
|
|
549
|
+
// If a struct then convert to tuple for the underlying call
|
|
550
|
+
return arg.struct && typeof a === 'object' && !Array.isArray(a)
|
|
551
|
+
? types_appArc56.getABITupleFromABIStruct(a, this._appSpec.structs[arg.struct], this._appSpec.structs)
|
|
552
|
+
: a;
|
|
553
|
+
}
|
|
554
|
+
const defaultValue = arg.defaultValue;
|
|
555
|
+
if (defaultValue) {
|
|
556
|
+
switch (defaultValue.source) {
|
|
557
|
+
case 'literal':
|
|
558
|
+
return types_appArc56.getABIDecodedValue(buffer.Buffer.from(defaultValue.data, 'base64'), m.method.args[i].defaultValue?.type ?? m.method.args[i].type, this._appSpec.structs);
|
|
559
|
+
case 'method': {
|
|
560
|
+
const method = this.getABIMethod(defaultValue.data);
|
|
561
|
+
const result = await this.send.call({
|
|
562
|
+
method: defaultValue.data,
|
|
563
|
+
args: method.args.map(() => undefined),
|
|
564
|
+
sender,
|
|
565
|
+
});
|
|
566
|
+
if (result.return === undefined) {
|
|
567
|
+
throw new Error('Default value method call did not return a value');
|
|
568
|
+
}
|
|
569
|
+
if (typeof result.return === 'object' && !(result.return instanceof Uint8Array) && !Array.isArray(result.return)) {
|
|
570
|
+
return types_appArc56.getABITupleFromABIStruct(result.return, this._appSpec.structs[method.returns.struct], this._appSpec.structs);
|
|
571
|
+
}
|
|
572
|
+
return result.return;
|
|
573
|
+
}
|
|
574
|
+
case 'local':
|
|
575
|
+
case 'global': {
|
|
576
|
+
const state = defaultValue.source === 'global' ? await this.getGlobalState() : await this.getLocalState(sender);
|
|
577
|
+
const value = Object.values(state).find((s) => s.keyBase64 === defaultValue.data);
|
|
578
|
+
if (!value) {
|
|
579
|
+
throw new Error(`Preparing default value for argument ${arg.name ?? `arg${i + 1}`} resulted in the failure: The key '${defaultValue.data}' could not be found in ${defaultValue.source} storage`);
|
|
580
|
+
}
|
|
581
|
+
return 'valueRaw' in value
|
|
582
|
+
? types_appArc56.getABIDecodedValue(value.valueRaw, m.method.args[i].defaultValue?.type ?? m.method.args[i].type, this._appSpec.structs)
|
|
583
|
+
: value.value;
|
|
584
|
+
}
|
|
585
|
+
case 'box': {
|
|
586
|
+
const value = await this.getBoxValue(buffer.Buffer.from(defaultValue.data, 'base64'));
|
|
587
|
+
return types_appArc56.getABIDecodedValue(value, m.method.args[i].defaultValue?.type ?? m.method.args[i].type, this._appSpec.structs);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (!algosdk.abiTypeIsTransaction(arg.type)) {
|
|
592
|
+
throw new Error(`No value provided for required argument ${arg.name ?? `arg${i + 1}`} in call to method ${m.name}`);
|
|
593
|
+
}
|
|
594
|
+
}) ?? []);
|
|
595
|
+
}
|
|
596
|
+
getBareParamsMethods() {
|
|
597
|
+
return {
|
|
598
|
+
/** Return params for an update call, including deploy-time TEAL template replacements and compilation if provided */
|
|
599
|
+
update: async (params) => {
|
|
600
|
+
return this.getBareParams({
|
|
601
|
+
...params,
|
|
602
|
+
...(await this.compile(params)),
|
|
603
|
+
}, OnApplicationComplete.UpdateApplicationOC);
|
|
604
|
+
},
|
|
605
|
+
/** Return params for an opt-in call */
|
|
606
|
+
optIn: (params) => {
|
|
607
|
+
return this.getBareParams(params, OnApplicationComplete.OptInOC);
|
|
608
|
+
},
|
|
609
|
+
/** Return params for a delete call */
|
|
610
|
+
delete: (params) => {
|
|
611
|
+
return this.getBareParams(params, OnApplicationComplete.DeleteApplicationOC);
|
|
612
|
+
},
|
|
613
|
+
/** Return params for a clear state call */
|
|
614
|
+
clearState: (params) => {
|
|
615
|
+
return this.getBareParams(params, OnApplicationComplete.ClearStateOC);
|
|
616
|
+
},
|
|
617
|
+
/** Return params for a close out call */
|
|
618
|
+
closeOut: (params) => {
|
|
619
|
+
return this.getBareParams(params, OnApplicationComplete.CloseOutOC);
|
|
620
|
+
},
|
|
621
|
+
/** Return params for a call (defaults to no-op) */
|
|
622
|
+
call: (params) => {
|
|
623
|
+
return this.getBareParams(params, params?.onComplete ?? OnApplicationComplete.NoOpOC);
|
|
624
|
+
},
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
getBareCreateTransactionMethods() {
|
|
628
|
+
return {
|
|
629
|
+
/** Returns a transaction for an update call, including deploy-time TEAL template replacements and compilation if provided */
|
|
630
|
+
update: async (params) => {
|
|
631
|
+
return this._algorand.createTransaction.appUpdate(await this.params.bare.update(params));
|
|
632
|
+
},
|
|
633
|
+
/** Returns a transaction for an opt-in call */
|
|
634
|
+
optIn: (params) => {
|
|
635
|
+
return this._algorand.createTransaction.appCall(this.params.bare.optIn(params));
|
|
636
|
+
},
|
|
637
|
+
/** Returns a transaction for a delete call */
|
|
638
|
+
delete: (params) => {
|
|
639
|
+
return this._algorand.createTransaction.appDelete(this.params.bare.delete(params));
|
|
640
|
+
},
|
|
641
|
+
/** Returns a transaction for a clear state call */
|
|
642
|
+
clearState: (params) => {
|
|
643
|
+
return this._algorand.createTransaction.appCall(this.params.bare.clearState(params));
|
|
644
|
+
},
|
|
645
|
+
/** Returns a transaction for a close out call */
|
|
646
|
+
closeOut: (params) => {
|
|
647
|
+
return this._algorand.createTransaction.appCall(this.params.bare.closeOut(params));
|
|
648
|
+
},
|
|
649
|
+
/** Returns a transaction for a call (defaults to no-op) */
|
|
650
|
+
call: (params) => {
|
|
651
|
+
return this._algorand.createTransaction.appCall(this.params.bare.call(params));
|
|
652
|
+
},
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
getBareSendMethods() {
|
|
656
|
+
return {
|
|
657
|
+
/** Signs and sends an update call, including deploy-time TEAL template replacements and compilation if provided */
|
|
658
|
+
update: async (params) => {
|
|
659
|
+
const compiled = await this.compile(params);
|
|
660
|
+
return {
|
|
661
|
+
...(await this.handleCallErrors(async () => this._algorand.send.appUpdate(await this.params.bare.update(params)))),
|
|
662
|
+
...compiled,
|
|
663
|
+
};
|
|
664
|
+
},
|
|
665
|
+
/** Signs and sends an opt-in call */
|
|
666
|
+
optIn: (params) => {
|
|
667
|
+
return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.optIn(params)));
|
|
668
|
+
},
|
|
669
|
+
/** Signs and sends a delete call */
|
|
670
|
+
delete: (params) => {
|
|
671
|
+
return this.handleCallErrors(() => this._algorand.send.appDelete(this.params.bare.delete(params)));
|
|
672
|
+
},
|
|
673
|
+
/** Signs and sends a clear state call */
|
|
674
|
+
clearState: (params) => {
|
|
675
|
+
return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.clearState(params)));
|
|
676
|
+
},
|
|
677
|
+
/** Signs and sends a close out call */
|
|
678
|
+
closeOut: (params) => {
|
|
679
|
+
return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.closeOut(params)));
|
|
680
|
+
},
|
|
681
|
+
/** Signs and sends a call (defaults to no-op) */
|
|
682
|
+
call: (params) => {
|
|
683
|
+
return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.call(params)));
|
|
684
|
+
},
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
getMethodCallParamsMethods() {
|
|
688
|
+
return {
|
|
689
|
+
/** Return params for a payment transaction to fund the app account */
|
|
690
|
+
fundAppAccount: (params) => {
|
|
691
|
+
return {
|
|
692
|
+
...params,
|
|
693
|
+
sender: this.getSender(params.sender),
|
|
694
|
+
signer: this.getSigner(params.sender, params.signer),
|
|
695
|
+
receiver: this.appAddress,
|
|
696
|
+
};
|
|
697
|
+
},
|
|
698
|
+
/** Return params for an update ABI call, including deploy-time TEAL template replacements and compilation if provided */
|
|
699
|
+
update: async (params) => {
|
|
700
|
+
return (await this.getABIParams({
|
|
701
|
+
...params,
|
|
702
|
+
...(await this.compile(params)),
|
|
703
|
+
}, OnApplicationComplete.UpdateApplicationOC));
|
|
704
|
+
},
|
|
705
|
+
/** Return params for an opt-in ABI call */
|
|
706
|
+
optIn: async (params) => {
|
|
707
|
+
return (await this.getABIParams(params, OnApplicationComplete.OptInOC));
|
|
708
|
+
},
|
|
709
|
+
/** Return params for an delete ABI call */
|
|
710
|
+
delete: async (params) => {
|
|
711
|
+
return (await this.getABIParams(params, OnApplicationComplete.DeleteApplicationOC));
|
|
712
|
+
},
|
|
713
|
+
/** Return params for an close out ABI call */
|
|
714
|
+
closeOut: async (params) => {
|
|
715
|
+
return (await this.getABIParams(params, OnApplicationComplete.CloseOutOC));
|
|
716
|
+
},
|
|
717
|
+
/** Return params for an ABI call */
|
|
718
|
+
call: async (params) => {
|
|
719
|
+
return (await this.getABIParams(params, params.onComplete ?? OnApplicationComplete.NoOpOC));
|
|
720
|
+
},
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
getMethodCallSendMethods() {
|
|
724
|
+
return {
|
|
725
|
+
/** Sign and send transactions for a payment transaction to fund the app account */
|
|
726
|
+
fundAppAccount: (params) => {
|
|
727
|
+
return this._algorand.send.payment(this.params.fundAppAccount(params));
|
|
728
|
+
},
|
|
729
|
+
/**
|
|
730
|
+
* Sign and send transactions for an update ABI call, including deploy-time TEAL template replacements and compilation if provided
|
|
731
|
+
*/
|
|
732
|
+
update: async (params) => {
|
|
733
|
+
const compiled = await this.compile(params);
|
|
734
|
+
return {
|
|
735
|
+
...(await this.handleCallErrors(async () => this.processMethodCallReturn(this._algorand.send.appUpdateMethodCall(await this.params.update({ ...params })), types_appArc56.getArc56Method(params.method, this._appSpec)))),
|
|
736
|
+
...compiled,
|
|
737
|
+
};
|
|
738
|
+
},
|
|
739
|
+
/**
|
|
740
|
+
* Sign and send transactions for an opt-in ABI call
|
|
741
|
+
*/
|
|
742
|
+
optIn: (params) => {
|
|
743
|
+
return this.handleCallErrors(async () => this.processMethodCallReturn(this._algorand.send.appCallMethodCall(await this.params.optIn(params)), types_appArc56.getArc56Method(params.method, this._appSpec)));
|
|
744
|
+
},
|
|
745
|
+
/**
|
|
746
|
+
* Sign and send transactions for a delete ABI call
|
|
747
|
+
*/
|
|
748
|
+
delete: (params) => {
|
|
749
|
+
return this.handleCallErrors(async () => this.processMethodCallReturn(this._algorand.send.appDeleteMethodCall(await this.params.delete(params)), types_appArc56.getArc56Method(params.method, this._appSpec)));
|
|
750
|
+
},
|
|
751
|
+
/**
|
|
752
|
+
* Sign and send transactions for a close out ABI call
|
|
753
|
+
*/
|
|
754
|
+
closeOut: (params) => {
|
|
755
|
+
return this.handleCallErrors(async () => this.processMethodCallReturn(this._algorand.send.appCallMethodCall(await this.params.closeOut(params)), types_appArc56.getArc56Method(params.method, this._appSpec)));
|
|
756
|
+
},
|
|
757
|
+
/**
|
|
758
|
+
* Sign and send transactions for a call (defaults to no-op)
|
|
759
|
+
*/
|
|
760
|
+
call: async (params) => {
|
|
761
|
+
// Read-only call - do it via simulate
|
|
762
|
+
if (params.onComplete === OnApplicationComplete.NoOpOC ||
|
|
763
|
+
(!params.onComplete && types_appArc56.getArc56Method(params.method, this._appSpec).method.readonly)) {
|
|
764
|
+
const result = await this._algorand
|
|
765
|
+
.newGroup()
|
|
766
|
+
.addAppCallMethodCall(await this.params.call(params))
|
|
767
|
+
.simulate({
|
|
768
|
+
allowUnnamedResources: params.populateAppCallResources ?? true,
|
|
769
|
+
// Simulate calls for a readonly method shouldn't invoke signing
|
|
770
|
+
skipSignatures: true,
|
|
771
|
+
});
|
|
772
|
+
return this.processMethodCallReturn({
|
|
773
|
+
...result,
|
|
774
|
+
transaction: result.transactions.at(-1),
|
|
775
|
+
confirmation: result.confirmations.at(-1),
|
|
776
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
|
|
777
|
+
return: (result.returns?.length ?? 0 > 0) ? result.returns?.at(-1) : undefined,
|
|
778
|
+
}, types_appArc56.getArc56Method(params.method, this._appSpec));
|
|
779
|
+
}
|
|
780
|
+
return this.handleCallErrors(async () => this.processMethodCallReturn(this._algorand.send.appCallMethodCall(await this.params.call(params)), types_appArc56.getArc56Method(params.method, this._appSpec)));
|
|
781
|
+
},
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
getMethodCallCreateTransactionMethods() {
|
|
785
|
+
return {
|
|
786
|
+
/** Return transaction for a payment transaction to fund the app account */
|
|
787
|
+
fundAppAccount: (params) => {
|
|
788
|
+
return this._algorand.createTransaction.payment(this.params.fundAppAccount(params));
|
|
789
|
+
},
|
|
790
|
+
/**
|
|
791
|
+
* Return transactions for an update ABI call, including deploy-time TEAL template replacements and compilation if provided
|
|
792
|
+
*/
|
|
793
|
+
update: async (params) => {
|
|
794
|
+
return this._algorand.createTransaction.appUpdateMethodCall(await this.params.update(params));
|
|
795
|
+
},
|
|
796
|
+
/**
|
|
797
|
+
* Return transactions for an opt-in ABI call
|
|
798
|
+
*/
|
|
799
|
+
optIn: async (params) => {
|
|
800
|
+
return this._algorand.createTransaction.appCallMethodCall(await this.params.optIn(params));
|
|
801
|
+
},
|
|
802
|
+
/**
|
|
803
|
+
* Return transactions for a delete ABI call
|
|
804
|
+
*/
|
|
805
|
+
delete: async (params) => {
|
|
806
|
+
return this._algorand.createTransaction.appDeleteMethodCall(await this.params.delete(params));
|
|
807
|
+
},
|
|
808
|
+
/**
|
|
809
|
+
* Return transactions for a close out ABI call
|
|
810
|
+
*/
|
|
811
|
+
closeOut: async (params) => {
|
|
812
|
+
return this._algorand.createTransaction.appCallMethodCall(await this.params.closeOut(params));
|
|
813
|
+
},
|
|
814
|
+
/**
|
|
815
|
+
* Return transactions for an ABI call (defaults to no-op)
|
|
816
|
+
*/
|
|
817
|
+
call: async (params) => {
|
|
818
|
+
return this._algorand.createTransaction.appCallMethodCall(await this.params.call(params));
|
|
819
|
+
},
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
/** Returns the sender for a call, using the provided sender or using the `defaultSender`
|
|
823
|
+
* if none provided and throws an error if neither provided */
|
|
824
|
+
getSender(sender) {
|
|
825
|
+
if (!sender && !this._defaultSender) {
|
|
826
|
+
throw new Error(`No sender provided and no default sender present in app client for call to app ${this._appName}`);
|
|
827
|
+
}
|
|
828
|
+
return sender ?? this._defaultSender;
|
|
829
|
+
}
|
|
830
|
+
/** Returns the signer for a call, using the provided signer or the `defaultSigner`
|
|
831
|
+
* if no signer was provided and the call will use default sender
|
|
832
|
+
* or `undefined` otherwise (so the signer is resolved from `AlgorandClient`) */
|
|
833
|
+
getSigner(sender, signer) {
|
|
834
|
+
return signer ?? (!sender ? this._defaultSigner : undefined);
|
|
835
|
+
}
|
|
836
|
+
getBareParams(params, onComplete) {
|
|
837
|
+
return {
|
|
838
|
+
...params,
|
|
839
|
+
appId: this._appId,
|
|
840
|
+
sender: this.getSender(params?.sender),
|
|
841
|
+
signer: this.getSigner(params?.sender, params?.signer),
|
|
842
|
+
onComplete,
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
async getABIParams(params, onComplete) {
|
|
846
|
+
const sender = this.getSender(params.sender);
|
|
847
|
+
const method = types_appArc56.getArc56Method(params.method, this._appSpec);
|
|
848
|
+
const args = await this.getABIArgsWithDefaultValues(params.method, params.args, sender);
|
|
849
|
+
return {
|
|
850
|
+
...params,
|
|
851
|
+
appId: this._appId,
|
|
852
|
+
sender: sender,
|
|
853
|
+
signer: this.getSigner(params.sender, params.signer),
|
|
854
|
+
method,
|
|
855
|
+
onComplete,
|
|
856
|
+
args,
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
/** Make the given call and catch any errors, augmenting with debugging information before re-throwing. */
|
|
860
|
+
async handleCallErrors(call) {
|
|
861
|
+
try {
|
|
862
|
+
return await call();
|
|
863
|
+
}
|
|
864
|
+
catch (e) {
|
|
865
|
+
throw await this.exposeLogicError(e);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
getBoxMethods() {
|
|
869
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
870
|
+
const that = this;
|
|
871
|
+
const stateMethods = {
|
|
872
|
+
/**
|
|
873
|
+
* Returns all single-key state values in a record keyed by the key name and the value a decoded ABI value.
|
|
874
|
+
*/
|
|
875
|
+
getAll: async () => {
|
|
876
|
+
return Object.fromEntries(await Promise.all(Object.keys(that._appSpec.state.keys.box).map(async (key) => [key, await stateMethods.getValue(key)])));
|
|
877
|
+
},
|
|
878
|
+
/**
|
|
879
|
+
* Returns a single state value for the current app with the value a decoded ABI value.
|
|
880
|
+
* @param name The name of the state value to retrieve the value for
|
|
881
|
+
* @returns
|
|
882
|
+
*/
|
|
883
|
+
getValue: async (name) => {
|
|
884
|
+
const metadata = that._appSpec.state.keys.box[name];
|
|
885
|
+
const value = await that.getBoxValue(buffer.Buffer.from(metadata.key, 'base64'));
|
|
886
|
+
return types_appArc56.getABIDecodedValue(value, metadata.valueType, that._appSpec.structs);
|
|
887
|
+
},
|
|
888
|
+
/**
|
|
889
|
+
*
|
|
890
|
+
* @param mapName The name of the map to read from
|
|
891
|
+
* @param key The key within the map (without any map prefix) as either a Buffer with the bytes or a value
|
|
892
|
+
* that will be converted to bytes by encoding it using the specified ABI key type
|
|
893
|
+
* in the ARC-56 spec
|
|
894
|
+
*/
|
|
895
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
896
|
+
getMapValue: async (mapName, key) => {
|
|
897
|
+
const metadata = that._appSpec.state.maps.box[mapName];
|
|
898
|
+
const prefix = buffer.Buffer.from(metadata.prefix ?? '', 'base64');
|
|
899
|
+
const encodedKey = buffer.Buffer.concat([prefix, types_appArc56.getABIEncodedValue(key, metadata.keyType, that._appSpec.structs)]);
|
|
900
|
+
const base64Key = buffer.Buffer.from(encodedKey).toString('base64');
|
|
901
|
+
const value = await that.getBoxValue(buffer.Buffer.from(base64Key, 'base64'));
|
|
902
|
+
return types_appArc56.getABIDecodedValue(value, metadata.valueType, that._appSpec.structs);
|
|
903
|
+
},
|
|
904
|
+
/**
|
|
905
|
+
*
|
|
906
|
+
* @param mapName The name of the map to read from
|
|
907
|
+
* @param key The key within the map as either a Buffer with the bytes or a value
|
|
908
|
+
* that will be converted to bytes by encoding it using the specified ABI key type
|
|
909
|
+
* in the ARC-56 spec
|
|
910
|
+
* @param appState
|
|
911
|
+
*/
|
|
912
|
+
getMap: async (mapName) => {
|
|
913
|
+
const metadata = that._appSpec.state.maps.box[mapName];
|
|
914
|
+
const prefix = buffer.Buffer.from(metadata.prefix ?? '', 'base64');
|
|
915
|
+
const boxNames = await that.getBoxNames();
|
|
916
|
+
return new Map(await Promise.all(boxNames
|
|
917
|
+
.filter((b) => util.binaryStartsWith(b.nameRaw, prefix))
|
|
918
|
+
.map(async (b) => {
|
|
919
|
+
const encodedKey = buffer.Buffer.concat([prefix, b.nameRaw]);
|
|
920
|
+
const base64Key = buffer.Buffer.from(encodedKey).toString('base64');
|
|
921
|
+
return [
|
|
922
|
+
types_appArc56.getABIDecodedValue(b.nameRaw.slice(prefix.length), metadata.keyType, that._appSpec.structs),
|
|
923
|
+
types_appArc56.getABIDecodedValue(await that.getBoxValue(buffer.Buffer.from(base64Key, 'base64')), metadata.valueType, that._appSpec.structs),
|
|
924
|
+
];
|
|
925
|
+
})));
|
|
926
|
+
},
|
|
927
|
+
};
|
|
928
|
+
return stateMethods;
|
|
929
|
+
}
|
|
930
|
+
getStateMethods(stateGetter, keyGetter, mapGetter) {
|
|
931
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
932
|
+
const that = this;
|
|
933
|
+
const stateMethods = {
|
|
934
|
+
/**
|
|
935
|
+
* Returns all single-key state values in a record keyed by the key name and the value a decoded ABI value.
|
|
936
|
+
*/
|
|
937
|
+
getAll: async () => {
|
|
938
|
+
const appState = await stateGetter();
|
|
939
|
+
return Object.fromEntries(await Promise.all(Object.keys(keyGetter()).map(async (key) => [key, await stateMethods.getValue(key, appState)])));
|
|
940
|
+
},
|
|
941
|
+
/**
|
|
942
|
+
* Returns a single state value for the current app with the value a decoded ABI value.
|
|
943
|
+
* @param name The name of the state value to retrieve the value for
|
|
944
|
+
* @param appState Optional cached value of the current state
|
|
945
|
+
* @returns
|
|
946
|
+
*/
|
|
947
|
+
getValue: async (name, appState) => {
|
|
948
|
+
const state = Object.values(appState ?? (await stateGetter()));
|
|
949
|
+
const metadata = keyGetter()[name];
|
|
950
|
+
const value = state.find((s) => s.keyBase64 === metadata.key);
|
|
951
|
+
if (value && 'valueRaw' in value) {
|
|
952
|
+
return types_appArc56.getABIDecodedValue(value.valueRaw, metadata.valueType, that._appSpec.structs);
|
|
953
|
+
}
|
|
954
|
+
return value?.value;
|
|
955
|
+
},
|
|
956
|
+
/**
|
|
957
|
+
* Returns a single value from the given map for the current app with the value a decoded ABI value.
|
|
958
|
+
* @param mapName The name of the map to read from
|
|
959
|
+
* @param key The key within the map (without any map prefix) as either a Buffer with the bytes or a value
|
|
960
|
+
* that will be converted to bytes by encoding it using the specified ABI key type
|
|
961
|
+
* in the ARC-56 spec
|
|
962
|
+
* @param appState Optional cached value of the current state
|
|
963
|
+
*/
|
|
964
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
965
|
+
getMapValue: async (mapName, key, appState) => {
|
|
966
|
+
const state = Object.values(appState ?? (await stateGetter()));
|
|
967
|
+
const metadata = mapGetter()[mapName];
|
|
968
|
+
const prefix = buffer.Buffer.from(metadata.prefix ?? '', 'base64');
|
|
969
|
+
const encodedKey = buffer.Buffer.concat([prefix, types_appArc56.getABIEncodedValue(key, metadata.keyType, that._appSpec.structs)]);
|
|
970
|
+
const base64Key = buffer.Buffer.from(encodedKey).toString('base64');
|
|
971
|
+
const value = state.find((s) => s.keyBase64 === base64Key);
|
|
972
|
+
if (value && 'valueRaw' in value) {
|
|
973
|
+
return types_appArc56.getABIDecodedValue(value.valueRaw, metadata.valueType, that._appSpec.structs);
|
|
974
|
+
}
|
|
975
|
+
return value?.value;
|
|
976
|
+
},
|
|
977
|
+
/**
|
|
978
|
+
* Returns all map values for the given map.
|
|
979
|
+
* @param mapName The name of the map to read from
|
|
980
|
+
* @param appState Optional cached value of the current state
|
|
981
|
+
* @returns A map of all key-value pairs in the map as a `Record<string, ABIValue>`
|
|
982
|
+
*/
|
|
983
|
+
getMap: async (mapName) => {
|
|
984
|
+
const state = Object.values(await stateGetter());
|
|
985
|
+
const metadata = mapGetter()[mapName];
|
|
986
|
+
const prefix = buffer.Buffer.from(metadata.prefix ?? '', 'base64');
|
|
987
|
+
return new Map(state
|
|
988
|
+
.filter((s) => util.binaryStartsWith(s.keyRaw, prefix))
|
|
989
|
+
.map((s) => {
|
|
990
|
+
const key = s.keyRaw.slice(prefix.length);
|
|
991
|
+
return [
|
|
992
|
+
types_appArc56.getABIDecodedValue(key, metadata.keyType, this._appSpec.structs),
|
|
993
|
+
types_appArc56.getABIDecodedValue('valueRaw' in s ? s.valueRaw : s.value, metadata.valueType, this._appSpec.structs),
|
|
994
|
+
];
|
|
995
|
+
}));
|
|
996
|
+
},
|
|
997
|
+
};
|
|
998
|
+
return stateMethods;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* @deprecated Use `AppClient` instead e.g. via `algorand.client.getAppClientById` or
|
|
1003
|
+
* `algorand.client.getAppClientByCreatorAndName`.
|
|
1004
|
+
* If you want to `create` or `deploy` then use `AppFactory` e.g. via `algorand.client.getAppFactory`,
|
|
1005
|
+
* which will in turn give you an `AppClient` instance against the created/deployed app to make other calls.
|
|
1006
|
+
*
|
|
1007
|
+
* Application client - a class that wraps an ARC-0032 app spec and provides high productivity methods to deploy and call the app */
|
|
43
1008
|
class ApplicationClient {
|
|
44
|
-
// todo: process ABI args as needed to make them nicer to deal with like beaker-ts
|
|
45
|
-
// todo: support readonly, noop method calls
|
|
46
|
-
// todo: find create, update, delete, etc. methods from app spec and call them by default
|
|
47
|
-
// todo: intelligent version management when deploying
|
|
48
1009
|
/**
|
|
1010
|
+
* @deprecated Use `AppClient` instead e.g. via `algorand.client.getAppClientById` or
|
|
1011
|
+
* `algorand.client.getAppClientByCreatorAndName`.
|
|
1012
|
+
* If you want to `create` or `deploy` then use `AppFactory` e.g. via `algorand.client.getAppFactory`,
|
|
1013
|
+
* which will in turn give you an `AppClient` instance against the created/deployed app to make other calls.
|
|
1014
|
+
*
|
|
49
1015
|
* Create a new ApplicationClient instance
|
|
50
1016
|
* @param appDetails The details of the app
|
|
51
1017
|
* @param algod An algod instance
|
|
@@ -80,9 +1046,11 @@ class ApplicationClient {
|
|
|
80
1046
|
this.params = params;
|
|
81
1047
|
}
|
|
82
1048
|
/**
|
|
83
|
-
*
|
|
1049
|
+
* @deprecated Use `AppClient.compile()` instead.
|
|
1050
|
+
*
|
|
1051
|
+
* Compiles the approval and clear state programs and sets up the source map.
|
|
84
1052
|
* @param compilation The deploy-time parameters for the compilation
|
|
85
|
-
* @returns The compiled approval and clear programs
|
|
1053
|
+
* @returns The compiled approval and clear state programs
|
|
86
1054
|
*/
|
|
87
1055
|
async compile(compilation) {
|
|
88
1056
|
const { deployTimeParams, updatable, deletable } = compilation ?? {};
|
|
@@ -97,15 +1065,12 @@ class ApplicationClient {
|
|
|
97
1065
|
const clear = appDeploy.performTemplateSubstitution(clearTemplate, deployTimeParams ?? this.deployTimeParams);
|
|
98
1066
|
const clearCompiled = await app.compileTeal(clear, this.algod);
|
|
99
1067
|
this._clearSourceMap = clearCompiled?.sourceMap;
|
|
100
|
-
if (config.Config.debug
|
|
101
|
-
|
|
1068
|
+
if (config.Config.debug) {
|
|
1069
|
+
await config.Config.events.emitAsync(types_lifecycleEvents.EventType.AppCompiled, {
|
|
102
1070
|
sources: [
|
|
103
|
-
|
|
104
|
-
|
|
1071
|
+
{ compiledTeal: approvalCompiled, appName: this._appName, fileName: 'approval' },
|
|
1072
|
+
{ compiledTeal: clearCompiled, appName: this._appName, fileName: 'clear' },
|
|
105
1073
|
],
|
|
106
|
-
projectRoot: config.Config.projectRoot,
|
|
107
|
-
client: this.algod,
|
|
108
|
-
withSources: true,
|
|
109
1074
|
});
|
|
110
1075
|
}
|
|
111
1076
|
return { approvalCompiled, clearCompiled };
|
|
@@ -132,6 +1097,8 @@ class ApplicationClient {
|
|
|
132
1097
|
this._clearSourceMap = new SourceMap(sourceMaps.clearSourceMap);
|
|
133
1098
|
}
|
|
134
1099
|
/**
|
|
1100
|
+
* @deprecated Use `deploy` from an `AppFactory` instance instead.
|
|
1101
|
+
*
|
|
135
1102
|
* Idempotently deploy (create, update/delete if changed) an app against the given name via the given creator account, including deploy-time template placeholder substitutions.
|
|
136
1103
|
*
|
|
137
1104
|
* To understand the architecture decisions behind this functionality please see https://github.com/algorandfoundation/algokit-cli/blob/main/docs/architecture-decisions/2023-01-12_smart-contract-deployment.md
|
|
@@ -217,6 +1184,8 @@ class ApplicationClient {
|
|
|
217
1184
|
}
|
|
218
1185
|
}
|
|
219
1186
|
/**
|
|
1187
|
+
* @deprecated Use `create` from an `AppFactory` instance instead.
|
|
1188
|
+
*
|
|
220
1189
|
* Creates a smart contract app, returns the details of the created app.
|
|
221
1190
|
* @param create The parameters to create the app with
|
|
222
1191
|
* @returns The details of the created app, or the transaction to create it if `skipSending` and the compilation result
|
|
@@ -257,10 +1226,12 @@ class ApplicationClient {
|
|
|
257
1226
|
return { ...result, ...{ compiledApproval: approvalCompiled, compiledClear: clearCompiled } };
|
|
258
1227
|
}
|
|
259
1228
|
catch (e) {
|
|
260
|
-
throw this.exposeLogicError(e);
|
|
1229
|
+
throw await this.exposeLogicError(e);
|
|
261
1230
|
}
|
|
262
1231
|
}
|
|
263
1232
|
/**
|
|
1233
|
+
* @deprecated Use `appClient.send.update` or `appClient.createTransaction.update` from an `AppClient` instance instead.
|
|
1234
|
+
*
|
|
264
1235
|
* Updates the smart contract app.
|
|
265
1236
|
* @param update The parameters to update the app with
|
|
266
1237
|
* @returns The transaction send result and the compilation result
|
|
@@ -289,10 +1260,12 @@ class ApplicationClient {
|
|
|
289
1260
|
return { ...result, ...{ compiledApproval: approvalCompiled, compiledClear: clearCompiled } };
|
|
290
1261
|
}
|
|
291
1262
|
catch (e) {
|
|
292
|
-
throw this.exposeLogicError(e);
|
|
1263
|
+
throw await this.exposeLogicError(e);
|
|
293
1264
|
}
|
|
294
1265
|
}
|
|
295
1266
|
/**
|
|
1267
|
+
* @deprecated Use `appClient.send.call` or `appClient.createTransaction.call` from an `AppClient` instance instead.
|
|
1268
|
+
*
|
|
296
1269
|
* Issues a no_op (normal) call to the app.
|
|
297
1270
|
* @param call The call details.
|
|
298
1271
|
* @returns The result of the call
|
|
@@ -326,6 +1299,8 @@ class ApplicationClient {
|
|
|
326
1299
|
return await this.callOfType(call, 'no_op');
|
|
327
1300
|
}
|
|
328
1301
|
/**
|
|
1302
|
+
* @deprecated Use `appClient.send.optIn` or `appClient.createTransaction.optIn` from an `AppClient` instance instead.
|
|
1303
|
+
*
|
|
329
1304
|
* Issues a opt_in call to the app.
|
|
330
1305
|
* @param call The call details.
|
|
331
1306
|
* @returns The result of the call
|
|
@@ -334,6 +1309,8 @@ class ApplicationClient {
|
|
|
334
1309
|
return await this.callOfType(call, 'opt_in');
|
|
335
1310
|
}
|
|
336
1311
|
/**
|
|
1312
|
+
* @deprecated Use `appClient.send.closeOut` or `appClient.createTransaction.closeOut` from an `AppClient` instance instead.
|
|
1313
|
+
*
|
|
337
1314
|
* Issues a close_out call to the app.
|
|
338
1315
|
* @param call The call details.
|
|
339
1316
|
* @returns The result of the call
|
|
@@ -342,6 +1319,8 @@ class ApplicationClient {
|
|
|
342
1319
|
return await this.callOfType(call, 'close_out');
|
|
343
1320
|
}
|
|
344
1321
|
/**
|
|
1322
|
+
* @deprecated Use `appClient.send.clearState` or `appClient.createTransaction.clearState` from an `AppClient` instance instead.
|
|
1323
|
+
*
|
|
345
1324
|
* Issues a clear_state call to the app.
|
|
346
1325
|
* @param call The call details.
|
|
347
1326
|
* @returns The result of the call
|
|
@@ -350,6 +1329,8 @@ class ApplicationClient {
|
|
|
350
1329
|
return await this.callOfType(call, 'clear_state');
|
|
351
1330
|
}
|
|
352
1331
|
/**
|
|
1332
|
+
* @deprecated Use `appClient.send.delete` or `appClient.createTransaction.delete` from an `AppClient` instance instead.
|
|
1333
|
+
*
|
|
353
1334
|
* Issues a delete_application call to the app.
|
|
354
1335
|
* @param call The call details.
|
|
355
1336
|
* @returns The result of the call
|
|
@@ -358,6 +1339,8 @@ class ApplicationClient {
|
|
|
358
1339
|
return await this.callOfType(call, 'delete_application');
|
|
359
1340
|
}
|
|
360
1341
|
/**
|
|
1342
|
+
* @deprecated Use `appClient.send.call` or `appClient.createTransaction.call` from an `AppClient` instance instead.
|
|
1343
|
+
*
|
|
361
1344
|
* Issues a call to the app with the given call type.
|
|
362
1345
|
* @param call The call details.
|
|
363
1346
|
* @param callType The call type
|
|
@@ -500,6 +1483,8 @@ class ApplicationClient {
|
|
|
500
1483
|
})));
|
|
501
1484
|
}
|
|
502
1485
|
/**
|
|
1486
|
+
* @deprecated Use `appClient.params.*` from an `AppClient` instance instead.
|
|
1487
|
+
*
|
|
503
1488
|
* Returns the arguments for an app call for the given ABI method or raw method specification.
|
|
504
1489
|
* @param args The call args specific to this application client
|
|
505
1490
|
* @param sender The sender of this call. Will be used to fetch any default argument values if applicable
|
|
@@ -557,6 +1542,8 @@ class ApplicationClient {
|
|
|
557
1542
|
}
|
|
558
1543
|
}
|
|
559
1544
|
/**
|
|
1545
|
+
* @deprecated Use `appClient.getABIMethod` instead.
|
|
1546
|
+
*
|
|
560
1547
|
* Returns the ABI Method parameters for the given method name string for the app represented by this application client instance
|
|
561
1548
|
* @param method Either the name of the method or the ABI method spec definition string
|
|
562
1549
|
* @returns The ABI method params for the given method
|
|
@@ -583,6 +1570,8 @@ class ApplicationClient {
|
|
|
583
1570
|
return methodParams ? new ABIMethod(methodParams) : undefined;
|
|
584
1571
|
}
|
|
585
1572
|
/**
|
|
1573
|
+
* @deprecated Use `appClient.appId` and `appClient.appAddress` from an `AppClient` instance instead.
|
|
1574
|
+
*
|
|
586
1575
|
* Gets the reference information for the current application instance.
|
|
587
1576
|
* `appId` will be 0 if it can't find an app.
|
|
588
1577
|
* @returns The app reference, or if deployed using the `deploy` method, the app metadata too
|
|
@@ -624,7 +1613,7 @@ class ApplicationClient {
|
|
|
624
1613
|
.toString()
|
|
625
1614
|
.split('\n'),
|
|
626
1615
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
627
|
-
isClear ? this._clearSourceMap : this._approvalSourceMap);
|
|
1616
|
+
(pc) => (isClear ? this._clearSourceMap : this._approvalSourceMap).getLineForPc(pc));
|
|
628
1617
|
else
|
|
629
1618
|
return e;
|
|
630
1619
|
}
|
|
@@ -633,5 +1622,6 @@ class ApplicationClient {
|
|
|
633
1622
|
}
|
|
634
1623
|
}
|
|
635
1624
|
|
|
1625
|
+
exports.AppClient = AppClient;
|
|
636
1626
|
exports.ApplicationClient = ApplicationClient;
|
|
637
1627
|
//# sourceMappingURL=app-client.js.map
|