@algorandfoundation/algokit-utils 7.0.0-beta.1 → 7.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/account/account.d.ts +7 -7
- package/account/account.js +7 -7
- package/account/account.mjs +7 -7
- package/account/get-account.d.ts +2 -2
- package/account/get-account.js +1 -1
- package/account/get-account.mjs +1 -1
- package/account/get-dispenser-account.d.ts +1 -1
- package/account/get-dispenser-account.js +1 -1
- package/account/get-dispenser-account.mjs +1 -1
- package/account/mnemonic-account.d.ts +1 -1
- package/account/mnemonic-account.js +1 -1
- package/account/mnemonic-account.mjs +1 -1
- package/app-deploy.d.ts +18 -1
- package/app-deploy.d.ts.map +1 -1
- package/app-deploy.js +142 -333
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +145 -336
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +38 -1
- package/app.d.ts.map +1 -1
- package/app.js +113 -370
- package/app.js.map +1 -1
- package/app.mjs +114 -371
- package/app.mjs.map +1 -1
- package/asset.d.ts +5 -5
- package/asset.js +5 -5
- package/asset.mjs +5 -5
- package/debugging/debugging.js +2 -2
- package/debugging/debugging.js.map +1 -1
- package/debugging/debugging.mjs +2 -2
- package/debugging/debugging.mjs.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +12 -12
- package/index.mjs +1 -1
- package/localnet/get-kmd-wallet-account.d.ts +1 -1
- package/localnet/get-kmd-wallet-account.js +1 -1
- package/localnet/get-kmd-wallet-account.mjs +1 -1
- package/localnet/get-localnet-dispenser-account.d.ts +1 -1
- package/localnet/get-localnet-dispenser-account.js +1 -1
- package/localnet/get-localnet-dispenser-account.mjs +1 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts +1 -1
- package/localnet/get-or-create-kmd-wallet-account.js +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs +1 -1
- package/localnet/is-localnet.d.ts +1 -1
- package/localnet/is-localnet.js +1 -1
- package/localnet/is-localnet.mjs +1 -1
- package/network-client.d.ts +2 -2
- package/network-client.d.ts.map +1 -1
- package/network-client.js +2 -2
- package/network-client.mjs +2 -2
- package/package.json +1 -1
- package/testing/fixtures/algorand-fixture.js +12 -12
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +12 -12
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/transaction/legacy-bridge.d.ts +31 -5
- package/transaction/legacy-bridge.d.ts.map +1 -1
- package/transaction/legacy-bridge.js +99 -5
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +98 -7
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transfer/transfer-algos.d.ts +1 -1
- package/transfer/transfer-algos.js +1 -1
- package/transfer/transfer-algos.mjs +1 -1
- package/transfer/transfer.d.ts +1 -1
- package/transfer/transfer.js +1 -1
- package/transfer/transfer.mjs +1 -1
- package/types/account-manager.d.ts +1 -1
- package/types/account-manager.d.ts.map +1 -1
- package/types/algorand-client-transaction-creator.d.ts +450 -20
- package/types/algorand-client-transaction-creator.d.ts.map +1 -1
- package/types/algorand-client-transaction-creator.js +406 -22
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +406 -22
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +750 -24
- package/types/algorand-client-transaction-sender.d.ts.map +1 -1
- package/types/algorand-client-transaction-sender.js +426 -12
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +426 -12
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +8 -0
- package/types/algorand-client.d.ts.map +1 -1
- package/types/algorand-client.js +14 -1
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +14 -1
- package/types/algorand-client.mjs.map +1 -1
- package/types/app-client.d.ts +13 -1
- package/types/app-client.d.ts.map +1 -1
- package/types/app-client.js +8 -5
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +9 -6
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +121 -0
- package/types/app-deployer.d.ts.map +1 -0
- package/types/app-deployer.js +354 -0
- package/types/app-deployer.js.map +1 -0
- package/types/app-deployer.mjs +352 -0
- package/types/app-deployer.mjs.map +1 -0
- package/types/app-manager.d.ts +235 -0
- package/types/app-manager.d.ts.map +1 -0
- package/types/app-manager.js +336 -0
- package/types/app-manager.js.map +1 -0
- package/types/app-manager.mjs +334 -0
- package/types/app-manager.mjs.map +1 -0
- package/types/app.d.ts +42 -7
- package/types/app.d.ts.map +1 -1
- package/types/app.js +1 -1
- package/types/app.js.map +1 -1
- package/types/app.mjs +1 -1
- package/types/app.mjs.map +1 -1
- package/types/client-manager.d.ts +2 -0
- package/types/client-manager.d.ts.map +1 -1
- package/types/client-manager.js +4 -0
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +4 -0
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +150 -39
- package/types/composer.d.ts.map +1 -1
- package/types/composer.js +218 -62
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +218 -62
- package/types/composer.mjs.map +1 -1
- package/types/expand.d.ts +8 -0
- package/types/expand.d.ts.map +1 -0
- package/types/expand.js +3 -0
- package/types/expand.js.map +1 -0
- package/types/expand.mjs +2 -0
- package/types/expand.mjs.map +1 -0
- package/types/transaction.d.ts +3 -0
- package/types/transaction.d.ts.map +1 -1
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var algosdk = require('algosdk');
|
|
4
|
+
var types_app = require('./app.js');
|
|
5
|
+
|
|
6
|
+
var modelsv2 = algosdk.modelsv2;
|
|
7
|
+
/** Allows management of application information. */
|
|
8
|
+
class AppManager {
|
|
9
|
+
/**
|
|
10
|
+
* Creates an `AppManager`
|
|
11
|
+
* @param algod An algod instance
|
|
12
|
+
*/
|
|
13
|
+
constructor(algod) {
|
|
14
|
+
this._compilationResults = {};
|
|
15
|
+
this._algod = algod;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Compiles the given TEAL using algod and returns the result, including source map.
|
|
19
|
+
*
|
|
20
|
+
* The result of this compilation is also cached keyed by the TEAL
|
|
21
|
+
* code so it can be retrieved via `getCompilationResult`.
|
|
22
|
+
*
|
|
23
|
+
* This function is re-entrant; it will only compile the same code once.
|
|
24
|
+
*
|
|
25
|
+
* @param tealCode The TEAL code
|
|
26
|
+
* @returns The information about the compiled file
|
|
27
|
+
*/
|
|
28
|
+
async compileTeal(tealCode) {
|
|
29
|
+
if (this._compilationResults[tealCode]) {
|
|
30
|
+
return this._compilationResults[tealCode];
|
|
31
|
+
}
|
|
32
|
+
const compiled = await this._algod.compile(tealCode).sourcemap(true).do();
|
|
33
|
+
const result = {
|
|
34
|
+
teal: tealCode,
|
|
35
|
+
compiled: compiled.result,
|
|
36
|
+
compiledHash: compiled.hash,
|
|
37
|
+
compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),
|
|
38
|
+
sourceMap: new algosdk.SourceMap(compiled['sourcemap']),
|
|
39
|
+
};
|
|
40
|
+
this._compilationResults[tealCode] = result;
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Performs template substitution of a teal template and compiles it, returning the compiled result.
|
|
45
|
+
*
|
|
46
|
+
* Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters
|
|
47
|
+
* if deployment metadata is specified.
|
|
48
|
+
*
|
|
49
|
+
* * `TMPL_UPDATABLE` for updatability / immutability control
|
|
50
|
+
* * `TMPL_DELETABLE` for deletability / permanence control
|
|
51
|
+
*
|
|
52
|
+
* @param tealTemplateCode The TEAL logic to compile
|
|
53
|
+
* @param templateParams Any parameters to replace in the .teal file before compiling
|
|
54
|
+
* @param deploymentMetadata The deployment metadata the app will be deployed with
|
|
55
|
+
* @returns The information about the compiled code
|
|
56
|
+
*/
|
|
57
|
+
async compileTealTemplate(tealTemplateCode, templateParams, deploymentMetadata) {
|
|
58
|
+
let tealCode = AppManager.stripTealComments(tealTemplateCode);
|
|
59
|
+
tealCode = AppManager.replaceTealTemplateParams(tealCode, templateParams);
|
|
60
|
+
if (deploymentMetadata) {
|
|
61
|
+
tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealCode, deploymentMetadata);
|
|
62
|
+
}
|
|
63
|
+
return await this.compileTeal(tealCode);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns a previous compilation result.
|
|
67
|
+
* @param tealCode The TEAL code
|
|
68
|
+
* @returns The information about the previously compiled file
|
|
69
|
+
* or `undefined` if that TEAL code wasn't previously compiled
|
|
70
|
+
*/
|
|
71
|
+
getCompilationResult(tealCode) {
|
|
72
|
+
return this._compilationResults[tealCode];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Returns the current app information for the app with the given ID.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const appInfo = await appManager.getById(12353n);
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param appId The ID of the app
|
|
83
|
+
* @returns The app information
|
|
84
|
+
*/
|
|
85
|
+
async getById(appId) {
|
|
86
|
+
const app = modelsv2.Application.from_obj_for_encoding(await this._algod.getApplicationByID(Number(appId)).do());
|
|
87
|
+
return {
|
|
88
|
+
appId: BigInt(app.id),
|
|
89
|
+
appAddress: algosdk.getApplicationAddress(app.id),
|
|
90
|
+
approvalProgram: app.params.approvalProgram,
|
|
91
|
+
clearStateProgram: app.params.clearStateProgram,
|
|
92
|
+
creator: app.params.creator,
|
|
93
|
+
localInts: Number(app.params.localStateSchema?.numUint ?? 0),
|
|
94
|
+
localByteSlices: Number(app.params.localStateSchema?.numByteSlice ?? 0),
|
|
95
|
+
globalInts: Number(app.params.globalStateSchema?.numUint ?? 0),
|
|
96
|
+
globalByteSlices: Number(app.params.globalStateSchema?.numByteSlice ?? 0),
|
|
97
|
+
extraProgramPages: Number(app.params.extraProgramPages ?? 0),
|
|
98
|
+
globalState: AppManager.decodeAppState(app.params.globalState ?? []),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns the current local state values for the given app ID and account address
|
|
103
|
+
*
|
|
104
|
+
* @param appId The ID of the app to return local state for
|
|
105
|
+
* @param address The string address of the account to get local state for the given app
|
|
106
|
+
* @returns The current local state for the given (app, account) combination
|
|
107
|
+
*/
|
|
108
|
+
async getLocalState(appId, address) {
|
|
109
|
+
const appInfo = modelsv2.AccountApplicationResponse.from_obj_for_encoding(await this._algod.accountApplicationInformation(address, Number(appId)).do());
|
|
110
|
+
if (!appInfo.appLocalState?.keyValue) {
|
|
111
|
+
throw new Error("Couldn't find local state");
|
|
112
|
+
}
|
|
113
|
+
return AppManager.decodeAppState(appInfo.appLocalState.keyValue);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns the names of the current boxes for the given app.
|
|
117
|
+
* @param appId The ID of the app return box names for
|
|
118
|
+
* @returns The current box names
|
|
119
|
+
*/
|
|
120
|
+
async getBoxNames(appId) {
|
|
121
|
+
const boxResult = await this._algod.getApplicationBoxes(Number(appId)).do();
|
|
122
|
+
return boxResult.boxes.map((b) => {
|
|
123
|
+
return {
|
|
124
|
+
nameRaw: b.name,
|
|
125
|
+
nameBase64: Buffer.from(b.name).toString('base64'),
|
|
126
|
+
name: Buffer.from(b.name).toString('utf-8'),
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Returns the value of the given box name for the given app.
|
|
132
|
+
* @param appId The ID of the app return box names for
|
|
133
|
+
* @param boxName The name of the box to return either as a string, binary array or `BoxName`
|
|
134
|
+
* @returns The current box value as a byte array
|
|
135
|
+
*/
|
|
136
|
+
async getBoxValue(appId, boxName) {
|
|
137
|
+
const name = AppManager.getBoxReference(boxName).name;
|
|
138
|
+
const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do();
|
|
139
|
+
return boxResult.value;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Returns the value of the given box names for the given app.
|
|
143
|
+
* @param appId The ID of the app return box names for
|
|
144
|
+
* @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`
|
|
145
|
+
* @returns The current box values as a byte array in the same order as the passed in box names
|
|
146
|
+
*/
|
|
147
|
+
async getBoxValues(appId, boxNames) {
|
|
148
|
+
return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValue(appId, boxName)));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns the value of the given box name for the given app decoded based on the given ABI type.
|
|
152
|
+
* @param request The parameters for the box value request
|
|
153
|
+
* @returns The current box value as an ABI value
|
|
154
|
+
*/
|
|
155
|
+
async getBoxValueFromABIType(request) {
|
|
156
|
+
const { appId, boxName, type } = request;
|
|
157
|
+
const value = await this.getBoxValue(appId, boxName);
|
|
158
|
+
return type.decode(value);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns the value of the given box names for the given app decoded based on the given ABI type.
|
|
162
|
+
* @param request The parameters for the box value request
|
|
163
|
+
* @returns The current box values as an ABI value in the same order as the passed in box names
|
|
164
|
+
*/
|
|
165
|
+
async getBoxValuesFromABIType(request) {
|
|
166
|
+
const { appId, boxNames, type } = request;
|
|
167
|
+
return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValueFromABIType({ appId, boxName, type })));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.
|
|
171
|
+
* @param boxId The box to return a reference for
|
|
172
|
+
* @returns The box reference ready to pass into a `algosdk.Transaction`
|
|
173
|
+
*/
|
|
174
|
+
static getBoxReference(boxId) {
|
|
175
|
+
const ref = typeof boxId === 'object' && 'appId' in boxId ? boxId : { appId: 0n, name: boxId };
|
|
176
|
+
return {
|
|
177
|
+
appIndex: Number(ref.appId),
|
|
178
|
+
name: typeof ref.name === 'string'
|
|
179
|
+
? new TextEncoder().encode(ref.name)
|
|
180
|
+
: 'length' in ref.name
|
|
181
|
+
? ref.name
|
|
182
|
+
: algosdk.decodeAddress(ref.name.addr).publicKey,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Converts an array of global/local state values from the algod api to a more friendly
|
|
187
|
+
* generic object keyed by the UTF-8 value of the key.
|
|
188
|
+
* @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`
|
|
189
|
+
* @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values
|
|
190
|
+
*/
|
|
191
|
+
static decodeAppState(state) {
|
|
192
|
+
const stateValues = {};
|
|
193
|
+
// Start with empty set
|
|
194
|
+
for (const stateVal of state) {
|
|
195
|
+
const keyBase64 = stateVal.key;
|
|
196
|
+
const keyRaw = Buffer.from(keyBase64, 'base64');
|
|
197
|
+
const key = keyRaw.toString('utf-8');
|
|
198
|
+
const tealValue = stateVal.value;
|
|
199
|
+
const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type;
|
|
200
|
+
let valueBase64;
|
|
201
|
+
let valueRaw;
|
|
202
|
+
switch (dataTypeFlag) {
|
|
203
|
+
case 1:
|
|
204
|
+
valueBase64 = tealValue.bytes ?? '';
|
|
205
|
+
valueRaw = Buffer.from(valueBase64, 'base64');
|
|
206
|
+
stateValues[key] = {
|
|
207
|
+
keyRaw,
|
|
208
|
+
keyBase64,
|
|
209
|
+
valueRaw: new Uint8Array(valueRaw),
|
|
210
|
+
valueBase64: valueBase64,
|
|
211
|
+
value: valueRaw.toString('utf-8'),
|
|
212
|
+
};
|
|
213
|
+
break;
|
|
214
|
+
case 2: {
|
|
215
|
+
const value = tealValue.uint ?? 0;
|
|
216
|
+
stateValues[key] = {
|
|
217
|
+
keyRaw,
|
|
218
|
+
keyBase64,
|
|
219
|
+
value,
|
|
220
|
+
};
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
default:
|
|
224
|
+
throw new Error(`Received unknown state data type of ${dataTypeFlag}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return stateValues;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Returns any ABI return values for the given app call arguments and transaction confirmation.
|
|
231
|
+
* @param confirmation The transaction confirmation from algod
|
|
232
|
+
* @param method The ABI method
|
|
233
|
+
* @returns The return value for the method call
|
|
234
|
+
*/
|
|
235
|
+
static getABIReturn(confirmation, method) {
|
|
236
|
+
if (!method || !confirmation || method.returns.type === 'void') {
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
// The parseMethodResponse method mutates the second parameter :(
|
|
240
|
+
const resultDummy = {
|
|
241
|
+
txID: '',
|
|
242
|
+
method,
|
|
243
|
+
rawReturnValue: new Uint8Array(),
|
|
244
|
+
};
|
|
245
|
+
const response = algosdk.AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation);
|
|
246
|
+
return !response.decodeError
|
|
247
|
+
? {
|
|
248
|
+
rawReturnValue: response.rawReturnValue,
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
250
|
+
returnValue: response.returnValue,
|
|
251
|
+
decodeError: undefined,
|
|
252
|
+
}
|
|
253
|
+
: {
|
|
254
|
+
rawReturnValue: undefined,
|
|
255
|
+
returnValue: undefined,
|
|
256
|
+
decodeError: response.decodeError,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.
|
|
261
|
+
*
|
|
262
|
+
* * `TMPL_UPDATABLE` for updatability / immutability control
|
|
263
|
+
* * `TMPL_DELETABLE` for deletability / permanence control
|
|
264
|
+
*
|
|
265
|
+
* Note: If these values are defined, but the corresponding `TMPL_*` value
|
|
266
|
+
* isn't in the teal code it will throw an exception.
|
|
267
|
+
*
|
|
268
|
+
* @param tealTemplateCode The TEAL template code to substitute
|
|
269
|
+
* @param params The deploy-time deployment control parameter value to replace
|
|
270
|
+
* @returns The replaced TEAL code
|
|
271
|
+
*/
|
|
272
|
+
static replaceTealTemplateDeployTimeControlParams(tealTemplateCode, params) {
|
|
273
|
+
if (params.updatable !== undefined) {
|
|
274
|
+
if (!tealTemplateCode.includes(types_app.UPDATABLE_TEMPLATE_NAME)) {
|
|
275
|
+
throw new Error(`Deploy-time updatability control requested for app deployment, but ${types_app.UPDATABLE_TEMPLATE_NAME} not present in TEAL code`);
|
|
276
|
+
}
|
|
277
|
+
tealTemplateCode = tealTemplateCode.replace(new RegExp(types_app.UPDATABLE_TEMPLATE_NAME, 'g'), (params.updatable ? 1 : 0).toString());
|
|
278
|
+
}
|
|
279
|
+
if (params.deletable !== undefined) {
|
|
280
|
+
if (!tealTemplateCode.includes(types_app.DELETABLE_TEMPLATE_NAME)) {
|
|
281
|
+
throw new Error(`Deploy-time deletability control requested for app deployment, but ${types_app.DELETABLE_TEMPLATE_NAME} not present in TEAL code`);
|
|
282
|
+
}
|
|
283
|
+
tealTemplateCode = tealTemplateCode.replace(new RegExp(types_app.DELETABLE_TEMPLATE_NAME, 'g'), (params.deletable ? 1 : 0).toString());
|
|
284
|
+
}
|
|
285
|
+
return tealTemplateCode;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Performs template substitution of a teal file.
|
|
289
|
+
*
|
|
290
|
+
* Looks for `TMPL_{parameter}` for template replacements.
|
|
291
|
+
*
|
|
292
|
+
* @param tealTemplateCode The TEAL template code to make parameter replacements in
|
|
293
|
+
* @param templateParams Any parameters to replace in the teal code
|
|
294
|
+
* @returns The TEAL code with replacements
|
|
295
|
+
*/
|
|
296
|
+
static replaceTealTemplateParams(tealTemplateCode, templateParams) {
|
|
297
|
+
if (templateParams !== undefined) {
|
|
298
|
+
for (const key in templateParams) {
|
|
299
|
+
const value = templateParams[key];
|
|
300
|
+
const token = `TMPL_${key.replace(/^TMPL_/, '')}`;
|
|
301
|
+
// If this is a number, first replace any byte representations of the number
|
|
302
|
+
// These may appear in the TEAL in order to circumvent int compression and preserve PC values
|
|
303
|
+
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
304
|
+
tealTemplateCode = tealTemplateCode.replace(new RegExp(`(?<=bytes )${token}`, 'g'), `0x${value.toString(16).padStart(16, '0')}`);
|
|
305
|
+
// We could probably return here since mixing pushint and pushbytes is likely not going to happen, but might as well do both
|
|
306
|
+
}
|
|
307
|
+
tealTemplateCode = tealTemplateCode.replace(new RegExp(token, 'g'), typeof value === 'string'
|
|
308
|
+
? `0x${Buffer.from(value, 'utf-8').toString('hex')}`
|
|
309
|
+
: ArrayBuffer.isView(value)
|
|
310
|
+
? `0x${Buffer.from(value).toString('hex')}`
|
|
311
|
+
: value.toString());
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return tealTemplateCode;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Remove comments from TEAL code (useful to reduce code size before compilation).
|
|
318
|
+
*
|
|
319
|
+
* @param tealCode The TEAL logic to strip
|
|
320
|
+
* @returns The TEAL without comments
|
|
321
|
+
*/
|
|
322
|
+
static stripTealComments(tealCode) {
|
|
323
|
+
// find // outside quotes, i.e. won't pick up "//not a comment"
|
|
324
|
+
const regex = /\/\/(?=([^"\\]*(\\.|"([^"\\]*\\.)*[^"\\]*"))*[^"]*$)/;
|
|
325
|
+
tealCode = tealCode
|
|
326
|
+
.split('\n')
|
|
327
|
+
.map((tealCodeLine) => {
|
|
328
|
+
return tealCodeLine.split(regex)[0].trim();
|
|
329
|
+
})
|
|
330
|
+
.join('\n');
|
|
331
|
+
return tealCode;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
exports.AppManager = AppManager;
|
|
336
|
+
//# sourceMappingURL=app-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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