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

Type inference #1301

Merged
merged 3 commits into from
Sep 27, 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
"examples/bytes",
"examples/call_raw",
"examples/candid_encoding",
"examples/canister",
"examples/complex_init",
"examples/composite_queries",
"examples/counter",
Expand Down Expand Up @@ -115,7 +116,6 @@ jobs:
"examples/randomness",
"examples/rejections",
"examples/robust_imports",
"examples/service",
"examples/simple_erc20",
"examples/simple_user_accounts",
"examples/stable_memory",
Expand Down
5 changes: 2 additions & 3 deletions canisters/ledger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

import {
blob,
Canister,
nat,
nat8,
nat32,
nat64,
Null,
Opt,
Principal,
Record,
Service,
query,
update,
text,
Expand Down Expand Up @@ -298,7 +297,7 @@ export const DecimalsResult = Record({
export type Address = text;
export const Address = text;

export const Ledger = Service({
export const Ledger = Canister({
// Transfers tokens from a subaccount of the caller to the destination address.
// The source address is computed from the principal of the caller and the specified subaccount.
// When successful, returns the index of the block containing the transaction.
Expand Down
4 changes: 2 additions & 2 deletions canisters/management/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
blob,
Canister,
Principal,
Service,
update,
Vec,
Void
Expand Down Expand Up @@ -44,7 +44,7 @@ export * from './canister_management';
export * from './http_request';
export * from './t_ecdsa';

export const managementCanister = Service({
export const managementCanister = Canister({
// bitcoin
bitcoin_get_balance: update([GetBalanceArgs], Satoshi),
bitcoin_get_current_fee_percentiles: update(
Expand Down
4 changes: 2 additions & 2 deletions examples/async_await/src/async_await.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { blob, ic, Service, update, Void } from 'azle';
import { blob, Canister, ic, update, Void } from 'azle';
import { managementCanister } from 'azle/canisters/management';

export default Service({
export default Canister({
getRandomnessDirectly: update([], blob, async () => {
return await ic.call(managementCanister.raw_rand);
}),
Expand Down
4 changes: 2 additions & 2 deletions examples/audio_recorder/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
blob,
Canister,
ic,
nat64,
Opt,
Expand All @@ -8,7 +9,6 @@ import {
query,
Record,
Result,
Service,
StableBTreeMap,
text,
update,
Expand Down Expand Up @@ -39,7 +39,7 @@ const AudioRecorderError = Variant({
let users = StableBTreeMap(principal, User, 0);
let recordings = StableBTreeMap(principal, Recording, 1);

export default Service({
export default Canister({
createUser: update([text], User, (username) => {
const id = generateId();
const user: typeof User = {
Expand Down
4 changes: 2 additions & 2 deletions examples/bitcoin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { blob, bool, ic, None, Service, text, update, Vec } from 'azle';
import { blob, bool, Canister, ic, None, text, update, Vec } from 'azle';
import {
GetUtxosResult,
managementCanister,
Expand All @@ -10,7 +10,7 @@ const BITCOIN_API_CYCLE_COST = 100_000_000n;
const BITCOIN_BASE_TRANSACTION_COST = 5_000_000_000n;
const BITCOIN_CYCLE_COST_PER_TRANSACTION_BYTE = 20_000_000n;

export default Service({
export default Canister({
getBalance: update([text], Satoshi, async (address) => {
return await ic.call(managementCanister.bitcoin_get_balance, {
args: [
Expand Down
4 changes: 2 additions & 2 deletions examples/blob_array/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { blob, query, Service, Vec } from 'azle';
import { blob, Canister, query, Vec } from 'azle';

export default Service({
export default Canister({
getBlob: query([], blob, () => {
return stringToBlob('hello');
}),
Expand Down
4 changes: 2 additions & 2 deletions examples/bytes/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { blob, Service, update } from 'azle';
import { blob, Canister, update } from 'azle';

export default Service({
export default Canister({
getBytes: update([blob], blob, (bytes) => {
return bytes;
})
Expand Down
13 changes: 11 additions & 2 deletions examples/call_raw/src/call_raw.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { ic, nat, nat64, principal, Result, Service, text, update } from 'azle';
import {
Canister,
ic,
nat,
nat64,
principal,
Result,
text,
update
} from 'azle';

export default Service({
export default Canister({
executeCallRaw: update(
[principal, text, text, nat64],
Result(text, text),
Expand Down
4 changes: 2 additions & 2 deletions examples/candid_encoding/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { blob, ic, query, Service, text } from 'azle';
import { blob, Canister, ic, query, text } from 'azle';

export default Service({
export default Canister({
// encodes a Candid string to Candid bytes
candidEncode: query([text], blob, (candidString) => {
return ic.candidEncode(candidString);
Expand Down
File renamed without changes.
31 changes: 31 additions & 0 deletions examples/canister/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"canisters": {
"canister": {
"type": "custom",
"build": "npx azle canister",
"root": "src",
"ts": "src/index.ts",
"candid": "src/index.did",
"wasm": ".azle/canister/canister.wasm",
"gzip": true,
"declarations": {
"output": "test/dfx_generated/canister",
"node_compatibility": true
},
"env": ["SOME_CANISTER_PRINCIPAL"]
},
"some_canister": {
"type": "custom",
"build": "npx azle some_canister",
"root": "src",
"ts": "src/some_canister.ts",
"candid": "src/some_canister.did",
"wasm": ".azle/some_canister/some_canister.wasm",
"gzip": true,
"declarations": {
"output": "test/dfx_generated/some_canister",
"node_compatibility": true
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
8 changes: 8 additions & 0 deletions examples/canister/src/index.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type rec_0 = record {someCanister:service {query1:() -> (bool) query; update1:() -> (text) }};
service: () -> {
canisterParam: (service {query1:() -> (bool) query; update1:() -> (text) }) -> (service {query1:() -> (bool) query; update1:() -> (text) }) query;
canisterReturnType: () -> (service {query1:() -> (bool) query; update1:() -> (text) }) query;
canisterNestedReturnType: () -> (rec_0);
canisterList: (vec service {query1:() -> (bool) query; update1:() -> (text) }) -> (vec service {query1:() -> (bool) query; update1:() -> (text) });
canisterCrossCanisterCall: (service {query1:() -> (bool) query; update1:() -> (text) }) -> (text);
}
55 changes: 55 additions & 0 deletions examples/canister/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
Canister,
ic,
Principal,
query,
Record,
text,
update,
Vec
} from 'azle';
import SomeCanister from './some_canister';

const Wrapper = Record({
someCanister: SomeCanister
});

export default Canister({
canisterParam: query([SomeCanister], SomeCanister, (someCanister) => {
return someCanister;
}),
canisterReturnType: query([], SomeCanister, () => {
return SomeCanister(
Principal.fromText(
process.env.SOME_CANISTER_PRINCIPAL ??
ic.trap('process.env.SOME_CANISTER_PRINCIPAL is undefined')
)
);
}),
canisterNestedReturnType: update([], Wrapper, () => {
return {
someCanister: SomeCanister(
Principal.fromText(
process.env.SOME_CANISTER_PRINCIPAL ??
ic.trap(
'process.env.SOME_CANISTER_PRINCIPAL is undefined'
)
)
)
};
}),
canisterList: update(
[Vec(SomeCanister)],
Vec(SomeCanister),
(someCanisters) => {
return someCanisters;
}
),
canisterCrossCanisterCall: update(
[SomeCanister],
text,
async (someCanister) => {
return await ic.call(someCanister.update1);
}
)
});
10 changes: 10 additions & 0 deletions examples/canister/src/some_canister.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { bool, Canister, query, text, update } from 'azle';

export default Canister({
query1: query([], bool, () => {
return true;
}),
update1: update([], text, () => {
return 'SomeCanister update1';
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import { getCanisterId } from 'azle/test';
async function pretest() {
await new Promise((resolve) => setTimeout(resolve, 5000));

execSync(`dfx canister uninstall-code service || true`, {
execSync(`dfx canister uninstall-code canister || true`, {
stdio: 'inherit'
});

execSync(`dfx canister uninstall-code some_service || true`, {
execSync(`dfx canister uninstall-code some_canister || true`, {
stdio: 'inherit'
});

execSync(`dfx canister create some_service || true`, {
execSync(`dfx canister create some_canister || true`, {
stdio: 'inherit'
});

execSync(
`SOME_SERVICE_PRINCIPAL=${getCanisterId('some_service')} dfx deploy`,
`SOME_CANISTER_PRINCIPAL=${getCanisterId('some_canister')} dfx deploy`,
{
stdio: 'inherit'
}
Expand Down
11 changes: 11 additions & 0 deletions examples/canister/test/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getCanisterId, runTests } from 'azle/test';
import { createActor } from './dfx_generated/canister';
import { getTests } from './tests';

const canister = createActor(getCanisterId('canister'), {
agentOptions: {
host: 'http://127.0.0.1:8000'
}
});

runTests(getTests(canister));
Loading