From 2f2e30d277b0ee504b79c2dba5b3bccfb62d9c2c Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Fri, 12 Jul 2024 17:08:07 -0600 Subject: [PATCH] idl to idlType --- .../composite_queries/src/canister1/index.ts | 4 +- .../composite_queries/src/canister2/index.ts | 2 +- examples/manual_reply/src/index.ts | 44 +++++++++--------- property_tests/arbitraries/canister_arb.ts | 4 +- src/compiler/compile_typescript_code.ts | 4 +- src/lib/candid/candid_type.ts | 4 +- src/lib/candid/index.ts | 2 +- src/lib/candid/recursive.ts | 10 ++-- src/lib/candid/serde/decode.ts | 21 +++++---- src/lib/candid/serde/encode.ts | 19 ++++---- src/lib/candid/serde/visitors/visit/record.ts | 4 +- .../visitors/visit/variant/azle_variant.ts | 4 +- src/lib/candid/{to_idl.ts => to_idl_type.ts} | 22 ++++----- src/lib/candid/types/constructed/blob.ts | 2 +- src/lib/candid/types/constructed/opt.ts | 6 +-- src/lib/candid/types/constructed/record.ts | 8 ++-- .../candid/types/constructed/to_idl_map.ts | 17 ++++--- src/lib/candid/types/constructed/tuple.ts | 10 ++-- src/lib/candid/types/constructed/variant.ts | 6 +-- src/lib/candid/types/constructed/vec.ts | 6 +-- src/lib/candid/types/primitive/bool.ts | 2 +- src/lib/candid/types/primitive/empty.ts | 2 +- .../candid/types/primitive/floats/float32.ts | 2 +- .../candid/types/primitive/floats/float64.ts | 2 +- src/lib/candid/types/primitive/ints/int.ts | 2 +- src/lib/candid/types/primitive/ints/int16.ts | 2 +- src/lib/candid/types/primitive/ints/int32.ts | 2 +- src/lib/candid/types/primitive/ints/int64.ts | 2 +- src/lib/candid/types/primitive/ints/int8.ts | 2 +- src/lib/candid/types/primitive/nats/nat.ts | 2 +- src/lib/candid/types/primitive/nats/nat16.ts | 2 +- src/lib/candid/types/primitive/nats/nat32.ts | 2 +- src/lib/candid/types/primitive/nats/nat64.ts | 2 +- src/lib/candid/types/primitive/nats/nat8.ts | 2 +- src/lib/candid/types/primitive/null.ts | 2 +- src/lib/candid/types/primitive/reserved.ts | 2 +- src/lib/candid/types/primitive/text.ts | 2 +- src/lib/candid/types/primitive/void.ts | 2 +- src/lib/candid/types/reference/func.ts | 8 ++-- src/lib/candid/types/reference/principal.ts | 4 +- .../service/canister_function/index.ts | 34 ++++++++------ .../canister_function/system_methods.ts | 15 +++--- src/lib/ic/reply.ts | 4 +- src/lib/server.ts | 4 +- src/lib/stable/execute_with_candid_serde.ts | 10 ++-- src/lib/stable/ic_apis/call.ts | 15 +++--- src/lib/stable/ic_apis/notify.ts | 6 +-- src/lib/stable/ic_apis/reply.ts | 8 ++-- src/lib/stable/init.ts | 4 +- src/lib/stable/post_upgrade.ts | 4 +- src/lib/stable/query.ts | 16 +++---- src/lib/stable/update.ts | 8 ++-- src/lib/system_types/result.ts | 8 ++-- .../async_await/src/async_await.ts | 10 ++-- .../class_syntax/bitcoin/src/index.ts | 14 +++--- .../class_syntax/canister/src/index.ts | 2 +- .../ckbtc/wallet/backend/index.ts | 16 +++---- .../composite_queries/src/canister1/index.ts | 20 ++++---- .../composite_queries/src/canister2/index.ts | 7 ++- .../src/canister1/index.ts | 16 +++---- .../cycles/src/intermediary/index.ts | 2 +- .../ethereum_json_rpc/src/index.ts | 8 ++-- .../func_types/canisters/func_types/index.ts | 2 +- .../heartbeat/src/heartbeat_async/index.ts | 2 +- .../icrc/canisters/proxy/index.ts | 36 +++++++-------- .../src/ledger_canister/index.ts | 24 +++++----- .../management_canister/src/index.ts | 46 +++++++++---------- .../class_syntax/manual_reply/src/index.ts | 40 ++++++++-------- .../threshold_ecdsa/src/index.ts | 8 ++-- .../motoko_examples/whoami/src/index.ts | 2 +- .../outgoing_http_requests/src/index.ts | 4 +- .../recursion/src/recursion/index.ts | 4 +- .../rejections/src/rejections/index.ts | 6 +-- .../class_syntax/timers/src/timers.ts | 4 +- 74 files changed, 340 insertions(+), 316 deletions(-) rename src/lib/candid/{to_idl.ts => to_idl_type.ts} (62%) diff --git a/examples/composite_queries/src/canister1/index.ts b/examples/composite_queries/src/canister1/index.ts index 0bb9595824..7265babda6 100644 --- a/examples/composite_queries/src/canister1/index.ts +++ b/examples/composite_queries/src/canister1/index.ts @@ -72,11 +72,11 @@ const CompQueryCanister = Canister({ ); const responseJson = await response.json(); - ic.reply({ data: responseJson, type: text }); + ic.reply({ data: responseJson, candidType: text }); } else { ic.reply({ data: await ic.call(canister2.manualQuery), - type: text + candidType: text }); } }, diff --git a/examples/composite_queries/src/canister2/index.ts b/examples/composite_queries/src/canister2/index.ts index 3677d56605..4828bc05b9 100644 --- a/examples/composite_queries/src/canister2/index.ts +++ b/examples/composite_queries/src/canister2/index.ts @@ -37,7 +37,7 @@ export default Canister({ () => { ic.reply({ data: 'Hello from Canister 2 manual query', - type: text + candidType: text }); }, { manual: true } diff --git a/examples/manual_reply/src/index.ts b/examples/manual_reply/src/index.ts index 0a81e8e8c0..0d384e7675 100644 --- a/examples/manual_reply/src/index.ts +++ b/examples/manual_reply/src/index.ts @@ -79,7 +79,7 @@ export default Canister({ return; } - ic.reply({ data: message, type: text }); + ic.reply({ data: message, candidType: text }); }, { manual: true } ), @@ -91,7 +91,7 @@ export default Canister({ data: new Uint8Array([ 83, 117, 114, 112, 114, 105, 115, 101, 33 ]), - type: blob + candidType: blob }); }, { manual: true } @@ -100,7 +100,7 @@ export default Canister({ [], Manual(float32), () => { - ic.reply({ data: 1245.678, type: float32 }); + ic.reply({ data: 1245.678, candidType: float32 }); }, { manual: true } ), @@ -108,7 +108,7 @@ export default Canister({ [], Manual(int8), () => { - ic.reply({ data: -100, type: int8 }); + ic.reply({ data: -100, candidType: int8 }); }, { manual: true } ), @@ -116,7 +116,7 @@ export default Canister({ [], Manual(nat), () => { - ic.reply({ data: 184467440737095516150n, type: nat }); + ic.reply({ data: 184467440737095516150n, candidType: nat }); }, { manual: true } ), @@ -124,7 +124,7 @@ export default Canister({ [], Manual(Null), () => { - ic.reply({ data: null, type: Null }); + ic.reply({ data: null, candidType: Null }); }, { manual: true } ), @@ -132,7 +132,7 @@ export default Canister({ [], Manual(Void), () => { - ic.reply({ data: undefined, type: Void }); + ic.reply({ data: undefined, candidType: Void }); }, { manual: true } ), @@ -156,7 +156,7 @@ export default Canister({ Gas: { Elemental: null } } }; - ic.reply({ data: element, type: Element }); + ic.reply({ data: element, candidType: Element }); }, { manual: true } ), @@ -164,7 +164,7 @@ export default Canister({ [], Manual(reserved), () => { - ic.reply({ data: undefined, type: reserved }); + ic.reply({ data: undefined, candidType: reserved }); }, { manual: true } ), @@ -172,7 +172,7 @@ export default Canister({ [], Manual(text), () => { - ic.reply({ data: 'hello', type: text }); + ic.reply({ data: 'hello', candidType: text }); }, { manual: true } ), @@ -181,7 +181,7 @@ export default Canister({ Manual(Gas), () => { const gas = { Toxic: null }; - ic.reply({ data: gas, type: Gas }); + ic.reply({ data: gas, candidType: Gas }); }, { manual: true } ), @@ -207,7 +207,7 @@ export default Canister({ return; } - ic.reply({ data: message, type: text }); + ic.reply({ data: message, candidType: text }); }, { manual: true } ), @@ -219,7 +219,7 @@ export default Canister({ data: new Uint8Array([ 83, 117, 114, 112, 114, 105, 115, 101, 33 ]), - type: blob + candidType: blob }); }, { manual: true } @@ -228,7 +228,7 @@ export default Canister({ [], Manual(float32), () => { - ic.reply({ data: 1245.678, type: float32 }); + ic.reply({ data: 1245.678, candidType: float32 }); }, { manual: true } ), @@ -236,7 +236,7 @@ export default Canister({ [], Manual(int8), () => { - ic.reply({ data: -100, type: int8 }); + ic.reply({ data: -100, candidType: int8 }); }, { manual: true } ), @@ -244,7 +244,7 @@ export default Canister({ [], Manual(nat), () => { - ic.reply({ data: 184_467_440_737_095_516_150n, type: nat }); + ic.reply({ data: 184_467_440_737_095_516_150n, candidType: nat }); }, { manual: true } ), @@ -252,7 +252,7 @@ export default Canister({ [], Manual(Null), () => { - ic.reply({ data: null, type: Null }); + ic.reply({ data: null, candidType: Null }); }, { manual: true } ), @@ -260,7 +260,7 @@ export default Canister({ [], Manual(Void), () => { - ic.reply({ data: undefined, type: Void }); + ic.reply({ data: undefined, candidType: Void }); }, { manual: true } ), @@ -284,7 +284,7 @@ export default Canister({ Gas: { Elemental: null } } }; - ic.reply({ data: element, type: Element }); + ic.reply({ data: element, candidType: Element }); }, { manual: true } ), @@ -292,7 +292,7 @@ export default Canister({ [], Manual(reserved), () => { - ic.reply({ data: undefined, type: reserved }); + ic.reply({ data: undefined, candidType: reserved }); }, { manual: true } ), @@ -300,7 +300,7 @@ export default Canister({ [], Manual(text), () => { - ic.reply({ data: 'hello', type: text }); + ic.reply({ data: 'hello', candidType: text }); }, { manual: true } ), @@ -309,7 +309,7 @@ export default Canister({ Manual(Gas), () => { const gas = { Toxic: null }; - ic.reply({ data: gas, type: Gas }); + ic.reply({ data: gas, candidType: Gas }); }, { manual: true } ) diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index 57ea2f42dc..82f0c9cf92 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -71,7 +71,7 @@ export function CanisterArb< const initArgs = config.initMethod?.params.map((param) => { const value = param.value.value; return value.runtimeCandidTypeObject - .getIdl([]) + .getIdlType([]) .accept(new CliStringVisitor(), { value: value.agentArgumentValue }); @@ -81,7 +81,7 @@ export function CanisterArb< (param) => { const value = param.value.value; return value.runtimeCandidTypeObject - .getIdl([]) + .getIdlType([]) .accept(new CliStringVisitor(), { value: value.agentArgumentValue }); diff --git a/src/compiler/compile_typescript_code.ts b/src/compiler/compile_typescript_code.ts index 134a8f47ec..5d24a5b0f5 100644 --- a/src/compiler/compile_typescript_code.ts +++ b/src/compiler/compile_typescript_code.ts @@ -52,10 +52,10 @@ export async function compileTypeScriptToJavaScript( const canisterMethods = CanisterMethods.default !== undefined ? CanisterMethods.default() : Server(() => globalThis._azleNodeServer)(); globalThis.candidInfoFunction = () => { - const candidInfo = canisterMethods.getIdl([]).accept(new DidVisitor(), { + const candidInfo = canisterMethods.getIdlType([]).accept(new DidVisitor(), { ...getDefaultVisitorData(), isFirstService: true, - systemFuncs: canisterMethods.getSystemFunctionIdls() + systemFuncs: canisterMethods.getSystemFunctionIdlTypes() }); return JSON.stringify({ diff --git a/src/lib/candid/candid_type.ts b/src/lib/candid/candid_type.ts index 9c228d51c3..2184b2bd31 100644 --- a/src/lib/candid/candid_type.ts +++ b/src/lib/candid/candid_type.ts @@ -1,7 +1,7 @@ import { IDL } from '@dfinity/candid'; -import { Parent } from './to_idl'; +import { Parent } from './to_idl_type'; export interface CandidType { - getIdl(parents: Parent[]): IDL.Type; + getIdlType(parents: Parent[]): IDL.Type; } diff --git a/src/lib/candid/index.ts b/src/lib/candid/index.ts index 4b9215d1d5..c82181af81 100644 --- a/src/lib/candid/index.ts +++ b/src/lib/candid/index.ts @@ -1,7 +1,7 @@ export * from './candid_type'; export * from './manual'; export * from './recursive'; -export * from './to_idl'; +export * from './to_idl_type'; export * from './type_mapping'; export * from './types/constructed'; export * from './types/primitive'; diff --git a/src/lib/candid/recursive.ts b/src/lib/candid/recursive.ts index ad9ce12885..ae123ec116 100644 --- a/src/lib/candid/recursive.ts +++ b/src/lib/candid/recursive.ts @@ -7,7 +7,7 @@ export type _AzleRecursiveFunction = { (...args: any[]): CandidType; azleName?: string; isRecursive?: boolean; - getIdl?: (parents: Parent[]) => IDL.Type; + getIdlType?: (parents: Parent[]) => IDL.Type; }; export function Recursive(candidTypeCallback: any): any { @@ -25,14 +25,14 @@ export function Recursive(candidTypeCallback: any): any { result.isRecursive = true; // TODO make this function's return type explicit https://github.com/demergent-labs/azle/issues/1860 // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - result.getIdl = (parents: Parent[]) => { - const idl = IDL.Rec(); + result.getIdlType = (parents: Parent[]) => { + const idlType = IDL.Rec(); let filler = candidTypeCallback(); if (filler.isCanister) { filler = filler(result); } - idl.fill(filler.getIdl([...parents, { idl: idl, name }])); - return idl; + idlType.fill(filler.getIdlType([...parents, { idlType, name }])); + return idlType; }; return result; diff --git a/src/lib/candid/serde/decode.ts b/src/lib/candid/serde/decode.ts index df7dbba976..f226359704 100644 --- a/src/lib/candid/serde/decode.ts +++ b/src/lib/candid/serde/decode.ts @@ -1,6 +1,6 @@ import { IDL } from '@dfinity/candid'; -import { CandidType, toIdl, toIdlArray } from '../../candid'; +import { CandidType, toIdlType, toIdlTypeArray } from '../../candid'; // eslint-disable-next-line @typescript-eslint/no-unused-vars import { AzleOpt, AzleTuple, AzleVec } from '../types/constructed'; // Used for links in comments import { DecodeVisitor } from './visitors/decode_visitor'; @@ -32,27 +32,28 @@ function decodeSingle(candidType: CandidType, data: ArrayBuffer): any { // needs to be aligned so that this isn't an error. Both are representing // candid IDLs, either from the @dfinity/candid library or the // Azle-augmented ones - const idl = toIdl(candidType); + const idlType = toIdlType(candidType); - const idlIsAzleVoid = Array.isArray(idl); + // The candid type was AzleVoid if when converted to an Idl Type it is [] + const candidTypeIsAzleVoid = Array.isArray(idlType); - if (idlIsAzleVoid) { + if (candidTypeIsAzleVoid) { return undefined; } - const candidDecodedValue = IDL.decode([idl], data)[0] as any; + const candidDecodedValue = IDL.decode([idlType], data)[0] as any; - return idl.accept(new DecodeVisitor(), { + return idlType.accept(new DecodeVisitor(), { candidType: candidType, js_data: candidDecodedValue }); } function decodeMultiple(candidTypes: CandidType[], data: ArrayBuffer): any[] { - const idls = toIdlArray(candidTypes); - const decoded = IDL.decode(idls, data); - return idls.map((idl, index) => - idl.accept(new DecodeVisitor(), { + const idlTypes = toIdlTypeArray(candidTypes); + const decoded = IDL.decode(idlTypes, data); + return idlTypes.map((idlType, index) => + idlType.accept(new DecodeVisitor(), { candidType: candidTypes[index], js_data: decoded[index] }) diff --git a/src/lib/candid/serde/encode.ts b/src/lib/candid/serde/encode.ts index fdbdb12afe..101417e5e1 100644 --- a/src/lib/candid/serde/encode.ts +++ b/src/lib/candid/serde/encode.ts @@ -1,6 +1,6 @@ import { IDL } from '@dfinity/candid'; -import { CandidType, toIdl, toIdlArray } from '../../candid'; +import { CandidType, toIdlType, toIdlTypeArray } from '../../candid'; // eslint-disable-next-line @typescript-eslint/no-unused-vars import { AzleOpt, AzleTuple, AzleVec } from '../types/constructed'; // Used for links in comments import { EncodeVisitor } from './visitors/encode_visitor'; @@ -33,30 +33,31 @@ export function encode( } function encodeSingle(candidType: CandidType, data: any): Uint8Array { - const idl = toIdl(candidType); + const idlType = toIdlType(candidType); - const idlIsAzleVoid = Array.isArray(idl); + // The candid type was AzleVoid if when converted to an Idl Type it is [] + const candidTypeIsAzleVoid = Array.isArray(idlType); - if (idlIsAzleVoid) { + if (candidTypeIsAzleVoid) { return new Uint8Array(IDL.encode([], [])); } - const encodeReadyKey = idl.accept(new EncodeVisitor(), { + const encodeReadyKey = idlType.accept(new EncodeVisitor(), { candidType: candidType, js_data: data }); - return new Uint8Array(IDL.encode([idl], [encodeReadyKey])); + return new Uint8Array(IDL.encode([idlType], [encodeReadyKey])); } function encodeMultiple(candidTypes: CandidType[], data: any[]): Uint8Array { - const idls = toIdlArray(candidTypes); + const idlTypes = toIdlTypeArray(candidTypes); const values = data.map((datum, index) => - idls[index].accept(new EncodeVisitor(), { + idlTypes[index].accept(new EncodeVisitor(), { candidType: candidTypes[index], js_data: datum }) ); - return new Uint8Array(IDL.encode(idls, values)); + return new Uint8Array(IDL.encode(idlTypes, values)); } diff --git a/src/lib/candid/serde/visitors/visit/record.ts b/src/lib/candid/serde/visitors/visit/record.ts index cd2a8c3bf5..be1148d8b6 100644 --- a/src/lib/candid/serde/visitors/visit/record.ts +++ b/src/lib/candid/serde/visitors/visit/record.ts @@ -9,13 +9,13 @@ export function visitRecord( fields: [string, IDL.Type][], data: VisitorData ): VisitorResult { - const candidFields = fields.reduce((acc, [memberName, memberIdl]) => { + const candidFields = fields.reduce((acc, [memberName, memberIdlTypes]) => { const fieldData = data.js_data[memberName]; const fieldClass = data.candidType[memberName]; return { ...acc, - [memberName]: memberIdl.accept(visitor, { + [memberName]: memberIdlTypes.accept(visitor, { js_data: fieldData, candidType: fieldClass }) diff --git a/src/lib/candid/serde/visitors/visit/variant/azle_variant.ts b/src/lib/candid/serde/visitors/visit/variant/azle_variant.ts index 4c20271eb7..0dd0f4feaf 100644 --- a/src/lib/candid/serde/visitors/visit/variant/azle_variant.ts +++ b/src/lib/candid/serde/visitors/visit/variant/azle_variant.ts @@ -10,7 +10,7 @@ export function visitAzleVariant( fields: [string, IDL.Type][], data: VisitorData ): Variant { - const candidFields = fields.reduce((acc, [memberName, memberIdl]) => { + const candidFields = fields.reduce((acc, [memberName, memberIdlTypes]) => { const fieldData = data.js_data[memberName]; const fieldClass = data.candidType[memberName]; if (fieldData === undefined) { @@ -19,7 +19,7 @@ export function visitAzleVariant( } return { ...acc, - [memberName]: memberIdl.accept(visitor, { + [memberName]: memberIdlTypes.accept(visitor, { candidType: fieldClass, js_data: fieldData }) diff --git a/src/lib/candid/to_idl.ts b/src/lib/candid/to_idl_type.ts similarity index 62% rename from src/lib/candid/to_idl.ts rename to src/lib/candid/to_idl_type.ts index cb510dfe1a..dc07441db7 100644 --- a/src/lib/candid/to_idl.ts +++ b/src/lib/candid/to_idl_type.ts @@ -3,11 +3,11 @@ import { IDL } from '@dfinity/candid'; import { CandidType } from './candid_type'; export type Parent = { - idl: IDL.RecClass; + idlType: IDL.RecClass; name: string; }; -export function toIdl( +export function toIdlType( candidType: CandidType, parents: Parent[] = [] ): IDL.Type { @@ -16,27 +16,27 @@ export function toIdl( (parent) => parent.name === candidType.azleName ); // If the parent isn't undefined (ie we found one with the same name) - // this is a recursive type and we should return the parent rec idl - // instead of calling getIdl + // this is a recursive type and we should return the parent rec idl type + // instead of calling getIdlType if (parent !== undefined) { - return parent.idl; + return parent.idlType; } } if ('isCanister' in candidType && candidType.isCanister) { - return toIdl((candidType as any)(), parents); + return toIdlType((candidType as any)(), parents); } - // All CandidTypes ought to have a getIdl function defined for them - return (candidType as any).getIdl(parents); + // All CandidTypes ought to have a getIdlType function defined for them + return (candidType as any).getIdlType(parents); } -export function toIdlArray( +export function toIdlTypeArray( candidTypes: CandidType | CandidType[], parents: Parent[] = [] ): IDL.Type[] { if (Array.isArray(candidTypes)) { - return candidTypes.map((value) => toIdl(value, parents)); + return candidTypes.map((value) => toIdlType(value, parents)); } - const idlType = toIdl(candidTypes, parents); + const idlType = toIdlType(candidTypes, parents); return Array.isArray(idlType) ? idlType : [idlType]; } diff --git a/src/lib/candid/types/constructed/blob.ts b/src/lib/candid/types/constructed/blob.ts index 8df7949404..f1985aa7e5 100644 --- a/src/lib/candid/types/constructed/blob.ts +++ b/src/lib/candid/types/constructed/blob.ts @@ -17,7 +17,7 @@ export class AzleBlob { return decode(this, bytes) as blob; } - static getIdl(): IDL.VecClass { + static getIdlType(): IDL.VecClass { return IDL.Vec(IDL.Nat8); } } diff --git a/src/lib/candid/types/constructed/opt.ts b/src/lib/candid/types/constructed/opt.ts index 1da7261071..50b07d27b3 100644 --- a/src/lib/candid/types/constructed/opt.ts +++ b/src/lib/candid/types/constructed/opt.ts @@ -3,7 +3,7 @@ import { IDL } from '@dfinity/candid'; import { CandidType } from '../../candid_type'; import { decode } from '../../serde/decode'; import { encode } from '../../serde/encode'; -import { Parent, toIdl } from '../../to_idl'; +import { Parent, toIdlType } from '../../to_idl_type'; import { TypeMapping } from '../../type_mapping'; import { RequireExactlyOne } from './variant'; @@ -52,7 +52,7 @@ export class AzleOpt { return decode(this, bytes); } - getIdl(parents: Parent[]): IDL.OptClass { - return IDL.Opt(toIdl(this.innerType, parents)); + getIdlType(parents: Parent[]): IDL.OptClass { + return IDL.Opt(toIdlType(this.innerType, parents)); } } diff --git a/src/lib/candid/types/constructed/record.ts b/src/lib/candid/types/constructed/record.ts index e9e1106c87..6ae7942970 100644 --- a/src/lib/candid/types/constructed/record.ts +++ b/src/lib/candid/types/constructed/record.ts @@ -3,9 +3,9 @@ import { IDL } from '@dfinity/candid'; import { CandidType } from '../../candid_type'; import { decode } from '../../serde/decode'; import { encode } from '../../serde/encode'; -import { Parent } from '../../to_idl'; +import { Parent } from '../../to_idl_type'; import { TypeMapping } from '../../type_mapping'; -import { CandidMap, toIdlMap } from './to_idl_map'; +import { CandidTypeMap, toIdlTypeMap } from './to_idl_map'; // TODO make this function's return type explicit https://github.com/demergent-labs/azle/issues/1860 // eslint-disable-next-line @typescript-eslint/explicit-function-return-type @@ -27,8 +27,8 @@ export function Record< fromBytes(bytes: Uint8Array) { return decode(this, bytes); }, - getIdl(parents: Parent[]): IDL.RecordClass { - return IDL.Record(toIdlMap(obj as CandidMap, parents)); + getIdlType(parents: Parent[]): IDL.RecordClass { + return IDL.Record(toIdlTypeMap(obj as CandidTypeMap, parents)); } }; } diff --git a/src/lib/candid/types/constructed/to_idl_map.ts b/src/lib/candid/types/constructed/to_idl_map.ts index 58c9353571..cdc7200f03 100644 --- a/src/lib/candid/types/constructed/to_idl_map.ts +++ b/src/lib/candid/types/constructed/to_idl_map.ts @@ -1,20 +1,23 @@ import { IDL } from '@dfinity/candid'; import { CandidType } from '../../candid_type'; -import { Parent, toIdl } from '../../to_idl'; +import { Parent, toIdlType } from '../../to_idl_type'; -export type CandidMap = { [key: string]: CandidType }; -export type IdlMap = { [key: string]: IDL.Type }; +export type CandidTypeMap = { [key: string]: CandidType }; +export type IdlTypeMap = { [key: string]: IDL.Type }; -export function toIdlMap(candidMap: CandidMap, parent: Parent[]): IdlMap { - const idlMap: IdlMap = {}; +export function toIdlTypeMap( + candidMap: CandidTypeMap, + parent: Parent[] +): IdlTypeMap { + const idlTypeMap: IdlTypeMap = {}; for (const key in candidMap) { if (Object.prototype.hasOwnProperty.call(candidMap, key)) { const candidType = candidMap[key]; - idlMap[key] = toIdl(candidType, parent); + idlTypeMap[key] = toIdlType(candidType, parent); } } - return idlMap; + return idlTypeMap; } diff --git a/src/lib/candid/types/constructed/tuple.ts b/src/lib/candid/types/constructed/tuple.ts index e3bdb4bf67..ff37cb3733 100644 --- a/src/lib/candid/types/constructed/tuple.ts +++ b/src/lib/candid/types/constructed/tuple.ts @@ -3,7 +3,7 @@ import { IDL } from '@dfinity/candid'; import { CandidType } from '../../candid_type'; import { decode } from '../../serde/decode'; import { encode } from '../../serde/encode'; -import { Parent, toIdl } from '../../to_idl'; +import { Parent, toIdlType } from '../../to_idl_type'; import { TypeMapping } from '../../type_mapping'; export class AzleTuple { @@ -30,11 +30,11 @@ export class AzleTuple { return decode(this, bytes); } - getIdl(parents: Parent[]): IDL.TupleClass { - const idls = this.innerTypes.map((value) => { - return toIdl(value, parents); + getIdlType(parents: Parent[]): IDL.TupleClass { + const idlTypes = this.innerTypes.map((value) => { + return toIdlType(value, parents); }); - return IDL.Tuple(...idls); + return IDL.Tuple(...idlTypes); } } diff --git a/src/lib/candid/types/constructed/variant.ts b/src/lib/candid/types/constructed/variant.ts index 1c76a36e54..a75381e9b6 100644 --- a/src/lib/candid/types/constructed/variant.ts +++ b/src/lib/candid/types/constructed/variant.ts @@ -4,7 +4,7 @@ import { CandidType } from '../../candid_type'; import { decode } from '../../serde/decode'; import { encode } from '../../serde/encode'; import { TypeMapping } from '../../type_mapping'; -import { CandidMap, toIdlMap } from './to_idl_map'; +import { CandidTypeMap, toIdlTypeMap } from './to_idl_map'; export type Variant< T extends { @@ -32,8 +32,8 @@ export function Variant< fromBytes(bytes: Uint8Array) { return decode(this, bytes); }, - getIdl(parents: any): IDL.VariantClass { - return IDL.Variant(toIdlMap(obj as CandidMap, parents)); + getIdlType(parents: any): IDL.VariantClass { + return IDL.Variant(toIdlTypeMap(obj as CandidTypeMap, parents)); } }; } diff --git a/src/lib/candid/types/constructed/vec.ts b/src/lib/candid/types/constructed/vec.ts index c74fa14425..95b3080d6a 100644 --- a/src/lib/candid/types/constructed/vec.ts +++ b/src/lib/candid/types/constructed/vec.ts @@ -3,7 +3,7 @@ import { IDL } from '@dfinity/candid'; import { CandidType } from '../../candid_type'; import { decode } from '../../serde/decode'; import { encode } from '../../serde/encode'; -import { Parent, toIdl } from '../../to_idl'; +import { Parent, toIdlType } from '../../to_idl_type'; import { TypeMapping } from '../../type_mapping'; export class AzleVec { @@ -26,8 +26,8 @@ export class AzleVec { return decode(this, bytes) as T[]; } - getIdl(parents: Parent[]): IDL.VecClass { - return IDL.Vec(toIdl(this.innerType, parents)); + getIdlType(parents: Parent[]): IDL.VecClass { + return IDL.Vec(toIdlType(this.innerType, parents)); } } diff --git a/src/lib/candid/types/primitive/bool.ts b/src/lib/candid/types/primitive/bool.ts index 9cdf586b3b..ead30ef3bb 100644 --- a/src/lib/candid/types/primitive/bool.ts +++ b/src/lib/candid/types/primitive/bool.ts @@ -17,7 +17,7 @@ export class AzleBool { return decode(this, bytes) as bool; } - static getIdl(): IDL.BoolClass { + static getIdlType(): IDL.BoolClass { return IDL.Bool; } } diff --git a/src/lib/candid/types/primitive/empty.ts b/src/lib/candid/types/primitive/empty.ts index 5137aedaa9..d394f52de0 100644 --- a/src/lib/candid/types/primitive/empty.ts +++ b/src/lib/candid/types/primitive/empty.ts @@ -17,7 +17,7 @@ export class AzleEmpty { return decode(this, bytes) as empty; } - static getIdl(): IDL.EmptyClass { + static getIdlType(): IDL.EmptyClass { return IDL.Empty; } } diff --git a/src/lib/candid/types/primitive/floats/float32.ts b/src/lib/candid/types/primitive/floats/float32.ts index 3fe3098155..ee73e35f28 100644 --- a/src/lib/candid/types/primitive/floats/float32.ts +++ b/src/lib/candid/types/primitive/floats/float32.ts @@ -17,7 +17,7 @@ export class AzleFloat32 { return decode(this, bytes) as float32; } - static getIdl(): IDL.FloatClass { + static getIdlType(): IDL.FloatClass { return IDL.Float32; } } diff --git a/src/lib/candid/types/primitive/floats/float64.ts b/src/lib/candid/types/primitive/floats/float64.ts index 2a7751911e..2019c41bb2 100644 --- a/src/lib/candid/types/primitive/floats/float64.ts +++ b/src/lib/candid/types/primitive/floats/float64.ts @@ -17,7 +17,7 @@ export class AzleFloat64 { return decode(this, bytes) as float64; } - static getIdl(): IDL.FloatClass { + static getIdlType(): IDL.FloatClass { return IDL.Float64; } } diff --git a/src/lib/candid/types/primitive/ints/int.ts b/src/lib/candid/types/primitive/ints/int.ts index 63cee2f4a6..09e982f94a 100644 --- a/src/lib/candid/types/primitive/ints/int.ts +++ b/src/lib/candid/types/primitive/ints/int.ts @@ -17,7 +17,7 @@ export class AzleInt { return decode(this, bytes) as int; } - static getIdl(): IDL.IntClass { + static getIdlType(): IDL.IntClass { return IDL.Int; } } diff --git a/src/lib/candid/types/primitive/ints/int16.ts b/src/lib/candid/types/primitive/ints/int16.ts index 5ccd935c53..3ec62a1563 100644 --- a/src/lib/candid/types/primitive/ints/int16.ts +++ b/src/lib/candid/types/primitive/ints/int16.ts @@ -17,7 +17,7 @@ export class AzleInt16 { return decode(this, bytes) as int16; } - static getIdl(): IDL.FixedIntClass { + static getIdlType(): IDL.FixedIntClass { return IDL.Int16; } } diff --git a/src/lib/candid/types/primitive/ints/int32.ts b/src/lib/candid/types/primitive/ints/int32.ts index 52f905b87f..7727e21a8f 100644 --- a/src/lib/candid/types/primitive/ints/int32.ts +++ b/src/lib/candid/types/primitive/ints/int32.ts @@ -17,7 +17,7 @@ export class AzleInt32 { return decode(this, bytes) as int32; } - static getIdl(): IDL.FixedIntClass { + static getIdlType(): IDL.FixedIntClass { return IDL.Int32; } } diff --git a/src/lib/candid/types/primitive/ints/int64.ts b/src/lib/candid/types/primitive/ints/int64.ts index fefd858261..0dfd291b13 100644 --- a/src/lib/candid/types/primitive/ints/int64.ts +++ b/src/lib/candid/types/primitive/ints/int64.ts @@ -17,7 +17,7 @@ export class AzleInt64 { return decode(this, bytes) as int64; } - static getIdl(): IDL.FixedIntClass { + static getIdlType(): IDL.FixedIntClass { return IDL.Int64; } } diff --git a/src/lib/candid/types/primitive/ints/int8.ts b/src/lib/candid/types/primitive/ints/int8.ts index 58cda65adc..93bf34db60 100644 --- a/src/lib/candid/types/primitive/ints/int8.ts +++ b/src/lib/candid/types/primitive/ints/int8.ts @@ -17,7 +17,7 @@ export class AzleInt8 { return decode(this, bytes) as int8; } - static getIdl(): IDL.FixedIntClass { + static getIdlType(): IDL.FixedIntClass { return IDL.Int8; } } diff --git a/src/lib/candid/types/primitive/nats/nat.ts b/src/lib/candid/types/primitive/nats/nat.ts index 586c316270..1f67982a4e 100644 --- a/src/lib/candid/types/primitive/nats/nat.ts +++ b/src/lib/candid/types/primitive/nats/nat.ts @@ -17,7 +17,7 @@ export class AzleNat { return decode(this, bytes) as nat; } - static getIdl(): IDL.NatClass { + static getIdlType(): IDL.NatClass { return IDL.Nat; } } diff --git a/src/lib/candid/types/primitive/nats/nat16.ts b/src/lib/candid/types/primitive/nats/nat16.ts index 04fb4b59c2..47744d3a86 100644 --- a/src/lib/candid/types/primitive/nats/nat16.ts +++ b/src/lib/candid/types/primitive/nats/nat16.ts @@ -17,7 +17,7 @@ export class AzleNat16 { return decode(this, bytes) as nat16; } - static getIdl(): IDL.FixedNatClass { + static getIdlType(): IDL.FixedNatClass { return IDL.Nat16; } } diff --git a/src/lib/candid/types/primitive/nats/nat32.ts b/src/lib/candid/types/primitive/nats/nat32.ts index 9c51b4b9bb..4d3bb433df 100644 --- a/src/lib/candid/types/primitive/nats/nat32.ts +++ b/src/lib/candid/types/primitive/nats/nat32.ts @@ -17,7 +17,7 @@ export class AzleNat32 { return decode(this, bytes) as nat32; } - static getIdl(): IDL.FixedNatClass { + static getIdlType(): IDL.FixedNatClass { return IDL.Nat32; } } diff --git a/src/lib/candid/types/primitive/nats/nat64.ts b/src/lib/candid/types/primitive/nats/nat64.ts index 3a9e3bfb4a..61d8055ebf 100644 --- a/src/lib/candid/types/primitive/nats/nat64.ts +++ b/src/lib/candid/types/primitive/nats/nat64.ts @@ -17,7 +17,7 @@ export class AzleNat64 { return decode(this, bytes) as nat64; } - static getIdl(): IDL.FixedNatClass { + static getIdlType(): IDL.FixedNatClass { return IDL.Nat64; } } diff --git a/src/lib/candid/types/primitive/nats/nat8.ts b/src/lib/candid/types/primitive/nats/nat8.ts index 6b6fee1ee7..fefc607c73 100644 --- a/src/lib/candid/types/primitive/nats/nat8.ts +++ b/src/lib/candid/types/primitive/nats/nat8.ts @@ -17,7 +17,7 @@ export class AzleNat8 { return decode(this, bytes) as nat8; } - static getIdl(): IDL.FixedNatClass { + static getIdlType(): IDL.FixedNatClass { return IDL.Nat8; } } diff --git a/src/lib/candid/types/primitive/null.ts b/src/lib/candid/types/primitive/null.ts index c7c49c4701..0006f9a2ed 100644 --- a/src/lib/candid/types/primitive/null.ts +++ b/src/lib/candid/types/primitive/null.ts @@ -17,7 +17,7 @@ export class AzleNull { return decode(this, bytes) as Null; } - static getIdl(): IDL.NullClass { + static getIdlType(): IDL.NullClass { return IDL.Null; } } diff --git a/src/lib/candid/types/primitive/reserved.ts b/src/lib/candid/types/primitive/reserved.ts index 7409eba949..b91ebb2ca4 100644 --- a/src/lib/candid/types/primitive/reserved.ts +++ b/src/lib/candid/types/primitive/reserved.ts @@ -17,7 +17,7 @@ export class AzleReserved { return decode(this, bytes); } - static getIdl(): IDL.ReservedClass { + static getIdlType(): IDL.ReservedClass { return IDL.Reserved; } } diff --git a/src/lib/candid/types/primitive/text.ts b/src/lib/candid/types/primitive/text.ts index f549bc02b2..d1c435772f 100644 --- a/src/lib/candid/types/primitive/text.ts +++ b/src/lib/candid/types/primitive/text.ts @@ -17,7 +17,7 @@ export class AzleText { return decode(this, bytes) as string; } - static getIdl(): IDL.TextClass { + static getIdlType(): IDL.TextClass { return IDL.Text; } } diff --git a/src/lib/candid/types/primitive/void.ts b/src/lib/candid/types/primitive/void.ts index 5817c3fda8..9ecb858517 100644 --- a/src/lib/candid/types/primitive/void.ts +++ b/src/lib/candid/types/primitive/void.ts @@ -17,7 +17,7 @@ export class AzleVoid { return decode(this, bytes) as undefined; } - static getIdl(): IDL.Type { + static getIdlType(): IDL.Type { return [] as unknown as IDL.Type; } } diff --git a/src/lib/candid/types/reference/func.ts b/src/lib/candid/types/reference/func.ts index 9a0e203ad1..5274949566 100644 --- a/src/lib/candid/types/reference/func.ts +++ b/src/lib/candid/types/reference/func.ts @@ -1,6 +1,6 @@ import { IDL } from '@dfinity/candid'; -import { CandidType, Parent, toIdlArray } from '../../index'; +import { CandidType, Parent, toIdlTypeArray } from '../../index'; import { decode } from '../../serde/decode'; import { encode } from '../../serde/encode'; import { Principal } from './principal'; @@ -29,10 +29,10 @@ export function Func( fromBytes(bytes: Uint8Array): Func { return decode(this, bytes) as Func; }, - getIdl(parents: Parent[]): IDL.FuncClass { + getIdlType(parents: Parent[]): IDL.FuncClass { return IDL.Func( - toIdlArray(paramCandidTypes, parents), - toIdlArray(returnCandidTypes, parents), + toIdlTypeArray(paramCandidTypes, parents), + toIdlTypeArray(returnCandidTypes, parents), modeToCandid[mode] ); } diff --git a/src/lib/candid/types/reference/principal.ts b/src/lib/candid/types/reference/principal.ts index 894ebf2b9a..9bbf74e258 100644 --- a/src/lib/candid/types/reference/principal.ts +++ b/src/lib/candid/types/reference/principal.ts @@ -3,7 +3,7 @@ import { Principal as DfinityPrincipal } from '@dfinity/principal'; import { decode } from '../../serde/decode'; import { encode } from '../../serde/encode'; -import { Parent } from '../../to_idl'; +import { Parent } from '../../to_idl_type'; export class Principal extends DfinityPrincipal { static _azleKind = 'Principal' as const; @@ -18,7 +18,7 @@ export class Principal extends DfinityPrincipal { return decode(this, bytes) as DfinityPrincipal; } - static getIdl(_parents: Parent[]): IDL.PrincipalClass { + static getIdlType(_parents: Parent[]): IDL.PrincipalClass { return IDL.Principal; } } diff --git a/src/lib/candid/types/reference/service/canister_function/index.ts b/src/lib/candid/types/reference/service/canister_function/index.ts index d00f6a80a8..33c62f8b48 100644 --- a/src/lib/candid/types/reference/service/canister_function/index.ts +++ b/src/lib/candid/types/reference/service/canister_function/index.ts @@ -4,13 +4,13 @@ import { IDL } from '@dfinity/candid'; import { CanisterMethodInfo } from '../../../../../canister_methods/types/canister_method_info'; import { ic } from '../../../../../ic'; -import { CandidType, Parent, toIdlArray } from '../../../../index'; +import { CandidType, Parent, toIdlTypeArray } from '../../../../index'; import { _AzleRecursiveFunction } from '../../../../recursive'; import { decode, encode } from '../../../../serde'; import { Principal } from '../../principal'; import { createQueryMethods, createUpdateMethods } from './query_update'; import { - createGetSystemFunctionIdlFunction, + createGetSystemFunctionIdlTypeFunction, createSystemMethod } from './system_methods'; @@ -28,8 +28,8 @@ type _AzleFunctionReturnType = { queries?: any[]; updates?: any[]; callbacks?: any; - getSystemFunctionIdls?: (parents: Parent[]) => IDL.FuncClass[]; - getIdl?: (parents: Parent[]) => IDL.Type; + getSystemFunctionIdlTypes?: (parents: Parent[]) => IDL.FuncClass[]; + getIdlType?: (parents: Parent[]) => IDL.Type; }; type CallRawFunction = typeof ic.callRaw; @@ -58,18 +58,18 @@ export function createCanisterFunction(canisterOptions: CanisterOptions) { canister.queries = createQueryMethods(canisterOptions); canister.updates = createUpdateMethods(canisterOptions); canister.callbacks = createCallbacks(canisterOptions); - canister.getIdl = createGetIdlFunction(canisterOptions); - canister.getSystemFunctionIdls = - createGetSystemFunctionIdlFunction(canisterOptions); + canister.getIdlType = createGetIdlTypeFunction(canisterOptions); + canister.getSystemFunctionIdlTypes = + createGetSystemFunctionIdlTypeFunction(canisterOptions); return canister; } -function createGetIdlFunction(canisterOptions: CanisterOptions) { +function createGetIdlTypeFunction(canisterOptions: CanisterOptions) { return (parents: Parent[]): IDL.ServiceClass => { const serviceFunctionInfo = canisterOptions as ServiceFunctionInfo; - // We don't want init, post upgrade, etc showing up in the idl + // We don't want init, post upgrade, etc showing up in the idl type const isQueryOrUpdate = (mode: string): boolean => { return mode === 'query' || mode === 'update'; }; @@ -82,7 +82,7 @@ function createGetIdlFunction(canisterOptions: CanisterOptions) { (accumulator, [methodName, functionInfo]) => { return { ...accumulator, - [methodName]: createUpdateOrQueryFunctionIdl( + [methodName]: createUpdateOrQueryFunctionIdlType( functionInfo, parents ) @@ -102,15 +102,21 @@ function createAnnotation(mode: 'query' | 'update'): string[] { return []; } -function createUpdateOrQueryFunctionIdl( +function createUpdateOrQueryFunctionIdlType( functionInfo: FunctionInfo, parents: Parent[] ): IDL.FuncClass { const annotations = createAnnotation(functionInfo.mode); - const paramIdls = toIdlArray(functionInfo.paramCandidTypes, parents); - const returnIdls = toIdlArray(functionInfo.returnCandidType, parents); + const paramIdlTypes = toIdlTypeArray( + functionInfo.paramCandidTypes, + parents + ); + const returnIdlTypes = toIdlTypeArray( + functionInfo.returnCandidType, + parents + ); - return IDL.Func(paramIdls, returnIdls, annotations); + return IDL.Func(paramIdlTypes, returnIdlTypes, annotations); } function createCallbacks(canisterOptions: CanisterOptions) { diff --git a/src/lib/candid/types/reference/service/canister_function/system_methods.ts b/src/lib/candid/types/reference/service/canister_function/system_methods.ts index 5b9f5174f0..ceb3342e7d 100644 --- a/src/lib/candid/types/reference/service/canister_function/system_methods.ts +++ b/src/lib/candid/types/reference/service/canister_function/system_methods.ts @@ -1,6 +1,6 @@ import { IDL } from '@dfinity/candid'; -import { Parent, toIdlArray } from '../../../../index'; +import { Parent, toIdlTypeArray } from '../../../../index'; import { _AzleRecursiveFunction } from '../../../../recursive'; import { CanisterOptions, ServiceFunctionInfo } from '.'; @@ -27,7 +27,7 @@ export function createSystemMethod( }; } -export function createGetSystemFunctionIdlFunction( +export function createGetSystemFunctionIdlTypeFunction( canisterOptions: CanisterOptions ) { return (parents: Parent[]): IDL.FuncClass[] => { @@ -38,19 +38,22 @@ export function createGetSystemFunctionIdlFunction( const mode = functionInfo.mode; const isSystemMethod = !(mode === 'update' || mode === 'query'); if (!isSystemMethod) { - // IDLs that are in update and query are already accounted for in the standard getIdl function + // IDLs that are in update and query are already accounted for in the standard getIdlType function return accumulator; } - const paramIdls = toIdlArray( + const paramIdlTypes = toIdlTypeArray( functionInfo.paramCandidTypes, parents ); - const returnIdl = toIdlArray( + const returnIdlType = toIdlTypeArray( functionInfo.returnCandidType, parents ); - return [...accumulator, IDL.Func(paramIdls, returnIdl, [mode])]; + return [ + ...accumulator, + IDL.Func(paramIdlTypes, returnIdlType, [mode]) + ]; }, [] as IDL.FuncClass[] ); diff --git a/src/lib/ic/reply.ts b/src/lib/ic/reply.ts index 2da3e03c76..b256e6d386 100644 --- a/src/lib/ic/reply.ts +++ b/src/lib/ic/reply.ts @@ -5,7 +5,7 @@ import { Void } from '../candid/types/primitive/void'; type ReplyInput = | { data: any; - type: CandidType; + candidType: CandidType; } | { raw: Uint8Array; @@ -38,7 +38,7 @@ export function reply(input: ReplyInput): Void { if ('raw' in input) { return globalThis._azleIc.replyRaw(input.raw.buffer); } else { - const { type, data } = input; + const { candidType: type, data } = input; return globalThis._azleIc.replyRaw(encode(type, data).buffer); } } diff --git a/src/lib/server.ts b/src/lib/server.ts index 092e06c8ea..6e94cb07dd 100644 --- a/src/lib/server.ts +++ b/src/lib/server.ts @@ -202,7 +202,7 @@ export async function httpHandler( streaming_strategy: None, upgrade: Some(true) }, - type: HttpResponse() + candidType: HttpResponse() }); return; @@ -310,7 +310,7 @@ export async function httpHandler( None: null } }, - type: HttpResponse() + candidType: HttpResponse() }); } } diff --git a/src/lib/stable/execute_with_candid_serde.ts b/src/lib/stable/execute_with_candid_serde.ts index 6a5d28a813..cef7a68ee3 100644 --- a/src/lib/stable/execute_with_candid_serde.ts +++ b/src/lib/stable/execute_with_candid_serde.ts @@ -16,11 +16,11 @@ export function executeWithCandidSerde( mode: CanisterMethodMode, args: any[], callback: any, - paramIdls: IDL.Type[], - returnIdl: IDL.Type | undefined, + paramIdlTypes: IDL.Type[], + returnIdlType: IDL.Type | undefined, manual: boolean ): void { - const decodedArgs = IDL.decode(paramIdls, args[0]); + const decodedArgs = IDL.decode(paramIdlTypes, args[0]); const result = getResult(decodedArgs, callback); @@ -36,7 +36,7 @@ export function executeWithCandidSerde( result .then((result: any) => { if (!manual) { - reply({ data: result, idl: returnIdl }); + reply({ data: result, idlType: returnIdlType }); } }) .catch((error: any) => { @@ -44,7 +44,7 @@ export function executeWithCandidSerde( }); } else { if (!manual) { - reply({ data: result, idl: returnIdl }); + reply({ data: result, idlType: returnIdlType }); } } } diff --git a/src/lib/stable/ic_apis/call.ts b/src/lib/stable/ic_apis/call.ts index 05f75173d7..0643631f45 100644 --- a/src/lib/stable/ic_apis/call.ts +++ b/src/lib/stable/ic_apis/call.ts @@ -6,8 +6,8 @@ export async function call( canisterId: Principal | string, method: string, options?: { - paramIdls?: IDL.Type[]; - returnIdl?: IDL.Type; + paramIdlTypes?: IDL.Type[]; + returnIdlType?: IDL.Type; args?: any[]; payment?: bigint; raw?: Uint8Array; @@ -23,7 +23,7 @@ export async function call( const globalResolveId = `_resolve_${promiseId}`; const globalRejectId = `_reject_${promiseId}`; - const returnIdl = options?.returnIdl; + const returnTypeIdl = options?.returnIdlType; const raw = options?.raw; // TODO perhaps we should be more robust @@ -35,8 +35,9 @@ export async function call( if (raw !== undefined) { resolve(new Uint8Array(result)); } else { - const idl = returnIdl === undefined ? [] : [returnIdl]; - resolve(IDL.decode(idl, result)[0]); + const idlType = + returnTypeIdl === undefined ? [] : [returnTypeIdl]; + resolve(IDL.decode(idlType, result)[0]); } delete globalThis._azleResolveIds[globalResolveId]; @@ -50,7 +51,7 @@ export async function call( delete globalThis._azleRejectIds[globalRejectId]; }; - const paramIdls = options?.paramIdls ?? []; + const paramIdlTypes = options?.paramIdlTypes ?? []; const args = options?.args ?? []; const payment = options?.payment ?? 0n; @@ -61,7 +62,7 @@ export async function call( const canisterIdBytes = canisterIdPrincipal.toUint8Array().buffer; const argsRawBuffer = raw === undefined - ? new Uint8Array(IDL.encode(paramIdls, args)).buffer + ? new Uint8Array(IDL.encode(paramIdlTypes, args)).buffer : raw.buffer; const paymentString = payment.toString(); diff --git a/src/lib/stable/ic_apis/notify.ts b/src/lib/stable/ic_apis/notify.ts index e37c12fced..878244e26a 100644 --- a/src/lib/stable/ic_apis/notify.ts +++ b/src/lib/stable/ic_apis/notify.ts @@ -12,7 +12,7 @@ export function notify( canisterId: Principal | string, method: string, options?: { - paramIdls?: IDL.Type[]; + paramIdlTypes?: IDL.Type[]; args?: any[]; payment?: bigint; raw?: Uint8Array; @@ -22,7 +22,7 @@ export function notify( return undefined; } - const paramIdls = options?.paramIdls ?? []; + const paramIdlTypes = options?.paramIdlTypes ?? []; const args = options?.args ?? []; const payment = options?.payment ?? 0n; const raw = options?.raw; @@ -34,7 +34,7 @@ export function notify( const canisterIdBytes = canisterIdPrincipal.toUint8Array().buffer; const argsRawBuffer = raw === undefined - ? new Uint8Array(IDL.encode(paramIdls, args)).buffer + ? new Uint8Array(IDL.encode(paramIdlTypes, args)).buffer : raw.buffer; const paymentString = payment.toString(); diff --git a/src/lib/stable/ic_apis/reply.ts b/src/lib/stable/ic_apis/reply.ts index 044530a658..9c26771436 100644 --- a/src/lib/stable/ic_apis/reply.ts +++ b/src/lib/stable/ic_apis/reply.ts @@ -3,7 +3,7 @@ import { IDL } from '..'; type ReplyInput = | { data: T; - idl?: IDL.Type; + idlType?: IDL.Type; } | { raw: Uint8Array; @@ -24,13 +24,13 @@ export function reply(input: ReplyInput): void { if ('raw' in input) { return globalThis._azleIc.replyRaw(input.raw.buffer); } else { - const idl = input.idl === undefined ? [] : [input.idl]; + const idlType = input.idlType === undefined ? [] : [input.idlType]; const data = - input.data === undefined && input.idl === undefined + input.data === undefined && input.idlType === undefined ? [] : [input.data]; // @ts-expect-error idl.d.ts specifies the wrong type for IDL.encode. It's actually a Uint8Array - return globalThis._azleIc.replyRaw(IDL.encode(idl, data).buffer); + return globalThis._azleIc.replyRaw(IDL.encode(idlType, data).buffer); } } diff --git a/src/lib/stable/init.ts b/src/lib/stable/init.ts index 935881368f..3b6926b037 100644 --- a/src/lib/stable/init.ts +++ b/src/lib/stable/init.ts @@ -2,7 +2,7 @@ import { IDL } from '@dfinity/candid'; import { executeWithCandidSerde } from './execute_with_candid_serde'; -export function init(paramIdls: IDL.Type[]): MethodDecorator { +export function init(paramIdlTypes: IDL.Type[]): MethodDecorator { return ( target: object, propertyKey: string | symbol, @@ -15,7 +15,7 @@ export function init(paramIdls: IDL.Type[]): MethodDecorator { 'init', args, originalMethod, - paramIdls, + paramIdlTypes, undefined, false // TODO implement manual check ); diff --git a/src/lib/stable/post_upgrade.ts b/src/lib/stable/post_upgrade.ts index 013bc21cb7..bc937b518e 100644 --- a/src/lib/stable/post_upgrade.ts +++ b/src/lib/stable/post_upgrade.ts @@ -2,7 +2,7 @@ import { IDL } from '@dfinity/candid'; import { executeWithCandidSerde } from './execute_with_candid_serde'; -export function postUpgrade(paramIdls: IDL.Type[]): MethodDecorator { +export function postUpgrade(paramIdlTypes: IDL.Type[]): MethodDecorator { return ( target: object, propertyKey: string | symbol, @@ -15,7 +15,7 @@ export function postUpgrade(paramIdls: IDL.Type[]): MethodDecorator { 'postUpgrade', args, originalMethod, - paramIdls, + paramIdlTypes, undefined, false // TODO implement manual check ); diff --git a/src/lib/stable/query.ts b/src/lib/stable/query.ts index 0b8784e9a1..f7ef93d90f 100644 --- a/src/lib/stable/query.ts +++ b/src/lib/stable/query.ts @@ -3,8 +3,8 @@ import { IDL } from '@dfinity/candid'; import { executeWithCandidSerde } from './execute_with_candid_serde'; export function query( - paramIdls: IDL.Type[], - returnIdl?: IDL.Type, + paramIdlTypes: IDL.Type[], + returnIdlType?: IDL.Type, options?: { composite?: boolean; manual?: boolean; @@ -22,8 +22,8 @@ export function query( 'query', args, originalMethod, - paramIdls, - returnIdl, + paramIdlTypes, + returnIdlType, options?.manual ?? false ); }; @@ -47,8 +47,8 @@ export function query( // TODO this implementation is for native decorators // export function query( -// paramIdls: IDL.Type[], -// returnIdl: IDL.Type +// paramIdlTypes: IDL.Type[], +// returnIdlType: IDL.Type // ) { // return ( // originalMethod: (this: This, ...args: Args) => Return, @@ -62,8 +62,8 @@ export function query( // 'query', // args, // originalMethod, -// paramIdls, -// returnIdl, +// paramIdlTypes, +// returnIdlType, // false // TODO implement manual check // ); diff --git a/src/lib/stable/update.ts b/src/lib/stable/update.ts index 78b378bccb..a63d3cd8d9 100644 --- a/src/lib/stable/update.ts +++ b/src/lib/stable/update.ts @@ -3,8 +3,8 @@ import { IDL } from '@dfinity/candid'; import { executeWithCandidSerde } from './execute_with_candid_serde'; export function update( - paramIdls: IDL.Type[], - returnIdl?: IDL.Type, + paramIdlTypes: IDL.Type[], + returnIdlType?: IDL.Type, options?: { manual?: boolean; } @@ -21,8 +21,8 @@ export function update( 'update', args, originalMethod, - paramIdls, - returnIdl, + paramIdlTypes, + returnIdlType, options?.manual ?? false ); }; diff --git a/src/lib/system_types/result.ts b/src/lib/system_types/result.ts index ec88cb8f87..5f0c37e099 100644 --- a/src/lib/system_types/result.ts +++ b/src/lib/system_types/result.ts @@ -1,7 +1,7 @@ import { IDL } from '@dfinity/candid'; import { CandidType } from '../candid/candid_type'; -import { Parent, toIdl } from '../candid/to_idl'; +import { Parent, toIdlType } from '../candid/to_idl_type'; import { RequireExactlyOne } from '../candid/types/constructed/variant'; export class AzleResult { @@ -13,10 +13,10 @@ export class AzleResult { Ok: T; Err: K; - getIdl(parents: Parent[]): IDL.VariantClass { + getIdlType(parents: Parent[]): IDL.VariantClass { return IDL.Variant({ - Ok: toIdl(this.Ok, parents), - Err: toIdl(this.Err, parents) + Ok: toIdlType(this.Ok, parents), + Err: toIdlType(this.Err, parents) }); } } diff --git a/tests/end_to_end/candid_rpc/class_syntax/async_await/src/async_await.ts b/tests/end_to_end/candid_rpc/class_syntax/async_await/src/async_await.ts index 130312d53d..b7930cd0bc 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/async_await/src/async_await.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/async_await/src/async_await.ts @@ -4,7 +4,7 @@ export default class { @update([], IDL.Vec(IDL.Nat8)) async getRandomnessDirectly(): Promise { return await call('aaaaa-aa', 'raw_rand', { - returnIdl: IDL.Vec(IDL.Nat8) + returnIdlType: IDL.Vec(IDL.Nat8) }); } @@ -28,7 +28,9 @@ export default class { @update([]) async returnPromiseVoid(): Promise { - await call('aaaaa-aa', 'raw_rand', { returnIdl: IDL.Vec(IDL.Nat8) }); + await call('aaaaa-aa', 'raw_rand', { + returnIdlType: IDL.Vec(IDL.Nat8) + }); } } @@ -45,5 +47,7 @@ async function getRandomnessLevel2(): Promise { } async function getRandomness(): Promise { - return await call('aaaaa-aa', 'raw_rand', { returnIdl: IDL.Vec(IDL.Nat8) }); + return await call('aaaaa-aa', 'raw_rand', { + returnIdlType: IDL.Vec(IDL.Nat8) + }); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/bitcoin/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/bitcoin/src/index.ts index 913eeda987..bcf121a5eb 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/bitcoin/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/bitcoin/src/index.ts @@ -17,8 +17,8 @@ export default class { @update([IDL.Text], Satoshi) async getBalance(address: string): Promise { return await call('aaaaa-aa', 'bitcoin_get_balance', { - paramIdls: [GetBalanceArgs], - returnIdl: Satoshi, + paramIdlTypes: [GetBalanceArgs], + returnIdlType: Satoshi, args: [ { address, @@ -33,8 +33,8 @@ export default class { @update([], IDL.Vec(MillisatoshiPerByte)) async getCurrentFeePercentiles(): Promise { return await call('aaaaa-aa', 'bitcoin_get_current_fee_percentiles', { - paramIdls: [GetCurrentFeePercentilesArgs], - returnIdl: IDL.Vec(MillisatoshiPerByte), + paramIdlTypes: [GetCurrentFeePercentilesArgs], + returnIdlType: IDL.Vec(MillisatoshiPerByte), args: [ { network: { regtest: null } @@ -47,8 +47,8 @@ export default class { @update([IDL.Text], GetUtxosResult) async getUtxos(address: string): Promise { return await call('aaaaa-aa', 'bitcoin_get_utxos', { - paramIdls: [GetUtxosArgs], - returnIdl: GetUtxosResult, + paramIdlTypes: [GetUtxosArgs], + returnIdlType: GetUtxosResult, args: [ { address, @@ -68,7 +68,7 @@ export default class { BITCOIN_CYCLE_COST_PER_TRANSACTION_BYTE; await call('aaaaa-aa', 'bitcoin_send_transaction', { - paramIdls: [SendTransactionArgs], + paramIdlTypes: [SendTransactionArgs], args: [ { transaction, diff --git a/tests/end_to_end/candid_rpc/class_syntax/canister/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/canister/src/index.ts index abcbac72a4..5455d2035e 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/canister/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/canister/src/index.ts @@ -34,7 +34,7 @@ export default class { @update([Canister], IDL.Text) async canisterCrossCanisterCall(someCanister: Canister): Promise { - return await call(someCanister, 'update1', { returnIdl: IDL.Text }); + return await call(someCanister, 'update1', { returnIdlType: IDL.Text }); } } diff --git a/tests/end_to_end/candid_rpc/class_syntax/ckbtc/wallet/backend/index.ts b/tests/end_to_end/candid_rpc/class_syntax/ckbtc/wallet/backend/index.ts index 359bdfc37a..ef7c1a3f07 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/ckbtc/wallet/backend/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/ckbtc/wallet/backend/index.ts @@ -19,8 +19,8 @@ export default class { @update([], IDL.Nat64) async getBalance(): Promise { return await call(getCkBtcPrincipal(), 'icrc1_balance_of', { - paramIdls: [Account], - returnIdl: IDL.Nat, + paramIdlTypes: [Account], + returnIdlType: IDL.Nat, args: [ { owner: id(), @@ -36,8 +36,8 @@ export default class { getMinterPrincipal(), 'update_balance', { - paramIdls: [UpdateBalanceArgs], - returnIdl: UpdateBalanceResult, + paramIdlTypes: [UpdateBalanceArgs], + returnIdlType: UpdateBalanceResult, args: [ { owner: [id()], @@ -55,8 +55,8 @@ export default class { @update([], IDL.Text) async getDepositAddress(): Promise { return await call(getMinterPrincipal(), 'get_btc_address', { - paramIdls: [GetBtcAddressArgs], - returnIdl: IDL.Text, + paramIdlTypes: [GetBtcAddressArgs], + returnIdlType: IDL.Text, args: [ { owner: [id()], @@ -70,8 +70,8 @@ export default class { @update([IDL.Text, IDL.Nat], TransferResult) async transfer(to: string, amount: bigint): Promise { return await call(getCkBtcPrincipal(), 'icrc1_transfer', { - paramIdls: [TransferArgs], - returnIdl: TransferResult, + paramIdlTypes: [TransferArgs], + returnIdlType: TransferResult, args: [ { from_subaccount: [ diff --git a/tests/end_to_end/candid_rpc/class_syntax/composite_queries/src/canister1/index.ts b/tests/end_to_end/candid_rpc/class_syntax/composite_queries/src/canister1/index.ts index 440700cafa..2833306f70 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/composite_queries/src/canister1/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/composite_queries/src/canister1/index.ts @@ -11,7 +11,7 @@ export default class { }) async simpleCompositeQuery(): Promise { return await call(canister2Id, 'simpleQuery', { - returnIdl: IDL.Text + returnIdlType: IDL.Text }); } @@ -21,7 +21,7 @@ export default class { }) async manualQuery(): Promise { return await call(canister2Id, 'manualQuery', { - returnIdl: IDL.Text + returnIdlType: IDL.Text }); } @@ -33,9 +33,9 @@ export default class { async totallyManualQuery(): Promise { reply({ data: await call(canister2Id, 'manualQuery', { - returnIdl: IDL.Text + returnIdlType: IDL.Text }), - idl: IDL.Text + idlType: IDL.Text }); } @@ -45,7 +45,7 @@ export default class { }) async deepQuery(): Promise { return await call(canister2Id, 'deepQuery', { - returnIdl: IDL.Text + returnIdlType: IDL.Text }); } @@ -55,7 +55,7 @@ export default class { }) async updateQuery(): Promise { return await call(canister2Id, 'updateQuery', { - returnIdl: IDL.Text + returnIdlType: IDL.Text }); } @@ -63,7 +63,7 @@ export default class { @query([], IDL.Text) async simpleQuery(): Promise { return await call(canister2Id, 'simpleQuery', { - returnIdl: IDL.Text + returnIdlType: IDL.Text }); } @@ -71,7 +71,7 @@ export default class { @update([], IDL.Text) async simpleUpdate(): Promise { return await call(canister2Id, 'deepQuery', { - returnIdl: IDL.Text + returnIdlType: IDL.Text }); } @@ -126,12 +126,12 @@ function getCanister2Id(): string { async function incCanister(): Promise { return await call(id(), 'incCounter', { - returnIdl: IDL.Nat + returnIdlType: IDL.Nat }); } async function incCanister2(): Promise { return await call(canister2Id, 'incCounter', { - returnIdl: IDL.Nat + returnIdlType: IDL.Nat }); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/composite_queries/src/canister2/index.ts b/tests/end_to_end/candid_rpc/class_syntax/composite_queries/src/canister2/index.ts index 6fc1f6d391..49b33c198e 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/composite_queries/src/canister2/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/composite_queries/src/canister2/index.ts @@ -25,7 +25,10 @@ export default class { manual: true }) manualQuery(): void { - reply({ data: 'Hello from Canister 2 manual query', idl: IDL.Text }); + reply({ + data: 'Hello from Canister 2 manual query', + idlType: IDL.Text + }); } @query([], IDL.Text, { @@ -33,7 +36,7 @@ export default class { }) async deepQuery(): Promise { return await call(canister3Id, 'deepQuery', { - returnIdl: IDL.Text + returnIdlType: IDL.Text }); } } diff --git a/tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls/src/canister1/index.ts b/tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls/src/canister1/index.ts index 03f51a1797..d49de3b094 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls/src/canister1/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls/src/canister1/index.ts @@ -8,8 +8,8 @@ export default class { @update([IDL.Text, IDL.Text, IDL.Nat64], IDL.Nat64) async transfer(from: string, to: string, amount: bigint): Promise { return await call(canister2Id, 'transfer', { - paramIdls: [IDL.Text, IDL.Text, IDL.Nat64], - returnIdl: IDL.Nat64, + paramIdlTypes: [IDL.Text, IDL.Text, IDL.Nat64], + returnIdlType: IDL.Nat64, args: [from, to, amount] }); } @@ -17,8 +17,8 @@ export default class { @update([IDL.Text], IDL.Nat64) async balance(id: string): Promise { return await call(canister2Id, 'balance', { - paramIdls: [IDL.Text], - returnIdl: IDL.Nat64, + paramIdlTypes: [IDL.Text], + returnIdlType: IDL.Nat64, args: [id] }); } @@ -26,8 +26,8 @@ export default class { @update([AccountArgs], IDL.Opt(Account)) async account(args: AccountArgs): Promise<[Account] | []> { return await call(canister2Id, 'account', { - paramIdls: [AccountArgs], - returnIdl: IDL.Opt(Account), + paramIdlTypes: [AccountArgs], + returnIdlType: IDL.Opt(Account), args: [args] }); } @@ -35,7 +35,7 @@ export default class { @update([], IDL.Vec(Account)) async accounts(): Promise { return await call(canister2Id, 'accounts', { - returnIdl: IDL.Vec(Account) + returnIdlType: IDL.Vec(Account) }); } @@ -47,7 +47,7 @@ export default class { @update([]) sendNotification(): void { return notify(canister2Id, 'receiveNotification', { - paramIdls: [IDL.Text], + paramIdlTypes: [IDL.Text], args: ['This is the notification'], payment: 10n }); diff --git a/tests/end_to_end/candid_rpc/class_syntax/cycles/src/intermediary/index.ts b/tests/end_to_end/candid_rpc/class_syntax/cycles/src/intermediary/index.ts index 3e0705463c..0baa7e8ef9 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/cycles/src/intermediary/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/cycles/src/intermediary/index.ts @@ -5,7 +5,7 @@ export default class { @update([], IDL.Nat64) async sendCycles(): Promise { return await call(getCyclesPrincipal(), 'receiveCycles', { - returnIdl: IDL.Nat64, + returnIdlType: IDL.Nat64, payment: 1_000_000n }); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts index ee05175e5f..8f6f290cae 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts @@ -67,8 +67,8 @@ async function getBalance( PRINCIPAL, managementCanister.http_request, { - paramIdls: [HttpRequestArgs], - returnIdl: HttpResponse, + paramIdlTypes: [HttpRequestArgs], + returnIdlType: HttpResponse, args: [ { url, @@ -110,8 +110,8 @@ async function getBlockByNumber(url: string, number: number): Promise { PRINCIPAL, managementCanister.http_request, { - paramIdls: [HttpRequestArgs], - returnIdl: HttpResponse, + paramIdlTypes: [HttpRequestArgs], + returnIdlType: HttpResponse, args: [ { url, diff --git a/tests/end_to_end/candid_rpc/class_syntax/func_types/canisters/func_types/index.ts b/tests/end_to_end/candid_rpc/class_syntax/func_types/canisters/func_types/index.ts index 08fddef1d0..881db2bd8e 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/func_types/canisters/func_types/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/func_types/canisters/func_types/index.ts @@ -117,7 +117,7 @@ export default class { @update([], NotifierFunc) async getNotifierFromNotifiersCanister(): Promise { return await call(getNotifierPrincipal(), 'getNotifier', { - returnIdl: NotifierFunc + returnIdlType: NotifierFunc }); } } diff --git a/tests/end_to_end/candid_rpc/class_syntax/heartbeat/src/heartbeat_async/index.ts b/tests/end_to_end/candid_rpc/class_syntax/heartbeat/src/heartbeat_async/index.ts index 26d8bd75db..c83c51f3c6 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/heartbeat/src/heartbeat_async/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/heartbeat/src/heartbeat_async/index.ts @@ -19,6 +19,6 @@ export default class { async function getRandomness(): Promise { return await call('aaaaa-aa', 'raw_rand', { - returnIdl: IDL.Vec(IDL.Nat8) + returnIdlType: IDL.Vec(IDL.Nat8) }); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/icrc/canisters/proxy/index.ts b/tests/end_to_end/candid_rpc/class_syntax/icrc/canisters/proxy/index.ts index e31fc35fb8..a4276fe946 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/icrc/canisters/proxy/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/icrc/canisters/proxy/index.ts @@ -17,57 +17,57 @@ export default class { @query([], IDL.Vec(IDL.Tuple(IDL.Text, Value)), { composite: true }) async icrc1_metadata(): Promise<[Text, Value][]> { return await call(getIcrcPrincipal(), 'icrc1_metadata', { - returnIdl: IDL.Vec(IDL.Tuple(IDL.Text, Value)) + returnIdlType: IDL.Vec(IDL.Tuple(IDL.Text, Value)) }); } @query([], IDL.Text, { composite: true }) async icrc1_name(): Promise { return await call(getIcrcPrincipal(), 'icrc1_name', { - returnIdl: IDL.Text + returnIdlType: IDL.Text }); } @query([], IDL.Nat8, { composite: true }) async icrc1_decimals(): Promise { return await call(getIcrcPrincipal(), 'icrc1_decimals', { - returnIdl: IDL.Nat8 + returnIdlType: IDL.Nat8 }); } @query([], IDL.Text, { composite: true }) async icrc1_symbol(): Promise { return await call(getIcrcPrincipal(), 'icrc1_symbol', { - returnIdl: IDL.Text + returnIdlType: IDL.Text }); } @query([], IDL.Nat, { composite: true }) async icrc1_fee(): Promise { return await call(getIcrcPrincipal(), 'icrc1_fee', { - returnIdl: IDL.Nat + returnIdlType: IDL.Nat }); } @query([], IDL.Nat, { composite: true }) async icrc1_total_supply(): Promise { return await call(getIcrcPrincipal(), 'icrc1_total_supply', { - returnIdl: IDL.Nat + returnIdlType: IDL.Nat }); } @query([], IDL.Opt(Account), { composite: true }) async icrc1_minting_account(): Promise<[Account] | []> { return await call(getIcrcPrincipal(), 'icrc1_minting_account', { - returnIdl: IDL.Opt(Account) + returnIdlType: IDL.Opt(Account) }); } @query([Account], IDL.Nat, { composite: true }) async icrc1_balance_of(account: Account): Promise { return await call(getIcrcPrincipal(), 'icrc1_balance_of', { - paramIdls: [Account], - returnIdl: IDL.Nat, + paramIdlTypes: [Account], + returnIdlType: IDL.Nat, args: [account] }); } @@ -75,8 +75,8 @@ export default class { @update([TransferArgs], TransferResult) async icrc1_transfer(transferArgs: TransferArgs): Promise { return await call(getIcrcPrincipal(), 'icrc1_transfer', { - paramIdls: [TransferArgs], - returnIdl: TransferResult, + paramIdlTypes: [TransferArgs], + returnIdlType: TransferResult, args: [transferArgs] }); } @@ -84,15 +84,15 @@ export default class { @query([], IDL.Vec(SupportedStandard), { composite: true }) async icrc1_supported_standards(): Promise { return await call(getIcrcPrincipal(), 'icrc1_supported_standards', { - returnIdl: IDL.Vec(SupportedStandard) + returnIdlType: IDL.Vec(SupportedStandard) }); } @update([ApproveArgs], ApproveResult) async icrc2_approve(approveArgs: ApproveArgs): Promise { return await call(getIcrcPrincipal(), 'icrc2_approve', { - paramIdls: [ApproveArgs], - returnIdl: ApproveResult, + paramIdlTypes: [ApproveArgs], + returnIdlType: ApproveResult, args: [approveArgs] }); } @@ -102,8 +102,8 @@ export default class { transferFromArgs: TransferFromArgs ): Promise { return await call(getIcrcPrincipal(), 'icrc2_transfer_from', { - paramIdls: [TransferFromArgs], - returnIdl: TransferFromResult, + paramIdlTypes: [TransferFromArgs], + returnIdlType: TransferFromResult, args: [transferFromArgs] }); } @@ -113,8 +113,8 @@ export default class { allowanceArgs: AllowanceArgs ): Promise { return await call(getIcrcPrincipal(), 'icrc2_allowance', { - paramIdls: [AllowanceArgs], - returnIdl: AllowanceResult, + paramIdlTypes: [AllowanceArgs], + returnIdlType: AllowanceResult, args: [allowanceArgs] }); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/ledger_canister/src/ledger_canister/index.ts b/tests/end_to_end/candid_rpc/class_syntax/ledger_canister/src/ledger_canister/index.ts index 84022cd9e1..d27a16bd9a 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/ledger_canister/src/ledger_canister/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/ledger_canister/src/ledger_canister/index.ts @@ -30,8 +30,8 @@ export default class { ? [] : [{ timestamp_nanos: createdAtTime[0] }]; return await call(getIcpCanisterPrincipal(), 'transfer', { - paramIdls: [TransferArgs], - returnIdl: TransferResult, + paramIdlTypes: [TransferArgs], + returnIdlType: TransferResult, args: [ { memo: 0n, @@ -52,8 +52,8 @@ export default class { @update([Address], Tokens) async getAccountBalance(address: Address): Promise { return await call(getIcpCanisterPrincipal(), 'account_balance', { - paramIdls: [AccountBalanceArgs], - returnIdl: Tokens, + paramIdlTypes: [AccountBalanceArgs], + returnIdlType: Tokens, args: [ { account: binaryAddressFromAddress(address) @@ -65,8 +65,8 @@ export default class { @update([], TransferFee) async getTransferFee(): Promise { return await call(getIcpCanisterPrincipal(), 'transfer_fee', { - paramIdls: [TransferFeeArg], - returnIdl: TransferFee, + paramIdlTypes: [TransferFeeArg], + returnIdlType: TransferFee, args: [{}] }); } @@ -76,8 +76,8 @@ export default class { getBlocksArgs: GetBlocksArgs ): Promise { return await call(getIcpCanisterPrincipal(), 'query_blocks', { - paramIdls: [GetBlocksArgs], - returnIdl: QueryBlocksResponse, + paramIdlTypes: [GetBlocksArgs], + returnIdlType: QueryBlocksResponse, args: [getBlocksArgs] }); } @@ -85,7 +85,7 @@ export default class { @update([], IDL.Text) async getSymbol(): Promise { const symbolResult = await call(getIcpCanisterPrincipal(), 'symbol', { - returnIdl: SymbolResult + returnIdlType: SymbolResult }); return symbolResult.symbol; @@ -94,7 +94,7 @@ export default class { @update([], IDL.Text) async getName(): Promise { const nameResult = await call(getIcpCanisterPrincipal(), 'name', { - returnIdl: NameResult + returnIdlType: NameResult }); return nameResult.name; @@ -105,7 +105,7 @@ export default class { const decimalsResult = await call( getIcpCanisterPrincipal(), 'decimals', - { returnIdl: DecimalsResult } + { returnIdlType: DecimalsResult } ); return decimalsResult.decimals; @@ -114,7 +114,7 @@ export default class { @update([], Archives) async getArchives(): Promise { return await call(getIcpCanisterPrincipal(), 'archives', { - returnIdl: Archives + returnIdlType: Archives }); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/management_canister/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/management_canister/src/index.ts index 11118b5b3d..fbbe51a289 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/management_canister/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/management_canister/src/index.ts @@ -46,7 +46,7 @@ export default class { @update([IDL.Principal], IDL.Bool) async executeUpdateSettings(canisterId: Principal): Promise { await call('aaaaa-aa', 'update_settings', { - paramIdls: [UpdateSettingsArgs], + paramIdlTypes: [UpdateSettingsArgs], args: [ { canister_id: canisterId, @@ -71,8 +71,8 @@ export default class { chunk: Uint8Array ): Promise { return await call('aaaaa-aa', 'upload_chunk', { - paramIdls: [UploadChunkArgs], - returnIdl: ChunkHash, + paramIdlTypes: [UploadChunkArgs], + returnIdlType: ChunkHash, args: [ { canister_id: canisterId, @@ -85,7 +85,7 @@ export default class { @update([IDL.Principal], IDL.Bool) async executeClearChunkStore(canisterId: Principal): Promise { await call('aaaaa-aa', 'clear_chunk_store', { - paramIdls: [ClearChunkStoreArgs], + paramIdlTypes: [ClearChunkStoreArgs], args: [ { canister_id: canisterId @@ -99,8 +99,8 @@ export default class { @update([IDL.Principal], StoredChunksResult) async getStoredChunks(canisterId: Principal): Promise { return await call('aaaaa-aa', 'stored_chunks', { - paramIdls: [StoredChunksArgs], - returnIdl: StoredChunksResult, + paramIdlTypes: [StoredChunksArgs], + returnIdlType: StoredChunksResult, args: [ { canister_id: canisterId @@ -115,7 +115,7 @@ export default class { wasmModule: Uint8Array ): Promise { await call('aaaaa-aa', 'install_code', { - paramIdls: [InstallCodeArgs], + paramIdlTypes: [InstallCodeArgs], args: [ { mode: { @@ -140,7 +140,7 @@ export default class { wasmModuleHash: Uint8Array ): Promise { await call('aaaaa-aa', 'install_chunked_code', { - paramIdls: [InstallChunkedCodeArgs], + paramIdlTypes: [InstallChunkedCodeArgs], args: [ { mode: { @@ -163,7 +163,7 @@ export default class { @update([IDL.Principal], IDL.Bool) async executeUninstallCode(canisterId: Principal): Promise { await call('aaaaa-aa', 'uninstall_code', { - paramIdls: [UninstallCodeArgs], + paramIdlTypes: [UninstallCodeArgs], args: [ { canister_id: canisterId, @@ -178,7 +178,7 @@ export default class { @update([IDL.Principal], IDL.Bool) async executeStartCanister(canisterId: Principal): Promise { await call('aaaaa-aa', 'start_canister', { - paramIdls: [StartCanisterArgs], + paramIdlTypes: [StartCanisterArgs], args: [ { canister_id: canisterId @@ -191,7 +191,7 @@ export default class { @update([IDL.Principal], IDL.Bool) async executeStopCanister(canisterId: Principal): Promise { await call('aaaaa-aa', 'stop_canister', { - paramIdls: [StopCanisterArgs], + paramIdlTypes: [StopCanisterArgs], args: [ { canister_id: canisterId @@ -205,8 +205,8 @@ export default class { @update([CanisterInfoArgs], CanisterInfoResult) async getCanisterInfo(args: CanisterInfoArgs): Promise { return await call('aaaaa-aa', 'canister_info', { - paramIdls: [CanisterInfoArgs], - returnIdl: CanisterInfoResult, + paramIdlTypes: [CanisterInfoArgs], + returnIdlType: CanisterInfoResult, args: [args] }); } @@ -216,8 +216,8 @@ export default class { args: CanisterStatusArgs ): Promise { return await call('aaaaa-aa', 'canister_status', { - paramIdls: [CanisterStatusArgs], - returnIdl: CanisterStatusResult, + paramIdlTypes: [CanisterStatusArgs], + returnIdlType: CanisterStatusResult, args: [args] }); } @@ -225,7 +225,7 @@ export default class { @update([IDL.Principal], IDL.Bool) async executeDeleteCanister(canisterId: Principal): Promise { await call('aaaaa-aa', 'delete_canister', { - paramIdls: [DeleteCanisterArgs], + paramIdlTypes: [DeleteCanisterArgs], args: [ { canister_id: canisterId @@ -239,7 +239,7 @@ export default class { @update([IDL.Principal], IDL.Bool) async executeDepositCycles(canisterId: Principal): Promise { await call('aaaaa-aa', 'deposit_cycles', { - paramIdls: [DepositCyclesArgs], + paramIdlTypes: [DepositCyclesArgs], args: [ { canister_id: canisterId @@ -254,7 +254,7 @@ export default class { @update([], IDL.Vec(IDL.Nat8)) async getRawRand(): Promise { return await call('aaaaa-aa', 'raw_rand', { - returnIdl: IDL.Vec(IDL.Nat8) + returnIdlType: IDL.Vec(IDL.Nat8) }); } // TODO we should test this like we test depositCycles @@ -264,8 +264,8 @@ export default class { 'aaaaa-aa', 'provisional_create_canister_with_cycles', { - paramIdls: [ProvisionalCreateCanisterWithCyclesArgs], - returnIdl: ProvisionalCreateCanisterWithCyclesResult, + paramIdlTypes: [ProvisionalCreateCanisterWithCyclesArgs], + returnIdlType: ProvisionalCreateCanisterWithCyclesResult, args: [ { amount: [], @@ -284,7 +284,7 @@ export default class { amount: bigint ): Promise { await call('aaaaa-aa', 'provisional_top_up_canister', { - paramIdls: [ProvisionalTopUpCanisterArgs], + paramIdlTypes: [ProvisionalTopUpCanisterArgs], args: [ { canister_id: canisterId, @@ -304,8 +304,8 @@ export default class { async function createCanister(): Promise { return await call('aaaaa-aa', 'create_canister', { - paramIdls: [CreateCanisterArgs], - returnIdl: CreateCanisterResult, + paramIdlTypes: [CreateCanisterArgs], + returnIdlType: CreateCanisterResult, args: [{ settings: [], sender_canister_version: [] }], payment: 50_000_000_000_000n }); diff --git a/tests/end_to_end/candid_rpc/class_syntax/manual_reply/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/manual_reply/src/index.ts index 5109cf55c3..a274f82852 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/manual_reply/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/manual_reply/src/index.ts @@ -95,35 +95,35 @@ export default class { return; } - reply({ data: message, idl: IDL.Text }); + reply({ data: message, idlType: IDL.Text }); } @update([], IDL.Vec(IDL.Nat8), { manual: true }) updateBlob(): void { reply({ data: new Uint8Array([83, 117, 114, 112, 114, 105, 115, 101, 33]), - idl: IDL.Vec(IDL.Nat8) + idlType: IDL.Vec(IDL.Nat8) }); } @update([], IDL.Float32, { manual: true }) updateFloat32(): void { - reply({ data: 1245.678, idl: IDL.Float32 }); + reply({ data: 1245.678, idlType: IDL.Float32 }); } @update([], IDL.Int8, { manual: true }) updateInt8(): void { - reply({ data: -100, idl: IDL.Int8 }); + reply({ data: -100, idlType: IDL.Int8 }); } @update([], IDL.Nat, { manual: true }) updateNat(): void { - reply({ data: 184467440737095516150n, idl: IDL.Nat }); + reply({ data: 184467440737095516150n, idlType: IDL.Nat }); } @update([], IDL.Null, { manual: true }) updateNull(): void { - reply({ data: null, idl: IDL.Null }); + reply({ data: null, idlType: IDL.Null }); } @update([], undefined, { manual: true }) @@ -141,23 +141,23 @@ export default class { ], state: { Gas: { Elemental: null } } }; - reply({ data: element, idl: Element }); + reply({ data: element, idlType: Element }); } @update([], IDL.Reserved, { manual: true }) updateReserved(): void { - reply({ data: undefined, idl: IDL.Reserved }); + reply({ data: undefined, idlType: IDL.Reserved }); } @update([], IDL.Text, { manual: true }) updateString(): void { - reply({ data: 'hello', idl: IDL.Text }); + reply({ data: 'hello', idlType: IDL.Text }); } @update([], Gas, { manual: true }) updateVariant(): void { const gas: Gas = { Toxic: null }; - reply({ data: gas, idl: Gas }); + reply({ data: gas, idlType: Gas }); } @update([], RawReply, { manual: true }) @@ -177,35 +177,35 @@ export default class { return; } - reply({ data: message, idl: IDL.Text }); + reply({ data: message, idlType: IDL.Text }); } @query([], IDL.Vec(IDL.Nat8), { manual: true }) queryBlob(): void { reply({ data: new Uint8Array([83, 117, 114, 112, 114, 105, 115, 101, 33]), - idl: IDL.Vec(IDL.Nat8) + idlType: IDL.Vec(IDL.Nat8) }); } @query([], IDL.Float32, { manual: true }) queryFloat32(): void { - reply({ data: 1245.678, idl: IDL.Float32 }); + reply({ data: 1245.678, idlType: IDL.Float32 }); } @query([], IDL.Int8, { manual: true }) queryInt8(): void { - reply({ data: -100, idl: IDL.Int8 }); + reply({ data: -100, idlType: IDL.Int8 }); } @query([], IDL.Nat, { manual: true }) queryNat(): void { - reply({ data: 184467440737095516150n, idl: IDL.Nat }); + reply({ data: 184467440737095516150n, idlType: IDL.Nat }); } @query([], IDL.Null, { manual: true }) queryNull(): void { - reply({ data: null, idl: IDL.Null }); + reply({ data: null, idlType: IDL.Null }); } @query([], undefined, { manual: true }) @@ -224,23 +224,23 @@ export default class { state: { Gas: { Elemental: null } } }; - reply({ data: element, idl: Element }); + reply({ data: element, idlType: Element }); } @query([], IDL.Reserved, { manual: true }) queryReserved(): void { - reply({ data: undefined, idl: IDL.Reserved }); + reply({ data: undefined, idlType: IDL.Reserved }); } @query([], IDL.Text, { manual: true }) queryString(): void { - reply({ data: 'hello', idl: IDL.Text }); + reply({ data: 'hello', idlType: IDL.Text }); } @query([], Gas, { manual: true }) queryVariant(): void { const gas: Gas = { Toxic: null }; - reply({ data: gas, idl: Gas }); + reply({ data: gas, idlType: Gas }); } } diff --git a/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/threshold_ecdsa/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/threshold_ecdsa/src/index.ts index 3d5a563ec6..e6446bcf1c 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/threshold_ecdsa/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/threshold_ecdsa/src/index.ts @@ -45,8 +45,8 @@ export default class { async function getPublicKeyResult(): Promise { return await call('aaaaa-aa', 'ecdsa_public_key', { - paramIdls: [EcdsaPublicKeyArgs], - returnIdl: EcdsaPublicKeyResult, + paramIdlTypes: [EcdsaPublicKeyArgs], + returnIdlType: EcdsaPublicKeyResult, args: [ { canister_id: [], @@ -64,8 +64,8 @@ async function getSignatureResult( messageHash: Uint8Array ): Promise { return await call('aaaaa-aa', 'sign_with_ecdsa', { - paramIdls: [SignWithEcdsaArgs], - returnIdl: SignWithEcdsaResult, + paramIdlTypes: [SignWithEcdsaArgs], + returnIdlType: SignWithEcdsaResult, args: [ { message_hash: messageHash, diff --git a/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/whoami/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/whoami/src/index.ts index e26c61a508..477d7d13de 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/whoami/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/whoami/src/index.ts @@ -47,7 +47,7 @@ class WhoAmI { // Return the principal identifier of this canister. @update([], IDL.Principal) async id(): Promise { - return await call(id(), 'whoami', { returnIdl: IDL.Principal }); + return await call(id(), 'whoami', { returnIdlType: IDL.Principal }); } // Return the principal identifier of this canister via the global `ic` object. // This is much quicker than `id()` above because it isn't making a cross- diff --git a/tests/end_to_end/candid_rpc/class_syntax/outgoing_http_requests/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/outgoing_http_requests/src/index.ts index 2f77f3af07..512eea0169 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/outgoing_http_requests/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/outgoing_http_requests/src/index.ts @@ -18,8 +18,8 @@ export default class { @update([], IDL.Text) async xkcd(): Promise { const httpResponse = await call('aaaaa-aa', 'http_request', { - paramIdls: [HttpRequestArgs], - returnIdl: HttpResponse, + paramIdlTypes: [HttpRequestArgs], + returnIdlType: HttpResponse, args: [ { url: `https://xkcd.com/642/info.0.json`, diff --git a/tests/end_to_end/candid_rpc/class_syntax/recursion/src/recursion/index.ts b/tests/end_to_end/candid_rpc/class_syntax/recursion/src/recursion/index.ts index 052b3ca718..86545b1f12 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/recursion/src/recursion/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/recursion/src/recursion/index.ts @@ -251,8 +251,8 @@ export default class { myFullCanister: MyFullCanister ): Promise { return await call(myFullCanister, 'myQuery', { - paramIdls: [MyFullCanister], - returnIdl: MyFullCanister, + paramIdlTypes: [MyFullCanister], + returnIdlType: MyFullCanister, args: [myFullCanister] }); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/rejections/src/rejections/index.ts b/tests/end_to_end/candid_rpc/class_syntax/rejections/src/rejections/index.ts index 13c8f0867d..45fbb7e465 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/rejections/src/rejections/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/rejections/src/rejections/index.ts @@ -37,7 +37,7 @@ export default class { @update([], RejectionCode) async getRejectionCodeNoError(): Promise { await call(getSomeCanisterPrincipal(), 'accept', { - returnIdl: IDL.Bool + returnIdlType: IDL.Bool }); return rejectCode(); @@ -58,7 +58,7 @@ export default class { async getRejectionCodeCanisterReject(): Promise { try { await call(getSomeCanisterPrincipal(), 'reject', { - paramIdls: [IDL.Text], + paramIdlTypes: [IDL.Text], args: ['reject'] }); } catch (error) { @@ -83,7 +83,7 @@ export default class { async getRejectionMessage(message: string): Promise { try { await call(getSomeCanisterPrincipal(), 'reject', { - paramIdls: [IDL.Text], + paramIdlTypes: [IDL.Text], args: [message] }); } catch (error) { diff --git a/tests/end_to_end/candid_rpc/class_syntax/timers/src/timers.ts b/tests/end_to_end/candid_rpc/class_syntax/timers/src/timers.ts index 9e3b175b48..7371939c92 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/timers/src/timers.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/timers/src/timers.ts @@ -126,5 +126,7 @@ async function repeatCrossCanisterTimerCallback(): Promise { } async function getRandomness(): Promise { - return await call('aaaaa-aa', 'raw_rand', { returnIdl: IDL.Vec(IDL.Nat8) }); + return await call('aaaaa-aa', 'raw_rand', { + returnIdlType: IDL.Vec(IDL.Nat8) + }); }