Skip to content

Commit

Permalink
Merge pull request #1247 from demergent-labs/visitors
Browse files Browse the repository at this point in the history
Add Decode Visitor
  • Loading branch information
lastmjs authored Sep 22, 2023
2 parents 7e5f67c + fdc4862 commit 853a7f7
Show file tree
Hide file tree
Showing 39 changed files with 881 additions and 367 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,14 @@
# "examples/update"

# These are the ones that don't work
# "examples/tuple_types",
# "examples/service",
# "examples/robust_imports",
# "examples/run_time_errors",
# "examples/complex_types",
# "examples/func_types",
# "examples/generics",
# "examples/tuple_types",
# "examples/complex_types",
# "examples/motoko_examples/superheroes",
# "examples/motoko_examples/threshold_ecdsa",
# "examples/run_time_errors",
# "examples/robust_imports",

name: Azle Tests
on:
Expand Down Expand Up @@ -183,6 +182,7 @@ jobs:
"examples/query",
"examples/randomness",
"examples/rejections",
"examples/service",
"examples/simple_erc20",
"examples/simple_user_accounts",
"examples/stable_memory",
Expand Down
5 changes: 3 additions & 2 deletions canisters/ledger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
Variant,
Vec,
candid,
principal
principal,
Func
} from '../../src/lib_new';
import {
ICRC1Account,
Expand Down Expand Up @@ -279,7 +280,7 @@ export class QueryArchiveResult extends Variant {

// A function that is used for fetching archived ledger blocks.
@func([GetBlocksArgs], QueryArchiveResult, 'query')
class QueryArchiveFn {}
class QueryArchiveFn extends Func {}

class ArchivedBlock extends Record {
// The index of the first archived block that can be fetched using the callback.
Expand Down
5 changes: 3 additions & 2 deletions canisters/management/http_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
Null,
nat64,
nat,
func
func,
Func
} from '../../src/lib_new';

export class HttpHeader extends Record {
Expand Down Expand Up @@ -63,7 +64,7 @@ export class HttpTransformArgs extends Record {
}

@func([HttpTransformArgs], HttpResponse, 'query')
export class HttpTransformFunc {}
export class HttpTransformFunc extends Func {}

export class HttpTransform extends Record {
/**
Expand Down
123 changes: 0 additions & 123 deletions examples/func_types/canisters/func_types/func_types.ts

This file was deleted.

127 changes: 127 additions & 0 deletions examples/func_types/canisters/func_types/index.ts
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);
}
}
3 changes: 3 additions & 0 deletions examples/func_types/canisters/notifiers/index.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service: () -> {
getNotifier: () -> (func (vec nat8) -> () oneway) query;
}
17 changes: 17 additions & 0 deletions examples/func_types/canisters/notifiers/index.ts
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'
);
}
}
1 change: 0 additions & 1 deletion examples/func_types/canisters/notifiers/notifiers.did

This file was deleted.

13 changes: 0 additions & 13 deletions examples/func_types/canisters/notifiers/notifiers.ts

This file was deleted.

8 changes: 0 additions & 8 deletions examples/func_types/canisters/notifiers/types.ts

This file was deleted.

8 changes: 4 additions & 4 deletions examples/func_types/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"type": "custom",
"build": "npx azle func_types",
"root": "src",
"ts": "canisters/func_types/func_types.ts",
"candid": "canisters/func_types/func_types.did",
"ts": "canisters/func_types/index.ts",
"candid": "canisters/func_types/index.did",
"wasm": ".azle/func_types/func_types.wasm.gz",
"declarations": {
"output": "test/dfx_generated/func_types",
Expand All @@ -17,8 +17,8 @@
"type": "custom",
"build": "npx azle notifiers",
"root": "src",
"ts": "canisters/notifiers/notifiers.ts",
"candid": "canisters/notifiers/notifiers.did",
"ts": "canisters/notifiers/index.ts",
"candid": "canisters/notifiers/index.did",
"wasm": ".azle/notifiers/notifiers.wasm.gz",
"declarations": {
"output": "test/dfx_generated/notifiers",
Expand Down
Loading

0 comments on commit 853a7f7

Please sign in to comment.