use bitflags::bitflags;
use fvm_ipld_encoding::strict_bytes;
use serde::{Deserialize, Serialize};
use serde_tuple::*;
use crate::ActorID;
#[derive(Serialize_tuple, Deserialize_tuple, PartialEq, Eq, Clone, Debug)]
pub struct StampedEvent {
pub emitter: ActorID,
pub event: ActorEvent,
}
impl StampedEvent {
pub fn new(emitter: ActorID, event: ActorEvent) -> Self {
Self { emitter, event }
}
}
#[derive(Serialize_tuple, Deserialize_tuple, PartialEq, Eq, Clone, Debug)]
#[serde(transparent)]
pub struct ActorEvent {
pub entries: Vec<Entry>,
}
impl From<Vec<Entry>> for ActorEvent {
fn from(entries: Vec<Entry>) -> Self {
Self { entries }
}
}
bitflags! {
#[derive(Deserialize, Serialize, Copy, Clone, Eq, PartialEq, Debug)]
#[repr(transparent)] #[serde(transparent)]
pub struct Flags: u64 {
const FLAG_INDEXED_KEY = 0b00000001;
const FLAG_INDEXED_VALUE = 0b00000010;
const FLAG_INDEXED_ALL = Self::FLAG_INDEXED_KEY.bits() | Self::FLAG_INDEXED_VALUE.bits();
}
}
#[derive(Serialize_tuple, Deserialize_tuple, PartialEq, Eq, Clone, Debug)]
pub struct Entry {
pub flags: Flags,
pub key: String,
pub codec: u64,
#[serde(with = "strict_bytes")]
pub value: Vec<u8>,
}