Environment & Invocation
Access runtime information about the current call and execution environment.
Invocation
Get information about the current endpoint call:
| Method | Returns | Description |
|---|---|---|
Invocation.ID() | Identifier | Unique ID of this invocation |
Invocation.Caller() | Identifier | Immediate caller (differs from Sender in cross-logic calls) |
Sender vs Caller
Sender— The actor who initiated the interaction (stays the same through cross-logic calls)Invocation.Caller()— The immediate caller (changes in cross-logic calls)
endpoint CheckCaller() -> (sender Identifier, caller Identifier):
sender = Sender // Original actor
caller = Invocation.Caller() // Immediate caller (could be another logic)
Environment
Access runtime environment data:
| Method | Returns | Description |
|---|---|---|
Environment.Timestamp() | U64 | Current interaction timestamp |
Environment.EffortCapacity() | U64 | Total fuel available |
Environment.EffortAvailable() | U64 | Remaining fuel |
Environment.VolumeCapacity() | U64 | Total storage space |
Environment.VolumeAvailable() | U64 | Remaining storage space |
endpoint GetEnvInfo() -> (
timestamp U64,
fuel_remaining U64,
invocation_id Identifier
):
timestamp = Environment.Timestamp()
fuel_remaining = Environment.EffortAvailable()
invocation_id = Invocation.ID()
Example: Time-based Logic
coco TimeLock
state actor:
locked_until U64
endpoint dynamic Lock(duration U64):
memory unlock_time = Environment.Timestamp() + duration
mutate unlock_time -> TimeLock.Sender.locked_until
endpoint dynamic Withdraw():
observe locked <- TimeLock.Sender.locked_until:
if Environment.Timestamp() < locked:
throw "Still locked"
// proceed with withdrawal