From dbea089781a956d46d2fd07d16fe4b6bd47dfc28 Mon Sep 17 00:00:00 2001 From: Dan Steren Date: Fri, 8 Sep 2023 17:30:43 -0600 Subject: [PATCH] Update syntax --- .../rejections/canisters/rejections/index.ts | 80 +++++++++++-------- .../canisters/some_service/index.ts | 31 +++---- 2 files changed, 63 insertions(+), 48 deletions(-) diff --git a/examples/rejections/canisters/rejections/index.ts b/examples/rejections/canisters/rejections/index.ts index f271ba09c5..2f836634f9 100644 --- a/examples/rejections/canisters/rejections/index.ts +++ b/examples/rejections/canisters/rejections/index.ts @@ -1,49 +1,63 @@ import { - CallResult, ic, Principal, RejectionCode, Service, - serviceUpdate, - $update + text, + update, + Void } from 'azle'; -import { someService } from '../some_service'; +import { default as SomeService } from '../some_service'; class Nonexistent extends Service { - @serviceUpdate - method: () => CallResult; + @update([], Void) + method: () => Void; } -export const nonexistentCanister = new Nonexistent( - Principal.fromText('rkp4c-7iaaa-aaaaa-aaaca-cai') -); +export default class extends Service { + nonexistentCanister = new Nonexistent( + Principal.fromText('rkp4c-7iaaa-aaaaa-aaaca-cai') + ); -$update; -export async function getRejectionCodeNoError(): Promise { - await someService.accept().call(); - return ic.rejectCode(); -} + someService = new SomeService( + Principal.fromText( + process.env.SOME_SERVICE_PRINCIPAL ?? + ic.trap('process.env.SOME_SERVICE_PRINCIPAL is undefined') + ) + ); -$update; -export async function getRejectionCodeDestinationInvalid(): Promise { - await nonexistentCanister.method().call(); - return ic.rejectCode(); -} + @update([], RejectionCode) + async getRejectionCodeNoError(): Promise { + await ic.call(this.someService.accept); -$update; -export async function getRejectionCodeCanisterReject(): Promise { - await someService.reject('reject').call(); - return ic.rejectCode(); -} + return ic.rejectCode(); + } -$update; -export async function getRejectionCodeCanisterError(): Promise { - await someService.error().call(); - return ic.rejectCode(); -} + @update([], RejectionCode) + async getRejectionCodeDestinationInvalid(): Promise { + await ic.call(this.nonexistentCanister.method); + + return ic.rejectCode(); + } + + @update([], RejectionCode) + async getRejectionCodeCanisterReject(): Promise { + await ic.call(this.someService.reject, { args: ['reject'] }); + + return ic.rejectCode(); + } + + @update([], RejectionCode) + async getRejectionCodeCanisterError(): Promise { + await ic.call(this.someService.error); + + return ic.rejectCode(); + } + + @update([text], text) + async getRejectionMessage(message: text): Promise { + await ic.call(this.someService.reject, { args: [message] }); -$update; -export async function getRejectionMessage(message: string): Promise { - await someService.reject(message).call(); - return ic.rejectMessage(); + return ic.rejectMessage(); + } } diff --git a/examples/rejections/canisters/some_service/index.ts b/examples/rejections/canisters/some_service/index.ts index 6260886690..03b309adfa 100644 --- a/examples/rejections/canisters/some_service/index.ts +++ b/examples/rejections/canisters/some_service/index.ts @@ -1,19 +1,20 @@ -import { CallResult, empty, ic, Principal, Service, serviceQuery } from 'azle'; +import { bool, empty, ic, query, Service, text } from 'azle'; -export class SomeService extends Service { - @serviceQuery - reject: (message: string) => CallResult; +type Manual = void; - @serviceQuery - accept: () => CallResult; +export default class extends Service { + @query([text], empty, { manual: true }) + reject(message: text): Manual { + ic.reject(message); + } - @serviceQuery - error: () => CallResult; -} + @query([], bool) + accept(): bool { + return true; + } -export const someService = new SomeService( - Principal.fromText( - process.env.SOME_SERVICE_PRINCIPAL ?? - ic.trap('process.env.SOME_SERVICE_PRINCIPAL is undefined') - ) -); + @query([], empty, { manual: true }) + error(): Manual { + // This errors because neither ic.reject nor ic.reply were called + } +}