Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ok and err #1311

Merged
merged 5 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions canisters/icrc/icrc_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
nat64,
Null,
Opt,
principal,
Principal,
Record,
text,
Expand All @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions canisters/icrc/icrc_2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
nat64,
Null,
Opt,
principal,
Principal,
Record,
text,
Expand All @@ -21,7 +20,7 @@ import {
} from './errors';

export class ICRC2Account extends Record {
@candid(principal)
@candid(Principal)
owner: Principal;

@candid(Opt(blob))
Expand Down
4 changes: 2 additions & 2 deletions canisters/ledger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
Tuple,
Variant,
Vec,
principal,
Principal,
Func
} from '../../src/lib_functional';
import {
Expand Down Expand Up @@ -275,7 +275,7 @@ export const QueryBlocksResponse = Record({
});

export const Archive = Record({
canister_id: principal
canister_id: Principal
});

export const Archives = Record({
Expand Down
14 changes: 7 additions & 7 deletions canisters/management/canister_management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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)
Expand All @@ -36,7 +36,7 @@ export const CreateCanisterArgs = Record({
});

export const CreateCanisterResult = Record({
canister_id: principal
canister_id: Principal
});

export const CanisterStatus = Variant({
Expand All @@ -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
Expand All @@ -61,7 +61,7 @@ export const CanisterStatusResult = Record({
});

export const CanisterStatusArgs = Record({
canister_id: principal
canister_id: Principal
});

export const UpdateSettingsArgs = Record({
Expand Down
4 changes: 2 additions & 2 deletions canisters/management/t_ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
blob,
Null,
Opt,
principal,
Principal,
Record,
text,
Variant,
Expand All @@ -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
});
Expand Down
69 changes: 28 additions & 41 deletions examples/audio_recorder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import {
blob,
Canister,
ic,
Err,
nat64,
Ok,
Opt,
principal,
Principal,
query,
Record,
Expand All @@ -17,27 +18,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) => {
Expand All @@ -56,18 +57,16 @@ 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) {
return {
Err: {
UserDoesNotExist: id
}
};
return Err({
UserDoesNotExist: id
});
}

const user = userOpt[0];
Expand All @@ -78,22 +77,18 @@ export default Canister({

users.remove(user.id);

return {
Ok: user
};
return Ok(user);
}),
createRecording: update(
[blob, text, principal],
[blob, text, Principal],
Result(Recording, AudioRecorderError),
(audio, name, userId) => {
const userOpt = users.get(userId);

if (userOpt.length === 0) {
return {
Err: {
UserDoesNotExist: userId
}
};
return Err({
UserDoesNotExist: userId
});
}

const user = userOpt[0];
Expand All @@ -116,39 +111,33 @@ export default Canister({

users.insert(updatedUser.id, updatedUser);

return {
Ok: recording
};
return Ok(recording);
}
),
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);

if (recordingOpt.length === 0) {
return {
Err: { RecordingDoesNotExist: id }
};
return Err({ RecordingDoesNotExist: id });
}

const recording = recordingOpt[0];

const userOpt = users.get(recording.userId);

if (userOpt.length === 0) {
return {
Err: {
UserDoesNotExist: recording.userId
}
};
return Err({
UserDoesNotExist: recording.userId
});
}

const user = userOpt[0];
Expand All @@ -165,9 +154,7 @@ export default Canister({

recordings.remove(id);

return {
Ok: recording
};
return Ok(recording);
}
)
});
Expand Down
6 changes: 3 additions & 3 deletions examples/call_raw/src/call_raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {
ic,
nat,
nat64,
principal,
Principal,
Result,
text,
update
} from 'azle';

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(
Expand All @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions examples/ic_api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
update,
bool,
text,
principal,
Principal,
Void
} from 'azle';

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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, () => {
Expand Down
5 changes: 2 additions & 3 deletions examples/init/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
None,
Null,
Opt,
principal,
Principal,
query,
Record,
Expand All @@ -28,7 +27,7 @@ let owner: Opt<Principal> = None;

export default Canister({
init: init(
[User, Reaction, principal],
[User, Reaction, Principal],
(initUser, initReaction, initOwner) => {
user = Some(initUser);
reaction = Some(initReaction);
Expand All @@ -41,7 +40,7 @@ export default Canister({
getReaction: query([], Opt(Reaction), () => {
return reaction;
}),
getOwner: query([], Opt(principal), () => {
getOwner: query([], Opt(Principal), () => {
return owner;
})
});
3 changes: 1 addition & 2 deletions examples/ledger_canister/src/ledger_canister/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
nat64,
None,
Opt,
principal,
Principal,
query,
Some,
Expand Down Expand Up @@ -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);
})
});
Loading
Loading