use crate::{
serialization::{
HexNumber,
HexType,
},
GenesisCommitment,
};
use fuel_core_storage::MerkleRoot;
use fuel_core_types::{
blockchain::primitives::DaBlockHeight,
entities::message::CompressedMessage,
fuel_asm::Word,
fuel_types::Address,
};
use serde::{
Deserialize,
Serialize,
};
use serde_with::{
serde_as,
skip_serializing_none,
};
#[skip_serializing_none]
#[serde_as]
#[derive(Clone, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
pub struct MessageConfig {
#[serde_as(as = "HexType")]
pub sender: Address,
#[serde_as(as = "HexType")]
pub recipient: Address,
#[serde_as(as = "HexNumber")]
pub nonce: Word,
#[serde_as(as = "HexNumber")]
pub amount: Word,
#[serde_as(as = "HexType")]
pub data: Vec<u8>,
#[serde_as(as = "HexNumber")]
pub da_height: DaBlockHeight,
}
impl From<MessageConfig> for CompressedMessage {
fn from(msg: MessageConfig) -> Self {
CompressedMessage {
sender: msg.sender,
recipient: msg.recipient,
nonce: msg.nonce,
amount: msg.amount,
data: msg.data,
da_height: msg.da_height,
}
}
}
impl GenesisCommitment for CompressedMessage {
fn root(&self) -> anyhow::Result<MerkleRoot> {
Ok(self.id().into())
}
}