diff --git a/canisters/icrc/icrc_1.ts b/canisters/icrc/icrc_1.ts index 2360287d59..79887669e7 100644 --- a/canisters/icrc/icrc_1.ts +++ b/canisters/icrc/icrc_1.ts @@ -6,7 +6,6 @@ import { nat64, Null, Opt, - principal, Principal, Record, text, @@ -28,7 +27,7 @@ export type ICRC1Subaccount = blob; export const ICRC1Subaccount = blob; export class ICRC1Account extends Record { - @candid(principal) + @candid(Principal) owner: Principal; @candid(Opt(ICRC1Subaccount)) diff --git a/canisters/icrc/icrc_2.ts b/canisters/icrc/icrc_2.ts index 3e233ed04d..62ace715a0 100644 --- a/canisters/icrc/icrc_2.ts +++ b/canisters/icrc/icrc_2.ts @@ -5,7 +5,6 @@ import { nat64, Null, Opt, - principal, Principal, Record, text, @@ -21,7 +20,7 @@ import { } from './errors'; export class ICRC2Account extends Record { - @candid(principal) + @candid(Principal) owner: Principal; @candid(Opt(blob)) diff --git a/canisters/ledger/index.ts b/canisters/ledger/index.ts index bc72dfe770..ab8cd6a907 100644 --- a/canisters/ledger/index.ts +++ b/canisters/ledger/index.ts @@ -22,7 +22,7 @@ import { Tuple, Variant, Vec, - principal, + Principal, Func } from '../../src/lib_functional'; import { @@ -275,7 +275,7 @@ export const QueryBlocksResponse = Record({ }); export const Archive = Record({ - canister_id: principal + canister_id: Principal }); export const Archives = Record({ diff --git a/canisters/management/canister_management.ts b/canisters/management/canister_management.ts index 804f00817b..87b8dc771b 100644 --- a/canisters/management/canister_management.ts +++ b/canisters/management/canister_management.ts @@ -2,15 +2,15 @@ import { Record, Opt, Vec, - principal, + Principal, nat, Variant, Null, blob } from '../../src/lib_functional'; -export const CanisterId = principal; -export const UserId = principal; +export const CanisterId = Principal; +export const UserId = Principal; export const WasmModule = blob; export const CanisterSettings = Record({ @@ -21,7 +21,7 @@ export const CanisterSettings = Record({ * Default value: A list containing only the caller of the * {@link Management.create_canister} call */ - controllers: Opt(Vec(principal)), + controllers: Opt(Vec(Principal)), compute_allocation: Opt(nat), memory_allocation: Opt(nat), freezing_threshold: Opt(nat) @@ -36,7 +36,7 @@ export const CreateCanisterArgs = Record({ }); export const CreateCanisterResult = Record({ - canister_id: principal + canister_id: Principal }); export const CanisterStatus = Variant({ @@ -46,7 +46,7 @@ export const CanisterStatus = Variant({ }); export const DefiniteCanisterSettings = Record({ - controllers: Vec(principal), + controllers: Vec(Principal), compute_allocation: nat, memory_allocation: nat, freezing_threshold: nat @@ -61,7 +61,7 @@ export const CanisterStatusResult = Record({ }); export const CanisterStatusArgs = Record({ - canister_id: principal + canister_id: Principal }); export const UpdateSettingsArgs = Record({ diff --git a/canisters/management/t_ecdsa.ts b/canisters/management/t_ecdsa.ts index 5e651c4379..6bbc4b6d13 100644 --- a/canisters/management/t_ecdsa.ts +++ b/canisters/management/t_ecdsa.ts @@ -2,7 +2,7 @@ import { blob, Null, Opt, - principal, + Principal, Record, text, Variant, @@ -19,7 +19,7 @@ export const KeyId = Record({ }); export const EcdsaPublicKeyArgs = Record({ - canister_id: Opt(principal), + canister_id: Opt(Principal), derivation_path: Vec(blob), key_id: KeyId }); diff --git a/examples/audio_recorder/src/index.ts b/examples/audio_recorder/src/index.ts index 0bf1aea4c3..091ec7660c 100644 --- a/examples/audio_recorder/src/index.ts +++ b/examples/audio_recorder/src/index.ts @@ -4,7 +4,6 @@ import { ic, nat64, Opt, - principal, Principal, query, Record, @@ -17,27 +16,27 @@ import { } from 'azle'; const User = Record({ - id: principal, + id: Principal, createdAt: nat64, - recordingIds: Vec(principal), + recordingIds: Vec(Principal), username: text }); const Recording = Record({ - id: principal, + id: Principal, audio: blob, createdAt: nat64, name: text, - userId: principal + userId: Principal }); const AudioRecorderError = Variant({ - RecordingDoesNotExist: principal, - UserDoesNotExist: principal + RecordingDoesNotExist: Principal, + UserDoesNotExist: Principal }); -let users = StableBTreeMap(principal, User, 0); -let recordings = StableBTreeMap(principal, Recording, 1); +let users = StableBTreeMap(Principal, User, 0); +let recordings = StableBTreeMap(Principal, Recording, 1); export default Canister({ createUser: update([text], User, (username) => { @@ -56,10 +55,10 @@ export default Canister({ readUsers: query([], Vec(User), () => { return users.values(); }), - readUserById: query([principal], Opt(User), (id) => { + readUserById: query([Principal], Opt(User), (id) => { return users.get(id); }), - deleteUser: update([principal], Result(User, AudioRecorderError), (id) => { + deleteUser: update([Principal], Result(User, AudioRecorderError), (id) => { const userOpt = users.get(id); if (userOpt.length === 0) { @@ -83,7 +82,7 @@ export default Canister({ }; }), createRecording: update( - [blob, text, principal], + [blob, text, Principal], Result(Recording, AudioRecorderError), (audio, name, userId) => { const userOpt = users.get(userId); @@ -124,11 +123,11 @@ export default Canister({ readRecordings: query([], Vec(Recording), () => { return recordings.values(); }), - readRecordingById: query([principal], Opt(Recording), (id) => { + readRecordingById: query([Principal], Opt(Recording), (id) => { return recordings.get(id); }), deleteRecording: update( - [principal], + [Principal], Result(Recording, AudioRecorderError), (id) => { const recordingOpt = recordings.get(id); diff --git a/examples/call_raw/src/call_raw.ts b/examples/call_raw/src/call_raw.ts index 7e353583bd..69f912b035 100644 --- a/examples/call_raw/src/call_raw.ts +++ b/examples/call_raw/src/call_raw.ts @@ -3,7 +3,7 @@ import { ic, nat, nat64, - principal, + Principal, Result, text, update @@ -11,7 +11,7 @@ import { export default Canister({ executeCallRaw: update( - [principal, text, text, nat64], + [Principal, text, text, nat64], Result(text, text), async (canisterId, method, candidArgs, payment) => { const result = await ic.callRaw( @@ -25,7 +25,7 @@ export default Canister({ } ), executeCallRaw128: update( - [principal, text, text, nat], + [Principal, text, text, nat], Result(text, text), async (canisterId, method, candidArgs, payment) => { const result = await ic.callRaw128( diff --git a/examples/ic_api/src/index.ts b/examples/ic_api/src/index.ts index b39a95fa84..012c4618be 100644 --- a/examples/ic_api/src/index.ts +++ b/examples/ic_api/src/index.ts @@ -13,7 +13,7 @@ import { update, bool, text, - principal, + Principal, Void } from 'azle'; @@ -70,7 +70,7 @@ export default Canister({ } ), // returns the principal of the identity that called this function - caller: query([], principal, () => { + caller: query([], Principal, () => { return ic.caller(); }), // returns the amount of cycles available in the canister @@ -98,7 +98,7 @@ export default Canister({ return ic.dataCertificate(); }), // returns this canister's id - id: query([], principal, () => { + id: query([], Principal, () => { return ic.id(); }), // Returns the number of instructions that the canister executed since the last @@ -107,7 +107,7 @@ export default Canister({ return ic.instructionCounter(); }), // determines whether the given principal is a controller of the canister - isController: query([principal], bool, (principal) => { + isController: query([Principal], bool, (principal) => { return ic.isController(principal); }), performanceCounter: query([], nat64, () => { diff --git a/examples/init/src/index.ts b/examples/init/src/index.ts index 1143e97148..9016275030 100644 --- a/examples/init/src/index.ts +++ b/examples/init/src/index.ts @@ -4,7 +4,6 @@ import { None, Null, Opt, - principal, Principal, query, Record, @@ -28,7 +27,7 @@ let owner: Opt = None; export default Canister({ init: init( - [User, Reaction, principal], + [User, Reaction, Principal], (initUser, initReaction, initOwner) => { user = Some(initUser); reaction = Some(initReaction); @@ -41,7 +40,7 @@ export default Canister({ getReaction: query([], Opt(Reaction), () => { return reaction; }), - getOwner: query([], Opt(principal), () => { + getOwner: query([], Opt(Principal), () => { return owner; }) }); diff --git a/examples/ledger_canister/src/ledger_canister/index.ts b/examples/ledger_canister/src/ledger_canister/index.ts index 69e715bc6d..607d0d4778 100644 --- a/examples/ledger_canister/src/ledger_canister/index.ts +++ b/examples/ledger_canister/src/ledger_canister/index.ts @@ -6,7 +6,6 @@ import { nat64, None, Opt, - principal, Principal, query, Some, @@ -101,7 +100,7 @@ export default Canister({ getArchives: update([], Archives, async () => { return await ic.call(icpCanister.archives, {}); }), - getAddressFromPrincipal: query([principal], text, (principal) => { + getAddressFromPrincipal: query([Principal], text, (principal) => { return hexAddressFromPrincipal(principal, 0); }) }); diff --git a/examples/list_of_lists/src/index.ts b/examples/list_of_lists/src/index.ts index 474f2054de..9fa4f2bc29 100644 --- a/examples/list_of_lists/src/index.ts +++ b/examples/list_of_lists/src/index.ts @@ -18,7 +18,7 @@ import { nat8, Null, Opt, - principal, + Principal, query, Record, reserved, @@ -113,8 +113,8 @@ export default Canister({ } ), listOfPrincipal: query( - [Vec(Vec(Vec(principal)))], - Vec(Vec(Vec(principal))), + [Vec(Vec(Vec(Principal)))], + Vec(Vec(Vec(Principal))), (param) => { return param; } diff --git a/examples/management_canister/src/index.ts b/examples/management_canister/src/index.ts index d0f51f95a0..4e7027998c 100644 --- a/examples/management_canister/src/index.ts +++ b/examples/management_canister/src/index.ts @@ -7,7 +7,6 @@ import { ic, nat, None, - principal, Principal, query, Some, @@ -43,7 +42,7 @@ export default Canister({ return createCanisterResult; }), - executeUpdateSettings: update([principal], bool, async (canisterId) => { + executeUpdateSettings: update([Principal], bool, async (canisterId) => { await ic.call(managementCanister.update_settings, { args: [ { @@ -61,7 +60,7 @@ export default Canister({ return true; }), executeInstallCode: update( - [principal, blob], + [Principal, blob], bool, async (canisterId, wasmModule) => { await ic.call(managementCanister.install_code, { @@ -81,7 +80,7 @@ export default Canister({ return true; } ), - executeUninstallCode: update([principal], bool, async (canisterId) => { + executeUninstallCode: update([Principal], bool, async (canisterId) => { await ic.call(managementCanister.uninstall_code, { args: [ { @@ -92,7 +91,7 @@ export default Canister({ return true; }), - executeStartCanister: update([principal], bool, async (canisterId) => { + executeStartCanister: update([Principal], bool, async (canisterId) => { await ic.call(managementCanister.start_canister, { args: [ { @@ -103,7 +102,7 @@ export default Canister({ return true; }), - executeStopCanister: update([principal], bool, async (canisterId) => { + executeStopCanister: update([Principal], bool, async (canisterId) => { await ic.call(managementCanister.stop_canister, { args: [ { @@ -127,7 +126,7 @@ export default Canister({ }); } ), - executeDeleteCanister: update([principal], bool, async (canisterId) => { + executeDeleteCanister: update([Principal], bool, async (canisterId) => { await ic.call(managementCanister.delete_canister, { args: [ { @@ -138,7 +137,7 @@ export default Canister({ return true; }), - executeDepositCycles: update([principal], bool, async (canisterId) => { + executeDepositCycles: update([Principal], bool, async (canisterId) => { await ic.call(managementCanister.deposit_cycles, { args: [ { @@ -173,7 +172,7 @@ export default Canister({ ), // TODO we should test this like we test depositCycles provisionalTopUpCanister: update( - [principal, nat], + [Principal, nat], bool, async (canisterId, amount) => { await ic.call(managementCanister.provisional_top_up_canister, { @@ -188,7 +187,7 @@ export default Canister({ return true; } ), - getCreatedCanisterId: query([], principal, () => { + getCreatedCanisterId: query([], Principal, () => { return state.createdCanisterId; }) }); diff --git a/examples/motoko_examples/whoami/src/index.ts b/examples/motoko_examples/whoami/src/index.ts index d693a676a1..7d5188ee22 100644 --- a/examples/motoko_examples/whoami/src/index.ts +++ b/examples/motoko_examples/whoami/src/index.ts @@ -3,7 +3,6 @@ import { ic, init, postUpgrade, - principal, Principal, query, update @@ -13,35 +12,35 @@ import { let install: Principal = Principal.fromText('aaaaa-aa'); let someone: Principal = Principal.fromText('aaaaa-aa'); -const whoami = update([], principal, () => { +const whoami = update([], Principal, () => { return ic.caller(); }); export default Canister({ // Manually save the calling principal and argument for later access. - init: init([principal], (somebody) => { + init: init([Principal], (somebody) => { install = ic.caller(); someone = somebody; }), // Manually re-save these variables after new deploys. - postUpgrade: postUpgrade([principal], (somebody) => { + postUpgrade: postUpgrade([Principal], (somebody) => { install = ic.caller(); someone = somebody; }), // Return the principal identifier of the wallet canister that installed this // canister. - installer: query([], principal, () => { + installer: query([], Principal, () => { return install; }), // Return the principal identifier that was provided as an installation // argument to this canister. - argument: query([], principal, () => { + argument: query([], Principal, () => { return someone; }), // Return the principal identifier of the caller of this method. whoami, // Return the principal identifier of this canister. - id: update([], principal, async () => { + id: update([], Principal, async () => { // TODO This is not an ideal solution but will work for now const self = Canister({ whoami @@ -53,7 +52,7 @@ export default Canister({ // This is much quicker than `id()` above because it isn't making a cross- // canister call to itself. Additionally, it can now be a `Query` which means it // doesn't have to go through consensus. - idQuick: query([], principal, () => { + idQuick: query([], Principal, () => { return ic.id(); }) }); diff --git a/examples/primitive_types/src/index.ts b/examples/primitive_types/src/index.ts index 5e860f43be..5cfa825322 100644 --- a/examples/primitive_types/src/index.ts +++ b/examples/primitive_types/src/index.ts @@ -15,7 +15,6 @@ import { nat64, nat8, Null, - principal, Principal, query, reserved, @@ -135,10 +134,10 @@ export default Canister({ console.log(typeof bool); return bool; }), - getPrincipal: query([], principal, () => { + getPrincipal: query([], Principal, () => { return Principal.fromText('rrkah-fqaaa-aaaaa-aaaaq-cai'); }), - printPrincipal: query([principal], principal, (principal) => { + printPrincipal: query([Principal], Principal, (principal) => { console.log(typeof principal); return principal; }), diff --git a/examples/principal/src/index.ts b/examples/principal/src/index.ts index 34603f5207..a927854bf8 100644 --- a/examples/principal/src/index.ts +++ b/examples/principal/src/index.ts @@ -3,7 +3,6 @@ import { Canister, Null, Principal, - principal, query, Record, text, @@ -11,21 +10,21 @@ import { } from 'azle'; const User = Record({ - id: principal, + id: Principal, username: text }); const Status = Variant({ - WaitingOn: principal, + WaitingOn: Principal, Online: Null, Offline: Null }); export default Canister({ - principalReturnType: query([], principal, () => { + principalReturnType: query([], Principal, () => { return Principal.fromText('aaaaa-aa'); }), - principalParam: query([principal], principal, (principal) => { + principalParam: query([Principal], Principal, (principal) => { return principal; }), principalInRecord: query([], User, () => { @@ -39,25 +38,25 @@ export default Canister({ WaitingOn: Principal.fromText('aaaaa-aa') }; }), - principalFromHex: query([text], principal, (principalHex) => { + principalFromHex: query([text], Principal, (principalHex) => { return Principal.fromHex(principalHex); }), - principalFromText: query([text], principal, (principalText) => { + principalFromText: query([text], Principal, (principalText) => { return Principal.fromText(principalText); }), - principalFromBlob: query([blob], principal, (principalBytes) => { + principalFromBlob: query([blob], Principal, (principalBytes) => { return Principal.fromUint8Array(Uint8Array.from(principalBytes)); }), - principalToHex: query([principal], text, (principal) => { + principalToHex: query([Principal], text, (principal) => { return principal.toHex(); }), - principalToText: query([principal], text, (principal) => { + principalToText: query([Principal], text, (principal) => { return principal.toText(); }), - principalToBlob: query([principal], blob, (principal) => { + principalToBlob: query([Principal], blob, (principal) => { return principal.toUint8Array(); }), - principalSelfAuthenticating: query([blob], principal, (publicKey) => { + principalSelfAuthenticating: query([blob], Principal, (publicKey) => { return Principal.selfAuthenticating(publicKey); }) }); diff --git a/examples/robust_imports/src/azle_coverage/fruit.ts b/examples/robust_imports/src/azle_coverage/fruit.ts index 8d113848b9..27cdf35cf0 100644 --- a/examples/robust_imports/src/azle_coverage/fruit.ts +++ b/examples/robust_imports/src/azle_coverage/fruit.ts @@ -26,7 +26,7 @@ export { Opt as Olive, postUpgrade as pomegranate, preUpgrade as pineapple, - principal as peach, + Principal as peach, Principal as Peach, query as quince, Record as Raspberry, diff --git a/examples/robust_imports/src/type_alias_decls/types.ts b/examples/robust_imports/src/type_alias_decls/types.ts index 62d8f70f11..d0ba2aad71 100644 --- a/examples/robust_imports/src/type_alias_decls/types.ts +++ b/examples/robust_imports/src/type_alias_decls/types.ts @@ -56,7 +56,7 @@ export const DeepNatAlias = deep.deepAlias.deeperAlias.deepestAlias.nat; export const DeepNat8Alias = deep.deepAlias.deeperAlias.deepestAlias.nat8; export const DeepOptAlias = deep.deepAlias.deeperAlias.deepestAlias.Opt; export const DeepPrincipalAlias = - deep.deepAlias.deeperAlias.deepestAlias.principal; + deep.deepAlias.deeperAlias.deepestAlias.Principal; export const Deep$queryAlias = deep.deepAlias.deeperAlias.deepestAlias.query; export const DeepRecordAlias = deep.deepAlias.deeperAlias.deepestAlias.Record; export const DeepReservedAlias = diff --git a/examples/stable_structures/src/canister3/stable_map_13.ts b/examples/stable_structures/src/canister3/stable_map_13.ts index 8397516618..a6136fe580 100644 --- a/examples/stable_structures/src/canister3/stable_map_13.ts +++ b/examples/stable_structures/src/canister3/stable_map_13.ts @@ -2,7 +2,7 @@ import { bool, nat64, Opt, - principal, + Principal, query, StableBTreeMap, text, @@ -11,18 +11,18 @@ import { Vec } from 'azle'; -let stableMap13 = StableBTreeMap(text, principal, 13); +let stableMap13 = StableBTreeMap(text, Principal, 13); export const stableMap13Methods = { stableMap13ContainsKey: query([text], bool, (key) => { return stableMap13.containsKey(key); }), - stableMap13Get: query([text], Opt(principal), (key) => { + stableMap13Get: query([text], Opt(Principal), (key) => { return stableMap13.get(key); }), stableMap13Insert: update( - [text, principal], - Opt(principal), + [text, Principal], + Opt(Principal), (key, value) => { return stableMap13.insert(key, value); } @@ -30,7 +30,7 @@ export const stableMap13Methods = { stableMap13IsEmpty: query([], bool, () => { return stableMap13.isEmpty(); }), - stableMap13Items: query([], Vec(Tuple(text, principal)), () => { + stableMap13Items: query([], Vec(Tuple(text, Principal)), () => { return stableMap13.items(); }), stableMap13Keys: query([], Vec(text), () => { @@ -39,10 +39,10 @@ export const stableMap13Methods = { stableMap13Len: query([], nat64, () => { return stableMap13.len(); }), - stableMap13Remove: update([text], Opt(principal), (key) => { + stableMap13Remove: update([text], Opt(Principal), (key) => { return stableMap13.remove(key); }), - stableMap13Values: query([], Vec(principal), () => { + stableMap13Values: query([], Vec(Principal), () => { return stableMap13.values(); }) }; diff --git a/src/lib_functional/candid/index.ts b/src/lib_functional/candid/index.ts index f5595f5723..f9d4c6759b 100644 --- a/src/lib_functional/candid/index.ts +++ b/src/lib_functional/candid/index.ts @@ -1,5 +1,4 @@ export * from './reference'; -import { IDL } from '@dfinity/candid'; import { AzleBlob, blob, @@ -29,7 +28,6 @@ import { int8, float64, float32, - Principal, AzleNull, Null, AzleReserved, @@ -38,7 +36,7 @@ import { empty, AzleBool, bool, - AzlePrincipal, + Principal, AzleResult, Result, AzleTuple, @@ -87,7 +85,7 @@ export type TypeMapping = T extends () => any ? Result : T extends AzleBlob ? blob - : T extends AzlePrincipal + : T extends typeof Principal ? Principal : T extends AzleNull ? Null diff --git a/src/lib_new/primitives.ts b/src/lib_new/primitives.ts index ef93275ca7..64f29e08af 100644 --- a/src/lib_new/primitives.ts +++ b/src/lib_new/primitives.ts @@ -1,5 +1,6 @@ import { IDL } from './index'; import { CandidClass, Parent, toIDLType } from './utils'; +import { Principal as DfinityPrincipal } from '@dfinity/principal'; export class AzleNat { _kind: 'AzleNat' = 'AzleNat'; @@ -147,6 +148,8 @@ export class AzleEmpty { export class AzleBool { _kind: 'AzleBool' = 'AzleBool'; + _azleCandidType?: '_azleCandidType'; + static getIDL() { return IDL.Bool; } @@ -161,12 +164,12 @@ export class AzleText { } } -export class AzlePrincipal { - _kind: 'AzlePrincipal' = 'AzlePrincipal'; +export class AzleVoid { + _kind: 'AzleVoid' = 'AzleVoid'; _azleCandidType?: '_azleCandidType'; static getIDL() { - return IDL.Principal; + return []; } } @@ -206,17 +209,23 @@ export const float32: AzleFloat32 = AzleFloat32 as any; export type float32 = number; export const float64: AzleFloat64 = AzleFloat64 as any; export type float64 = number; -export const principal: AzlePrincipal = AzlePrincipal as any; -export { Principal } from '@dfinity/principal'; export type Vec = T[]; export type Tuple = T; +export class Principal extends DfinityPrincipal { + static _azleCandidType?: '_azleCandidType'; + + static getIDL?() { + return IDL.Principal; + } +} + /** * Represents an optional value: every {@link Opt} is either `Some` and contains * a value, or `None` and does not. */ export type Opt = [Value] | []; -export const Void = []; +export const Void: [] = []; export type Void = void; /**