-
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 #1850 from demergent-labs/cross_cansiter_calls
implement cross_canister_calls example, notify, trap
- Loading branch information
Showing
21 changed files
with
10,313 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { call } from './call'; | ||
export { notify } from './notify'; | ||
export { trap } from './trap'; |
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,42 @@ | ||
import { IDL, Principal } from '../'; | ||
|
||
/** | ||
* Performs a cross-canister call without awaiting the result | ||
* @param canisterId | ||
* @param method | ||
* @param argsRaw | ||
* @param payment | ||
* @returns | ||
*/ | ||
export function notify( | ||
canisterId: Principal | string, | ||
method: string, | ||
options?: { | ||
paramIdls?: IDL.Type[]; | ||
args?: any[]; | ||
payment?: bigint; | ||
} | ||
): void { | ||
if (globalThis._azleIc === undefined) { | ||
return undefined as any; | ||
} | ||
|
||
const paramIdls = options?.paramIdls ?? []; | ||
const args = options?.args ?? []; | ||
const payment = options?.payment ?? 0n; | ||
|
||
const canisterIdPrincipal = | ||
typeof canisterId === 'string' | ||
? Principal.fromText(canisterId) | ||
: canisterId; | ||
const canisterIdBytes = canisterIdPrincipal.toUint8Array().buffer; | ||
const argsRawBuffer = new Uint8Array(IDL.encode(paramIdls, args)).buffer; | ||
const paymentString = payment.toString(); | ||
|
||
return globalThis._azleIc.notifyRaw( | ||
canisterIdBytes, | ||
method, | ||
argsRawBuffer, | ||
paymentString | ||
); | ||
} |
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 @@ | ||
/** | ||
* Stops execution and rejects the current request with a `CANISTER_ERROR` | ||
* (5) rejection code and the provided message | ||
* @param message the rejection message | ||
*/ | ||
export function trap(message: string): never { | ||
if (globalThis._azleIc === undefined) { | ||
return undefined as never; | ||
} | ||
|
||
return globalThis._azleIc.trap(message); | ||
} |
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
4 changes: 4 additions & 0 deletions
4
tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls/.gitignore
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,4 @@ | ||
.azle | ||
.dfx | ||
dfx_generated | ||
node_modules |
26 changes: 26 additions & 0 deletions
26
tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls/dfx.json
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,26 @@ | ||
{ | ||
"canisters": { | ||
"canister1": { | ||
"type": "azle", | ||
"main": "src/canister1/index.ts", | ||
"candid": "src/canister1/index.did", | ||
"candid_gen": "custom", | ||
"env": ["CANISTER2_PRINCIPAL", "AZLE_TEST_FETCH"], | ||
"assets": [["src/canister2/index.did", "candid/canister2.did"]], | ||
"declarations": { | ||
"output": "test/dfx_generated/canister1", | ||
"node_compatibility": true | ||
} | ||
}, | ||
"canister2": { | ||
"type": "azle", | ||
"main": "src/canister2/index.ts", | ||
"candid": "src/canister2/index.did", | ||
"candid_gen": "custom", | ||
"declarations": { | ||
"output": "test/dfx_generated/canister2", | ||
"node_compatibility": true | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/end_to_end/candid_rpc/class_syntax/cross_canister_calls/jest.config.js
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,10 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest', | ||
'^.+\\.js$': 'ts-jest' | ||
}, | ||
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed | ||
}; |
Oops, something went wrong.