Attribute Macro pbc_contract_codegen::callback
source · #[callback]
Expand description
Public callback contract annotation
OPTIONAL HOOK: This is an optional hook, only required if the contract needs callback functionality.
Annotated function is a callback from an event sent by this contract. Unlike actions, callbacks must specify their shortname explicitly.
If the annotated function panics the contract state will be rolled back to the state before the callback.
Must have a signature of the following format:
#[callback(shortname = 0x13)]
pub fn callback_internal_name(
contract_context: ContractContext,
callback_context: CallbackContext,
state: ContractState,
// ... Invocation RPC arguments
) -> (ContractState, Vec<EventGroup>)
with following constraints:
ContractState
must be the type annotated withstate
, and must have anpbc_traits::ReadWriteState
implementation.- Additional arguments are must have
pbc_traits::ReadRPC
andpbc_traits::WriteRPC
implementations. These are treated as invocation arguments, and are included in the ABI.
The callback receives the previous state, along with two context objects, and the declared
arguments. The CallbackContext
object contains the execution status of all the events
sent by the original transaction.
Just like actions, callbacks must return the new state, along with a vector of
EventGroup
; a list of interactions with other contracts.
§Shortname
In addition to the readable name the callback needs a shortname, a small unique identifier.
This shortname must be set using the shortname = <shortname>
attribute.
This has to be a u32
and gets encoded as LEB128 (up to 5 bytes). These bytes are then
encoded as lowercase zero-padded hex.