-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update rejections to functional runtime syntax
- Loading branch information
Showing
7 changed files
with
88 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
import { | ||
ic, | ||
init, | ||
Principal, | ||
RejectionCode, | ||
Service, | ||
text, | ||
update, | ||
Void | ||
} from 'azle'; | ||
import { default as SomeService } from '../some_service'; | ||
import SomeService from '../some_service'; | ||
|
||
class Nonexistent extends Service { | ||
@update([], Void) | ||
method: () => Void; | ||
} | ||
const Nonexistent = Service({ | ||
method: update([], Void) | ||
}); | ||
|
||
export default class extends Service { | ||
nonexistentCanister = new Nonexistent( | ||
Principal.fromText('rkp4c-7iaaa-aaaaa-aaaca-cai') | ||
); | ||
let someService: typeof SomeService; | ||
let nonexistentCanister: typeof Nonexistent; | ||
|
||
someService = new SomeService( | ||
Principal.fromText( | ||
process.env.SOME_SERVICE_PRINCIPAL ?? | ||
ic.trap('process.env.SOME_SERVICE_PRINCIPAL is undefined') | ||
) | ||
); | ||
export default Service({ | ||
init: init([], () => { | ||
someService = SomeService( | ||
Principal.fromText( | ||
process.env.SOME_SERVICE_PRINCIPAL ?? | ||
ic.trap('process.env.SOME_SERVICE_PRINCIPAL is undefined') | ||
) | ||
); | ||
|
||
@update([], RejectionCode) | ||
async getRejectionCodeNoError(): Promise<RejectionCode> { | ||
await ic.call(this.someService.accept); | ||
nonexistentCanister = Nonexistent( | ||
Principal.fromText('rkp4c-7iaaa-aaaaa-aaaca-cai') | ||
); | ||
}), | ||
|
||
getRejectionCodeNoError: update([], RejectionCode, async () => { | ||
await ic.call(someService.accept); | ||
|
||
return ic.rejectCode(); | ||
} | ||
}), | ||
|
||
@update([], RejectionCode) | ||
async getRejectionCodeDestinationInvalid(): Promise<RejectionCode> { | ||
getRejectionCodeDestinationInvalid: update([], RejectionCode, async () => { | ||
try { | ||
await ic.call(this.nonexistentCanister.method); | ||
await ic.call(nonexistentCanister.method); | ||
} catch (error) {} | ||
|
||
return ic.rejectCode(); | ||
} | ||
}), | ||
|
||
@update([], RejectionCode) | ||
async getRejectionCodeCanisterReject(): Promise<RejectionCode> { | ||
getRejectionCodeCanisterReject: update([], RejectionCode, async () => { | ||
try { | ||
await ic.call(this.someService.reject, { args: ['reject'] }); | ||
await ic.call(someService.reject, { args: ['reject'] }); | ||
} catch (error) {} | ||
|
||
return ic.rejectCode(); | ||
} | ||
}), | ||
|
||
@update([], RejectionCode) | ||
async getRejectionCodeCanisterError(): Promise<RejectionCode> { | ||
getRejectionCodeCanisterError: update([], RejectionCode, async () => { | ||
try { | ||
await ic.call(this.someService.error); | ||
await ic.call(someService.error); | ||
} catch (error) {} | ||
|
||
return ic.rejectCode(); | ||
} | ||
}), | ||
|
||
@update([text], text) | ||
async getRejectionMessage(message: text): Promise<text> { | ||
getRejectionMessage: update([text], text, async (message: text) => { | ||
try { | ||
await ic.call(this.someService.reject, { args: [message] }); | ||
await ic.call(someService.reject, { args: [message] }); | ||
} catch (error) {} | ||
|
||
return ic.rejectMessage(); | ||
} | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import { bool, empty, ic, query, Service, text } from 'azle'; | ||
import { bool, empty, ic, Manual, query, Service, text } from 'azle'; | ||
|
||
type Manual<T> = void; | ||
export default Service({ | ||
reject: query( | ||
[text], | ||
Manual(empty), | ||
(message) => { | ||
ic.reject(message); | ||
}, | ||
{ manual: true } | ||
), | ||
|
||
export default class extends Service { | ||
@query([text], empty, { manual: true }) | ||
reject(message: text): Manual<empty> { | ||
ic.reject(message); | ||
} | ||
|
||
@query([], bool) | ||
accept(): bool { | ||
accept: query([], bool, () => { | ||
return true; | ||
} | ||
}), | ||
|
||
@query([], empty, { manual: true }) | ||
error(): Manual<empty> { | ||
// This errors because neither ic.reject nor ic.reply were called | ||
} | ||
} | ||
error: query( | ||
[], | ||
Manual(empty), | ||
() => { | ||
// This errors because neither ic.reject nor ic.reply were called | ||
}, | ||
{ manual: true } | ||
) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters