-
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 #1227 from demergent-labs/manual_examples
Manual examples
- Loading branch information
Showing
25 changed files
with
337 additions
and
374 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
14 changes: 0 additions & 14 deletions
14
examples/composite_queries/canisters/canister1/canister1.did
This file was deleted.
Oops, something went wrong.
141 changes: 0 additions & 141 deletions
141
examples/composite_queries/canisters/canister1/canister1.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
service: () -> { | ||
simpleCompositeQuery: () -> (text) query; | ||
manualQuery: () -> (text) query; | ||
totallyManualQuery: () -> (text) query; | ||
deepQuery: () -> (text) query; | ||
updateQuery: () -> (text) query; | ||
simpleQuery: () -> (text) query; | ||
simpleUpdate: () -> (text); | ||
incCounter: () -> (nat) query; | ||
incCanister1: () -> (nat) query; | ||
incCanister2: () -> (nat) 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,89 @@ | ||
import { ic, Manual, nat, Principal, query, Service, text, update } from 'azle'; | ||
import Canister2 from '../canister2'; | ||
|
||
class Canister1 extends Service { | ||
canister2 = new Canister2( | ||
Principal.fromText( | ||
process.env.CANISTER2_PRINCIPAL ?? | ||
ic.trap('process.env.CANISTER2_PRINCIPAL is undefined') | ||
) | ||
); | ||
|
||
counter: nat = 0n; | ||
|
||
// Composite query calling a query | ||
@query([], text) | ||
async simpleCompositeQuery(): Promise<text> { | ||
return await ic.call(this.canister2.simpleQuery); | ||
} | ||
|
||
// Composite query calling a manual query | ||
@query([], text) | ||
async manualQuery(): Promise<text> { | ||
return await ic.call(this.canister2.manualQuery); | ||
} | ||
|
||
// Manual composite query calling a manual query | ||
@query([], text, { manual: true }) | ||
async totallyManualQuery(): Promise<Manual<text>> { | ||
ic.reply(await ic.call(this.canister2.manualQuery), text); | ||
} | ||
|
||
// Composite query calling another composite query | ||
@query([], text) | ||
async deepQuery(): Promise<text> { | ||
return await ic.call(this.canister2.deepQuery); | ||
} | ||
|
||
// Composite query calling an update method. SHOULDN'T WORK | ||
@query([], text) | ||
async updateQuery(): Promise<text> { | ||
return await ic.call(this.canister2.updateQuery); | ||
} | ||
|
||
// Composite query being called by a query method. SHOULDN'T WORK | ||
@query([], text) | ||
async simpleQuery(): Promise<text> { | ||
return await ic.call(this.canister2.simpleQuery); | ||
} | ||
|
||
// Composite query being called by an update method. SHOULDN'T WORK | ||
@update([], text) | ||
async simpleUpdate(): Promise<text> { | ||
return await ic.call(this.canister2.deepQuery); | ||
} | ||
|
||
// Composite query that modifies the state. Should revert after the call is done | ||
@query([], nat) | ||
async incCounter(): Promise<nat> { | ||
this.counter += 1n; | ||
|
||
return this.counter; | ||
} | ||
|
||
// Composite query calling queries on the same canister | ||
@query([], nat) | ||
async incCanister1(): Promise<nat> { | ||
this.counter += 1n; | ||
|
||
const canister1AResult = await ic.call(this.incCounter); | ||
|
||
const canister1BResult = await ic.call(this.incCounter); | ||
|
||
return this.counter + canister1AResult + canister1BResult; | ||
} | ||
|
||
// Composite query calling queries that modify the state | ||
@query([], nat) | ||
async incCanister2(): Promise<nat> { | ||
this.counter += 1n; | ||
|
||
const canister2AResult = await ic.call(this.canister2.incCounter); | ||
|
||
const canister2BResult = await ic.call(this.canister2.incCounter); | ||
|
||
return this.counter + canister2AResult + canister2BResult; | ||
} | ||
} | ||
|
||
export default Canister1; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
examples/composite_queries/canisters/canister2/canister2.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
service: () -> { | ||
incCounter: () -> (nat) query; | ||
simpleQuery: () -> (text) query; | ||
updateQuery: () -> (text); | ||
manualQuery: () -> (text) query; | ||
deepQuery: () -> (text) 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,40 @@ | ||
import { ic, Manual, nat, Principal, query, Service, text, update } from 'azle'; | ||
import Canister3 from '../canister3'; | ||
|
||
export default class extends Service { | ||
canister3 = new Canister3( | ||
Principal.fromText( | ||
process.env.CANISTER3_PRINCIPAL ?? | ||
ic.trap('process.env.CANISTER3_PRINCIPAL is undefined') | ||
) | ||
); | ||
|
||
counter: nat = 0n; | ||
|
||
// TODO is this supposed to be a query? | ||
@query([], nat) | ||
async incCounter(): Promise<nat> { | ||
this.counter += 1n; | ||
return this.counter; | ||
} | ||
|
||
@query([], text) | ||
simpleQuery(): text { | ||
return 'Hello from Canister 2'; | ||
} | ||
|
||
@update([], text) | ||
updateQuery(): text { | ||
return 'Hello from a Canister 2 update'; | ||
} | ||
|
||
@query([], text, { manual: true }) | ||
manualQuery(): Manual<text> { | ||
ic.reply('Hello from Canister 2 manual query', text); | ||
} | ||
|
||
@query([], text) | ||
async deepQuery(): Promise<text> { | ||
return await ic.call(this.canister3.deepQuery); | ||
} | ||
} |
Oops, something went wrong.