Comparing version 0.0.33 to 0.0.34
@@ -1,4 +0,4 @@ | ||
import algosdk, { AtomicTransactionComposer } from "algosdk"; | ||
import { Schema } from "../"; | ||
import { ApplicationState, AccountState } from "./state"; | ||
import algosdk, { AtomicTransactionComposer } from 'algosdk'; | ||
import { Schema } from '../'; | ||
import { ApplicationState, AccountState } from './state'; | ||
export declare type MethodArg = algosdk.ABIArgument | algosdk.Transaction | object | MethodArg[]; | ||
@@ -8,2 +8,7 @@ export declare type MethodArgs = Record<string, MethodArg>; | ||
export declare type TransactionOverrides = Partial<algosdk.TransactionParams>; | ||
export declare type TransactionResult = { | ||
confirmedRound: number; | ||
txIDs: string[]; | ||
methodResults: algosdk.ABIResult[]; | ||
}; | ||
export declare function decodeNamedTuple(v: algosdk.ABIValue | undefined, keys: string[]): object; | ||
@@ -19,3 +24,3 @@ export interface InnerTransaction { | ||
method: algosdk.ABIMethod; | ||
txInfo: Record<string, any> | undefined; | ||
txInfo: Record<string, unknown> | undefined; | ||
returnValue: algosdk.ABIValue | undefined; | ||
@@ -51,27 +56,7 @@ decodeError: Error | undefined; | ||
create(txParams?: TransactionOverrides): Promise<[number, string, string]>; | ||
delete(txParams?: TransactionOverrides): Promise<{ | ||
confirmedRound: number; | ||
txIDs: string[]; | ||
methodResults: algosdk.ABIResult[]; | ||
}>; | ||
update(txParams?: TransactionOverrides): Promise<{ | ||
confirmedRound: number; | ||
txIDs: string[]; | ||
methodResults: algosdk.ABIResult[]; | ||
}>; | ||
optIn(txParams?: TransactionOverrides): Promise<{ | ||
confirmedRound: number; | ||
txIDs: string[]; | ||
methodResults: algosdk.ABIResult[]; | ||
}>; | ||
closeOut(txParams?: TransactionOverrides): Promise<{ | ||
confirmedRound: number; | ||
txIDs: string[]; | ||
methodResults: algosdk.ABIResult[]; | ||
}>; | ||
clearState(txParams?: TransactionOverrides): Promise<{ | ||
confirmedRound: number; | ||
txIDs: string[]; | ||
methodResults: algosdk.ABIResult[]; | ||
}>; | ||
delete(txParams?: TransactionOverrides): Promise<TransactionResult>; | ||
update(txParams?: TransactionOverrides): Promise<TransactionResult>; | ||
optIn(txParams?: TransactionOverrides): Promise<TransactionResult>; | ||
closeOut(txParams?: TransactionOverrides): Promise<TransactionResult>; | ||
clearState(txParams?: TransactionOverrides): Promise<TransactionResult>; | ||
execute(atc: AtomicTransactionComposer): Promise<algosdk.ABIResult>; | ||
@@ -78,0 +63,0 @@ addMethodCall(method: algosdk.ABIMethod, args?: MethodArgs, txParams?: TransactionOverrides, atc?: algosdk.AtomicTransactionComposer): Promise<algosdk.AtomicTransactionComposer>; |
@@ -82,5 +82,5 @@ "use strict"; | ||
if (!Array.isArray(v)) | ||
throw Error("Expected array"); | ||
throw Error('Expected array'); | ||
if (v.length != keys.length) | ||
throw Error("Different key length than value length"); | ||
throw Error('Different key length than value length'); | ||
return Object.fromEntries(keys.map(function (key, idx) { | ||
@@ -100,13 +100,14 @@ return [key, v[idx]]; | ||
this.inners = []; | ||
if ((result === null || result === void 0 ? void 0 : result.txInfo) !== undefined && "inner-txns" in result.txInfo) { | ||
if ((result === null || result === void 0 ? void 0 : result.txInfo) !== undefined && 'inner-txns' in result.txInfo) { | ||
// TODO: this only parses 1 level deep | ||
var outer_1 = result.txInfo["txn"]["txn"]; | ||
this.inners = result.txInfo["inner-txns"].map(function (itxn) { | ||
var et = itxn["txn"]["txn"]; | ||
var outer_1 = result.txInfo['txn']['txn']; | ||
// eslint-disable-next-line | ||
this.inners = result.txInfo['inner-txns'].map(function (itxn) { | ||
var et = itxn['txn']['txn']; | ||
et.gen = outer_1.gen; | ||
et.gh = outer_1.gh; | ||
return { | ||
createdAsset: itxn["asset-index"], | ||
createdApp: itxn["application-index"], | ||
txn: algosdk_1.default.Transaction.from_obj_for_encoding(itxn["txn"]["txn"]), | ||
createdAsset: itxn['asset-index'], | ||
createdApp: itxn['application-index'], | ||
txn: algosdk_1.default.Transaction.from_obj_for_encoding(itxn['txn']['txn']), | ||
}; | ||
@@ -129,3 +130,3 @@ }); | ||
this.appId = 0; | ||
this.appAddress = ""; | ||
this.appAddress = ''; | ||
} | ||
@@ -144,4 +145,4 @@ this.sender = opts.sender; | ||
return [2 /*return*/, [ | ||
new Uint8Array(Buffer.from(result["result"], "base64")), | ||
new algosdk_1.default.SourceMap(result["sourcemap"]), | ||
new Uint8Array(Buffer.from(result['result'], 'base64')), | ||
new algosdk_1.default.SourceMap(result['sourcemap']), | ||
]]; | ||
@@ -159,5 +160,5 @@ } | ||
if (this.approvalProgram === undefined || this.clearProgram === undefined) | ||
throw Error("no approval or clear program defined"); | ||
throw Error('no approval or clear program defined'); | ||
if (!(this.approvalProgramBinary === undefined)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.compile(Buffer.from(this.approvalProgram, "base64").toString())]; | ||
return [4 /*yield*/, this.compile(Buffer.from(this.approvalProgram, 'base64').toString())]; | ||
case 1: | ||
@@ -170,3 +171,3 @@ _a = _c.sent(), appBin = _a[0], appMap = _a[1]; | ||
if (!(this.clearProgramBinary === undefined)) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, this.compile(Buffer.from(this.clearProgram, "base64").toString())]; | ||
return [4 /*yield*/, this.compile(Buffer.from(this.clearProgram, 'base64').toString())]; | ||
case 3: | ||
@@ -192,5 +193,5 @@ _b = _c.sent(), clearBin = _b[0], clearMap = _b[1]; | ||
this.clearProgramBinary === undefined) | ||
throw Error("no approval or clear program binaries defined"); | ||
throw Error('no approval or clear program binaries defined'); | ||
if (this.signer === undefined) | ||
throw Error("no signer defined"); | ||
throw Error('no signer defined'); | ||
return [4 /*yield*/, this.getSuggestedParams(txParams)]; | ||
@@ -212,7 +213,7 @@ case 2: | ||
if (txid === undefined) | ||
throw new Error("No transaction id returned from execute"); | ||
throw new Error('No transaction id returned from execute'); | ||
return [4 /*yield*/, this.client.pendingTransactionInformation(txid).do()]; | ||
case 5: | ||
txinfo = _a.sent(); | ||
this.appId = txinfo["application-index"]; | ||
this.appId = txinfo['application-index']; | ||
this.appAddress = algosdk_1.default.getApplicationAddress(this.appId); | ||
@@ -230,3 +231,3 @@ return [2 /*return*/, [this.appId, this.appAddress, txid]]; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var sp, atc, e_2; | ||
var sp, atc; | ||
return __generator(this, function (_a) { | ||
@@ -236,3 +237,3 @@ switch (_a.label) { | ||
if (this.signer === undefined) | ||
throw Error("no signer defined"); | ||
throw Error('no signer defined'); | ||
return [4 /*yield*/, this.getSuggestedParams(txParams)]; | ||
@@ -246,11 +247,9 @@ case 1: | ||
}); | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 4, , 5]); | ||
return [4 /*yield*/, atc.execute(this.client, 4)]; | ||
case 3: return [2 /*return*/, _a.sent()]; | ||
case 4: | ||
e_2 = _a.sent(); | ||
throw this.wrapLogicError(e_2); | ||
case 5: return [2 /*return*/]; | ||
try { | ||
return [2 /*return*/, atc.execute(this.client, 4)]; | ||
} | ||
catch (e) { | ||
throw this.wrapLogicError(e); | ||
} | ||
return [2 /*return*/]; | ||
} | ||
@@ -262,3 +261,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var sp, atc, e_3; | ||
var sp, atc, e_2; | ||
return __generator(this, function (_a) { | ||
@@ -271,5 +270,5 @@ switch (_a.label) { | ||
this.clearProgramBinary === undefined) | ||
throw Error("no approval or clear program binaries defined"); | ||
throw Error('no approval or clear program binaries defined'); | ||
if (this.signer === undefined) | ||
throw Error("no signer defined"); | ||
throw Error('no signer defined'); | ||
return [4 /*yield*/, this.getSuggestedParams(txParams)]; | ||
@@ -289,4 +288,4 @@ case 2: | ||
case 5: | ||
e_3 = _a.sent(); | ||
throw this.wrapLogicError(e_3); | ||
e_2 = _a.sent(); | ||
throw this.wrapLogicError(e_2); | ||
case 6: return [2 /*return*/]; | ||
@@ -299,3 +298,3 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var sp, atc, e_4; | ||
var sp, atc, e_3; | ||
return __generator(this, function (_a) { | ||
@@ -305,3 +304,3 @@ switch (_a.label) { | ||
if (this.signer === undefined) | ||
throw Error("no signer defined"); | ||
throw Error('no signer defined'); | ||
return [4 /*yield*/, this.getSuggestedParams(txParams)]; | ||
@@ -321,4 +320,4 @@ case 1: | ||
case 4: | ||
e_4 = _a.sent(); | ||
throw this.wrapLogicError(e_4); | ||
e_3 = _a.sent(); | ||
throw this.wrapLogicError(e_3); | ||
case 5: return [2 /*return*/]; | ||
@@ -331,3 +330,3 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var sp, atc, e_5; | ||
var sp, atc, e_4; | ||
return __generator(this, function (_a) { | ||
@@ -337,3 +336,3 @@ switch (_a.label) { | ||
if (this.signer === undefined) | ||
throw Error("no signer defined"); | ||
throw Error('no signer defined'); | ||
return [4 /*yield*/, this.getSuggestedParams(txParams)]; | ||
@@ -353,4 +352,4 @@ case 1: | ||
case 4: | ||
e_5 = _a.sent(); | ||
throw this.wrapLogicError(e_5); | ||
e_4 = _a.sent(); | ||
throw this.wrapLogicError(e_4); | ||
case 5: return [2 /*return*/]; | ||
@@ -363,3 +362,3 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var sp, atc, e_6; | ||
var sp, atc, e_5; | ||
return __generator(this, function (_a) { | ||
@@ -369,3 +368,3 @@ switch (_a.label) { | ||
if (this.signer === undefined) | ||
throw Error("no signer defined"); | ||
throw Error('no signer defined'); | ||
return [4 /*yield*/, this.getSuggestedParams(txParams)]; | ||
@@ -389,4 +388,4 @@ case 1: | ||
case 4: | ||
e_6 = _a.sent(); | ||
throw this.wrapLogicError(e_6); | ||
e_5 = _a.sent(); | ||
throw this.wrapLogicError(e_5); | ||
case 5: return [2 /*return*/]; | ||
@@ -399,3 +398,3 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, e_7; | ||
var result, e_6; | ||
return __generator(this, function (_a) { | ||
@@ -412,4 +411,4 @@ switch (_a.label) { | ||
case 2: | ||
e_7 = _a.sent(); | ||
throw this.wrapLogicError(e_7); | ||
e_6 = _a.sent(); | ||
throw this.wrapLogicError(e_6); | ||
case 3: return [2 /*return*/]; | ||
@@ -430,3 +429,3 @@ } | ||
if (this.signer === undefined) | ||
throw new Error("no signer defined"); | ||
throw new Error('no signer defined'); | ||
return [4 /*yield*/, this.getSuggestedParams(txParams)]; | ||
@@ -453,7 +452,9 @@ case 1: | ||
// TODO: other types? | ||
if (expected_arg.type instanceof algosdk_1.default.ABIAddressType || expected_arg.type == algosdk_1.ABIReferenceType.account) { | ||
if (expected_arg.type instanceof algosdk_1.default.ABIAddressType || | ||
expected_arg.type == algosdk_1.ABIReferenceType.account) { | ||
arg = algosdk_1.default.encodeAddress(arg); | ||
} | ||
} | ||
else if (arg instanceof Object && !algosdk_1.default.isTransactionWithSigner(arg)) { | ||
else if (arg instanceof Object && | ||
!algosdk_1.default.isTransactionWithSigner(arg)) { | ||
arg = Object.values(arg); | ||
@@ -475,3 +476,3 @@ } | ||
if (led.msg !== undefined) | ||
return new logic_error_1.LogicError(led, Buffer.from(this.approvalProgram, "base64").toString().split("\n"), this.approvalProgramMap); | ||
return new logic_error_1.LogicError(led, Buffer.from(this.approvalProgram, 'base64').toString().split('\n'), this.approvalProgramMap); | ||
else | ||
@@ -488,5 +489,5 @@ return e; | ||
switch (_a) { | ||
case "global-state": return [3 /*break*/, 1]; | ||
case "local-state": return [3 /*break*/, 3]; | ||
case "abi-method": return [3 /*break*/, 5]; | ||
case 'global-state': return [3 /*break*/, 1]; | ||
case 'local-state': return [3 /*break*/, 3]; | ||
case 'abi-method': return [3 /*break*/, 5]; | ||
} | ||
@@ -512,3 +513,3 @@ return [3 /*break*/, 7]; | ||
if (this.methods === undefined) | ||
throw new Error("no methods defined, cannot resolve hint"); | ||
throw new Error('no methods defined, cannot resolve hint'); | ||
meth = algosdk_1.default.getMethodByName(this.methods, data); | ||
@@ -544,5 +545,5 @@ _b = this.execute; | ||
appInfo = _a.sent(); | ||
if (!("params" in appInfo) || !("global-state" in appInfo["params"])) | ||
throw new Error("No global state found"); | ||
return [2 /*return*/, (0, state_1.decodeState)(appInfo["params"]["global-state"], raw)]; | ||
if (!('params' in appInfo) || !('global-state' in appInfo['params'])) | ||
throw new Error('No global state found'); | ||
return [2 /*return*/, (0, state_1.decodeState)(appInfo['params']['global-state'], raw)]; | ||
} | ||
@@ -565,6 +566,6 @@ }); | ||
acctInfo = _a.sent(); | ||
if (!("app-local-state" in acctInfo) || | ||
!("key-value" in acctInfo["app-local-state"])) | ||
if (!('app-local-state' in acctInfo) || | ||
!('key-value' in acctInfo['app-local-state'])) | ||
return [2 /*return*/, {}]; | ||
return [2 /*return*/, (0, state_1.decodeState)(acctInfo["app-local-state"]["key-value"], raw)]; | ||
return [2 /*return*/, (0, state_1.decodeState)(acctInfo['app-local-state']['key-value'], raw)]; | ||
} | ||
@@ -579,3 +580,3 @@ }); | ||
if (this.acctSchema === undefined) | ||
throw new Error("No account schema defined"); | ||
throw new Error('No account schema defined'); | ||
var s = (0, __1.getStateSchema)(this.acctSchema); | ||
@@ -586,3 +587,3 @@ return { numLocalInts: s.uints, numLocalByteSlices: s.bytes }; | ||
if (this.appSchema === undefined) | ||
throw new Error("No app schema defined"); | ||
throw new Error('No app schema defined'); | ||
var s = (0, __1.getStateSchema)(this.appSchema); | ||
@@ -589,0 +590,0 @@ return { numGlobalInts: s.uints, numGlobalByteSlices: s.bytes }; |
@@ -27,3 +27,3 @@ "use strict"; | ||
msg: res[2], | ||
pc: parseInt(res[3] ? res[3] : "0"), | ||
pc: parseInt(res[3] ? res[3] : '0'), | ||
}; | ||
@@ -45,6 +45,8 @@ } | ||
var start = _this.teal_line > _this.lines ? _this.teal_line - _this.lines : 0; | ||
var stop_1 = program.length > _this.teal_line + _this.lines ? _this.teal_line + _this.lines : program.length; | ||
var stop_1 = program.length > _this.teal_line + _this.lines | ||
? _this.teal_line + _this.lines | ||
: program.length; | ||
var stack_lines = program.slice(start, stop_1); | ||
stack_lines[stack_lines.length / 2] += " <--- Error"; | ||
_this.stack = stack_lines.join("\n"); | ||
stack_lines[stack_lines.length / 2] += ' <--- Error'; | ||
_this.stack = stack_lines.join('\n'); | ||
} | ||
@@ -51,0 +53,0 @@ return _this; |
@@ -31,13 +31,13 @@ #!/usr/bin/env node | ||
var path = __importStar(require("path")); | ||
var pjson = require("../package.json"); | ||
var pjson = require('../package.json'); // eslint-disable-line | ||
var program = new commander_1.Command(); | ||
program | ||
.name("beaker") | ||
.description("Utilities for working with beaker applications") | ||
.name('beaker') | ||
.description('Utilities for working with beaker applications') | ||
.version(pjson['version']); | ||
program | ||
.command("generate") | ||
.description("Generates an application client given an application spec") | ||
.arguments("<path-to-spec> <path-to-write>") | ||
.option("-l, --local", "whether or not to use local import") | ||
.command('generate') | ||
.description('Generates an application client given an application spec') | ||
.arguments('<path-to-spec> <path-to-write>') | ||
.option('-l, --local', 'whether or not to use local import') | ||
.action(function (specPath, srcPath, options) { | ||
@@ -48,11 +48,11 @@ var importPath = options.local ? '../../src/' : undefined; | ||
if (!fs.lstatSync(srcPath).isDirectory()) { | ||
throw Error("Path argument must be a directory"); | ||
throw Error('Path argument must be a directory'); | ||
} | ||
if (!fs.lstatSync(specPath).isFile()) { | ||
throw Error("Path to spec must be a file"); | ||
throw Error('Path to spec must be a file'); | ||
} | ||
console.log("Writing client to: ".concat(srcPath)); | ||
var jsonObj = JSON.parse(fs.readFileSync(specPath).toString()); | ||
if (!("contract" in jsonObj)) { | ||
jsonObj = { "hints": {}, "source": {}, "schema": {}, "contract": jsonObj }; | ||
if (!('contract' in jsonObj)) { | ||
jsonObj = { hints: {}, source: {}, schema: {}, contract: jsonObj }; | ||
} | ||
@@ -59,0 +59,0 @@ (0, _1.generateApplicationClient)(jsonObj, srcPath, importPath); |
@@ -1,2 +0,2 @@ | ||
import type algosdk from "algosdk"; | ||
import type algosdk from 'algosdk'; | ||
export declare enum AVMType { | ||
@@ -3,0 +3,0 @@ uint64 = 0, |
@@ -1,2 +0,2 @@ | ||
import type { AppSpec } from "./appspec"; | ||
import type { AppSpec } from './appspec'; | ||
export declare function generateApplicationClient(appSpec: AppSpec, path: string, beakerPath?: string): void; |
@@ -44,40 +44,40 @@ "use strict"; | ||
// https://ts-ast-viewer.com/# | ||
var CLIENT_NAME = "bkr.ApplicationClient"; | ||
var CLIENT_NAME = 'bkr.ApplicationClient'; | ||
// TODO: only import if we _need_ them | ||
var CLIENT_IMPORTS = "* as bkr"; | ||
var CLIENT_PATH = "beaker-ts"; | ||
var ALGOSDK_IMPORTS = "algosdk"; | ||
var ALGOSDK_PATH = "algosdk"; | ||
var REF_TYPES = ["account", "application", "asset"]; | ||
var CLIENT_PATH = 'beaker-ts'; | ||
var ALGOSDK_IMPORTS = 'algosdk'; | ||
var ALGOSDK_PATH = 'algosdk'; | ||
var REF_TYPES = ['account', 'application', 'asset']; | ||
var TXN_TYPES = [ | ||
"txn", | ||
"pay", | ||
"axfer", | ||
"acfg", | ||
"appl", | ||
"keyreg", | ||
"frz", | ||
'txn', | ||
'pay', | ||
'axfer', | ||
'acfg', | ||
'appl', | ||
'keyreg', | ||
'frz', | ||
]; | ||
// native types | ||
var UINT8_ARRAY_IDENT = typescript_1.factory.createIdentifier("Uint8Array"); | ||
var UINT8_ARRAY_IDENT = typescript_1.factory.createIdentifier('Uint8Array'); | ||
var UINT8_ARRAY_TYPE = typescript_1.factory.createTypeReferenceNode(UINT8_ARRAY_IDENT); | ||
// sdk types | ||
var ABI_METHOD_IDENT = typescript_1.factory.createIdentifier("algosdk.ABIMethod"); | ||
var ABI_METHOD_IDENT = typescript_1.factory.createIdentifier('algosdk.ABIMethod'); | ||
var ABI_METHOD_TYPE = typescript_1.factory.createTypeReferenceNode(ABI_METHOD_IDENT); | ||
var ATC_IDENT = typescript_1.factory.createIdentifier("algosdk.AtomicTransactionComposer"); | ||
var ATC_IDENT = typescript_1.factory.createIdentifier('algosdk.AtomicTransactionComposer'); | ||
var ATC_TYPE = typescript_1.factory.createTypeReferenceNode(ATC_IDENT); | ||
// bkr types | ||
var ABI_RESULT_IDENT = typescript_1.factory.createIdentifier("bkr.ABIResult"); | ||
var DECODE_NAMED_TUPLE_IDENT = typescript_1.factory.createIdentifier("bkr.decodeNamedTuple"); | ||
var SCHEMA_TYPE = typescript_1.factory.createTypeReferenceNode("bkr.Schema"); | ||
var TRANSACTION_OVERRIDES_TYPE = typescript_1.factory.createTypeReferenceNode("bkr.TransactionOverrides"); | ||
var ABI_RESULT_IDENT = typescript_1.factory.createIdentifier('bkr.ABIResult'); | ||
var DECODE_NAMED_TUPLE_IDENT = typescript_1.factory.createIdentifier('bkr.decodeNamedTuple'); | ||
var SCHEMA_TYPE = typescript_1.factory.createTypeReferenceNode('bkr.Schema'); | ||
var TRANSACTION_OVERRIDES_TYPE = typescript_1.factory.createTypeReferenceNode('bkr.TransactionOverrides'); | ||
function tsTypeFromAbiType(argType) { | ||
if (typeof argType === "string") { | ||
if (typeof argType === 'string') { | ||
if (TXN_TYPES.includes(argType)) | ||
return typescript_1.factory.createUnionTypeNode([ | ||
typescript_1.factory.createTypeReferenceNode("algosdk.TransactionWithSigner"), | ||
typescript_1.factory.createTypeReferenceNode("algosdk.Transaction"), | ||
typescript_1.factory.createTypeReferenceNode('algosdk.TransactionWithSigner'), | ||
typescript_1.factory.createTypeReferenceNode('algosdk.Transaction'), | ||
]); | ||
if (REF_TYPES.includes(argType)) { | ||
if (["application", "asset"].includes(argType)) | ||
if (['application', 'asset'].includes(argType)) | ||
return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.BigIntKeyword); | ||
@@ -87,3 +87,3 @@ return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword); | ||
} | ||
var abiType = typeof argType === "string" ? algosdk_1.default.ABIType.from(argType) : argType; | ||
var abiType = typeof argType === 'string' ? algosdk_1.default.ABIType.from(argType) : argType; | ||
switch (abiType.constructor) { | ||
@@ -127,13 +127,13 @@ case algosdk_1.default.ABIByteType: | ||
case typescript_1.default.SyntaxKind.StringKeyword: | ||
return typescript_1.factory.createStringLiteral(""); | ||
return typescript_1.factory.createStringLiteral(''); | ||
case typescript_1.default.SyntaxKind.NumberKeyword: | ||
return typescript_1.factory.createNumericLiteral(0); | ||
case typescript_1.default.SyntaxKind.BigIntKeyword: | ||
return typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier("BigInt"), undefined, [typescript_1.factory.createNumericLiteral("0")]); | ||
return typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier('BigInt'), undefined, [typescript_1.factory.createNumericLiteral('0')]); | ||
case typescript_1.default.SyntaxKind.BooleanKeyword: | ||
return typescript_1.factory.createIdentifier("false"); | ||
return typescript_1.factory.createIdentifier('false'); | ||
case typescript_1.default.SyntaxKind.TypeReference: | ||
return typescript_1.factory.createNewExpression(UINT8_ARRAY_IDENT, undefined, []); | ||
} | ||
return typescript_1.factory.createIdentifier("undefined"); | ||
return typescript_1.factory.createIdentifier('undefined'); | ||
} | ||
@@ -149,3 +149,3 @@ function generateApplicationClient(appSpec, path, beakerPath) { | ||
.createPrinter() | ||
.printList(typescript_1.default.ListFormat.MultiLine, typescript_1.factory.createNodeArray(nodes), typescript_1.default.createSourceFile(name, "", typescript_1.default.ScriptTarget.ESNext, true, typescript_1.default.ScriptKind.TS)); | ||
.printList(typescript_1.default.ListFormat.MultiLine, typescript_1.factory.createNodeArray(nodes), typescript_1.default.createSourceFile(name, '', typescript_1.default.ScriptTarget.ESNext, true, typescript_1.default.ScriptKind.TS)); | ||
var file_name = "".concat(name.toLowerCase(), "_client.ts"); | ||
@@ -177,3 +177,3 @@ (0, fs_1.writeFileSync)(path + file_name, outputFile); | ||
// create desc property | ||
return typescript_1.factory.createPropertyDeclaration(undefined, undefined, typescript_1.factory.createIdentifier("compose"), undefined, undefined, typescript_1.factory.createObjectLiteralExpression(spec.contract.methods.map(function (meth) { | ||
return typescript_1.factory.createPropertyDeclaration(undefined, undefined, typescript_1.factory.createIdentifier('compose'), undefined, undefined, typescript_1.factory.createObjectLiteralExpression(spec.contract.methods.map(function (meth) { | ||
var _a = generateComposeMethodImpl(meth, spec), key = _a[0], value = _a[1]; | ||
@@ -183,3 +183,3 @@ return typescript_1.factory.createPropertyAssignment(key, value); | ||
} | ||
// Creates the methods on the AppClient class used to call specific ABI methods | ||
// Creates the methods on the AppClient class used to call specific ABI methods | ||
function generateMethodImpl(method, spec) { | ||
@@ -210,15 +210,15 @@ var params = []; | ||
var data = void 0; | ||
if (typeof defaultArg.data == "string") { | ||
if (typeof defaultArg.data == 'string') { | ||
data = typescript_1.factory.createStringLiteral(defaultArg.data); | ||
} | ||
else if (typeof defaultArg.data == "bigint") { | ||
else if (typeof defaultArg.data == 'bigint') { | ||
data = typescript_1.factory.createBigIntLiteral(defaultArg.data.toString()); | ||
} | ||
else if (typeof defaultArg.data == "number") { | ||
else if (typeof defaultArg.data == 'number') { | ||
data = typescript_1.factory.createNumericLiteral(defaultArg.data); | ||
} | ||
else { | ||
data = typescript_1.factory.createIdentifier("undefined"); | ||
data = typescript_1.factory.createIdentifier('undefined'); | ||
} | ||
argVal = typescript_1.factory.createConditionalExpression(typescript_1.factory.createBinaryExpression(argVal, typescript_1.factory.createToken(typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken), typescript_1.factory.createIdentifier("undefined")), typescript_1.factory.createToken(typescript_1.default.SyntaxKind.QuestionToken), typescript_1.factory.createAsExpression(typescript_1.factory.createAwaitExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier("this.resolve"), undefined, [typescript_1.factory.createStringLiteral(defaultArg.source), data])), argType), typescript_1.factory.createToken(typescript_1.default.SyntaxKind.ColonToken), argVal); | ||
argVal = typescript_1.factory.createConditionalExpression(typescript_1.factory.createBinaryExpression(argVal, typescript_1.factory.createToken(typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken), typescript_1.factory.createIdentifier('undefined')), typescript_1.factory.createToken(typescript_1.default.SyntaxKind.QuestionToken), typescript_1.factory.createAsExpression(typescript_1.factory.createAwaitExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier('this.resolve'), undefined, [typescript_1.factory.createStringLiteral(defaultArg.source), data])), argType), typescript_1.factory.createToken(typescript_1.default.SyntaxKind.ColonToken), argVal); | ||
} | ||
@@ -234,11 +234,11 @@ abiMethodArgs.push(typescript_1.factory.createPropertyAssignment(argName, argVal)); | ||
if (argParams.length > 0) { | ||
params.push(typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier("args"), undefined, typescript_1.factory.createTypeLiteralNode(argParams))); | ||
params.push(typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier('args'), undefined, typescript_1.factory.createTypeLiteralNode(argParams))); | ||
} | ||
// Any tx overrides | ||
var txnParams = typescript_1.factory.createIdentifier("txnParams"); | ||
var txnParams = typescript_1.factory.createIdentifier('txnParams'); | ||
params.push(typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, txnParams, typescript_1.factory.createToken(typescript_1.default.SyntaxKind.QuestionToken), TRANSACTION_OVERRIDES_TYPE)); | ||
// Set up return type | ||
var abiRetType = typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.VoidKeyword); | ||
var resultArgs = [typescript_1.factory.createIdentifier("result")]; | ||
if (method.returns.type.toString() !== "void") { | ||
var resultArgs = [typescript_1.factory.createIdentifier('result')]; | ||
if (method.returns.type.toString() !== 'void') { | ||
abiRetType = tsTypeFromAbiType(method.returns.type.toString()); | ||
@@ -249,8 +249,8 @@ // Always `output` here because pyteal, | ||
(hint === null || hint === void 0 ? void 0 : hint.structs) !== undefined && | ||
"output" in hint.structs) { | ||
var outputHint = hint.structs["output"]; | ||
'output' in hint.structs) { | ||
var outputHint = hint.structs['output']; | ||
if (outputHint !== undefined) { | ||
abiRetType = typescript_1.factory.createTypeReferenceNode(outputHint === null || outputHint === void 0 ? void 0 : outputHint.name); | ||
resultArgs.push(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(outputHint.name), typescript_1.factory.createIdentifier("decodeResult")), undefined, [ | ||
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier("result"), typescript_1.factory.createIdentifier("returnValue")), | ||
resultArgs.push(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(outputHint.name), typescript_1.factory.createIdentifier('decodeResult')), undefined, [ | ||
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier('result'), typescript_1.factory.createIdentifier('returnValue')), | ||
])); | ||
@@ -260,3 +260,3 @@ } | ||
else { | ||
resultArgs.push(typescript_1.factory.createAsExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier("result"), typescript_1.factory.createIdentifier("returnValue")), abiRetType)); | ||
resultArgs.push(typescript_1.factory.createAsExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier('result'), typescript_1.factory.createIdentifier('returnValue')), abiRetType)); | ||
} | ||
@@ -269,12 +269,10 @@ } | ||
composeArgs.push(txnParams); | ||
var composeExpr = typescript_1.factory.createAwaitExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier("this.compose." + method.name), undefined, composeArgs)); | ||
var composeExpr = typescript_1.factory.createAwaitExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier('this.compose.' + method.name), undefined, composeArgs)); | ||
var body = typescript_1.factory.createBlock([ | ||
typescript_1.factory.createVariableStatement(undefined, typescript_1.factory.createVariableDeclarationList([ | ||
typescript_1.factory.createVariableDeclaration(typescript_1.factory.createIdentifier("result"), undefined, undefined, typescript_1.factory.createAwaitExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createThis(), typescript_1.factory.createIdentifier("execute")), undefined, [composeExpr]))), | ||
typescript_1.factory.createVariableDeclaration(typescript_1.factory.createIdentifier('result'), undefined, undefined, typescript_1.factory.createAwaitExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createThis(), typescript_1.factory.createIdentifier('execute')), undefined, [composeExpr]))), | ||
], typescript_1.default.NodeFlags.Const)), | ||
typescript_1.factory.createReturnStatement(typescript_1.factory.createNewExpression(ABI_RESULT_IDENT, [abiRetType], resultArgs)), | ||
], true); | ||
var retType = typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier("Promise"), [ | ||
typescript_1.factory.createTypeReferenceNode(ABI_RESULT_IDENT, [abiRetType]), | ||
]); | ||
var retType = typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier('Promise'), [typescript_1.factory.createTypeReferenceNode(ABI_RESULT_IDENT, [abiRetType])]); | ||
var methodSpec = typescript_1.factory.createMethodDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.AsyncKeyword)], undefined, method.name, undefined, undefined, params, retType, body); | ||
@@ -291,4 +289,4 @@ return methodSpec; | ||
var hint = method.name in spec.hints ? spec.hints[method.name] : {}; | ||
callArgs.push(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier("algosdk.getMethodByName"), undefined, [ | ||
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createThis(), typescript_1.factory.createIdentifier("methods")), | ||
callArgs.push(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier('algosdk.getMethodByName'), undefined, [ | ||
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createThis(), typescript_1.factory.createIdentifier('methods')), | ||
typescript_1.factory.createStringLiteral(method.name), | ||
@@ -298,4 +296,5 @@ ])); | ||
var arg = _a[_i]; | ||
if (arg.name === undefined) | ||
if (arg.name === undefined) { | ||
continue; | ||
} | ||
var argName = typescript_1.factory.createIdentifier(arg.name); | ||
@@ -317,15 +316,15 @@ var argType = tsTypeFromAbiType(arg.type.toString()); | ||
var data = void 0; | ||
if (typeof defaultArg.data == "string") { | ||
if (typeof defaultArg.data == 'string') { | ||
data = typescript_1.factory.createStringLiteral(defaultArg.data); | ||
} | ||
else if (typeof defaultArg.data == "bigint") { | ||
else if (typeof defaultArg.data == 'bigint') { | ||
data = typescript_1.factory.createBigIntLiteral(defaultArg.data.toString()); | ||
} | ||
else if (typeof defaultArg.data == "number") { | ||
else if (typeof defaultArg.data == 'number') { | ||
data = typescript_1.factory.createNumericLiteral(defaultArg.data); | ||
} | ||
else { | ||
data = typescript_1.factory.createIdentifier("undefined"); | ||
data = typescript_1.factory.createIdentifier('undefined'); | ||
} | ||
argVal = typescript_1.factory.createConditionalExpression(typescript_1.factory.createBinaryExpression(argVal, typescript_1.factory.createToken(typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken), typescript_1.factory.createIdentifier("undefined")), typescript_1.factory.createToken(typescript_1.default.SyntaxKind.QuestionToken), typescript_1.factory.createAwaitExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier("this.resolve"), undefined, [typescript_1.factory.createStringLiteral(defaultArg.source), data])), typescript_1.factory.createToken(typescript_1.default.SyntaxKind.ColonToken), argVal); | ||
argVal = typescript_1.factory.createConditionalExpression(typescript_1.factory.createBinaryExpression(argVal, typescript_1.factory.createToken(typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken), typescript_1.factory.createIdentifier('undefined')), typescript_1.factory.createToken(typescript_1.default.SyntaxKind.QuestionToken), typescript_1.factory.createAwaitExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier('this.resolve'), undefined, [typescript_1.factory.createStringLiteral(defaultArg.source), data])), typescript_1.factory.createToken(typescript_1.default.SyntaxKind.ColonToken), argVal); | ||
} | ||
@@ -340,18 +339,16 @@ abiMethodArgs.push(typescript_1.factory.createPropertyAssignment(argName, argVal)); | ||
if (argParams.length > 0) { | ||
params.push(typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier("args"), undefined, typescript_1.factory.createTypeLiteralNode(argParams))); | ||
params.push(typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier('args'), undefined, typescript_1.factory.createTypeLiteralNode(argParams))); | ||
} | ||
var txnParams = typescript_1.factory.createIdentifier("txnParams"); | ||
var txnParams = typescript_1.factory.createIdentifier('txnParams'); | ||
params.push(typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, txnParams, typescript_1.factory.createToken(typescript_1.default.SyntaxKind.QuestionToken), TRANSACTION_OVERRIDES_TYPE)); | ||
var atcParam = typescript_1.factory.createIdentifier("atc"); | ||
var atcParam = typescript_1.factory.createIdentifier('atc'); | ||
params.push(typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, atcParam, typescript_1.factory.createToken(typescript_1.default.SyntaxKind.QuestionToken), ATC_TYPE)); | ||
var body = typescript_1.factory.createBlock([ | ||
typescript_1.factory.createReturnStatement(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createThis(), typescript_1.factory.createIdentifier("addMethodCall")), undefined, __spreadArray(__spreadArray([], callArgs, true), [ | ||
typescript_1.factory.createReturnStatement(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createThis(), typescript_1.factory.createIdentifier('addMethodCall')), undefined, __spreadArray(__spreadArray([], callArgs, true), [ | ||
typescript_1.factory.createObjectLiteralExpression(abiMethodArgs), | ||
txnParams, | ||
atcParam, | ||
], false))) | ||
], false))), | ||
], true); | ||
var retType = typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier("Promise"), [ | ||
typescript_1.factory.createTypeReferenceNode(ATC_IDENT), | ||
]); | ||
var retType = typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier('Promise'), [typescript_1.factory.createTypeReferenceNode(ATC_IDENT)]); | ||
var fncSpec = typescript_1.factory.createArrowFunction([typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.AsyncKeyword)], undefined, params, retType, undefined, body); | ||
@@ -363,6 +360,6 @@ return [method.name, fncSpec]; | ||
return typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier(sv[0]), typescript_1.factory.createObjectLiteralExpression([ | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier("type"), typescript_1.factory.createIdentifier("bkr.AVMType.".concat(sv[1].type))), | ||
objStrProperty("key", sv[1].key), | ||
objStrProperty("desc", sv[1].desc), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier("static"), sv[1].static ? typescript_1.factory.createTrue() : typescript_1.factory.createFalse()), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier('type'), typescript_1.factory.createIdentifier("bkr.AVMType.".concat(sv[1].type))), | ||
objStrProperty('key', sv[1].key), | ||
objStrProperty('desc', sv[1].desc), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier('static'), sv[1].static ? typescript_1.factory.createTrue() : typescript_1.factory.createFalse()), | ||
])); | ||
@@ -372,10 +369,10 @@ }); | ||
return typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier(sv[0]), typescript_1.factory.createObjectLiteralExpression([ | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier("type"), typescript_1.factory.createIdentifier("bkr.AVMType.".concat(sv[1].type.toString()))), | ||
objStrProperty("desc", sv[1].desc), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier("max_keys"), typescript_1.factory.createNumericLiteral(sv[1].max_keys ? sv[1].max_keys : 0)), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier('type'), typescript_1.factory.createIdentifier("bkr.AVMType.".concat(sv[1].type.toString()))), | ||
objStrProperty('desc', sv[1].desc), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier('max_keys'), typescript_1.factory.createNumericLiteral(sv[1].max_keys ? sv[1].max_keys : 0)), | ||
])); | ||
}); | ||
return typescript_1.factory.createObjectLiteralExpression([ | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier("declared"), typescript_1.factory.createObjectLiteralExpression(declaredAppSchemaProps)), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier("dynamic"), typescript_1.factory.createObjectLiteralExpression(dynamicAppSchemaProps)), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier('declared'), typescript_1.factory.createObjectLiteralExpression(declaredAppSchemaProps)), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier('dynamic'), typescript_1.factory.createObjectLiteralExpression(dynamicAppSchemaProps)), | ||
]); | ||
@@ -412,4 +409,4 @@ } | ||
} | ||
members.push(typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], typescript_1.factory.createIdentifier("codec"), undefined, typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createQualifiedName(typescript_1.factory.createIdentifier("algosdk"), typescript_1.factory.createIdentifier("ABIType")), undefined), typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier("algosdk"), typescript_1.factory.createIdentifier("ABIType")), typescript_1.factory.createIdentifier("from")), undefined, [typescript_1.factory.createStringLiteral("(".concat(tupleTypes.join(","), ")"))]))); | ||
members.push(typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], typescript_1.factory.createIdentifier("fields"), undefined, typescript_1.factory.createTypeReferenceNode("string[]"), typescript_1.factory.createArrayLiteralExpression(tupleNames.map(function (name) { | ||
members.push(typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], typescript_1.factory.createIdentifier('codec'), undefined, typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createQualifiedName(typescript_1.factory.createIdentifier('algosdk'), typescript_1.factory.createIdentifier('ABIType')), undefined), typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier('algosdk'), typescript_1.factory.createIdentifier('ABIType')), typescript_1.factory.createIdentifier('from')), undefined, [typescript_1.factory.createStringLiteral("(".concat(tupleTypes.join(','), ")"))]))); | ||
members.push(typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], typescript_1.factory.createIdentifier('fields'), undefined, typescript_1.factory.createTypeReferenceNode('string[]'), typescript_1.factory.createArrayLiteralExpression(tupleNames.map(function (name) { | ||
return typescript_1.factory.createStringLiteral(name); | ||
@@ -419,19 +416,19 @@ })))); | ||
// Add static `decodeResult(val: ABIValue): <T>` method | ||
typescript_1.factory.createMethodDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], undefined, typescript_1.factory.createIdentifier("decodeResult"), undefined, undefined, [ | ||
typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier("val"), undefined, typescript_1.factory.createUnionTypeNode([ | ||
typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createQualifiedName(typescript_1.factory.createIdentifier("algosdk"), typescript_1.factory.createIdentifier("ABIValue")), undefined), | ||
typescript_1.factory.createTypeReferenceNode("undefined"), | ||
typescript_1.factory.createMethodDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], undefined, typescript_1.factory.createIdentifier('decodeResult'), undefined, undefined, [ | ||
typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier('val'), undefined, typescript_1.factory.createUnionTypeNode([ | ||
typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createQualifiedName(typescript_1.factory.createIdentifier('algosdk'), typescript_1.factory.createIdentifier('ABIValue')), undefined), | ||
typescript_1.factory.createTypeReferenceNode('undefined'), | ||
]), undefined), | ||
], typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined), typescript_1.factory.createBlock([ | ||
typescript_1.factory.createReturnStatement(typescript_1.factory.createAsExpression(typescript_1.factory.createCallExpression(DECODE_NAMED_TUPLE_IDENT, undefined, [ | ||
typescript_1.factory.createIdentifier("val"), | ||
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(s.name), typescript_1.factory.createIdentifier("fields")), | ||
typescript_1.factory.createIdentifier('val'), | ||
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(s.name), typescript_1.factory.createIdentifier('fields')), | ||
]), typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined))), | ||
], true))); | ||
members.push(typescript_1.factory.createMethodDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], undefined, typescript_1.factory.createIdentifier("decodeBytes"), undefined, undefined, [ | ||
typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier("val"), undefined, UINT8_ARRAY_TYPE, undefined), | ||
members.push(typescript_1.factory.createMethodDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], undefined, typescript_1.factory.createIdentifier('decodeBytes'), undefined, undefined, [ | ||
typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier('val'), undefined, UINT8_ARRAY_TYPE, undefined), | ||
], typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined), typescript_1.factory.createBlock([ | ||
typescript_1.factory.createReturnStatement(typescript_1.factory.createAsExpression(typescript_1.factory.createCallExpression(DECODE_NAMED_TUPLE_IDENT, undefined, [ | ||
typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(s.name), typescript_1.factory.createIdentifier("codec")), typescript_1.factory.createIdentifier("decode")), undefined, [typescript_1.factory.createIdentifier("val")]), | ||
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(s.name), typescript_1.factory.createIdentifier("fields")), | ||
typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(s.name), typescript_1.factory.createIdentifier('codec')), typescript_1.factory.createIdentifier('decode')), undefined, [typescript_1.factory.createIdentifier('val')]), | ||
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(s.name), typescript_1.factory.createIdentifier('fields')), | ||
]), typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined))), | ||
@@ -447,7 +444,7 @@ ], true))); | ||
// create desc property | ||
var descrProp = typescript_1.factory.createPropertyDeclaration(undefined, undefined, typescript_1.factory.createIdentifier("desc"), undefined, typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword), typescript_1.factory.createStringLiteral(descr ? descr : "")); | ||
var descrProp = typescript_1.factory.createPropertyDeclaration(undefined, undefined, typescript_1.factory.createIdentifier('desc'), undefined, typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword), typescript_1.factory.createStringLiteral(descr ? descr : '')); | ||
// Create approval program property | ||
var approvalProp; | ||
if (source.approval !== undefined) { | ||
approvalProp = typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.OverrideKeyword)], typescript_1.factory.createIdentifier("approvalProgram"), undefined, typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword), typescript_1.factory.createStringLiteral(source.approval)); | ||
approvalProp = typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.OverrideKeyword)], typescript_1.factory.createIdentifier('approvalProgram'), undefined, typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword), typescript_1.factory.createStringLiteral(source.approval)); | ||
} | ||
@@ -457,3 +454,3 @@ // Create clear program property | ||
if (source.clear !== undefined) { | ||
clearProp = typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.OverrideKeyword)], typescript_1.factory.createIdentifier("clearProgram"), undefined, typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword), typescript_1.factory.createStringLiteral(source.clear)); | ||
clearProp = typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.OverrideKeyword)], typescript_1.factory.createIdentifier('clearProgram'), undefined, typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword), typescript_1.factory.createStringLiteral(source.clear)); | ||
} | ||
@@ -463,3 +460,3 @@ // Create App Schema Property | ||
if (schema.global !== undefined) { | ||
appSchemaProp = typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.OverrideKeyword)], typescript_1.factory.createIdentifier("appSchema"), undefined, SCHEMA_TYPE, copySchemaObject(schema.global)); | ||
appSchemaProp = typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.OverrideKeyword)], typescript_1.factory.createIdentifier('appSchema'), undefined, SCHEMA_TYPE, copySchemaObject(schema.global)); | ||
} | ||
@@ -469,3 +466,3 @@ // Create Acct schema property | ||
if (schema.local !== undefined) { | ||
acctSchemaProp = typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.OverrideKeyword)], typescript_1.factory.createIdentifier("acctSchema"), undefined, SCHEMA_TYPE, copySchemaObject(schema.local)); | ||
acctSchemaProp = typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.OverrideKeyword)], typescript_1.factory.createIdentifier('acctSchema'), undefined, SCHEMA_TYPE, copySchemaObject(schema.local)); | ||
} | ||
@@ -478,18 +475,18 @@ // Add methods | ||
return typescript_1.factory.createObjectLiteralExpression([ | ||
objStrProperty("type", arg.type.toString()), | ||
objStrProperty("name", arg.name), | ||
objStrProperty("desc", arg.description) | ||
objStrProperty('type', arg.type.toString()), | ||
objStrProperty('name', arg.name), | ||
objStrProperty('desc', arg.description), | ||
]); | ||
}); | ||
var returnObj = typescript_1.factory.createObjectLiteralExpression([ | ||
objStrProperty("type", meth.returns.type.toString()), | ||
objStrProperty("desc", meth.returns.description) | ||
objStrProperty('type', meth.returns.type.toString()), | ||
objStrProperty('desc', meth.returns.description), | ||
]); | ||
// Create ABIMethod object | ||
// Create ABIMethod object | ||
methodAssignments.push(typescript_1.factory.createNewExpression(ABI_METHOD_IDENT, undefined, [ | ||
typescript_1.factory.createObjectLiteralExpression([ | ||
objStrProperty("name", meth.name), | ||
objStrProperty("desc", meth.description), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier("args"), typescript_1.factory.createArrayLiteralExpression(argObjs)), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier("returns"), returnObj), | ||
objStrProperty('name', meth.name), | ||
objStrProperty('desc', meth.description), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier('args'), typescript_1.factory.createArrayLiteralExpression(argObjs)), | ||
typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier('returns'), returnObj), | ||
]), | ||
@@ -499,3 +496,3 @@ ])); | ||
// create methods property | ||
var methodProps = typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.OverrideKeyword)], typescript_1.factory.createIdentifier("methods"), undefined, typescript_1.factory.createArrayTypeNode(ABI_METHOD_TYPE), typescript_1.factory.createArrayLiteralExpression(methodAssignments, true)); | ||
var methodProps = typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.OverrideKeyword)], typescript_1.factory.createIdentifier('methods'), undefined, typescript_1.factory.createArrayTypeNode(ABI_METHOD_TYPE), typescript_1.factory.createArrayLiteralExpression(methodAssignments, true)); | ||
var props = [descrProp]; | ||
@@ -514,4 +511,4 @@ if (appSchemaProp !== undefined) | ||
function objStrProperty(k, v) { | ||
var val = v === undefined ? "" : v; | ||
var val = v === undefined ? '' : v; | ||
return typescript_1.factory.createPropertyAssignment(typescript_1.factory.createIdentifier(k), typescript_1.factory.createStringLiteral(val)); | ||
} |
@@ -1,5 +0,5 @@ | ||
export { ApplicationClient, ABIResult, MethodArg, MethodArgs, decodeNamedTuple, TransactionOverrides } from "./application_client/application_client"; | ||
export { LogicError, parseLogicError } from "./application_client/logic_error"; | ||
export { generateApplicationClient } from "./generate/generate"; | ||
export { HintSpec, DeclaredSchemaValueSpec, DynamicSchemaValueSpec, Schema, StateSchema, SchemaSpec, AppSources, AppSpec, AVMType, getStateSchema } from "./generate/appspec"; | ||
export * as sandbox from "./sandbox"; | ||
export { ApplicationClient, ABIResult, MethodArg, MethodArgs, decodeNamedTuple, TransactionOverrides, } from './application_client/application_client'; | ||
export { LogicError, parseLogicError } from './application_client/logic_error'; | ||
export { generateApplicationClient } from './generate/generate'; | ||
export { HintSpec, DeclaredSchemaValueSpec, DynamicSchemaValueSpec, Schema, StateSchema, SchemaSpec, AppSources, AppSpec, AVMType, getStateSchema, } from './generate/appspec'; | ||
export * as sandbox from './sandbox'; |
@@ -44,7 +44,7 @@ "use strict"; | ||
var algosdk_1 = __importDefault(require("algosdk")); | ||
var kmd_token = "a".repeat(64); | ||
var kmd_host = "http://localhost"; | ||
var kmd_port = "4002"; | ||
var kmd_wallet = "unencrypted-default-wallet"; | ||
var kmd_password = ""; | ||
var kmd_token = 'a'.repeat(64); | ||
var kmd_host = 'http://localhost'; | ||
var kmd_port = '4002'; | ||
var kmd_wallet = 'unencrypted-default-wallet'; | ||
var kmd_password = ''; | ||
function getAccounts() { | ||
@@ -66,3 +66,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
if (walletId === undefined) | ||
throw Error("No wallet named: " + kmd_wallet); | ||
throw Error('No wallet named: ' + kmd_wallet); | ||
return [4 /*yield*/, kmdClient.initWalletHandle(walletId, kmd_password)]; | ||
@@ -80,5 +80,3 @@ case 2: | ||
} | ||
return [4 /*yield*/, Promise.all(acctPromises) | ||
// Don't need to wait for it | ||
]; | ||
return [4 /*yield*/, Promise.all(acctPromises)]; | ||
case 4: | ||
@@ -92,3 +90,7 @@ keys = _d.sent(); | ||
var signer = algosdk_1.default.makeBasicAccountTransactionSigner(acct); | ||
return { addr: acct.addr, privateKey: acct.sk, signer: signer }; | ||
return { | ||
addr: acct.addr, | ||
privateKey: acct.sk, | ||
signer: signer, | ||
}; | ||
})]; | ||
@@ -95,0 +97,0 @@ } |
@@ -9,8 +9,8 @@ "use strict"; | ||
function getAlgodClient() { | ||
return new algosdk_1.default.Algodv2("a".repeat(64), "http://localhost", 4001); | ||
return new algosdk_1.default.Algodv2('a'.repeat(64), 'http://localhost', 4001); | ||
} | ||
exports.getAlgodClient = getAlgodClient; | ||
function getIndexerClient() { | ||
return new algosdk_1.default.Indexer("a".repeat(64), "http://localhost", 8980); | ||
return new algosdk_1.default.Indexer('a'.repeat(64), 'http://localhost', 8980); | ||
} | ||
exports.getIndexerClient = getIndexerClient; |
{ | ||
"name": "beaker-ts", | ||
"version": "0.0.33", | ||
"version": "0.0.34", | ||
"description": "", | ||
@@ -8,20 +8,16 @@ "main": "./lib/index.js", | ||
"build": "tsc -p .", | ||
"beaker": "npx ts-node src/beaker.ts", | ||
"genhello":"npm run beaker -- generate --local examples/hello/hello.json examples/hello/", | ||
"beaker": "npx ts-node src/beaker.ts", | ||
"genhello": "npm run beaker -- generate --local examples/hello/hello.json examples/hello/", | ||
"hello": "npx ts-node examples/hello/index.ts", | ||
"genstructer":"npm run beaker -- generate --local examples/struct/structer.json examples/struct/", | ||
"genstructer": "npm run beaker -- generate --local examples/struct/structer.json examples/struct/", | ||
"structer": "npx ts-node examples/struct/index.ts", | ||
"genopup":"npm run beaker -- generate --local examples/opup/opup.json examples/opup/", | ||
"genopup": "npm run beaker -- generate --local examples/opup/opup.json examples/opup/", | ||
"opup": "npx ts-node examples/opup/index.ts", | ||
"genamm":"npm run beaker -- generate --local examples/amm/amm.json examples/amm/", | ||
"genamm": "npm run beaker -- generate --local examples/amm/amm.json examples/amm/", | ||
"amm": "npx ts-node examples/amm/index.ts", | ||
"genavm7":"npm run beaker -- generate --local examples/demo_avm7/demo_avm7.json examples/demo_avm7/", | ||
"genavm7": "npm run beaker -- generate --local examples/demo_avm7/demo_avm7.json examples/demo_avm7/", | ||
"avm7": "npx ts-node examples/demo_avm7/index.ts", | ||
"regen":"npm run genhello && npm run genstructer && npm run genopup && npm run genavm7 && npm run genamm" | ||
"regen": "npm run genhello && npm run genstructer && npm run genopup && npm run genavm7 && npm run genamm", | ||
"lint": "eslint \"src/**/*.ts\"", | ||
"format": "prettier --write \"src/**/*.ts\"" | ||
}, | ||
@@ -35,4 +31,13 @@ "bin": { | ||
"devDependencies": { | ||
"@tsconfig/node16-strictest": "^1.0.3", | ||
"@types/node": "^18.6.4", | ||
"@tsconfig/node16-strictest": "^1.0.3" | ||
"@typescript-eslint/eslint-plugin": "^5.38.0", | ||
"eslint": "^7.32.0 || ^8.2.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.25.3", | ||
"eslint-plugin-jsx-a11y": "^6.5.1", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-react": "^7.28.0", | ||
"eslint-plugin-react-hooks": "^4.3.0", | ||
"prettier": "^2.7.1" | ||
}, | ||
@@ -39,0 +44,0 @@ "dependencies": { |
@@ -19,10 +19,6 @@ # Beaker Typescript Client Generator | ||
# Write the ApplicationSpec as json | ||
with open("hello.json", "w") as f: | ||
f.write(json.dumps(HelloBeaker().application_spec())) | ||
# OR | ||
with open("contract.json", "w") as f: | ||
f.write(json.dumps(HelloBeaker().contract.dictify())) | ||
if __name__ == "__main__": | ||
# Writes contract.json, HelloBeaker.json, approval.teal, and clear.teal | ||
# to the `artifacts` directory | ||
HelloBeaker().dump("artifacts") | ||
``` | ||
@@ -29,0 +25,0 @@ |
@@ -1,6 +0,6 @@ | ||
import algosdk, { ABIReferenceType, AtomicTransactionComposer } from "algosdk"; | ||
import algosdk, { ABIReferenceType, AtomicTransactionComposer } from 'algosdk'; | ||
import { getStateSchema, Schema } from "../"; | ||
import { parseLogicError, LogicError } from "./logic_error"; | ||
import { ApplicationState, AccountState, decodeState } from "./state"; | ||
import { getStateSchema, Schema } from '../'; | ||
import { parseLogicError, LogicError } from './logic_error'; | ||
import { ApplicationState, AccountState, decodeState } from './state'; | ||
@@ -15,11 +15,16 @@ export type MethodArg = | ||
export type TransactionOverrides = Partial<algosdk.TransactionParams>; | ||
export type TransactionResult = { | ||
confirmedRound: number; | ||
txIDs: string[]; | ||
methodResults: algosdk.ABIResult[]; | ||
}; | ||
export function decodeNamedTuple( | ||
v: algosdk.ABIValue | undefined, | ||
keys: string[] | ||
keys: string[], | ||
): object { | ||
if (v === undefined) return {}; | ||
if (!Array.isArray(v)) throw Error("Expected array"); | ||
if (!Array.isArray(v)) throw Error('Expected array'); | ||
if (v.length != keys.length) | ||
throw Error("Different key length than value length"); | ||
throw Error('Different key length than value length'); | ||
@@ -29,3 +34,3 @@ return Object.fromEntries( | ||
return [key, v[idx]]; | ||
}) | ||
}), | ||
); | ||
@@ -44,3 +49,3 @@ } | ||
method: algosdk.ABIMethod; | ||
txInfo: Record<string, any> | undefined; | ||
txInfo: Record<string, unknown> | undefined; | ||
returnValue: algosdk.ABIValue | undefined; | ||
@@ -61,14 +66,16 @@ decodeError: Error | undefined; | ||
this.inners = []; | ||
if (result?.txInfo !== undefined && "inner-txns" in result.txInfo) { | ||
if (result?.txInfo !== undefined && 'inner-txns' in result.txInfo) { | ||
// TODO: this only parses 1 level deep | ||
const outer = result.txInfo["txn"]["txn"] as algosdk.EncodedTransaction; | ||
this.inners = result.txInfo["inner-txns"].map((itxn: any) => { | ||
const et = itxn["txn"]["txn"] as algosdk.EncodedTransaction; | ||
const outer = result.txInfo['txn']['txn'] as algosdk.EncodedTransaction; | ||
// eslint-disable-next-line | ||
this.inners = result.txInfo['inner-txns'].map((itxn: any) => { | ||
const et = itxn['txn']['txn'] as algosdk.EncodedTransaction; | ||
et.gen = outer.gen; | ||
et.gh = outer.gh; | ||
return { | ||
createdAsset: itxn["asset-index"] as bigint, | ||
createdApp: itxn["application-index"], | ||
createdAsset: itxn['asset-index'] as bigint, | ||
createdApp: itxn['application-index'], | ||
txn: algosdk.Transaction.from_obj_for_encoding( | ||
itxn["txn"]["txn"] as algosdk.EncodedTransaction | ||
itxn['txn']['txn'] as algosdk.EncodedTransaction, | ||
), | ||
@@ -119,3 +126,3 @@ } as InnerTransaction; | ||
this.appId = 0; | ||
this.appAddress = ""; | ||
this.appAddress = ''; | ||
} | ||
@@ -130,14 +137,14 @@ | ||
return [ | ||
new Uint8Array(Buffer.from(result["result"], "base64")), | ||
new algosdk.SourceMap(result["sourcemap"]), | ||
new Uint8Array(Buffer.from(result['result'], 'base64')), | ||
new algosdk.SourceMap(result['sourcemap']), | ||
]; | ||
} | ||
private async ensurePrograms() { | ||
private async ensurePrograms(): Promise<void> { | ||
if (this.approvalProgram === undefined || this.clearProgram === undefined) | ||
throw Error("no approval or clear program defined"); | ||
throw Error('no approval or clear program defined'); | ||
if (this.approvalProgramBinary === undefined) { | ||
const [appBin, appMap] = await this.compile( | ||
Buffer.from(this.approvalProgram, "base64").toString() | ||
Buffer.from(this.approvalProgram, 'base64').toString(), | ||
); | ||
@@ -150,3 +157,3 @@ this.approvalProgramBinary = appBin; | ||
const [clearBin, clearMap] = await this.compile( | ||
Buffer.from(this.clearProgram, "base64").toString() | ||
Buffer.from(this.clearProgram, 'base64').toString(), | ||
); | ||
@@ -159,3 +166,3 @@ this.clearProgramBinary = clearBin; | ||
async create( | ||
txParams?: TransactionOverrides | ||
txParams?: TransactionOverrides, | ||
): Promise<[number, string, string]> { | ||
@@ -168,5 +175,5 @@ await this.ensurePrograms(); | ||
) | ||
throw Error("no approval or clear program binaries defined"); | ||
throw Error('no approval or clear program binaries defined'); | ||
if (this.signer === undefined) throw Error("no signer defined"); | ||
if (this.signer === undefined) throw Error('no signer defined'); | ||
@@ -195,6 +202,6 @@ const sp = await this.getSuggestedParams(txParams); | ||
if (txid === undefined) | ||
throw new Error("No transaction id returned from execute"); | ||
throw new Error('No transaction id returned from execute'); | ||
const txinfo = await this.client.pendingTransactionInformation(txid).do(); | ||
this.appId = txinfo["application-index"]; | ||
this.appId = txinfo['application-index']; | ||
this.appAddress = algosdk.getApplicationAddress(this.appId); | ||
@@ -207,4 +214,4 @@ return [this.appId, this.appAddress, txid]; | ||
async delete(txParams?: TransactionOverrides) { | ||
if (this.signer === undefined) throw Error("no signer defined"); | ||
async delete(txParams?: TransactionOverrides): Promise<TransactionResult> { | ||
if (this.signer === undefined) throw Error('no signer defined'); | ||
@@ -226,3 +233,3 @@ const sp = await this.getSuggestedParams(txParams); | ||
try { | ||
return await atc.execute(this.client, 4); | ||
return atc.execute(this.client, 4); | ||
} catch (e) { | ||
@@ -233,3 +240,3 @@ throw this.wrapLogicError(e as Error); | ||
async update(txParams?: TransactionOverrides) { | ||
async update(txParams?: TransactionOverrides): Promise<TransactionResult> { | ||
await this.ensurePrograms(); | ||
@@ -241,5 +248,5 @@ | ||
) | ||
throw Error("no approval or clear program binaries defined"); | ||
throw Error('no approval or clear program binaries defined'); | ||
if (this.signer === undefined) throw Error("no signer defined"); | ||
if (this.signer === undefined) throw Error('no signer defined'); | ||
@@ -268,4 +275,4 @@ const sp = await this.getSuggestedParams(txParams); | ||
async optIn(txParams?: TransactionOverrides) { | ||
if (this.signer === undefined) throw Error("no signer defined"); | ||
async optIn(txParams?: TransactionOverrides): Promise<TransactionResult> { | ||
if (this.signer === undefined) throw Error('no signer defined'); | ||
@@ -292,4 +299,4 @@ const sp = await this.getSuggestedParams(txParams); | ||
async closeOut(txParams?: TransactionOverrides) { | ||
if (this.signer === undefined) throw Error("no signer defined"); | ||
async closeOut(txParams?: TransactionOverrides): Promise<TransactionResult> { | ||
if (this.signer === undefined) throw Error('no signer defined'); | ||
@@ -316,4 +323,6 @@ const sp = await this.getSuggestedParams(txParams); | ||
async clearState(txParams?: TransactionOverrides) { | ||
if (this.signer === undefined) throw Error("no signer defined"); | ||
async clearState( | ||
txParams?: TransactionOverrides, | ||
): Promise<TransactionResult> { | ||
if (this.signer === undefined) throw Error('no signer defined'); | ||
@@ -339,5 +348,3 @@ const sp = await this.getSuggestedParams(txParams); | ||
async execute( | ||
atc: AtomicTransactionComposer | ||
): Promise<algosdk.ABIResult> { | ||
async execute(atc: AtomicTransactionComposer): Promise<algosdk.ABIResult> { | ||
try { | ||
@@ -359,8 +366,7 @@ const result = await atc.execute(this.client, 4); | ||
): Promise<algosdk.AtomicTransactionComposer> { | ||
if(atc === undefined){ | ||
atc = new algosdk.AtomicTransactionComposer() | ||
if (atc === undefined) { | ||
atc = new algosdk.AtomicTransactionComposer(); | ||
} | ||
if (this.signer === undefined) throw new Error("no signer defined"); | ||
if (this.signer === undefined) throw new Error('no signer defined'); | ||
@@ -388,6 +394,12 @@ const sp = await this.getSuggestedParams(txParams); | ||
// TODO: other types? | ||
if (expected_arg.type instanceof algosdk.ABIAddressType || expected_arg.type == ABIReferenceType.account){ | ||
arg = algosdk.encodeAddress(arg) | ||
if ( | ||
expected_arg.type instanceof algosdk.ABIAddressType || | ||
expected_arg.type == ABIReferenceType.account | ||
) { | ||
arg = algosdk.encodeAddress(arg); | ||
} | ||
}else if ( arg instanceof Object && !algosdk.isTransactionWithSigner(arg)) { | ||
} else if ( | ||
arg instanceof Object && | ||
!algosdk.isTransactionWithSigner(arg) | ||
) { | ||
arg = Object.values(arg); | ||
@@ -424,4 +436,4 @@ } | ||
led, | ||
Buffer.from(this.approvalProgram, "base64").toString().split("\n"), | ||
this.approvalProgramMap | ||
Buffer.from(this.approvalProgram, 'base64').toString().split('\n'), | ||
this.approvalProgramMap, | ||
); | ||
@@ -433,11 +445,11 @@ else return e; | ||
source: string, | ||
data: bigint | number | string | Uint8Array | ||
data: bigint | number | string | Uint8Array, | ||
): Promise<MethodArg> { | ||
let val; | ||
switch (source) { | ||
case "global-state": | ||
// Use the raw return value, so encode the key as hex since | ||
case 'global-state': | ||
// Use the raw return value, so encode the key as hex since | ||
// that is what we get back from the call to getAppState | ||
const appState = await this.getApplicationState(true); | ||
const key = Buffer.from(data as string).toString('hex') | ||
const key = Buffer.from(data as string).toString('hex'); | ||
@@ -449,3 +461,3 @@ val = appState[key]; | ||
return val; | ||
case "local-state": | ||
case 'local-state': | ||
// TODO: how do we pass in which account to resolve against ? | ||
@@ -458,8 +470,8 @@ // This assumes the current client sender | ||
return val; | ||
case "abi-method": | ||
case 'abi-method': | ||
// TODO: args? | ||
if(this.methods === undefined) | ||
throw new Error("no methods defined, cannot resolve hint") | ||
const meth = algosdk.getMethodByName(this.methods, data as string) | ||
return this.execute(await this.addMethodCall(meth, undefined)) | ||
if (this.methods === undefined) | ||
throw new Error('no methods defined, cannot resolve hint'); | ||
const meth = algosdk.getMethodByName(this.methods, data as string); | ||
return this.execute(await this.addMethodCall(meth, undefined)); | ||
default: | ||
@@ -471,3 +483,3 @@ return data; | ||
async getSuggestedParams( | ||
txParams?: TransactionOverrides | ||
txParams?: TransactionOverrides, | ||
): Promise<algosdk.SuggestedParams> { | ||
@@ -481,7 +493,7 @@ if (txParams !== undefined && txParams.suggestedParams !== undefined) | ||
const appInfo = await this.client.getApplicationByID(this.appId).do(); | ||
if (!("params" in appInfo) || !("global-state" in appInfo["params"])) | ||
throw new Error("No global state found"); | ||
if (!('params' in appInfo) || !('global-state' in appInfo['params'])) | ||
throw new Error('No global state found'); | ||
return decodeState( | ||
appInfo["params"]["global-state"], | ||
raw | ||
appInfo['params']['global-state'], | ||
raw, | ||
) as ApplicationState; | ||
@@ -492,3 +504,3 @@ } | ||
address?: string, | ||
raw?: boolean | ||
raw?: boolean, | ||
): Promise<AccountState> { | ||
@@ -500,9 +512,9 @@ if (address === undefined) address = this.getSender(); | ||
if ( | ||
!("app-local-state" in acctInfo) || | ||
!("key-value" in acctInfo["app-local-state"]) | ||
!('app-local-state' in acctInfo) || | ||
!('key-value' in acctInfo['app-local-state']) | ||
) | ||
return {} as AccountState | ||
return {} as AccountState; | ||
return decodeState( | ||
acctInfo["app-local-state"]["key-value"], | ||
raw | ||
acctInfo['app-local-state']['key-value'], | ||
raw, | ||
) as AccountState; | ||
@@ -520,3 +532,3 @@ } | ||
if (this.acctSchema === undefined) | ||
throw new Error("No account schema defined"); | ||
throw new Error('No account schema defined'); | ||
const s = getStateSchema(this.acctSchema); | ||
@@ -530,3 +542,3 @@ return { numLocalInts: s.uints, numLocalByteSlices: s.bytes }; | ||
} { | ||
if (this.appSchema === undefined) throw new Error("No app schema defined"); | ||
if (this.appSchema === undefined) throw new Error('No app schema defined'); | ||
const s = getStateSchema(this.appSchema); | ||
@@ -533,0 +545,0 @@ return { numGlobalInts: s.uints, numGlobalByteSlices: s.bytes }; |
@@ -1,52 +0,59 @@ | ||
import type algosdk from 'algosdk' | ||
import type algosdk from 'algosdk'; | ||
const LOGIC_ERROR = /TransactionPool.Remember: transaction ([A-Z0-9]+): logic eval error: (.*). Details: pc=([0-9]+), opcodes=.*/ | ||
const LOGIC_ERROR = | ||
/TransactionPool.Remember: transaction ([A-Z0-9]+): logic eval error: (.*). Details: pc=([0-9]+), opcodes=.*/; | ||
interface LogicErrorDetails { | ||
txId: string | ||
pc: number | ||
msg: string | ||
txId: string; | ||
pc: number; | ||
msg: string; | ||
} | ||
export function parseLogicError(errMsg: string): LogicErrorDetails { | ||
const res = LOGIC_ERROR.exec(errMsg) | ||
if(res === null || res.length<=3) return {} as LogicErrorDetails | ||
const res = LOGIC_ERROR.exec(errMsg); | ||
if (res === null || res.length <= 3) return {} as LogicErrorDetails; | ||
return { | ||
txId: res[1], | ||
msg: res[2], | ||
pc: parseInt(res[3]?res[3]:"0"), | ||
} as LogicErrorDetails | ||
return { | ||
txId: res[1], | ||
msg: res[2], | ||
pc: parseInt(res[3] ? res[3] : '0'), | ||
} as LogicErrorDetails; | ||
} | ||
export class LogicError extends Error { | ||
led: LogicErrorDetails; | ||
program: string[]; | ||
lines: number = 5; | ||
teal_line: number=0; | ||
override stack?: string; | ||
led: LogicErrorDetails; | ||
program: string[]; | ||
lines = 5; | ||
teal_line = 0; | ||
override stack?: string; | ||
constructor(led: LogicErrorDetails, program: string[], map: algosdk.SourceMap){ | ||
super() | ||
this.led = led | ||
this.program = program | ||
constructor( | ||
led: LogicErrorDetails, | ||
program: string[], | ||
map: algosdk.SourceMap, | ||
) { | ||
super(); | ||
this.led = led; | ||
this.program = program; | ||
const line = map.getLineForPc(led.pc) | ||
this.teal_line = line === undefined?0:line | ||
const line = map.getLineForPc(led.pc); | ||
this.teal_line = line === undefined ? 0 : line; | ||
this.message = `${this.led.msg.slice(0, 20)}... at:${line}` | ||
this.message = `${this.led.msg.slice(0, 20)}... at:${line}`; | ||
if(this.teal_line>0){ | ||
if (this.teal_line > 0) { | ||
const start = | ||
this.teal_line > this.lines ? this.teal_line - this.lines : 0; | ||
const stop = | ||
program.length > this.teal_line + this.lines | ||
? this.teal_line + this.lines | ||
: program.length; | ||
const start = this.teal_line>this.lines?this.teal_line-this.lines:0 | ||
const stop = program.length>this.teal_line+this.lines?this.teal_line+this.lines:program.length | ||
const stack_lines = program.slice(start, stop); | ||
const stack_lines = program.slice(start,stop) | ||
stack_lines[stack_lines.length / 2] += ' <--- Error'; | ||
stack_lines[stack_lines.length/2] += " <--- Error" | ||
this.stack = stack_lines.join("\n") | ||
} | ||
this.stack = stack_lines.join('\n'); | ||
} | ||
} | ||
} | ||
} |
@@ -1,15 +0,13 @@ | ||
// Represents the global-state and global-state-delta we get back from | ||
// AlgodClient requests, state-deltas will contain an action, state will | ||
// AlgodClient requests, state-deltas will contain an action, state will | ||
// contain the type. In both cases 1 is for bytes, 2 is for ints. We use | ||
// This to convert the array to a more friendly object | ||
// This to convert the array to a more friendly object | ||
export interface StateValue { | ||
key: string | ||
value: { | ||
bytes: string | ||
uint: number | ||
type?: number | ||
action?: number | ||
} | ||
key: string; | ||
value: { | ||
bytes: string; | ||
uint: number; | ||
type?: number; | ||
action?: number; | ||
}; | ||
} | ||
@@ -19,11 +17,11 @@ | ||
export interface State { | ||
[key: string] : string | number | Uint8Array | ||
[key: string]: string | number | Uint8Array; | ||
} | ||
function strOrHex(v: Buffer): string { | ||
try{ | ||
return v.toString('utf-8') | ||
} catch(e) { | ||
return v.toString('hex') | ||
} | ||
try { | ||
return v.toString('utf-8'); | ||
} catch (e) { | ||
return v.toString('hex'); | ||
} | ||
} | ||
@@ -33,30 +31,29 @@ | ||
// friendly generic object | ||
export function decodeState(state: StateValue[], raw?:boolean): State { | ||
export function decodeState(state: StateValue[], raw?: boolean): State { | ||
const obj = {} as State; | ||
const obj = {} as State | ||
// Start with empty set | ||
for (const stateVal of state) { | ||
const keyBuff = Buffer.from(stateVal.key, 'base64'); | ||
const key = raw ? keyBuff.toString('hex') : strOrHex(keyBuff); | ||
const value = stateVal.value; | ||
// Start with empty set | ||
for(const stateVal of state){ | ||
const keyBuff = Buffer.from(stateVal.key, 'base64') | ||
const key = raw?keyBuff.toString('hex'):strOrHex(keyBuff) | ||
const value = stateVal.value | ||
// In both global-state and state deltas, 1 is bytes and 2 is int | ||
const dataTypeFlag = value.action?value.action:value.type | ||
switch(dataTypeFlag){ | ||
case 1: | ||
const valBuff = Buffer.from(value.bytes, 'base64') | ||
obj[key] = raw?new Uint8Array(valBuff):strOrHex(valBuff) | ||
break; | ||
case 2: | ||
obj[key] = value.uint | ||
break; | ||
default: // ?? | ||
} | ||
// In both global-state and state deltas, 1 is bytes and 2 is int | ||
const dataTypeFlag = value.action ? value.action : value.type; | ||
switch (dataTypeFlag) { | ||
case 1: | ||
const valBuff = Buffer.from(value.bytes, 'base64'); | ||
obj[key] = raw ? new Uint8Array(valBuff) : strOrHex(valBuff); | ||
break; | ||
case 2: | ||
obj[key] = value.uint; | ||
break; | ||
default: // ?? | ||
} | ||
} | ||
return obj | ||
} | ||
return obj; | ||
} | ||
export type ApplicationState = State; | ||
export type AccountState = State; | ||
export type AccountState = State; |
#!/usr/bin/env node | ||
import { Command } from "commander"; | ||
import { generateApplicationClient } from "."; | ||
import { Command } from 'commander'; | ||
import { generateApplicationClient } from '.'; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
const pjson = require("../package.json") | ||
const pjson = require('../package.json'); // eslint-disable-line | ||
const program = new Command(); | ||
program | ||
.name("beaker") | ||
.description("Utilities for working with beaker applications") | ||
.name('beaker') | ||
.description('Utilities for working with beaker applications') | ||
.version(pjson['version']); | ||
program | ||
.command("generate") | ||
.description("Generates an application client given an application spec") | ||
.arguments("<path-to-spec> <path-to-write>") | ||
.option("-l, --local", "whether or not to use local import") | ||
.command('generate') | ||
.description('Generates an application client given an application spec') | ||
.arguments('<path-to-spec> <path-to-write>') | ||
.option('-l, --local', 'whether or not to use local import') | ||
.action((specPath, srcPath, options) => { | ||
const importPath = options.local?'../../src/':undefined | ||
const importPath = options.local ? '../../src/' : undefined; | ||
@@ -29,23 +28,19 @@ if (srcPath.slice(-1) !== path.sep) srcPath += path.sep; | ||
if (!fs.lstatSync(srcPath).isDirectory()) { | ||
throw Error("Path argument must be a directory"); | ||
throw Error('Path argument must be a directory'); | ||
} | ||
if (!fs.lstatSync(specPath).isFile()) { | ||
throw Error("Path to spec must be a file"); | ||
throw Error('Path to spec must be a file'); | ||
} | ||
console.log(`Writing client to: ${srcPath}`) | ||
console.log(`Writing client to: ${srcPath}`); | ||
let jsonObj = JSON.parse(fs.readFileSync(specPath).toString()) | ||
if (!("contract" in jsonObj)){ | ||
jsonObj = { "hints":{}, "source":{}, "schema":{}, "contract":jsonObj } | ||
let jsonObj = JSON.parse(fs.readFileSync(specPath).toString()); | ||
if (!('contract' in jsonObj)) { | ||
jsonObj = { hints: {}, source: {}, schema: {}, contract: jsonObj }; | ||
} | ||
generateApplicationClient( | ||
jsonObj, | ||
srcPath, | ||
importPath | ||
); | ||
}) | ||
generateApplicationClient(jsonObj, srcPath, importPath); | ||
}); | ||
program.parse() | ||
program.parse(); |
@@ -1,2 +0,2 @@ | ||
import type algosdk from "algosdk"; | ||
import type algosdk from 'algosdk'; | ||
@@ -8,19 +8,19 @@ export enum AVMType { | ||
type StructElement = [string, string] | ||
type StructElement = [string, string]; | ||
export interface Struct { | ||
name: string, | ||
elements: StructElement[] | ||
name: string; | ||
elements: StructElement[]; | ||
} | ||
export interface DefaultArgument { | ||
source: string | ||
data: string | bigint | number | ||
source: string; | ||
data: string | bigint | number; | ||
} | ||
export interface Hint { | ||
structs: Record<string, Struct> | ||
readonly: boolean | ||
default_arguments: Record<string, DefaultArgument> | ||
structs: Record<string, Struct>; | ||
readonly: boolean; | ||
default_arguments: Record<string, DefaultArgument>; | ||
} | ||
export type HintSpec = Record<string, Hint> | ||
export type HintSpec = Record<string, Hint>; | ||
@@ -41,4 +41,4 @@ export interface DeclaredSchemaValueSpec { | ||
export interface Schema { | ||
declared: Record<string, DeclaredSchemaValueSpec> | ||
dynamic: Record<string, DynamicSchemaValueSpec> | ||
declared: Record<string, DeclaredSchemaValueSpec>; | ||
dynamic: Record<string, DynamicSchemaValueSpec>; | ||
} | ||
@@ -45,0 +45,0 @@ |
@@ -8,7 +8,7 @@ import type { | ||
Struct, | ||
} from "./appspec"; | ||
} from './appspec'; | ||
import algosdk from "algosdk"; | ||
import ts, { factory } from "typescript"; | ||
import { writeFileSync } from "fs"; | ||
import algosdk from 'algosdk'; | ||
import ts, { factory } from 'typescript'; | ||
import { writeFileSync } from 'fs'; | ||
@@ -18,50 +18,52 @@ // AMAZING resource: | ||
const CLIENT_NAME = "bkr.ApplicationClient"; | ||
const CLIENT_NAME = 'bkr.ApplicationClient'; | ||
// TODO: only import if we _need_ them | ||
const CLIENT_IMPORTS = `* as bkr`; | ||
const CLIENT_PATH = "beaker-ts"; | ||
const CLIENT_PATH = 'beaker-ts'; | ||
const ALGOSDK_IMPORTS = "algosdk"; | ||
const ALGOSDK_PATH = "algosdk"; | ||
const ALGOSDK_IMPORTS = 'algosdk'; | ||
const ALGOSDK_PATH = 'algosdk'; | ||
const REF_TYPES: string[] = ["account", "application", "asset"]; | ||
const REF_TYPES: string[] = ['account', 'application', 'asset']; | ||
const TXN_TYPES: string[] = [ | ||
"txn", | ||
"pay", | ||
"axfer", | ||
"acfg", | ||
"appl", | ||
"keyreg", | ||
"frz", | ||
'txn', | ||
'pay', | ||
'axfer', | ||
'acfg', | ||
'appl', | ||
'keyreg', | ||
'frz', | ||
]; | ||
// native types | ||
const UINT8_ARRAY_IDENT = factory.createIdentifier("Uint8Array") | ||
const UINT8_ARRAY_TYPE = factory.createTypeReferenceNode(UINT8_ARRAY_IDENT) | ||
const UINT8_ARRAY_IDENT = factory.createIdentifier('Uint8Array'); | ||
const UINT8_ARRAY_TYPE = factory.createTypeReferenceNode(UINT8_ARRAY_IDENT); | ||
// sdk types | ||
const ABI_METHOD_IDENT = factory.createIdentifier("algosdk.ABIMethod") | ||
const ABI_METHOD_TYPE = factory.createTypeReferenceNode( ABI_METHOD_IDENT) | ||
const ATC_IDENT = factory.createIdentifier("algosdk.AtomicTransactionComposer") | ||
const ATC_TYPE = factory.createTypeReferenceNode(ATC_IDENT) | ||
const ABI_METHOD_IDENT = factory.createIdentifier('algosdk.ABIMethod'); | ||
const ABI_METHOD_TYPE = factory.createTypeReferenceNode(ABI_METHOD_IDENT); | ||
const ATC_IDENT = factory.createIdentifier('algosdk.AtomicTransactionComposer'); | ||
const ATC_TYPE = factory.createTypeReferenceNode(ATC_IDENT); | ||
// bkr types | ||
const ABI_RESULT_IDENT = factory.createIdentifier("bkr.ABIResult") | ||
const DECODE_NAMED_TUPLE_IDENT = factory.createIdentifier("bkr.decodeNamedTuple") | ||
const SCHEMA_TYPE = factory.createTypeReferenceNode("bkr.Schema") | ||
const TRANSACTION_OVERRIDES_TYPE = factory.createTypeReferenceNode("bkr.TransactionOverrides") | ||
const ABI_RESULT_IDENT = factory.createIdentifier('bkr.ABIResult'); | ||
const DECODE_NAMED_TUPLE_IDENT = factory.createIdentifier( | ||
'bkr.decodeNamedTuple', | ||
); | ||
const SCHEMA_TYPE = factory.createTypeReferenceNode('bkr.Schema'); | ||
const TRANSACTION_OVERRIDES_TYPE = factory.createTypeReferenceNode( | ||
'bkr.TransactionOverrides', | ||
); | ||
function tsTypeFromAbiType(argType: string | algosdk.ABIType): ts.TypeNode { | ||
if (typeof argType === "string") { | ||
if (typeof argType === 'string') { | ||
if (TXN_TYPES.includes(argType)) | ||
return factory.createUnionTypeNode([ | ||
factory.createTypeReferenceNode("algosdk.TransactionWithSigner"), | ||
factory.createTypeReferenceNode("algosdk.Transaction"), | ||
factory.createTypeReferenceNode('algosdk.TransactionWithSigner'), | ||
factory.createTypeReferenceNode('algosdk.Transaction'), | ||
]); | ||
if (REF_TYPES.includes(argType)) { | ||
if (["application", "asset"].includes(argType)) | ||
if (['application', 'asset'].includes(argType)) | ||
return factory.createKeywordTypeNode(ts.SyntaxKind.BigIntKeyword); | ||
@@ -74,3 +76,3 @@ | ||
const abiType = | ||
typeof argType === "string" ? algosdk.ABIType.from(argType) : argType; | ||
typeof argType === 'string' ? algosdk.ABIType.from(argType) : argType; | ||
switch (abiType.constructor) { | ||
@@ -92,7 +94,7 @@ case algosdk.ABIByteType: | ||
case algosdk.ABIByteType: | ||
return UINT8_ARRAY_TYPE | ||
return UINT8_ARRAY_TYPE; | ||
} | ||
return factory.createArrayTypeNode( | ||
tsTypeFromAbiType(asStaticArr.childType) | ||
tsTypeFromAbiType(asStaticArr.childType), | ||
); | ||
@@ -105,3 +107,3 @@ case algosdk.ABIArrayDynamicType: | ||
case algosdk.ABIByteType: | ||
return UINT8_ARRAY_TYPE | ||
return UINT8_ARRAY_TYPE; | ||
} | ||
@@ -116,3 +118,3 @@ | ||
return tsTypeFromAbiType(elem); | ||
}) | ||
}), | ||
); | ||
@@ -127,3 +129,3 @@ } | ||
case ts.SyntaxKind.StringKeyword: | ||
return factory.createStringLiteral(""); | ||
return factory.createStringLiteral(''); | ||
case ts.SyntaxKind.NumberKeyword: | ||
@@ -133,17 +135,13 @@ return factory.createNumericLiteral(0); | ||
return factory.createCallExpression( | ||
factory.createIdentifier("BigInt"), | ||
factory.createIdentifier('BigInt'), | ||
undefined, | ||
[factory.createNumericLiteral("0")] | ||
[factory.createNumericLiteral('0')], | ||
); | ||
case ts.SyntaxKind.BooleanKeyword: | ||
return factory.createIdentifier("false"); | ||
return factory.createIdentifier('false'); | ||
case ts.SyntaxKind.TypeReference: | ||
return factory.createNewExpression( | ||
UINT8_ARRAY_IDENT, | ||
undefined, | ||
[] | ||
); | ||
return factory.createNewExpression(UINT8_ARRAY_IDENT, undefined, []); | ||
} | ||
return factory.createIdentifier("undefined"); | ||
return factory.createIdentifier('undefined'); | ||
} | ||
@@ -154,4 +152,4 @@ | ||
path: string, | ||
beakerPath?: string | ||
) { | ||
beakerPath?: string, | ||
): void { | ||
const name = appSpec.contract.name; | ||
@@ -174,7 +172,7 @@ | ||
name, | ||
"", | ||
'', | ||
ts.ScriptTarget.ESNext, | ||
true, | ||
ts.ScriptKind.TS | ||
) | ||
ts.ScriptKind.TS, | ||
), | ||
); | ||
@@ -196,6 +194,6 @@ | ||
factory.createIdentifier(ALGOSDK_IMPORTS), | ||
undefined | ||
undefined, | ||
), | ||
factory.createStringLiteral(ALGOSDK_PATH), | ||
undefined | ||
undefined, | ||
), | ||
@@ -210,6 +208,6 @@ | ||
factory.createIdentifier(CLIENT_IMPORTS), | ||
undefined | ||
undefined, | ||
), | ||
factory.createStringLiteral(beakerPath ? beakerPath : CLIENT_PATH), | ||
undefined | ||
undefined, | ||
), | ||
@@ -229,3 +227,3 @@ ]; | ||
factory.createIdentifier(CLIENT_NAME), | ||
undefined | ||
undefined, | ||
), | ||
@@ -237,6 +235,6 @@ ]), | ||
...appSpec.contract.methods.map((meth) => | ||
generateMethodImpl(meth, appSpec) | ||
generateMethodImpl(meth, appSpec), | ||
), | ||
generateComposeMethods(appSpec), | ||
] | ||
], | ||
); | ||
@@ -250,3 +248,3 @@ } | ||
undefined, | ||
factory.createIdentifier("compose"), | ||
factory.createIdentifier('compose'), | ||
undefined, | ||
@@ -256,4 +254,4 @@ undefined, | ||
spec.contract.methods.map((meth) => { | ||
const [key, value] = generateComposeMethodImpl(meth, spec) | ||
return factory.createPropertyAssignment(key, value) | ||
const [key, value] = generateComposeMethodImpl(meth, spec); | ||
return factory.createPropertyAssignment(key, value); | ||
}), | ||
@@ -265,8 +263,7 @@ true, | ||
// Creates the methods on the AppClient class used to call specific ABI methods | ||
// Creates the methods on the AppClient class used to call specific ABI methods | ||
function generateMethodImpl( | ||
method: algosdk.ABIMethod, | ||
spec: AppSpec | ||
spec: AppSpec, | ||
): ts.ClassElement { | ||
const params: ts.ParameterDeclaration[] = []; | ||
@@ -304,10 +301,10 @@ const abiMethodArgs: ts.PropertyAssignment[] = []; | ||
let data: ts.Expression; | ||
if (typeof defaultArg.data == "string") { | ||
if (typeof defaultArg.data == 'string') { | ||
data = factory.createStringLiteral(defaultArg.data); | ||
} else if (typeof defaultArg.data == "bigint") { | ||
} else if (typeof defaultArg.data == 'bigint') { | ||
data = factory.createBigIntLiteral(defaultArg.data.toString()); | ||
} else if (typeof defaultArg.data == "number") { | ||
} else if (typeof defaultArg.data == 'number') { | ||
data = factory.createNumericLiteral(defaultArg.data); | ||
} else { | ||
data = factory.createIdentifier("undefined"); | ||
data = factory.createIdentifier('undefined'); | ||
} | ||
@@ -319,3 +316,3 @@ | ||
factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), | ||
factory.createIdentifier("undefined") | ||
factory.createIdentifier('undefined'), | ||
), | ||
@@ -326,11 +323,11 @@ factory.createToken(ts.SyntaxKind.QuestionToken), | ||
factory.createCallExpression( | ||
factory.createIdentifier("this.resolve"), | ||
factory.createIdentifier('this.resolve'), | ||
undefined, | ||
[factory.createStringLiteral(defaultArg.source), data] | ||
) | ||
[factory.createStringLiteral(defaultArg.source), data], | ||
), | ||
), | ||
argType | ||
argType, | ||
), | ||
factory.createToken(ts.SyntaxKind.ColonToken), | ||
argVal | ||
argVal, | ||
); | ||
@@ -348,3 +345,3 @@ } | ||
argParams.push( | ||
factory.createPropertySignature(undefined, arg.name, optional, argType) | ||
factory.createPropertySignature(undefined, arg.name, optional, argType), | ||
); | ||
@@ -354,3 +351,3 @@ } | ||
// Expect args | ||
if(argParams.length>0){ | ||
if (argParams.length > 0) { | ||
params.push( | ||
@@ -361,6 +358,6 @@ factory.createParameterDeclaration( | ||
undefined, | ||
factory.createIdentifier("args"), | ||
factory.createIdentifier('args'), | ||
undefined, | ||
factory.createTypeLiteralNode(argParams) | ||
) | ||
factory.createTypeLiteralNode(argParams), | ||
), | ||
); | ||
@@ -371,3 +368,3 @@ } | ||
const txnParams = factory.createIdentifier("txnParams"); | ||
const txnParams = factory.createIdentifier('txnParams'); | ||
params.push( | ||
@@ -381,3 +378,3 @@ factory.createParameterDeclaration( | ||
TRANSACTION_OVERRIDES_TYPE, | ||
) | ||
), | ||
); | ||
@@ -387,7 +384,7 @@ | ||
let abiRetType: ts.TypeNode = factory.createKeywordTypeNode( | ||
ts.SyntaxKind.VoidKeyword | ||
ts.SyntaxKind.VoidKeyword, | ||
); | ||
let resultArgs: ts.Expression[] = [factory.createIdentifier("result")]; | ||
const resultArgs: ts.Expression[] = [factory.createIdentifier('result')]; | ||
if (method.returns.type.toString() !== "void") { | ||
if (method.returns.type.toString() !== 'void') { | ||
abiRetType = tsTypeFromAbiType(method.returns.type.toString()); | ||
@@ -399,5 +396,5 @@ // Always `output` here because pyteal, | ||
hint?.structs !== undefined && | ||
"output" in hint.structs | ||
'output' in hint.structs | ||
) { | ||
const outputHint = hint.structs["output"]; | ||
const outputHint = hint.structs['output']; | ||
if (outputHint !== undefined) { | ||
@@ -409,3 +406,3 @@ abiRetType = factory.createTypeReferenceNode(outputHint?.name); | ||
factory.createIdentifier(outputHint.name), | ||
factory.createIdentifier("decodeResult") | ||
factory.createIdentifier('decodeResult'), | ||
), | ||
@@ -415,7 +412,7 @@ undefined, | ||
factory.createPropertyAccessExpression( | ||
factory.createIdentifier("result"), | ||
factory.createIdentifier("returnValue") | ||
factory.createIdentifier('result'), | ||
factory.createIdentifier('returnValue'), | ||
), | ||
] | ||
) | ||
], | ||
), | ||
); | ||
@@ -427,7 +424,7 @@ } | ||
factory.createPropertyAccessExpression( | ||
factory.createIdentifier("result"), | ||
factory.createIdentifier("returnValue") | ||
factory.createIdentifier('result'), | ||
factory.createIdentifier('returnValue'), | ||
), | ||
abiRetType | ||
) | ||
abiRetType, | ||
), | ||
); | ||
@@ -439,11 +436,15 @@ } | ||
if(argParams.length>0){ | ||
composeArgs.push(factory.createObjectLiteralExpression(abiMethodArgs)) | ||
if (argParams.length > 0) { | ||
composeArgs.push(factory.createObjectLiteralExpression(abiMethodArgs)); | ||
} | ||
composeArgs.push(txnParams) | ||
composeArgs.push(txnParams); | ||
const composeExpr = factory.createAwaitExpression( | ||
factory.createCallExpression(factory.createIdentifier("this.compose."+method.name), undefined, composeArgs) | ||
) | ||
const composeExpr = factory.createAwaitExpression( | ||
factory.createCallExpression( | ||
factory.createIdentifier('this.compose.' + method.name), | ||
undefined, | ||
composeArgs, | ||
), | ||
); | ||
@@ -457,3 +458,3 @@ const body = factory.createBlock( | ||
factory.createVariableDeclaration( | ||
factory.createIdentifier("result"), | ||
factory.createIdentifier('result'), | ||
undefined, | ||
@@ -465,27 +466,23 @@ undefined, | ||
factory.createThis(), | ||
factory.createIdentifier("execute") | ||
factory.createIdentifier('execute'), | ||
), | ||
undefined, | ||
[ composeExpr ] | ||
) | ||
) | ||
[composeExpr], | ||
), | ||
), | ||
), | ||
], | ||
ts.NodeFlags.Const | ||
) | ||
ts.NodeFlags.Const, | ||
), | ||
), | ||
factory.createReturnStatement( | ||
factory.createNewExpression( | ||
ABI_RESULT_IDENT, [abiRetType], resultArgs | ||
) | ||
factory.createNewExpression(ABI_RESULT_IDENT, [abiRetType], resultArgs), | ||
), | ||
], | ||
true | ||
true, | ||
); | ||
let retType = factory.createTypeReferenceNode( | ||
factory.createIdentifier("Promise"), | ||
[ | ||
factory.createTypeReferenceNode(ABI_RESULT_IDENT, [abiRetType]), | ||
] | ||
const retType = factory.createTypeReferenceNode( | ||
factory.createIdentifier('Promise'), | ||
[factory.createTypeReferenceNode(ABI_RESULT_IDENT, [abiRetType])], | ||
); | ||
@@ -502,3 +499,3 @@ | ||
retType, | ||
body | ||
body, | ||
); | ||
@@ -513,5 +510,4 @@ | ||
method: algosdk.ABIMethod, | ||
spec: AppSpec | ||
spec: AppSpec, | ||
): [string, ts.ArrowFunction] { | ||
const params: ts.ParameterDeclaration[] = []; | ||
@@ -527,3 +523,3 @@ const callArgs: ts.Expression[] = []; | ||
factory.createCallExpression( | ||
factory.createIdentifier("algosdk.getMethodByName"), | ||
factory.createIdentifier('algosdk.getMethodByName'), | ||
undefined, | ||
@@ -533,11 +529,13 @@ [ | ||
factory.createThis(), | ||
factory.createIdentifier("methods") | ||
factory.createIdentifier('methods'), | ||
), | ||
factory.createStringLiteral(method.name), | ||
] | ||
) | ||
], | ||
), | ||
); | ||
for (const arg of method.args) { | ||
if (arg.name === undefined) continue; | ||
if (arg.name === undefined) { | ||
continue; | ||
} | ||
@@ -566,10 +564,10 @@ const argName: ts.Identifier = factory.createIdentifier(arg.name); | ||
let data: ts.Expression; | ||
if (typeof defaultArg.data == "string") { | ||
if (typeof defaultArg.data == 'string') { | ||
data = factory.createStringLiteral(defaultArg.data); | ||
} else if (typeof defaultArg.data == "bigint") { | ||
} else if (typeof defaultArg.data == 'bigint') { | ||
data = factory.createBigIntLiteral(defaultArg.data.toString()); | ||
} else if (typeof defaultArg.data == "number") { | ||
} else if (typeof defaultArg.data == 'number') { | ||
data = factory.createNumericLiteral(defaultArg.data); | ||
} else { | ||
data = factory.createIdentifier("undefined"); | ||
data = factory.createIdentifier('undefined'); | ||
} | ||
@@ -581,14 +579,14 @@ | ||
factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), | ||
factory.createIdentifier("undefined") | ||
factory.createIdentifier('undefined'), | ||
), | ||
factory.createToken(ts.SyntaxKind.QuestionToken), | ||
factory.createAwaitExpression( | ||
factory.createCallExpression( | ||
factory.createIdentifier("this.resolve"), | ||
undefined, | ||
[factory.createStringLiteral(defaultArg.source), data] | ||
) | ||
factory.createAwaitExpression( | ||
factory.createCallExpression( | ||
factory.createIdentifier('this.resolve'), | ||
undefined, | ||
[factory.createStringLiteral(defaultArg.source), data], | ||
), | ||
), | ||
factory.createToken(ts.SyntaxKind.ColonToken), | ||
argVal | ||
argVal, | ||
); | ||
@@ -605,3 +603,3 @@ } | ||
argParams.push( | ||
factory.createPropertySignature(undefined, arg.name, optional, argType) | ||
factory.createPropertySignature(undefined, arg.name, optional, argType), | ||
); | ||
@@ -611,3 +609,3 @@ } | ||
// Expect args | ||
if(argParams.length>0){ | ||
if (argParams.length > 0) { | ||
params.push( | ||
@@ -618,10 +616,10 @@ factory.createParameterDeclaration( | ||
undefined, | ||
factory.createIdentifier("args"), | ||
factory.createIdentifier('args'), | ||
undefined, | ||
factory.createTypeLiteralNode(argParams) | ||
) | ||
factory.createTypeLiteralNode(argParams), | ||
), | ||
); | ||
} | ||
const txnParams = factory.createIdentifier("txnParams"); | ||
const txnParams = factory.createIdentifier('txnParams'); | ||
params.push( | ||
@@ -635,6 +633,6 @@ factory.createParameterDeclaration( | ||
TRANSACTION_OVERRIDES_TYPE, | ||
) | ||
), | ||
); | ||
const atcParam = factory.createIdentifier("atc"); | ||
const atcParam = factory.createIdentifier('atc'); | ||
params.push( | ||
@@ -648,3 +646,3 @@ factory.createParameterDeclaration( | ||
ATC_TYPE, | ||
) | ||
), | ||
); | ||
@@ -658,3 +656,3 @@ | ||
factory.createThis(), | ||
factory.createIdentifier("addMethodCall") | ||
factory.createIdentifier('addMethodCall'), | ||
), | ||
@@ -667,14 +665,12 @@ undefined, | ||
atcParam, | ||
] | ||
) | ||
) | ||
], | ||
), | ||
), | ||
], | ||
true | ||
true, | ||
); | ||
let retType = factory.createTypeReferenceNode( | ||
factory.createIdentifier("Promise"), | ||
[ | ||
factory.createTypeReferenceNode(ATC_IDENT), | ||
] | ||
const retType = factory.createTypeReferenceNode( | ||
factory.createIdentifier('Promise'), | ||
[factory.createTypeReferenceNode(ATC_IDENT)], | ||
); | ||
@@ -691,3 +687,2 @@ | ||
return [method.name, fncSpec]; | ||
@@ -703,14 +698,14 @@ } | ||
factory.createPropertyAssignment( | ||
factory.createIdentifier("type"), | ||
factory.createIdentifier(`bkr.AVMType.${sv[1].type}`) | ||
factory.createIdentifier('type'), | ||
factory.createIdentifier(`bkr.AVMType.${sv[1].type}`), | ||
), | ||
objStrProperty("key", sv[1].key), | ||
objStrProperty("desc", sv[1].desc), | ||
objStrProperty('key', sv[1].key), | ||
objStrProperty('desc', sv[1].desc), | ||
factory.createPropertyAssignment( | ||
factory.createIdentifier("static"), | ||
sv[1].static ? factory.createTrue() : factory.createFalse() | ||
factory.createIdentifier('static'), | ||
sv[1].static ? factory.createTrue() : factory.createFalse(), | ||
), | ||
]) | ||
]), | ||
); | ||
} | ||
}, | ||
); | ||
@@ -724,13 +719,13 @@ | ||
factory.createPropertyAssignment( | ||
factory.createIdentifier("type"), | ||
factory.createIdentifier(`bkr.AVMType.${sv[1].type.toString()}`) | ||
factory.createIdentifier('type'), | ||
factory.createIdentifier(`bkr.AVMType.${sv[1].type.toString()}`), | ||
), | ||
objStrProperty("desc", sv[1].desc), | ||
objStrProperty('desc', sv[1].desc), | ||
factory.createPropertyAssignment( | ||
factory.createIdentifier("max_keys"), | ||
factory.createNumericLiteral(sv[1].max_keys ? sv[1].max_keys : 0) | ||
factory.createIdentifier('max_keys'), | ||
factory.createNumericLiteral(sv[1].max_keys ? sv[1].max_keys : 0), | ||
), | ||
]) | ||
]), | ||
); | ||
} | ||
}, | ||
); | ||
@@ -740,8 +735,8 @@ | ||
factory.createPropertyAssignment( | ||
factory.createIdentifier("declared"), | ||
factory.createObjectLiteralExpression(declaredAppSchemaProps) | ||
factory.createIdentifier('declared'), | ||
factory.createObjectLiteralExpression(declaredAppSchemaProps), | ||
), | ||
factory.createPropertyAssignment( | ||
factory.createIdentifier("dynamic"), | ||
factory.createObjectLiteralExpression(dynamicAppSchemaProps) | ||
factory.createIdentifier('dynamic'), | ||
factory.createObjectLiteralExpression(dynamicAppSchemaProps), | ||
), | ||
@@ -788,4 +783,4 @@ ]); | ||
tsType, | ||
defaultValueFromTsType(tsType) | ||
) | ||
defaultValueFromTsType(tsType), | ||
), | ||
); | ||
@@ -798,10 +793,10 @@ } | ||
[factory.createModifier(ts.SyntaxKind.StaticKeyword)], | ||
factory.createIdentifier("codec"), | ||
factory.createIdentifier('codec'), | ||
undefined, | ||
factory.createTypeReferenceNode( | ||
factory.createQualifiedName( | ||
factory.createIdentifier("algosdk"), | ||
factory.createIdentifier("ABIType") | ||
factory.createIdentifier('algosdk'), | ||
factory.createIdentifier('ABIType'), | ||
), | ||
undefined | ||
undefined, | ||
), | ||
@@ -811,11 +806,11 @@ factory.createCallExpression( | ||
factory.createPropertyAccessExpression( | ||
factory.createIdentifier("algosdk"), | ||
factory.createIdentifier("ABIType") | ||
factory.createIdentifier('algosdk'), | ||
factory.createIdentifier('ABIType'), | ||
), | ||
factory.createIdentifier("from") | ||
factory.createIdentifier('from'), | ||
), | ||
undefined, | ||
[factory.createStringLiteral(`(${tupleTypes.join(",")})`)] | ||
) | ||
) | ||
[factory.createStringLiteral(`(${tupleTypes.join(',')})`)], | ||
), | ||
), | ||
); | ||
@@ -826,11 +821,11 @@ members.push( | ||
[factory.createModifier(ts.SyntaxKind.StaticKeyword)], | ||
factory.createIdentifier("fields"), | ||
factory.createIdentifier('fields'), | ||
undefined, | ||
factory.createTypeReferenceNode("string[]"), | ||
factory.createTypeReferenceNode('string[]'), | ||
factory.createArrayLiteralExpression( | ||
tupleNames.map((name) => { | ||
return factory.createStringLiteral(name); | ||
}) | ||
) | ||
) | ||
}), | ||
), | ||
), | ||
); | ||
@@ -844,3 +839,3 @@ | ||
undefined, | ||
factory.createIdentifier("decodeResult"), | ||
factory.createIdentifier('decodeResult'), | ||
undefined, | ||
@@ -853,3 +848,3 @@ undefined, | ||
undefined, | ||
factory.createIdentifier("val"), | ||
factory.createIdentifier('val'), | ||
undefined, | ||
@@ -859,10 +854,10 @@ factory.createUnionTypeNode([ | ||
factory.createQualifiedName( | ||
factory.createIdentifier("algosdk"), | ||
factory.createIdentifier("ABIValue") | ||
factory.createIdentifier('algosdk'), | ||
factory.createIdentifier('ABIValue'), | ||
), | ||
undefined | ||
undefined, | ||
), | ||
factory.createTypeReferenceNode("undefined"), | ||
factory.createTypeReferenceNode('undefined'), | ||
]), | ||
undefined | ||
undefined, | ||
), | ||
@@ -872,3 +867,3 @@ ], | ||
factory.createIdentifier(s.name), | ||
undefined | ||
undefined, | ||
), | ||
@@ -883,19 +878,19 @@ factory.createBlock( | ||
[ | ||
factory.createIdentifier("val"), | ||
factory.createIdentifier('val'), | ||
factory.createPropertyAccessExpression( | ||
factory.createIdentifier(s.name), | ||
factory.createIdentifier("fields") | ||
factory.createIdentifier('fields'), | ||
), | ||
] | ||
], | ||
), | ||
factory.createTypeReferenceNode( | ||
factory.createIdentifier(s.name), | ||
undefined | ||
) | ||
) | ||
undefined, | ||
), | ||
), | ||
), | ||
], | ||
true | ||
) | ||
) | ||
true, | ||
), | ||
), | ||
); | ||
@@ -908,3 +903,3 @@ | ||
undefined, | ||
factory.createIdentifier("decodeBytes"), | ||
factory.createIdentifier('decodeBytes'), | ||
undefined, | ||
@@ -917,6 +912,6 @@ undefined, | ||
undefined, | ||
factory.createIdentifier("val"), | ||
factory.createIdentifier('val'), | ||
undefined, | ||
UINT8_ARRAY_TYPE, | ||
undefined | ||
undefined, | ||
), | ||
@@ -926,3 +921,3 @@ ], | ||
factory.createIdentifier(s.name), | ||
undefined | ||
undefined, | ||
), | ||
@@ -941,25 +936,25 @@ factory.createBlock( | ||
factory.createIdentifier(s.name), | ||
factory.createIdentifier("codec") | ||
factory.createIdentifier('codec'), | ||
), | ||
factory.createIdentifier("decode") | ||
factory.createIdentifier('decode'), | ||
), | ||
undefined, | ||
[factory.createIdentifier("val")] | ||
[factory.createIdentifier('val')], | ||
), | ||
factory.createPropertyAccessExpression( | ||
factory.createIdentifier(s.name), | ||
factory.createIdentifier("fields") | ||
factory.createIdentifier('fields'), | ||
), | ||
] | ||
], | ||
), | ||
factory.createTypeReferenceNode( | ||
factory.createIdentifier(s.name), | ||
undefined | ||
) | ||
) | ||
undefined, | ||
), | ||
), | ||
), | ||
], | ||
true | ||
) | ||
) | ||
true, | ||
), | ||
), | ||
); | ||
@@ -973,3 +968,3 @@ | ||
undefined, | ||
members | ||
members, | ||
); | ||
@@ -988,18 +983,18 @@ } | ||
undefined, | ||
factory.createIdentifier("desc"), | ||
factory.createIdentifier('desc'), | ||
undefined, | ||
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), | ||
factory.createStringLiteral(descr ? descr : "") | ||
factory.createStringLiteral(descr ? descr : ''), | ||
); | ||
// Create approval program property | ||
let approvalProp | ||
if(source.approval !== undefined){ | ||
let approvalProp; | ||
if (source.approval !== undefined) { | ||
approvalProp = factory.createPropertyDeclaration( | ||
undefined, | ||
[factory.createModifier(ts.SyntaxKind.OverrideKeyword)], | ||
factory.createIdentifier("approvalProgram"), | ||
factory.createIdentifier('approvalProgram'), | ||
undefined, | ||
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), | ||
factory.createStringLiteral(source.approval) | ||
factory.createStringLiteral(source.approval), | ||
); | ||
@@ -1009,11 +1004,11 @@ } | ||
// Create clear program property | ||
let clearProp | ||
if(source.clear !== undefined){ | ||
let clearProp; | ||
if (source.clear !== undefined) { | ||
clearProp = factory.createPropertyDeclaration( | ||
undefined, | ||
[factory.createModifier(ts.SyntaxKind.OverrideKeyword)], | ||
factory.createIdentifier("clearProgram"), | ||
factory.createIdentifier('clearProgram'), | ||
undefined, | ||
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), | ||
factory.createStringLiteral(source.clear) | ||
factory.createStringLiteral(source.clear), | ||
); | ||
@@ -1023,11 +1018,11 @@ } | ||
// Create App Schema Property | ||
let appSchemaProp | ||
if(schema.global !== undefined){ | ||
let appSchemaProp; | ||
if (schema.global !== undefined) { | ||
appSchemaProp = factory.createPropertyDeclaration( | ||
undefined, | ||
[factory.createModifier(ts.SyntaxKind.OverrideKeyword)], | ||
factory.createIdentifier("appSchema"), | ||
factory.createIdentifier('appSchema'), | ||
undefined, | ||
SCHEMA_TYPE, | ||
copySchemaObject(schema.global) | ||
copySchemaObject(schema.global), | ||
); | ||
@@ -1037,11 +1032,11 @@ } | ||
// Create Acct schema property | ||
let acctSchemaProp | ||
if(schema.local !== undefined) { | ||
let acctSchemaProp; | ||
if (schema.local !== undefined) { | ||
acctSchemaProp = factory.createPropertyDeclaration( | ||
undefined, | ||
[factory.createModifier(ts.SyntaxKind.OverrideKeyword)], | ||
factory.createIdentifier("acctSchema"), | ||
factory.createIdentifier('acctSchema'), | ||
undefined, | ||
SCHEMA_TYPE, | ||
copySchemaObject(schema.local) | ||
copySchemaObject(schema.local), | ||
); | ||
@@ -1053,8 +1048,7 @@ } | ||
for (const meth of methods) { | ||
const argObjs: ts.ObjectLiteralExpression[] = meth.args.map((arg) => { | ||
return factory.createObjectLiteralExpression([ | ||
objStrProperty("type", arg.type.toString()), | ||
objStrProperty("name", arg.name), | ||
objStrProperty("desc", arg.description) | ||
objStrProperty('type', arg.type.toString()), | ||
objStrProperty('name', arg.name), | ||
objStrProperty('desc', arg.description), | ||
]); | ||
@@ -1064,26 +1058,22 @@ }); | ||
const returnObj = factory.createObjectLiteralExpression([ | ||
objStrProperty("type", meth.returns.type.toString()), | ||
objStrProperty("desc", meth.returns.description) | ||
objStrProperty('type', meth.returns.type.toString()), | ||
objStrProperty('desc', meth.returns.description), | ||
]); | ||
// Create ABIMethod object | ||
// Create ABIMethod object | ||
methodAssignments.push( | ||
factory.createNewExpression( | ||
ABI_METHOD_IDENT, | ||
undefined, | ||
[ | ||
factory.createObjectLiteralExpression([ | ||
objStrProperty("name", meth.name), | ||
objStrProperty("desc", meth.description), | ||
factory.createPropertyAssignment( | ||
factory.createIdentifier("args"), | ||
factory.createArrayLiteralExpression(argObjs) | ||
), | ||
factory.createPropertyAssignment( | ||
factory.createIdentifier("returns"), | ||
returnObj | ||
), | ||
]), | ||
] | ||
) | ||
factory.createNewExpression(ABI_METHOD_IDENT, undefined, [ | ||
factory.createObjectLiteralExpression([ | ||
objStrProperty('name', meth.name), | ||
objStrProperty('desc', meth.description), | ||
factory.createPropertyAssignment( | ||
factory.createIdentifier('args'), | ||
factory.createArrayLiteralExpression(argObjs), | ||
), | ||
factory.createPropertyAssignment( | ||
factory.createIdentifier('returns'), | ||
returnObj, | ||
), | ||
]), | ||
]), | ||
); | ||
@@ -1096,25 +1086,27 @@ } | ||
[factory.createModifier(ts.SyntaxKind.OverrideKeyword)], | ||
factory.createIdentifier("methods"), | ||
factory.createIdentifier('methods'), | ||
undefined, | ||
factory.createArrayTypeNode(ABI_METHOD_TYPE), | ||
factory.createArrayLiteralExpression(methodAssignments, true) | ||
factory.createArrayLiteralExpression(methodAssignments, true), | ||
); | ||
const props = [descrProp] | ||
if(appSchemaProp !== undefined) props.push(appSchemaProp) | ||
if(acctSchemaProp !== undefined) props.push(acctSchemaProp) | ||
if(approvalProp !== undefined) props.push(approvalProp) | ||
if(clearProp !== undefined) props.push(clearProp) | ||
props.push(methodProps) | ||
const props = [descrProp]; | ||
if (appSchemaProp !== undefined) props.push(appSchemaProp); | ||
if (acctSchemaProp !== undefined) props.push(acctSchemaProp); | ||
if (approvalProp !== undefined) props.push(approvalProp); | ||
if (clearProp !== undefined) props.push(clearProp); | ||
props.push(methodProps); | ||
return props | ||
return props; | ||
} | ||
function objStrProperty(k: string, v: string | undefined): ts.PropertyAssignment { | ||
const val = v===undefined?"":v | ||
function objStrProperty( | ||
k: string, | ||
v: string | undefined, | ||
): ts.PropertyAssignment { | ||
const val = v === undefined ? '' : v; | ||
return factory.createPropertyAssignment( | ||
factory.createIdentifier(k), | ||
factory.createStringLiteral(val) | ||
) | ||
} | ||
factory.createIdentifier(k), | ||
factory.createStringLiteral(val), | ||
); | ||
} |
@@ -1,7 +0,25 @@ | ||
export { ApplicationClient, ABIResult, MethodArg, MethodArgs, decodeNamedTuple, TransactionOverrides } from "./application_client/application_client"; | ||
export { LogicError, parseLogicError } from "./application_client/logic_error"; | ||
export { | ||
ApplicationClient, | ||
ABIResult, | ||
MethodArg, | ||
MethodArgs, | ||
decodeNamedTuple, | ||
TransactionOverrides, | ||
} from './application_client/application_client'; | ||
export { LogicError, parseLogicError } from './application_client/logic_error'; | ||
export {generateApplicationClient} from "./generate/generate"; | ||
export { HintSpec, DeclaredSchemaValueSpec, DynamicSchemaValueSpec, Schema, StateSchema, SchemaSpec, AppSources, AppSpec, AVMType, getStateSchema } from "./generate/appspec"; | ||
export { generateApplicationClient } from './generate/generate'; | ||
export { | ||
HintSpec, | ||
DeclaredSchemaValueSpec, | ||
DynamicSchemaValueSpec, | ||
Schema, | ||
StateSchema, | ||
SchemaSpec, | ||
AppSources, | ||
AppSpec, | ||
AVMType, | ||
getStateSchema, | ||
} from './generate/appspec'; | ||
export * as sandbox from "./sandbox"; | ||
export * as sandbox from './sandbox'; |
@@ -1,47 +0,50 @@ | ||
import algosdk from 'algosdk' | ||
import algosdk from 'algosdk'; | ||
const kmd_token = "a".repeat(64) | ||
const kmd_host = "http://localhost" | ||
const kmd_port = "4002" | ||
const kmd_wallet ="unencrypted-default-wallet" | ||
const kmd_password = "" | ||
const kmd_token = 'a'.repeat(64); | ||
const kmd_host = 'http://localhost'; | ||
const kmd_port = '4002'; | ||
const kmd_wallet = 'unencrypted-default-wallet'; | ||
const kmd_password = ''; | ||
export type SandboxAccount = { | ||
addr: string | ||
privateKey: Buffer | ||
signer: algosdk.TransactionSigner | ||
} | ||
addr: string; | ||
privateKey: Buffer; | ||
signer: algosdk.TransactionSigner; | ||
}; | ||
export async function getAccounts(): Promise<SandboxAccount[]> { | ||
const kmdClient = new algosdk.Kmd(kmd_token, kmd_host, kmd_port) | ||
const kmdClient = new algosdk.Kmd(kmd_token, kmd_host, kmd_port); | ||
const wallets = await kmdClient.listWallets() | ||
const wallets = await kmdClient.listWallets(); | ||
let walletId; | ||
for(const wallet of wallets['wallets']){ | ||
if(wallet['name'] === kmd_wallet) walletId = wallet['id'] | ||
} | ||
let walletId; | ||
for (const wallet of wallets['wallets']) { | ||
if (wallet['name'] === kmd_wallet) walletId = wallet['id']; | ||
} | ||
if (walletId===undefined) throw Error("No wallet named: "+kmd_wallet) | ||
if (walletId === undefined) throw Error('No wallet named: ' + kmd_wallet); | ||
const handleResp = await kmdClient.initWalletHandle(walletId, kmd_password) | ||
const handle = handleResp['wallet_handle_token'] | ||
const handleResp = await kmdClient.initWalletHandle(walletId, kmd_password); | ||
const handle = handleResp['wallet_handle_token']; | ||
const addresses = await kmdClient.listKeys(handle) | ||
const acctPromises: Promise<{private_key: Buffer}>[] = [] | ||
for(const addr of addresses['addresses']){ | ||
acctPromises.push(kmdClient.exportKey(handle, kmd_password, addr)) | ||
} | ||
const keys = await Promise.all(acctPromises) | ||
const addresses = await kmdClient.listKeys(handle); | ||
const acctPromises: Promise<{ private_key: Buffer }>[] = []; | ||
for (const addr of addresses['addresses']) { | ||
acctPromises.push(kmdClient.exportKey(handle, kmd_password, addr)); | ||
} | ||
const keys = await Promise.all(acctPromises); | ||
// Don't need to wait for it | ||
kmdClient.releaseWalletHandle(handle) | ||
// Don't need to wait for it | ||
kmdClient.releaseWalletHandle(handle); | ||
return keys.map((k)=>{ | ||
const addr = algosdk.encodeAddress(k.private_key.slice(32)) | ||
const acct = {sk:k.private_key, addr: addr} as algosdk.Account | ||
const signer = algosdk.makeBasicAccountTransactionSigner(acct) | ||
return {addr: acct.addr, privateKey: acct.sk, signer:signer} as SandboxAccount | ||
}) | ||
return keys.map((k) => { | ||
const addr = algosdk.encodeAddress(k.private_key.slice(32)); | ||
const acct = { sk: k.private_key, addr: addr } as algosdk.Account; | ||
const signer = algosdk.makeBasicAccountTransactionSigner(acct); | ||
return { | ||
addr: acct.addr, | ||
privateKey: acct.sk, | ||
signer: signer, | ||
} as SandboxAccount; | ||
}); | ||
} | ||
@@ -1,10 +0,9 @@ | ||
import algosdk from 'algosdk' | ||
import algosdk from 'algosdk'; | ||
export function getAlgodClient(): algosdk.Algodv2 { | ||
return new algosdk.Algodv2("a".repeat(64), "http://localhost", 4001) | ||
return new algosdk.Algodv2('a'.repeat(64), 'http://localhost', 4001); | ||
} | ||
export function getIndexerClient(): algosdk.Indexer { | ||
return new algosdk.Indexer("a".repeat(64), "http://localhost", 8980) | ||
return new algosdk.Indexer('a'.repeat(64), 'http://localhost', 8980); | ||
} |
@@ -1,2 +0,2 @@ | ||
export {getAlgodClient, getIndexerClient} from './clients' | ||
export {getAccounts} from './accounts' | ||
export { getAlgodClient, getIndexerClient } from './clients'; | ||
export { getAccounts } from './accounts'; |
240131
53
4119
11
94