Attribute Macro pbc_contract_codegen::zk_on_external_event
source · #[zk_on_external_event]
Expand description
External event zero-knowledge contract annotation
OPTIONAL HOOK: This is an optional hook, and is not required for a well-formed zero-knowledge contract. The default behaviour is to do nothing.
If the annotated function panics changes to the contract state will be rolled back.
Annotated function is automatically called when the contract is informed of a new external event
that has been confirmed by the EVM oracle to have occurred on an external EVM chain. This can
only happen after the use of
ZkStateChange::SubscribeToEvmEvents
.
This hook is exclusively called by the blockchain itself, and cannot be called manually from the
dashboard, nor from another contract.
Allows the contract to automatically react to EVM events.
Annotated function must have a signature of following format:
use pbc_contract_common::zk::evm_event::{ExternalEventId, EventSubscriptionId};
#[zk_on_external_event]
pub fn zk_on_external_event(
context: ContractContext,
state: ContractState,
zk_state: ZkState<Metadata>,
subscription_id: EventSubscriptionId,
event_id: ExternalEventId,
) -> (ContractState, Vec<EventGroup>, Vec<ZkStateChange>)
Where ZkState
can be further accessed to read the event, etc.