You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Casper 2.0 introduces a new way to emit native events. Here is how we can
integrate it with Odra.
Step 1: Contract Installation
On contract installation it's possible to define a contract's topics. Because we
already have a good tooling for serialization/deserialization Rust structs
into/from bytes we can have just one topic: events.
FFI to use:
pubfncasper_add_package_version(package_hash_ptr:*constu8,package_hash_size:usize,version_ptr:*constu32,entry_points_ptr:*constu8,entry_points_size:usize,named_keys_ptr:*constu8,named_keys_size:usize,message_topics_ptr:*constu8,// <- This message_topics_size:usize,// <- and this.output_ptr:*mutu8,output_size:usize,) -> i32;
Step 2: Event emitting.
On event emission using ContractEnv::emit_event from the point of view of the
contract developer nothing changes. The event is emitted using new ffi:
The main change between CES and Native Events is how they are emitted to the outside world.
In CES, they were simply recorded in the contract's state, so even old events could be retrieved.
In Native Events, they are emitted in processing_results of each deploy.
It takes a form of this struct:
pubstructMessage{/// The identity of the entity that produced the message.entity_hash:EntityAddr,// TODO: this should be EntityAddr/// The payload of the message.message:MessagePayload,/// The name of the topic on which the message was emitted on.topic_name:String,/// The hash of the name of the topic.topic_name_hash:TopicNameHash,/// Message index in the topic.topic_index:u32,/// Message index in the block.block_index:u64,}
This means we have to drop the old style of testing events:
Remove HostRef::get_event,
Remove HostEnv::events_count and all dependant code,
Accessing events have to be organized around HostEnv::last_call_result.
odra_vm has to be adjusted to support that.
Step 4: Livenet
Same HostEnv should work both for tests and for livenet.
Message format
In CES events can't be nested structs or enums. Since the inception of CES we
implemented Contract Metadata format, that allows for that. We should serialize
events like any other odra_struct, because right now we have a specialized
serialization for events. It should be discussed with Make.
The text was updated successfully, but these errors were encountered:
Native Events
Casper 2.0 introduces a new way to emit native events. Here is how we can
integrate it with Odra.
Step 1: Contract Installation
On contract installation it's possible to define a contract's topics. Because we
already have a good tooling for serialization/deserialization Rust structs
into/from bytes we can have just one topic:
events
.FFI to use:
Step 2: Event emitting.
On event emission using
ContractEnv::emit_event
from the point of view of thecontract developer nothing changes. The event is emitted using new ffi:
Step 3: Testing events.
The main change between CES and Native Events is how they are emitted to the outside world.
In CES, they were simply recorded in the contract's state, so even old events could be retrieved.
In Native Events, they are emitted in
processing_results
of each deploy.It takes a form of this struct:
This means we have to drop the old style of testing events:
HostRef::get_event
,HostEnv::events_count
and all dependant code,Accessing events have to be organized around
HostEnv::last_call_result
.odra_vm
has to be adjusted to support that.Step 4: Livenet
Same
HostEnv
should work both for tests and for livenet.Message format
In CES events can't be nested structs or enums. Since the inception of CES we
implemented Contract Metadata format, that allows for that. We should serialize
events like any other
odra_struct
, because right now we have a specializedserialization for events. It should be discussed with Make.
The text was updated successfully, but these errors were encountered: