@algorandfoundation/algokit-utils 7.0.0-beta.3 → 7.0.0-beta.5
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/amount.d.ts +14 -4
- package/amount.d.ts.map +1 -1
- 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 -0
- package/app-client.d.ts.map +1 -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.map +1 -1
- package/app-deploy.js +4 -6
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +5 -7
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +2 -2
- package/app.d.ts.map +1 -1
- package/app.js +7 -3
- package/app.js.map +1 -1
- package/app.mjs +7 -3
- package/app.mjs.map +1 -1
- package/asset.d.ts.map +1 -1
- package/asset.js +0 -3
- package/asset.js.map +1 -1
- package/asset.mjs +0 -3
- package/asset.mjs.map +1 -1
- package/debugging/debugging.d.ts +1 -1
- package/debugging/debugging.d.ts.map +1 -1
- package/debugging/debugging.js +4 -5
- package/debugging/debugging.js.map +1 -1
- package/debugging/debugging.mjs +4 -5
- package/debugging/debugging.mjs.map +1 -1
- package/index.d.ts +4 -4
- package/index.d.ts.map +1 -1
- package/index.js +37 -37
- package/index.mjs +5 -5
- package/package.json +1 -1
- package/testing/test-logger.d.ts.map +1 -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/transaction/legacy-bridge.d.ts +3 -3
- package/transaction/legacy-bridge.d.ts.map +1 -1
- package/transaction/legacy-bridge.js +1 -1
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +2 -2
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/transaction.d.ts +34 -3
- package/transaction/transaction.d.ts.map +1 -1
- package/transaction/transaction.js +42 -11
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +42 -11
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/transfer.js +2 -2
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs +2 -2
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +2 -2
- package/types/account-manager.d.ts.map +1 -1
- package/types/account-manager.js +1 -1
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +1 -1
- package/types/account-manager.mjs.map +1 -1
- package/types/algorand-client-interface.d.ts +29 -0
- package/types/algorand-client-interface.d.ts.map +1 -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-sender.d.ts +12 -12
- package/types/algorand-client-transaction-sender.d.ts.map +1 -1
- package/types/algorand-client-transaction-sender.js +22 -6
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +22 -6
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +2 -1
- package/types/algorand-client.d.ts.map +1 -1
- package/types/algorand-client.js +1 -1
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +1 -1
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.d.ts +10 -10
- package/types/amount.d.ts.map +1 -1
- 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 +326 -0
- package/types/app-arc56.d.ts.map +1 -0
- package/types/app-arc56.js +163 -0
- package/types/app-arc56.js.map +1 -0
- package/types/app-arc56.mjs +154 -0
- package/types/app-arc56.mjs.map +1 -0
- package/types/app-client.d.ts +1479 -7
- package/types/app-client.d.ts.map +1 -1
- package/types/app-client.js +814 -8
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +814 -9
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +19 -13
- package/types/app-deployer.d.ts.map +1 -1
- package/types/app-deployer.js +2 -2
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +2 -2
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +967 -0
- package/types/app-factory.d.ts.map +1 -0
- package/types/app-factory.js +322 -0
- package/types/app-factory.js.map +1 -0
- package/types/app-factory.mjs +320 -0
- package/types/app-factory.mjs.map +1 -0
- package/types/app-manager.d.ts +12 -2
- package/types/app-manager.d.ts.map +1 -1
- package/types/app-manager.js +10 -1
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +10 -1
- package/types/app-manager.mjs.map +1 -1
- package/types/app-spec.d.ts +2 -0
- package/types/app-spec.d.ts.map +1 -1
- package/types/app-spec.js +115 -0
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +114 -0
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +6 -2
- package/types/app.d.ts.map +1 -1
- package/types/asset-manager.d.ts +2 -1
- package/types/asset-manager.d.ts.map +1 -1
- package/types/asset-manager.js +0 -1
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +0 -1
- package/types/asset-manager.mjs.map +1 -1
- package/types/client-manager.d.ts +109 -50
- package/types/client-manager.d.ts.map +1 -1
- package/types/client-manager.js +137 -23
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +138 -24
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +31 -14
- package/types/composer.d.ts.map +1 -1
- package/types/composer.js +65 -10
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +66 -11
- package/types/composer.mjs.map +1 -1
- package/types/debugging.d.ts +3 -2
- package/types/debugging.d.ts.map +1 -1
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.d.ts +1 -1
- package/types/dispenser-client.d.ts.map +1 -1
- package/types/dispenser-client.js +1 -1
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs +1 -1
- package/types/dispenser-client.mjs.map +1 -1
- package/types/network-client.d.ts +13 -0
- package/types/network-client.d.ts.map +1 -1
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +3 -3
- package/types/testing.d.ts.map +1 -1
- package/types/transaction.d.ts +14 -1
- package/types/transaction.d.ts.map +1 -1
- package/util.d.ts +2 -1
- package/util.d.ts.map +1 -1
- package/util.js +11 -1
- package/util.js.map +1 -1
- package/util.mjs +11 -2
- package/util.mjs.map +1 -1
package/types/app-client.js
CHANGED
|
@@ -8,7 +8,11 @@ var config = require('../config.js');
|
|
|
8
8
|
var debugging = require('../debugging/debugging.js');
|
|
9
9
|
var legacyBridge = require('../transaction/legacy-bridge.js');
|
|
10
10
|
var transaction = require('../transaction/transaction.js');
|
|
11
|
+
var util = require('../util.js');
|
|
11
12
|
var types_app = require('./app.js');
|
|
13
|
+
var types_appArc56 = require('./app-arc56.js');
|
|
14
|
+
var types_appManager = require('./app-manager.js');
|
|
15
|
+
var types_appSpec = require('./app-spec.js');
|
|
12
16
|
var types_debugging = require('./debugging.js');
|
|
13
17
|
var types_logicError = require('./logic-error.js');
|
|
14
18
|
|
|
@@ -16,6 +20,7 @@ var ABIMethod = algosdk.ABIMethod;
|
|
|
16
20
|
var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
|
|
17
21
|
var getApplicationAddress = algosdk.getApplicationAddress;
|
|
18
22
|
var Indexer = algosdk.Indexer;
|
|
23
|
+
var OnApplicationComplete = algosdk.OnApplicationComplete;
|
|
19
24
|
var SourceMap = algosdk.SourceMap;
|
|
20
25
|
/**
|
|
21
26
|
* Determines deploy time control (UPDATABLE, DELETABLE) value by inspecting application specification
|
|
@@ -39,13 +44,787 @@ function getDeployTimeControl(approval, appSpec, templateVariableName, callConfi
|
|
|
39
44
|
return !!abiCallConfig && abiCallConfig !== 'NEVER';
|
|
40
45
|
});
|
|
41
46
|
}
|
|
42
|
-
/**
|
|
47
|
+
/** ARC-56/ARC-32 application client that allows you to manage calls and
|
|
48
|
+
* state for a specific deployed instance of an app (with a known app ID). */
|
|
49
|
+
class AppClient {
|
|
50
|
+
constructor(params) {
|
|
51
|
+
this._appId = params.appId;
|
|
52
|
+
this._appAddress = algosdk.getApplicationAddress(this._appId);
|
|
53
|
+
this._appSpec = AppClient.normaliseAppSpec(params.appSpec);
|
|
54
|
+
this._appName = params.appName ?? this._appSpec.name;
|
|
55
|
+
this._algorand = params.algorand;
|
|
56
|
+
this._defaultSender = params.defaultSender;
|
|
57
|
+
this._approvalSourceMap = params.approvalSourceMap;
|
|
58
|
+
this._clearSourceMap = params.clearSourceMap;
|
|
59
|
+
this._localStateMethods = (address) => this.getStateMethods(() => this.getLocalState(address), () => this._appSpec.state.keys.local, () => this._appSpec.state.maps.local);
|
|
60
|
+
this._globalStateMethods = this.getStateMethods(() => this.getGlobalState(), () => this._appSpec.state.keys.global, () => this._appSpec.state.maps.global);
|
|
61
|
+
this._boxStateMethods = this.getBoxMethods();
|
|
62
|
+
this._paramsMethods = {
|
|
63
|
+
...this.getMethodCallParamsMethods(),
|
|
64
|
+
bare: this.getBareParamsMethods(),
|
|
65
|
+
};
|
|
66
|
+
this._transactionsMethods = { ...this.getMethodCallTransactionsMethods(), bare: this.getBareTransactionsMethods() };
|
|
67
|
+
this._sendMethods = { ...this.getMethodCallSendMethods(), bare: this.getBareSendMethods() };
|
|
68
|
+
}
|
|
69
|
+
/** Start a new `AlgoKitComposer` transaction group */
|
|
70
|
+
newGroup() {
|
|
71
|
+
return this._algorand.newGroup();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns a new `AppClient` client, resolving the app by creator address and name
|
|
75
|
+
* using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
|
|
76
|
+
* @param params The parameters to create the app client
|
|
77
|
+
*/
|
|
78
|
+
static async fromCreatorAndName(params) {
|
|
79
|
+
const appSpec = AppClient.normaliseAppSpec(params.appSpec);
|
|
80
|
+
const appLookup = params.appLookupCache ?? (await params.algorand.appDeployer.getCreatorAppsByName(params.creatorAddress, params.ignoreCache));
|
|
81
|
+
const appMetadata = appLookup.apps[params.appName ?? appSpec.name];
|
|
82
|
+
if (!appMetadata) {
|
|
83
|
+
throw new Error(`App not found for creator ${params.creatorAddress} and name ${params.appName ?? appSpec.name}`);
|
|
84
|
+
}
|
|
85
|
+
return new AppClient({
|
|
86
|
+
...params,
|
|
87
|
+
algorand: params.algorand,
|
|
88
|
+
appId: appMetadata.appId,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns an `AppClient` instance for the current network based on
|
|
93
|
+
* pre-determined network-specific app IDs specified in the ARC-56 app spec.
|
|
94
|
+
*
|
|
95
|
+
* If no IDs are in the app spec or the network isn't recognised, an error is thrown.
|
|
96
|
+
* @param params The parameters to create the app client
|
|
97
|
+
*/
|
|
98
|
+
static async fromNetwork(params) {
|
|
99
|
+
const network = await params.algorand.client.network();
|
|
100
|
+
const appSpec = AppClient.normaliseAppSpec(params.appSpec);
|
|
101
|
+
const networkNames = [network.genesisHash];
|
|
102
|
+
if (network.isLocalNet)
|
|
103
|
+
networkNames.push('localnet');
|
|
104
|
+
if (network.isTestNet)
|
|
105
|
+
networkNames.push('testnet');
|
|
106
|
+
if (network.isMainNet)
|
|
107
|
+
networkNames.push('mainnet');
|
|
108
|
+
const availableAppSpecNetworks = Object.keys(appSpec.networks ?? {});
|
|
109
|
+
const networkIndex = availableAppSpecNetworks.findIndex((n) => networkNames.includes(n));
|
|
110
|
+
if (networkIndex === -1) {
|
|
111
|
+
throw new Error(`No app ID found for network ${JSON.stringify(networkNames)} in the app spec`);
|
|
112
|
+
}
|
|
113
|
+
const appId = BigInt(appSpec.networks[networkIndex].appID);
|
|
114
|
+
return new AppClient({ ...params, appId, appSpec });
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Takes a string or parsed JSON object that could be ARC-32 or ARC-56 format and
|
|
118
|
+
* normalises it into a parsed ARC-56 contract object.
|
|
119
|
+
* @param spec The spec to normalise
|
|
120
|
+
* @returns The normalised ARC-56 contract object
|
|
121
|
+
*/
|
|
122
|
+
static normaliseAppSpec(spec) {
|
|
123
|
+
const parsedSpec = typeof spec === 'string' ? JSON.parse(spec) : spec;
|
|
124
|
+
const appSpec = 'hints' in parsedSpec ? types_appSpec.arc32ToArc56(parsedSpec) : parsedSpec;
|
|
125
|
+
return appSpec;
|
|
126
|
+
}
|
|
127
|
+
/** The ID of the app instance this client is linked to. */
|
|
128
|
+
get appId() {
|
|
129
|
+
return this._appId;
|
|
130
|
+
}
|
|
131
|
+
/** The app address of the app instance this client is linked to. */
|
|
132
|
+
get appAddress() {
|
|
133
|
+
return this._appAddress;
|
|
134
|
+
}
|
|
135
|
+
/** The name of the app (from the ARC-32 / ARC-56 app spec). */
|
|
136
|
+
get appName() {
|
|
137
|
+
return this._appName;
|
|
138
|
+
}
|
|
139
|
+
/** The ARC-56 app spec being used */
|
|
140
|
+
get appSpec() {
|
|
141
|
+
return this._appSpec;
|
|
142
|
+
}
|
|
143
|
+
/** Get parameters to define transactions to the current app */
|
|
144
|
+
get params() {
|
|
145
|
+
return this._paramsMethods;
|
|
146
|
+
}
|
|
147
|
+
/** Get transactions for the current app */
|
|
148
|
+
get transactions() {
|
|
149
|
+
return this._transactionsMethods;
|
|
150
|
+
}
|
|
151
|
+
/** Send calls to the current app */
|
|
152
|
+
get send() {
|
|
153
|
+
return this._sendMethods;
|
|
154
|
+
}
|
|
155
|
+
get state() {
|
|
156
|
+
return {
|
|
157
|
+
/**
|
|
158
|
+
* Methods to access local state for the current app
|
|
159
|
+
* @param address The address of the account to get the local state for
|
|
160
|
+
*/
|
|
161
|
+
local: this._localStateMethods,
|
|
162
|
+
/**
|
|
163
|
+
* Methods to access global state for the current app
|
|
164
|
+
*/
|
|
165
|
+
global: this._globalStateMethods,
|
|
166
|
+
/**
|
|
167
|
+
* Methods to access box storage for the current app
|
|
168
|
+
*/
|
|
169
|
+
box: this._boxStateMethods,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Funds Algo into the app account for this app.
|
|
174
|
+
* @param params The parameters for the funding transaction
|
|
175
|
+
* @returns The result of the funding
|
|
176
|
+
*/
|
|
177
|
+
async fundAppAccount(params) {
|
|
178
|
+
return this.send.fundAppAccount(params);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Returns raw global state for the current app.
|
|
182
|
+
* @returns The global state
|
|
183
|
+
*/
|
|
184
|
+
async getGlobalState() {
|
|
185
|
+
return await this._algorand.app.getGlobalState(this.appId);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Returns raw local state for the given account address.
|
|
189
|
+
* @param address The address of the account to get the local state for
|
|
190
|
+
* @returns The local state
|
|
191
|
+
*/
|
|
192
|
+
async getLocalState(address) {
|
|
193
|
+
return await this._algorand.app.getLocalState(this.appId, address);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Returns the names of all current boxes for the current app.
|
|
197
|
+
* @returns The names of the boxes
|
|
198
|
+
*/
|
|
199
|
+
async getBoxNames() {
|
|
200
|
+
return await this._algorand.app.getBoxNames(this.appId);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Returns the value of the given box for the current app.
|
|
204
|
+
* @param name The identifier of the box to return
|
|
205
|
+
* @returns The current box value as a byte array
|
|
206
|
+
*/
|
|
207
|
+
async getBoxValue(name) {
|
|
208
|
+
return await this._algorand.app.getBoxValue(this.appId, name);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Returns the value of the given box for the current app.
|
|
212
|
+
* @param name The identifier of the box to return
|
|
213
|
+
* @param type
|
|
214
|
+
* @returns The current box value as a byte array
|
|
215
|
+
*/
|
|
216
|
+
async getBoxValueFromABIType(name, type) {
|
|
217
|
+
return await this._algorand.app.getBoxValueFromABIType({
|
|
218
|
+
appId: this.appId,
|
|
219
|
+
boxName: name,
|
|
220
|
+
type,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Returns the values of all current boxes for the current app.
|
|
225
|
+
* Note: This will issue multiple HTTP requests (one per box) and it's not an atomic operation so values may be out of sync.
|
|
226
|
+
* @param filter Optional filter to filter which boxes' values are returned
|
|
227
|
+
* @returns The (name, value) pair of the boxes with values as raw byte arrays
|
|
228
|
+
*/
|
|
229
|
+
async getBoxValues(filter) {
|
|
230
|
+
const names = (await this.getBoxNames()).filter(filter ?? ((_) => true));
|
|
231
|
+
const values = await this._algorand.app.getBoxValues(this.appId, names.map((name) => name.nameRaw));
|
|
232
|
+
return names.map((name, i) => ({ name, value: values[i] }));
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Returns the values of all current boxes for the current app decoded using an ABI Type.
|
|
236
|
+
* Note: This will issue multiple HTTP requests (one per box) and it's not an atomic operation so values may be out of sync.
|
|
237
|
+
* @param type The ABI type to decode the values with
|
|
238
|
+
* @param filter Optional filter to filter which boxes' values are returned
|
|
239
|
+
* @returns The (name, value) pair of the boxes with values as the ABI Value
|
|
240
|
+
*/
|
|
241
|
+
async getBoxValuesFromABIType(type, filter) {
|
|
242
|
+
const names = (await this.getBoxNames()).filter(filter ?? ((_) => true));
|
|
243
|
+
const values = await this._algorand.app.getBoxValuesFromABIType({
|
|
244
|
+
appId: this.appId,
|
|
245
|
+
boxNames: names.map((name) => name.nameRaw),
|
|
246
|
+
type,
|
|
247
|
+
});
|
|
248
|
+
return names.map((name, i) => ({ name, value: values[i] }));
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Takes an error that may include a logic error from a call to the current app and re-exposes the
|
|
252
|
+
* error to include source code information via the source map and ARC-56 spec.
|
|
253
|
+
* @param e The error to parse
|
|
254
|
+
* @param isClearStateProgram Whether or not the code was running the clear state program (defaults to approval program)
|
|
255
|
+
* @returns The new error, or if there was no logic error or source map then the wrapped error with source details
|
|
256
|
+
*/
|
|
257
|
+
exposeLogicError(e, isClearStateProgram) {
|
|
258
|
+
return AppClient.exposeLogicError(e, this._appSpec, {
|
|
259
|
+
isClearStateProgram,
|
|
260
|
+
approvalSourceMap: this._approvalSourceMap,
|
|
261
|
+
clearSourceMap: this._clearSourceMap,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Export the current source maps for the app.
|
|
266
|
+
* @returns The source maps
|
|
267
|
+
*/
|
|
268
|
+
exportSourceMaps() {
|
|
269
|
+
if (!this._approvalSourceMap || !this._clearSourceMap) {
|
|
270
|
+
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");
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
approvalSourceMap: this._approvalSourceMap,
|
|
274
|
+
clearSourceMap: this._clearSourceMap,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Import source maps for the app.
|
|
279
|
+
* @param sourceMaps The source maps to import
|
|
280
|
+
*/
|
|
281
|
+
importSourceMaps(sourceMaps) {
|
|
282
|
+
this._approvalSourceMap = new SourceMap(sourceMaps.approvalSourceMap);
|
|
283
|
+
this._clearSourceMap = new SourceMap(sourceMaps.clearSourceMap);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Returns the ABI Method for the given method name string for the app represented by this application client instance
|
|
287
|
+
* @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.
|
|
288
|
+
* e.g. `my_method` or `my_method(unit64,string)bytes`
|
|
289
|
+
* @returns A tuple with: [ARC-56 `Method`, algosdk `ABIMethod`]
|
|
290
|
+
*/
|
|
291
|
+
getABIMethod(methodNameOrSignature) {
|
|
292
|
+
return types_appArc56.getArc56Method(methodNameOrSignature, this._appSpec);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Checks for decode errors on the SendAppTransactionResult and maps the return value to the specified type
|
|
296
|
+
* on the ARC-56 method.
|
|
297
|
+
*
|
|
298
|
+
* If the return type is a struct then the struct will be returned.
|
|
299
|
+
*
|
|
300
|
+
* @param result The SendAppTransactionResult to be mapped
|
|
301
|
+
* @param method The method that was called
|
|
302
|
+
* @returns The smart contract response with an updated return value
|
|
303
|
+
*/
|
|
304
|
+
async parseMethodCallReturn(result, method) {
|
|
305
|
+
const resultValue = await result;
|
|
306
|
+
return { ...resultValue, return: types_appArc56.getArc56ReturnValue(resultValue.return, method, this._appSpec.structs) };
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Takes an error that may include a logic error from a call to the current app and re-exposes the
|
|
310
|
+
* error to include source code information via the source map and ARC-56 spec.
|
|
311
|
+
* @param e The error to parse
|
|
312
|
+
* @param appSpec The app spec for the app
|
|
313
|
+
* @param details Additional information to inform the error
|
|
314
|
+
* @returns The new error, or if there was no logic error or source map then the wrapped error with source details
|
|
315
|
+
*/
|
|
316
|
+
static exposeLogicError(e, appSpec, details) {
|
|
317
|
+
const { isClearStateProgram, approvalSourceMap, clearSourceMap } = details;
|
|
318
|
+
if ((!isClearStateProgram && approvalSourceMap == undefined) || (isClearStateProgram && clearSourceMap == undefined))
|
|
319
|
+
return e;
|
|
320
|
+
const errorDetails = types_logicError.LogicError.parseLogicError(e);
|
|
321
|
+
const errorMessage = (isClearStateProgram ? appSpec.sourceInfo?.clear : appSpec.sourceInfo?.approval)?.find((s) => s?.pc?.includes(errorDetails?.pc ?? -1))?.errorMessage;
|
|
322
|
+
if (errorDetails !== undefined && appSpec.source)
|
|
323
|
+
e = new types_logicError.LogicError(errorDetails, buffer.Buffer.from(isClearStateProgram ? appSpec.source.clear : appSpec.source.approval, 'base64')
|
|
324
|
+
.toString()
|
|
325
|
+
.split('\n'),
|
|
326
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
327
|
+
isClearStateProgram ? clearSourceMap : approvalSourceMap);
|
|
328
|
+
if (errorMessage) {
|
|
329
|
+
const appId = JSON.stringify(e).match(/(?<=app=)\d+/)?.[0] || '';
|
|
330
|
+
const txId = JSON.stringify(e).match(/(?<=transaction )\S+(?=:)/)?.[0];
|
|
331
|
+
const error = new Error(`Runtime error when executing ${appSpec.name} (appId: ${appId}) in transaction ${txId}: ${errorMessage}`);
|
|
332
|
+
error.cause = e;
|
|
333
|
+
return error;
|
|
334
|
+
}
|
|
335
|
+
return e;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Compiles the approval and clear state programs (if TEAL templates provided),
|
|
339
|
+
* performing any provided deploy-time parameter replacement and returns
|
|
340
|
+
* the compiled code and any compilation results (including source maps).
|
|
341
|
+
*
|
|
342
|
+
* If no TEAL templates provided it will use any byte code provided in the app spec.
|
|
343
|
+
*
|
|
344
|
+
* Will store any generated source maps for later use in debugging.
|
|
345
|
+
* @param appSpec The app spec for the app
|
|
346
|
+
* @param compilation Any compilation parameters to use
|
|
347
|
+
*/
|
|
348
|
+
static async compile(appSpec, appManager, compilation) {
|
|
349
|
+
const { deployTimeParams, updatable, deletable } = compilation ?? {};
|
|
350
|
+
if (!appSpec.source) {
|
|
351
|
+
if (!appSpec.byteCode?.approval || !appSpec.byteCode?.clear) {
|
|
352
|
+
throw new Error(`Attempt to compile app ${appSpec.name} without source or byteCode`);
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
approvalProgram: buffer.Buffer.from(appSpec.byteCode.approval, 'base64'),
|
|
356
|
+
clearStateProgram: buffer.Buffer.from(appSpec.byteCode.clear, 'base64'),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
const approvalTemplate = buffer.Buffer.from(appSpec.source.approval, 'base64').toString('utf-8');
|
|
360
|
+
const compiledApproval = await appManager.compileTealTemplate(approvalTemplate, deployTimeParams, {
|
|
361
|
+
updatable,
|
|
362
|
+
deletable,
|
|
363
|
+
});
|
|
364
|
+
const clearTemplate = buffer.Buffer.from(appSpec.source.clear, 'base64').toString('utf-8');
|
|
365
|
+
const compiledClear = await appManager.compileTealTemplate(clearTemplate, deployTimeParams);
|
|
366
|
+
if (config.Config.debug && config.Config.projectRoot) {
|
|
367
|
+
debugging.persistSourceMaps({
|
|
368
|
+
sources: [
|
|
369
|
+
types_debugging.PersistSourceMapInput.fromCompiledTeal(compiledApproval, appSpec.name, 'approval.teal'),
|
|
370
|
+
types_debugging.PersistSourceMapInput.fromCompiledTeal(compiledClear, appSpec.name, 'clear.teal'),
|
|
371
|
+
],
|
|
372
|
+
projectRoot: config.Config.projectRoot,
|
|
373
|
+
appManager,
|
|
374
|
+
withSources: true,
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
approvalProgram: compiledApproval.compiledBase64ToBytes,
|
|
379
|
+
compiledApproval,
|
|
380
|
+
clearStateProgram: compiledClear.compiledBase64ToBytes,
|
|
381
|
+
compiledClear,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Returns ABI method arguments ready for a method call params object with default values populated
|
|
386
|
+
* and structs replaced with tuples.
|
|
387
|
+
*
|
|
388
|
+
* It does this by replacing any `undefined` values with the equivalent default value from the given ARC-56 app spec.
|
|
389
|
+
* @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.
|
|
390
|
+
* e.g. `my_method` or `my_method(unit64,string)bytes`
|
|
391
|
+
* @param args The arguments to the method with `undefined` for any that should be populated with a default value
|
|
392
|
+
* @param appSpec The app spec for the app
|
|
393
|
+
*/
|
|
394
|
+
static getABIArgsWithDefaultValues(methodNameOrSignature, args, appSpec) {
|
|
395
|
+
const m = types_appArc56.getArc56Method(methodNameOrSignature, appSpec);
|
|
396
|
+
return args?.map((a, i) => {
|
|
397
|
+
const arg = m.args[i];
|
|
398
|
+
if (a !== undefined) {
|
|
399
|
+
// If a struct then convert to tuple for the underlying call
|
|
400
|
+
return arg.struct && typeof a === 'object' && !Array.isArray(a)
|
|
401
|
+
? types_appArc56.getABITupleFromABIStruct(a, appSpec.structs[arg.struct])
|
|
402
|
+
: a;
|
|
403
|
+
}
|
|
404
|
+
// todo: expand this to match previous ApplicationClient implementation when ARC-56 spec is updated to support other default value options
|
|
405
|
+
const defaultValue = arg.defaultValue;
|
|
406
|
+
if (defaultValue)
|
|
407
|
+
return types_appArc56.getABIDecodedValue(buffer.Buffer.from(defaultValue, 'base64'), m.method.args[i].type, {});
|
|
408
|
+
throw new Error(`No value provided for required argument ${arg.name ?? `arg${i + 1}`} in call to method ${m.name}`);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
getBareParamsMethods() {
|
|
412
|
+
return {
|
|
413
|
+
/** Return params for an update call, including deploy-time TEAL template replacements and compilation if provided */
|
|
414
|
+
update: async (params) => {
|
|
415
|
+
return this.getBareParams({
|
|
416
|
+
...params,
|
|
417
|
+
...(await this.compile(params)),
|
|
418
|
+
}, OnApplicationComplete.UpdateApplicationOC);
|
|
419
|
+
},
|
|
420
|
+
/** Return params for an opt-in call */
|
|
421
|
+
optIn: (params) => {
|
|
422
|
+
return this.getBareParams(params, OnApplicationComplete.OptInOC);
|
|
423
|
+
},
|
|
424
|
+
/** Return params for a delete call */
|
|
425
|
+
delete: (params) => {
|
|
426
|
+
return this.getBareParams(params, OnApplicationComplete.DeleteApplicationOC);
|
|
427
|
+
},
|
|
428
|
+
/** Return params for a clear state call */
|
|
429
|
+
clearState: (params) => {
|
|
430
|
+
return this.getBareParams(params, OnApplicationComplete.ClearStateOC);
|
|
431
|
+
},
|
|
432
|
+
/** Return params for a close out call */
|
|
433
|
+
closeOut: (params) => {
|
|
434
|
+
return this.getBareParams(params, OnApplicationComplete.CloseOutOC);
|
|
435
|
+
},
|
|
436
|
+
/** Return params for a call (defaults to no-op) */
|
|
437
|
+
call: (params) => {
|
|
438
|
+
return this.getBareParams(params, params?.onComplete ?? OnApplicationComplete.NoOpOC);
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
getBareTransactionsMethods() {
|
|
443
|
+
return {
|
|
444
|
+
/** Returns a transaction for an update call, including deploy-time TEAL template replacements and compilation if provided */
|
|
445
|
+
update: async (params) => {
|
|
446
|
+
return this._algorand.transactions.appUpdate(await this.params.bare.update(params));
|
|
447
|
+
},
|
|
448
|
+
/** Returns a transaction for an opt-in call */
|
|
449
|
+
optIn: (params) => {
|
|
450
|
+
return this._algorand.transactions.appCall(this.params.bare.optIn(params));
|
|
451
|
+
},
|
|
452
|
+
/** Returns a transaction for a delete call */
|
|
453
|
+
delete: (params) => {
|
|
454
|
+
return this._algorand.transactions.appDelete(this.params.bare.delete(params));
|
|
455
|
+
},
|
|
456
|
+
/** Returns a transaction for a clear state call */
|
|
457
|
+
clearState: (params) => {
|
|
458
|
+
return this._algorand.transactions.appCall(this.params.bare.clearState(params));
|
|
459
|
+
},
|
|
460
|
+
/** Returns a transaction for a close out call */
|
|
461
|
+
closeOut: (params) => {
|
|
462
|
+
return this._algorand.transactions.appCall(this.params.bare.closeOut(params));
|
|
463
|
+
},
|
|
464
|
+
/** Returns a transaction for a call (defaults to no-op) */
|
|
465
|
+
call: (params) => {
|
|
466
|
+
return this._algorand.transactions.appCall(this.params.bare.call(params));
|
|
467
|
+
},
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
getBareSendMethods() {
|
|
471
|
+
return {
|
|
472
|
+
/** Signs and sends an update call, including deploy-time TEAL template replacements and compilation if provided */
|
|
473
|
+
update: async (params) => {
|
|
474
|
+
return await this.handleCallErrors(async () => this._algorand.send.appUpdate(await this.params.bare.update(params)));
|
|
475
|
+
},
|
|
476
|
+
/** Signs and sends an opt-in call */
|
|
477
|
+
optIn: (params) => {
|
|
478
|
+
return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.optIn(params)));
|
|
479
|
+
},
|
|
480
|
+
/** Signs and sends a delete call */
|
|
481
|
+
delete: (params) => {
|
|
482
|
+
return this.handleCallErrors(() => this._algorand.send.appDelete(this.params.bare.delete(params)));
|
|
483
|
+
},
|
|
484
|
+
/** Signs and sends a clear state call */
|
|
485
|
+
clearState: (params) => {
|
|
486
|
+
return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.clearState(params)));
|
|
487
|
+
},
|
|
488
|
+
/** Signs and sends a close out call */
|
|
489
|
+
closeOut: (params) => {
|
|
490
|
+
return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.closeOut(params)));
|
|
491
|
+
},
|
|
492
|
+
/** Signs and sends a call (defaults to no-op) */
|
|
493
|
+
call: (params) => {
|
|
494
|
+
return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.call(params)));
|
|
495
|
+
},
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
getMethodCallParamsMethods() {
|
|
499
|
+
return {
|
|
500
|
+
/** Return params for a payment transaction to fund the app account */
|
|
501
|
+
fundAppAccount: (params) => {
|
|
502
|
+
return {
|
|
503
|
+
...params,
|
|
504
|
+
sender: this.getSender(params.sender),
|
|
505
|
+
receiver: this.appAddress,
|
|
506
|
+
};
|
|
507
|
+
},
|
|
508
|
+
/** Return params for an update ABI call, including deploy-time TEAL template replacements and compilation if provided */
|
|
509
|
+
update: async (params) => {
|
|
510
|
+
return this.getABIParams({
|
|
511
|
+
...params,
|
|
512
|
+
...(await this.compile(params)),
|
|
513
|
+
}, OnApplicationComplete.UpdateApplicationOC);
|
|
514
|
+
},
|
|
515
|
+
/** Return params for an opt-in ABI call */
|
|
516
|
+
optIn: (params) => {
|
|
517
|
+
return this.getABIParams(params, OnApplicationComplete.OptInOC);
|
|
518
|
+
},
|
|
519
|
+
/** Return params for an delete ABI call */
|
|
520
|
+
delete: (params) => {
|
|
521
|
+
return this.getABIParams(params, OnApplicationComplete.DeleteApplicationOC);
|
|
522
|
+
},
|
|
523
|
+
/** Return params for an close out ABI call */
|
|
524
|
+
closeOut: (params) => {
|
|
525
|
+
return this.getABIParams(params, OnApplicationComplete.CloseOutOC);
|
|
526
|
+
},
|
|
527
|
+
/** Return params for an ABI call */
|
|
528
|
+
call: (params) => {
|
|
529
|
+
return this.getABIParams(params, params.onComplete ?? OnApplicationComplete.NoOpOC);
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
getMethodCallSendMethods() {
|
|
534
|
+
return {
|
|
535
|
+
/** Sign and send transactions for a payment transaction to fund the app account */
|
|
536
|
+
fundAppAccount: (params) => {
|
|
537
|
+
return this._algorand.send.payment(this.params.fundAppAccount(params));
|
|
538
|
+
},
|
|
539
|
+
/**
|
|
540
|
+
* Sign and send transactions for an update ABI call, including deploy-time TEAL template replacements and compilation if provided
|
|
541
|
+
*/
|
|
542
|
+
update: async (params) => {
|
|
543
|
+
const compiled = await this.compile(params);
|
|
544
|
+
return {
|
|
545
|
+
...(await this.handleCallErrors(async () => this.parseMethodCallReturn(this._algorand.send.appUpdateMethodCall(await this.params.update({ ...params })), types_appArc56.getArc56Method(params.method, this._appSpec)))),
|
|
546
|
+
...compiled,
|
|
547
|
+
};
|
|
548
|
+
},
|
|
549
|
+
/**
|
|
550
|
+
* Sign and send transactions for an opt-in ABI call
|
|
551
|
+
*/
|
|
552
|
+
optIn: (params) => {
|
|
553
|
+
return this.handleCallErrors(() => this.parseMethodCallReturn(this._algorand.send.appCallMethodCall(this.params.optIn(params)), types_appArc56.getArc56Method(params.method, this._appSpec)));
|
|
554
|
+
},
|
|
555
|
+
/**
|
|
556
|
+
* Sign and send transactions for a delete ABI call
|
|
557
|
+
*/
|
|
558
|
+
delete: (params) => {
|
|
559
|
+
return this.handleCallErrors(() => this.parseMethodCallReturn(this._algorand.send.appDeleteMethodCall(this.params.delete(params)), types_appArc56.getArc56Method(params.method, this._appSpec)));
|
|
560
|
+
},
|
|
561
|
+
/**
|
|
562
|
+
* Sign and send transactions for a close out ABI call
|
|
563
|
+
*/
|
|
564
|
+
closeOut: (params) => {
|
|
565
|
+
return this.handleCallErrors(() => this.parseMethodCallReturn(this._algorand.send.appCallMethodCall(this.params.closeOut(params)), types_appArc56.getArc56Method(params.method, this._appSpec)));
|
|
566
|
+
},
|
|
567
|
+
/**
|
|
568
|
+
* Sign and send transactions for a call (defaults to no-op)
|
|
569
|
+
*/
|
|
570
|
+
call: async (params) => {
|
|
571
|
+
// Read-only call - do it via simulate
|
|
572
|
+
if (params.onComplete === OnApplicationComplete.NoOpOC ||
|
|
573
|
+
(!params.onComplete && types_appArc56.getArc56Method(params.method, this._appSpec).method.readonly)) {
|
|
574
|
+
const result = await this._algorand.newGroup().addAppCallMethodCall(this.params.call(params)).simulate();
|
|
575
|
+
return this.parseMethodCallReturn({
|
|
576
|
+
...result,
|
|
577
|
+
transaction: result.transactions.at(-1),
|
|
578
|
+
confirmation: result.confirmations.at(-1),
|
|
579
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
|
|
580
|
+
return: (result.returns?.length ?? 0 > 0) ? result.returns?.at(-1) : undefined,
|
|
581
|
+
}, types_appArc56.getArc56Method(params.method, this._appSpec));
|
|
582
|
+
}
|
|
583
|
+
return this.handleCallErrors(() => this.parseMethodCallReturn(this._algorand.send.appCallMethodCall(this.params.call(params)), types_appArc56.getArc56Method(params.method, this._appSpec)));
|
|
584
|
+
},
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
getMethodCallTransactionsMethods() {
|
|
588
|
+
return {
|
|
589
|
+
/** Return transaction for a payment transaction to fund the app account */
|
|
590
|
+
fundAppAccount: (params) => {
|
|
591
|
+
return this._algorand.transactions.payment(this.params.fundAppAccount(params));
|
|
592
|
+
},
|
|
593
|
+
/**
|
|
594
|
+
* Return transactions for an update ABI call, including deploy-time TEAL template replacements and compilation if provided
|
|
595
|
+
*/
|
|
596
|
+
update: async (params) => {
|
|
597
|
+
return this._algorand.transactions.appUpdateMethodCall(await this.params.update(params));
|
|
598
|
+
},
|
|
599
|
+
/**
|
|
600
|
+
* Return transactions for an opt-in ABI call
|
|
601
|
+
*/
|
|
602
|
+
optIn: (params) => {
|
|
603
|
+
return this._algorand.transactions.appCallMethodCall(this.params.optIn(params));
|
|
604
|
+
},
|
|
605
|
+
/**
|
|
606
|
+
* Return transactions for a delete ABI call
|
|
607
|
+
*/
|
|
608
|
+
delete: (params) => {
|
|
609
|
+
return this._algorand.transactions.appDeleteMethodCall(this.params.delete(params));
|
|
610
|
+
},
|
|
611
|
+
/**
|
|
612
|
+
* Return transactions for a close out ABI call
|
|
613
|
+
*/
|
|
614
|
+
closeOut: (params) => {
|
|
615
|
+
return this._algorand.transactions.appCallMethodCall(this.params.closeOut(params));
|
|
616
|
+
},
|
|
617
|
+
/**
|
|
618
|
+
* Return transactions for an ABI call (defaults to no-op)
|
|
619
|
+
*/
|
|
620
|
+
call: (params) => {
|
|
621
|
+
return this._algorand.transactions.appCallMethodCall(this.params.call(params));
|
|
622
|
+
},
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Compiles the approval and clear state programs (if TEAL templates provided),
|
|
627
|
+
* performing any provided deploy-time parameter replacement and stores
|
|
628
|
+
* the source maps.
|
|
629
|
+
*
|
|
630
|
+
* If no TEAL templates provided it will use any byte code provided in the app spec.
|
|
631
|
+
*
|
|
632
|
+
* Will store any generated source maps for later use in debugging.
|
|
633
|
+
*/
|
|
634
|
+
async compile(compilation) {
|
|
635
|
+
const result = await AppClient.compile(this._appSpec, this._algorand.app, compilation);
|
|
636
|
+
if (result.compiledApproval) {
|
|
637
|
+
this._approvalSourceMap = result.compiledApproval.sourceMap;
|
|
638
|
+
}
|
|
639
|
+
if (result.compiledClear) {
|
|
640
|
+
this._clearSourceMap = result.compiledClear.sourceMap;
|
|
641
|
+
}
|
|
642
|
+
return result;
|
|
643
|
+
}
|
|
644
|
+
/** Returns the sender for a call, using the `defaultSender`
|
|
645
|
+
* if none provided and throws an error if neither provided */
|
|
646
|
+
getSender(sender) {
|
|
647
|
+
if (!sender && !this._defaultSender) {
|
|
648
|
+
throw new Error(`No sender provided and no default sender present in app client for call to app ${this._appName}`);
|
|
649
|
+
}
|
|
650
|
+
return sender ?? this._defaultSender;
|
|
651
|
+
}
|
|
652
|
+
getBareParams(params, onComplete) {
|
|
653
|
+
return {
|
|
654
|
+
...params,
|
|
655
|
+
appId: this._appId,
|
|
656
|
+
sender: this.getSender(params?.sender),
|
|
657
|
+
onComplete,
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
getABIParams(params, onComplete) {
|
|
661
|
+
const method = types_appArc56.getArc56Method(params.method, this._appSpec);
|
|
662
|
+
const args = AppClient.getABIArgsWithDefaultValues(params.method, params.args, this._appSpec);
|
|
663
|
+
return {
|
|
664
|
+
...params,
|
|
665
|
+
appId: this._appId,
|
|
666
|
+
sender: this.getSender(params.sender),
|
|
667
|
+
method,
|
|
668
|
+
onComplete,
|
|
669
|
+
args,
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
/** Make the given call and catch any errors, augmenting with debugging information before re-throwing. */
|
|
673
|
+
async handleCallErrors(call) {
|
|
674
|
+
try {
|
|
675
|
+
return await call();
|
|
676
|
+
}
|
|
677
|
+
catch (e) {
|
|
678
|
+
throw this.exposeLogicError(e);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
getBoxMethods() {
|
|
682
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
683
|
+
const that = this;
|
|
684
|
+
const stateMethods = {
|
|
685
|
+
/**
|
|
686
|
+
* Returns all single-key state values in a record keyed by the key name and the value a decoded ABI value.
|
|
687
|
+
*/
|
|
688
|
+
getAll: async () => {
|
|
689
|
+
return Object.fromEntries(await Promise.all(Object.keys(that._appSpec.state.keys.box).map(async (key) => [key, await stateMethods.getValue(key)])));
|
|
690
|
+
},
|
|
691
|
+
/**
|
|
692
|
+
* Returns a single state value for the current app with the value a decoded ABI value.
|
|
693
|
+
* @param name The name of the state value to retrieve the value for
|
|
694
|
+
* @returns
|
|
695
|
+
*/
|
|
696
|
+
getValue: async (name) => {
|
|
697
|
+
const metadata = that._appSpec.state.keys.box[name];
|
|
698
|
+
const value = await that.getBoxValue(buffer.Buffer.from(metadata.key, 'base64'));
|
|
699
|
+
return types_appArc56.getABIDecodedValue(value, metadata.valueType, that._appSpec.structs);
|
|
700
|
+
},
|
|
701
|
+
/**
|
|
702
|
+
*
|
|
703
|
+
* @param mapName The name of the map to read from
|
|
704
|
+
* @param key The key within the map (without any map prefix) as either a Buffer with the bytes or a value
|
|
705
|
+
* that will be converted to bytes by encoding it using the specified ABI key type
|
|
706
|
+
* in the ARC-56 spec
|
|
707
|
+
*/
|
|
708
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
709
|
+
getMapValue: async (mapName, key) => {
|
|
710
|
+
const metadata = that._appSpec.state.maps.box[mapName];
|
|
711
|
+
const prefix = buffer.Buffer.from(metadata.prefix ?? '', 'base64');
|
|
712
|
+
const encodedKey = buffer.Buffer.concat([prefix, types_appArc56.getABIEncodedValue(key, metadata.keyType, that._appSpec.structs)]);
|
|
713
|
+
const base64Key = buffer.Buffer.from(encodedKey).toString('base64');
|
|
714
|
+
const value = await that.getBoxValue(buffer.Buffer.from(base64Key, 'base64'));
|
|
715
|
+
return types_appArc56.getABIDecodedValue(value, metadata.valueType, that._appSpec.structs);
|
|
716
|
+
},
|
|
717
|
+
/**
|
|
718
|
+
*
|
|
719
|
+
* @param mapName The name of the map to read from
|
|
720
|
+
* @param key The key within the map as either a Buffer with the bytes or a value
|
|
721
|
+
* that will be converted to bytes by encoding it using the specified ABI key type
|
|
722
|
+
* in the ARC-56 spec
|
|
723
|
+
* @param appState
|
|
724
|
+
*/
|
|
725
|
+
getMap: async (mapName) => {
|
|
726
|
+
const metadata = that._appSpec.state.maps.box[mapName];
|
|
727
|
+
const prefix = buffer.Buffer.from(metadata.prefix ?? '', 'base64');
|
|
728
|
+
const boxNames = await that.getBoxNames();
|
|
729
|
+
return new Map(await Promise.all(boxNames
|
|
730
|
+
.filter((b) => util.binaryStartsWith(b.nameRaw, prefix))
|
|
731
|
+
.map(async (b) => {
|
|
732
|
+
const encodedKey = buffer.Buffer.concat([prefix, b.nameRaw]);
|
|
733
|
+
const base64Key = buffer.Buffer.from(encodedKey).toString('base64');
|
|
734
|
+
return [
|
|
735
|
+
types_appArc56.getABIDecodedValue(b.nameRaw.slice(prefix.length), metadata.keyType, that._appSpec.structs),
|
|
736
|
+
types_appArc56.getABIDecodedValue(await that.getBoxValue(buffer.Buffer.from(base64Key, 'base64')), metadata.valueType, that._appSpec.structs),
|
|
737
|
+
];
|
|
738
|
+
})));
|
|
739
|
+
},
|
|
740
|
+
};
|
|
741
|
+
return stateMethods;
|
|
742
|
+
}
|
|
743
|
+
getStateMethods(stateGetter, keyGetter, mapGetter) {
|
|
744
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
745
|
+
const that = this;
|
|
746
|
+
const stateMethods = {
|
|
747
|
+
/**
|
|
748
|
+
* Returns all single-key state values in a record keyed by the key name and the value a decoded ABI value.
|
|
749
|
+
*/
|
|
750
|
+
getAll: async () => {
|
|
751
|
+
const appState = await stateGetter();
|
|
752
|
+
return Object.fromEntries(await Promise.all(Object.keys(keyGetter()).map(async (key) => [key, await stateMethods.getValue(key, appState)])));
|
|
753
|
+
},
|
|
754
|
+
/**
|
|
755
|
+
* Returns a single state value for the current app with the value a decoded ABI value.
|
|
756
|
+
* @param name The name of the state value to retrieve the value for
|
|
757
|
+
* @param appState Optional cached value of the current state
|
|
758
|
+
* @returns
|
|
759
|
+
*/
|
|
760
|
+
getValue: async (name, appState) => {
|
|
761
|
+
const state = Object.values(appState ?? (await stateGetter()));
|
|
762
|
+
const metadata = keyGetter()[name];
|
|
763
|
+
const value = state.find((s) => s.keyBase64 === metadata.key);
|
|
764
|
+
if (value && 'valueRaw' in value) {
|
|
765
|
+
return types_appArc56.getABIDecodedValue(value.valueRaw, metadata.valueType, that._appSpec.structs);
|
|
766
|
+
}
|
|
767
|
+
return value?.value;
|
|
768
|
+
},
|
|
769
|
+
/**
|
|
770
|
+
* Returns a single value from the given map for the current app with the value a decoded ABI value.
|
|
771
|
+
* @param mapName The name of the map to read from
|
|
772
|
+
* @param key The key within the map (without any map prefix) as either a Buffer with the bytes or a value
|
|
773
|
+
* that will be converted to bytes by encoding it using the specified ABI key type
|
|
774
|
+
* in the ARC-56 spec
|
|
775
|
+
* @param appState Optional cached value of the current state
|
|
776
|
+
*/
|
|
777
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
778
|
+
getMapValue: async (mapName, key, appState) => {
|
|
779
|
+
const state = Object.values(appState ?? (await stateGetter()));
|
|
780
|
+
const metadata = mapGetter()[mapName];
|
|
781
|
+
const prefix = buffer.Buffer.from(metadata.prefix ?? '', 'base64');
|
|
782
|
+
const encodedKey = buffer.Buffer.concat([prefix, types_appArc56.getABIEncodedValue(key, metadata.keyType, that._appSpec.structs)]);
|
|
783
|
+
const base64Key = buffer.Buffer.from(encodedKey).toString('base64');
|
|
784
|
+
const value = state.find((s) => s.keyBase64 === base64Key);
|
|
785
|
+
if (value && 'valueRaw' in value) {
|
|
786
|
+
return types_appArc56.getABIDecodedValue(value.valueRaw, metadata.valueType, that._appSpec.structs);
|
|
787
|
+
}
|
|
788
|
+
return value?.value;
|
|
789
|
+
},
|
|
790
|
+
/**
|
|
791
|
+
* Returns all map values for the given map.
|
|
792
|
+
* @param mapName The name of the map to read from
|
|
793
|
+
* @param appState Optional cached value of the current state
|
|
794
|
+
* @returns A map of all key-value pairs in the map as a `Record<string, ABIValue>`
|
|
795
|
+
*/
|
|
796
|
+
getMap: async (mapName) => {
|
|
797
|
+
const state = Object.values(await stateGetter());
|
|
798
|
+
const metadata = mapGetter()[mapName];
|
|
799
|
+
const prefix = buffer.Buffer.from(metadata.prefix ?? '', 'base64');
|
|
800
|
+
return new Map(state
|
|
801
|
+
.filter((s) => util.binaryStartsWith(s.keyRaw, prefix))
|
|
802
|
+
.map((s) => {
|
|
803
|
+
const key = s.keyRaw.slice(prefix.length);
|
|
804
|
+
return [
|
|
805
|
+
types_appArc56.getABIDecodedValue(key, metadata.keyType, this._appSpec.structs),
|
|
806
|
+
types_appArc56.getABIDecodedValue('valueRaw' in s ? s.valueRaw : s.value, metadata.valueType, this._appSpec.structs),
|
|
807
|
+
];
|
|
808
|
+
}));
|
|
809
|
+
},
|
|
810
|
+
};
|
|
811
|
+
return stateMethods;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* @deprecated Use `AppClient` instead e.g. via `algorand.client.getAppClientById` or
|
|
816
|
+
* `algorand.client.getAppClientByCreatorAndName`.
|
|
817
|
+
* If you want to `create` or `deploy` then use `AppFactory` e.g. via `algorand.client.getAppFactory`,
|
|
818
|
+
* which will in turn give you an `AppClient` instance against the created/deployed app to make other calls.
|
|
819
|
+
*
|
|
820
|
+
* Application client - a class that wraps an ARC-0032 app spec and provides high productivity methods to deploy and call the app */
|
|
43
821
|
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
822
|
/**
|
|
823
|
+
* @deprecated Use `AppClient` instead e.g. via `algorand.client.getAppClientById` or
|
|
824
|
+
* `algorand.client.getAppClientByCreatorAndName`.
|
|
825
|
+
* If you want to `create` or `deploy` then use `AppFactory` e.g. via `algorand.client.getAppFactory`,
|
|
826
|
+
* which will in turn give you an `AppClient` instance against the created/deployed app to make other calls.
|
|
827
|
+
*
|
|
49
828
|
* Create a new ApplicationClient instance
|
|
50
829
|
* @param appDetails The details of the app
|
|
51
830
|
* @param algod An algod instance
|
|
@@ -80,9 +859,11 @@ class ApplicationClient {
|
|
|
80
859
|
this.params = params;
|
|
81
860
|
}
|
|
82
861
|
/**
|
|
83
|
-
*
|
|
862
|
+
* @deprecated Use `AppClient.compile()` instead.
|
|
863
|
+
*
|
|
864
|
+
* Compiles the approval and clear state programs and sets up the source map.
|
|
84
865
|
* @param compilation The deploy-time parameters for the compilation
|
|
85
|
-
* @returns The compiled approval and clear programs
|
|
866
|
+
* @returns The compiled approval and clear state programs
|
|
86
867
|
*/
|
|
87
868
|
async compile(compilation) {
|
|
88
869
|
const { deployTimeParams, updatable, deletable } = compilation ?? {};
|
|
@@ -104,7 +885,7 @@ class ApplicationClient {
|
|
|
104
885
|
types_debugging.PersistSourceMapInput.fromCompiledTeal(clearCompiled, this._appName, 'clear.teal'),
|
|
105
886
|
],
|
|
106
887
|
projectRoot: config.Config.projectRoot,
|
|
107
|
-
|
|
888
|
+
appManager: new types_appManager.AppManager(this.algod),
|
|
108
889
|
withSources: true,
|
|
109
890
|
});
|
|
110
891
|
}
|
|
@@ -132,6 +913,8 @@ class ApplicationClient {
|
|
|
132
913
|
this._clearSourceMap = new SourceMap(sourceMaps.clearSourceMap);
|
|
133
914
|
}
|
|
134
915
|
/**
|
|
916
|
+
* @deprecated Use `deploy` from an `AppFactory` instance instead.
|
|
917
|
+
*
|
|
135
918
|
* 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
919
|
*
|
|
137
920
|
* 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 +1000,8 @@ class ApplicationClient {
|
|
|
217
1000
|
}
|
|
218
1001
|
}
|
|
219
1002
|
/**
|
|
1003
|
+
* @deprecated Use `create` from an `AppFactory` instance instead.
|
|
1004
|
+
*
|
|
220
1005
|
* Creates a smart contract app, returns the details of the created app.
|
|
221
1006
|
* @param create The parameters to create the app with
|
|
222
1007
|
* @returns The details of the created app, or the transaction to create it if `skipSending` and the compilation result
|
|
@@ -261,6 +1046,8 @@ class ApplicationClient {
|
|
|
261
1046
|
}
|
|
262
1047
|
}
|
|
263
1048
|
/**
|
|
1049
|
+
* @deprecated Use `appClient.send.update` or `appClient.transactions.update` from an `AppClient` instance instead.
|
|
1050
|
+
*
|
|
264
1051
|
* Updates the smart contract app.
|
|
265
1052
|
* @param update The parameters to update the app with
|
|
266
1053
|
* @returns The transaction send result and the compilation result
|
|
@@ -293,6 +1080,8 @@ class ApplicationClient {
|
|
|
293
1080
|
}
|
|
294
1081
|
}
|
|
295
1082
|
/**
|
|
1083
|
+
* @deprecated Use `appClient.send.call` or `appClient.transactions.call` from an `AppClient` instance instead.
|
|
1084
|
+
*
|
|
296
1085
|
* Issues a no_op (normal) call to the app.
|
|
297
1086
|
* @param call The call details.
|
|
298
1087
|
* @returns The result of the call
|
|
@@ -326,6 +1115,8 @@ class ApplicationClient {
|
|
|
326
1115
|
return await this.callOfType(call, 'no_op');
|
|
327
1116
|
}
|
|
328
1117
|
/**
|
|
1118
|
+
* @deprecated Use `appClient.send.optIn` or `appClient.transactions.optIn` from an `AppClient` instance instead.
|
|
1119
|
+
*
|
|
329
1120
|
* Issues a opt_in call to the app.
|
|
330
1121
|
* @param call The call details.
|
|
331
1122
|
* @returns The result of the call
|
|
@@ -334,6 +1125,8 @@ class ApplicationClient {
|
|
|
334
1125
|
return await this.callOfType(call, 'opt_in');
|
|
335
1126
|
}
|
|
336
1127
|
/**
|
|
1128
|
+
* @deprecated Use `appClient.send.closeOut` or `appClient.transactions.closeOut` from an `AppClient` instance instead.
|
|
1129
|
+
*
|
|
337
1130
|
* Issues a close_out call to the app.
|
|
338
1131
|
* @param call The call details.
|
|
339
1132
|
* @returns The result of the call
|
|
@@ -342,6 +1135,8 @@ class ApplicationClient {
|
|
|
342
1135
|
return await this.callOfType(call, 'close_out');
|
|
343
1136
|
}
|
|
344
1137
|
/**
|
|
1138
|
+
* @deprecated Use `appClient.send.clearState` or `appClient.transactions.clearState` from an `AppClient` instance instead.
|
|
1139
|
+
*
|
|
345
1140
|
* Issues a clear_state call to the app.
|
|
346
1141
|
* @param call The call details.
|
|
347
1142
|
* @returns The result of the call
|
|
@@ -350,6 +1145,8 @@ class ApplicationClient {
|
|
|
350
1145
|
return await this.callOfType(call, 'clear_state');
|
|
351
1146
|
}
|
|
352
1147
|
/**
|
|
1148
|
+
* @deprecated Use `appClient.send.delete` or `appClient.transactions.delete` from an `AppClient` instance instead.
|
|
1149
|
+
*
|
|
353
1150
|
* Issues a delete_application call to the app.
|
|
354
1151
|
* @param call The call details.
|
|
355
1152
|
* @returns The result of the call
|
|
@@ -358,6 +1155,8 @@ class ApplicationClient {
|
|
|
358
1155
|
return await this.callOfType(call, 'delete_application');
|
|
359
1156
|
}
|
|
360
1157
|
/**
|
|
1158
|
+
* @deprecated Use `appClient.send.call` or `appClient.transactions.call` from an `AppClient` instance instead.
|
|
1159
|
+
*
|
|
361
1160
|
* Issues a call to the app with the given call type.
|
|
362
1161
|
* @param call The call details.
|
|
363
1162
|
* @param callType The call type
|
|
@@ -500,6 +1299,8 @@ class ApplicationClient {
|
|
|
500
1299
|
})));
|
|
501
1300
|
}
|
|
502
1301
|
/**
|
|
1302
|
+
* @deprecated Use `appClient.params.*` from an `AppClient` instance instead.
|
|
1303
|
+
*
|
|
503
1304
|
* Returns the arguments for an app call for the given ABI method or raw method specification.
|
|
504
1305
|
* @param args The call args specific to this application client
|
|
505
1306
|
* @param sender The sender of this call. Will be used to fetch any default argument values if applicable
|
|
@@ -557,6 +1358,8 @@ class ApplicationClient {
|
|
|
557
1358
|
}
|
|
558
1359
|
}
|
|
559
1360
|
/**
|
|
1361
|
+
* @deprecated Use `appClient.getABIMethod` instead.
|
|
1362
|
+
*
|
|
560
1363
|
* Returns the ABI Method parameters for the given method name string for the app represented by this application client instance
|
|
561
1364
|
* @param method Either the name of the method or the ABI method spec definition string
|
|
562
1365
|
* @returns The ABI method params for the given method
|
|
@@ -583,6 +1386,8 @@ class ApplicationClient {
|
|
|
583
1386
|
return methodParams ? new ABIMethod(methodParams) : undefined;
|
|
584
1387
|
}
|
|
585
1388
|
/**
|
|
1389
|
+
* @deprecated Use `appClient.appId` and `appClient.appAddress` from an `AppClient` instance instead.
|
|
1390
|
+
*
|
|
586
1391
|
* Gets the reference information for the current application instance.
|
|
587
1392
|
* `appId` will be 0 if it can't find an app.
|
|
588
1393
|
* @returns The app reference, or if deployed using the `deploy` method, the app metadata too
|
|
@@ -633,5 +1438,6 @@ class ApplicationClient {
|
|
|
633
1438
|
}
|
|
634
1439
|
}
|
|
635
1440
|
|
|
1441
|
+
exports.AppClient = AppClient;
|
|
636
1442
|
exports.ApplicationClient = ApplicationClient;
|
|
637
1443
|
//# sourceMappingURL=app-client.js.map
|