use codec::{Decode, Encode};
use frame_support::PalletError;
use scale_info::TypeInfo;
use snowbridge_beacon_primitives::{BeaconHeader, ExecutionProof};
use sp_core::{H160, H256};
use sp_runtime::RuntimeDebug;
use sp_std::vec::Vec;
pub trait Verifier {
fn verify(event: &Log, proof: &Proof) -> Result<(), VerificationError>;
}
#[derive(Clone, Encode, Decode, RuntimeDebug, PalletError, TypeInfo)]
#[cfg_attr(feature = "std", derive(PartialEq))]
pub enum VerificationError {
HeaderNotFound,
LogNotFound,
InvalidLog,
InvalidProof,
InvalidExecutionProof(#[codec(skip)] &'static str),
}
pub type MessageNonce = u64;
#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)]
pub struct Message {
pub event_log: Log,
pub proof: Proof,
}
const MAX_TOPICS: usize = 4;
#[derive(Clone, RuntimeDebug)]
pub enum LogValidationError {
TooManyTopics,
}
#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)]
pub struct Log {
pub address: H160,
pub topics: Vec<H256>,
pub data: Vec<u8>,
}
impl Log {
pub fn validate(&self) -> Result<(), LogValidationError> {
if self.topics.len() > MAX_TOPICS {
return Err(LogValidationError::TooManyTopics)
}
Ok(())
}
}
#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)]
pub struct Proof {
pub receipt_proof: (Vec<Vec<u8>>, Vec<Vec<u8>>),
pub execution_proof: ExecutionProof,
}
#[derive(Clone, RuntimeDebug)]
pub struct InboundQueueFixture {
pub message: Message,
pub finalized_header: BeaconHeader,
pub block_roots_root: H256,
}