-
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.
Merge pull request #1247 from demergent-labs/visitors
Add Decode Visitor
- Loading branch information
Showing
39 changed files
with
881 additions
and
367 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
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 was deleted.
Oops, something went wrong.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { | ||
Func, | ||
init, | ||
ic, | ||
nat64, | ||
Opt, | ||
Principal, | ||
query, | ||
Record, | ||
Service, | ||
StableBTreeMap, | ||
update, | ||
Variant, | ||
Vec, | ||
candid, | ||
text, | ||
func, | ||
Void, | ||
Null | ||
} from 'azle'; | ||
import Notifier, { NotifierFunc } from '../notifiers'; | ||
|
||
@func([text], text, 'query') | ||
class BasicFunc extends Func {} | ||
|
||
@func([User, Reaction], nat64, 'update') | ||
class ComplexFunc extends Func {} | ||
|
||
class User extends Record { | ||
@candid(text) | ||
id: text; | ||
|
||
@candid(BasicFunc) | ||
basicFunc: BasicFunc; | ||
|
||
@candid(ComplexFunc) | ||
complexFunc: ComplexFunc; | ||
} | ||
|
||
class Reaction extends Variant { | ||
Good: null; | ||
Bad: null; | ||
BasicFunc: BasicFunc; | ||
ComplexFunc: ComplexFunc; | ||
} | ||
|
||
@func([nat64, text], Void, 'query') | ||
class StableFunc extends Func {} | ||
|
||
@func( | ||
[Opt(Null), Vec(Null), Null, Vec(Vec(Null)), Vec(Opt(Null))], | ||
Null, | ||
'query' | ||
) | ||
class NullFunc extends Func {} | ||
|
||
export default class extends Service { | ||
stableStorage = new StableBTreeMap<text, StableFunc>(text, StableFunc, 0); | ||
|
||
@init([]) | ||
init() { | ||
this.stableStorage.insert( | ||
'stableFunc', | ||
new StableFunc(Principal.from('aaaaa-aa'), 'start_canister') | ||
); | ||
} | ||
|
||
@query([], StableFunc) | ||
getStableFunc(): StableFunc { | ||
const stableFuncOpt = this.stableStorage.get('stableFunc'); | ||
if (stableFuncOpt.length === 1) { | ||
return stableFuncOpt[0]; | ||
} | ||
return new StableFunc(Principal.from('aaaaa-aa'), 'raw_rand'); | ||
} | ||
|
||
@query([BasicFunc], BasicFunc) | ||
basicFuncParam(basicFunc: BasicFunc): BasicFunc { | ||
return basicFunc; | ||
} | ||
|
||
@query([NullFunc], NullFunc) | ||
nullFuncParam(nullFunc: NullFunc): NullFunc { | ||
return nullFunc; | ||
} | ||
|
||
@query([Vec(BasicFunc)], Vec(BasicFunc)) | ||
basicFuncParamArray(basicFunc: Vec<BasicFunc>): Vec<BasicFunc> { | ||
return basicFunc; | ||
} | ||
|
||
@query([], BasicFunc) | ||
basicFuncReturnType(): BasicFunc { | ||
return new BasicFunc(Principal.fromText('aaaaa-aa'), 'create_canister'); | ||
} | ||
|
||
@query([], Vec(BasicFunc)) | ||
basicFuncReturnTypeArray(): Vec<BasicFunc> { | ||
return [ | ||
new BasicFunc(Principal.fromText('aaaaa-aa'), 'create_canister'), | ||
new BasicFunc(Principal.fromText('aaaaa-aa'), 'update_settings'), | ||
new BasicFunc(Principal.fromText('aaaaa-aa'), 'install_code') | ||
]; | ||
} | ||
|
||
@query([ComplexFunc], ComplexFunc) | ||
complexFuncParam(complexFunc: ComplexFunc): ComplexFunc { | ||
return complexFunc; | ||
} | ||
|
||
@query([], ComplexFunc) | ||
complexFuncReturnType(): ComplexFunc { | ||
return [Principal.fromText('aaaaa-aa'), 'stop_canister']; | ||
} | ||
|
||
@update([], NotifierFunc) | ||
async getNotifierFromNotifiersCanister(): Promise<NotifierFunc> { | ||
const notifiersCanister: Notifier = new Notifier( | ||
Principal.fromText( | ||
process.env.NOTIFIERS_PRINCIPAL ?? | ||
ic.trap('process.env.NOTIFIERS_PRINCIPAL is undefined') | ||
) | ||
); | ||
|
||
return await ic.call(notifiersCanister.getNotifier); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
service: () -> { | ||
getNotifier: () -> (func (vec nat8) -> () oneway) query; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ic, Principal, query, blob, Func, Service, Void, func } from 'azle'; | ||
|
||
@func([blob], Void, 'oneway') | ||
export class NotifierFunc extends Func {} | ||
|
||
export default class extends Service { | ||
@query([], NotifierFunc) | ||
getNotifier(): NotifierFunc { | ||
return new NotifierFunc( | ||
Principal.fromText( | ||
process.env.NOTIFIERS_PRINCIPAL ?? | ||
ic.trap('process.env.NOTIFIERS_PRINCIPAL is undefined') | ||
), | ||
'notify' | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.