Skip to content

Commit

Permalink
double check call context
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Jan 13, 2025
1 parent 72292fe commit 801c73a
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 41 deletions.
2 changes: 0 additions & 2 deletions src/lib/stable/ic_apis/accept_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { inspectMessage } from '../canister_methods/inspect_message'; // Used fo
*
* @remarks
* - Signals that a message should proceed to execution
* - Cannot be called after reject_message
* - Traps if called outside {@link inspectMessage} context
* - **Call Context**:
* - inspectMessage
*/
Expand Down
6 changes: 4 additions & 2 deletions src/lib/stable/ic_apis/arg_data_raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
* @remarks
* - **Call Context**:
* - init
* - postUpgrade
* - update
* - query
* - query (replicated and non-replicated)
* - composite query
* - reply
* - after a cross-canister call
* - after a cross-canister call from a composite query
* - inspectMessage
*/
export function argDataRaw(): Uint8Array {
Expand Down
7 changes: 5 additions & 2 deletions src/lib/stable/ic_apis/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ import { idlDecode, idlEncode } from '../execute_with_candid_serde';
* - **Call Context**:
* - update
* - composite query
* - reply
* - after a cross-canister call
* - after a rejected cross-canister call
* - after a cross-canister call from a composite query
* - after a rejected cross-canister call from a composite query
* - heartbeat
* - global_timer
* - timer
*/
export async function call<Args extends any[] | undefined, Return = any>(
canisterId: Principal | string,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stable/ic_apis/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Principal } from '@dfinity/principal';
* - For user calls, returns the user's Principal
* - For anonymous calls, returns the anonymous Principal
* - **Call Context**:
* - Any method
* - Any method (not start)
*/
export function caller(): Principal {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stable/ic_apis/canister_balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @remarks
* - **Call Context**:
* - Any method
* - Any method (not start)
*/
export function canisterBalance(): bigint {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stable/ic_apis/canister_version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* have been made to the canister's state or configuration.
*
* - **Call Context**:
* - Any method
* - Any method (not start)
*/
export function canisterVersion(): bigint {
if (
Expand Down
7 changes: 4 additions & 3 deletions src/lib/stable/ic_apis/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { id } from './id';
* - Current instruction limits are ~40B for update calls
* - See: https://internetcomputer.org/docs/current/developer-docs/smart-contracts/maintain/resource-limits
* - **Call Context**:
* - Update calls and their reply/reject callbacks
* - Timers
* - Heartbeat methods
* - update
* - after a cross-canister call (only from updates?)
* - heartbeat
* - timer
*/
export async function chunk(): Promise<void> {
if (
Expand Down
8 changes: 6 additions & 2 deletions src/lib/stable/ic_apis/clear_timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
* - No effect if timer ID doesn't exist
* - **Call Context**:
* - init
* - postUpgrade
* - preUpgrade
* - update
* - reply
* - after a cross-canister call
* - after a rejected cross-canister call
* - heartbeat
* - global_timer
* - timer
* - Note: Assuming same as timer
* - Note: Also cleanupCallback
*/
export function clearTimer(timerId: bigint): void {
if (
Expand Down
7 changes: 5 additions & 2 deletions src/lib/stable/ic_apis/cycles_burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
* - Cannot burn more cycles than the canister has available
* - **Call Context**:
* - init
* - postUpgrade
* - preUpgrade
* - update
* - reply
* - after a cross-canister call
* - after a rejected cross-canister call
* - heartbeat
* - global_timer
* - timer
* - Note: Also cleanupCallback
*/
export function cyclesBurn(amount: bigint): bigint {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stable/ic_apis/data_certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { setCertifiedData } from './set_certified_data'; // Used for links in co
* - Enables query calls to return certified responses
* - Only meaningful during query calls
* - **Call Context**:
* - query
* - query (non-replicated)
* - composite query
*/
export function dataCertificate(): Uint8Array | undefined {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stable/ic_apis/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Principal } from '@dfinity/principal';
* @remarks
* - Every canister has a unique Principal
* - **Call Context**:
* - Any method
* - Any method (not start)
*/
export function id(): Principal {
if (
Expand Down
3 changes: 2 additions & 1 deletion src/lib/stable/ic_apis/msg_cycles_accept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* - Cannot accept more cycles than are available in the current call
* - **Call Context**:
* - update
* - reply
* - after a cross-canister call
* - after a rejected cross-canister call
*/
export function msgCyclesAccept(maxAmount: bigint): bigint {
if (
Expand Down
3 changes: 2 additions & 1 deletion src/lib/stable/ic_apis/msg_cycles_available.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* - Amount decreases as cycles are accepted by the canister
* - **Call Context**:
* - update
* - reply
* - after a cross-canister call
* - after a rejected cross-canister call
*/
export function msgCyclesAvailable(): bigint {
if (
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stable/ic_apis/msg_cycles_refunded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* - Only meaningful after a cross-canister call
* - Refunded cycles are already added to canister balance
* - **Call Context**:
* - reply callback
* - reject callback
* - after a cross-canister call
* - after a rejected cross-canister call
*/
export function msgCyclesRefunded(): bigint {
if (
Expand Down
8 changes: 6 additions & 2 deletions src/lib/stable/ic_apis/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ import { idlEncode } from '../execute_with_candid_serde';
* - **Call Context**:
* - update
* - composite query
* - reply
* - after a cross-canister call
* - after a rejected cross-canister call
* - after a cross-canister call from a composite query
* - after a rejected cross-canister call from a composite query
* - heartbeat
* - global_timer
* - timer
* - Note: Assuming same as call
*/
export function notify(
canisterId: Principal | string,
Expand Down
7 changes: 5 additions & 2 deletions src/lib/stable/ic_apis/reject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
* - Used in canister methods marked with { manual: true }
* - **Call Context**:
* - update
* - query
* - query (replicated and non-replicated)
* - composite query
* - reply
* - after a cross-canister call
* - after a rejected cross-canister call
* - after a cross-canister call from a composite query
* - after a rejected cross-canister call from a composite query
*/
export function reject(message: string): void {
if (
Expand Down
8 changes: 4 additions & 4 deletions src/lib/stable/ic_apis/reject_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export const RejectionCode = IDL.Variant({
*
* @remarks
* - **Call Context**:
* - reply callback
* - reply callback in a composite query
* - reject callback
* - reject callback in a composite query
* - after a cross-canister call
* - after a rejected cross-canister call
* - after a cross-canister call from a composite query
* - after a rejected cross-canister call from a composite query
*/
export function rejectCode(): RejectionCode {
if (
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stable/ic_apis/reject_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { rejectCode } from './reject_code'; // Used for links in comments
* - Will trap if there is no reject message available
* - Always check {@link rejectCode} before calling this function
* - **Call Context**:
* - reject callback
* - reject callback in a composite query
* - after a rejected cross-canister call
* - after a rejected cross-canister call from a composite query
*/
export function rejectMessage(): string {
if (
Expand Down
7 changes: 5 additions & 2 deletions src/lib/stable/ic_apis/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ type ReplyInput<T> =
* - If idlType is omitted, the data will be encoded as an empty type
* - **Call Context**:
* - update
* - query
* - query (replicated and non-replicated)
* - composite query
* - reply
* - after a cross-canister call
* - after a rejected cross-canister call
* - after a cross-canister call from a composite query
* - after a rejected cross-canister call from a composite query
*/
export function reply<T>(input: ReplyInput<T>): void {
if (
Expand Down
6 changes: 4 additions & 2 deletions src/lib/stable/ic_apis/set_certified_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import { dataCertificate } from './data_certificate'; // Used for links in comme
* - Limited to 32 bytes of data (traps if exceeded)
* - **Call Context**:
* - init
* - postUpgrade
* - preUpgrade
* - update
* - reply
* - after a cross-canister call
* - after a rejected cross-canister call
* - heartbeat
* - global_timer
* - timer
*/
export function setCertifiedData(data: Uint8Array): void {
if (
Expand Down
7 changes: 5 additions & 2 deletions src/lib/stable/ic_apis/set_timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ import { v4 } from 'uuid';
* - The callback registration is automatically cleaned up after execution
* - **Call Context**:
* - init
* - postUpgrade
* - preUpgrade
* - update
* - reply
* - after a cross-canister call
* - after a rejected cross-canister call
* - heartbeat
* - global_timer
* - timer
* - Note: Also cleanupCallback
*/
export function setTimer(
delay: bigint,
Expand Down
7 changes: 5 additions & 2 deletions src/lib/stable/ic_apis/set_timer_interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ import { v4 } from 'uuid';
* - Callbacks remain registered even if they throw errors
* - **Call Context**:
* - init
* - postUpgrade
* - preUpgrade
* - update
* - reply
* - after a cross-canister call
* - after a rejected cross-canister call
* - heartbeat
* - global_timer
* - timer
* - Note: Also cleanupCallback
*/
export function setTimerInterval(
interval: bigint,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stable/ic_apis/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* - Returns the number of nanoseconds since 1970-01-01 (Unix epoch).
* - Within an invocation of one entry point, the time is constant
* - **Call Context**:
* - Any method
* - Any method (not start)
*/
export function time(): bigint {
if (
Expand Down

0 comments on commit 801c73a

Please sign in to comment.