use thiserror::Error;
use datasize::DataSize;
use casper_hashing::Digest;
use casper_types::ProtocolVersion;
use crate::core::{engine_state::error::Error, runtime::stack::RuntimeStackOverflow};
#[derive(Debug, Error, DataSize)]
pub enum GetEraValidatorsError {
#[error("Invalid state hash")]
RootNotFound,
#[error(transparent)]
Other(#[from] Error),
#[error("Era validators missing")]
EraValidatorsMissing,
#[error("Unexpected query failure")]
UnexpectedQueryFailure,
#[error("CLValue conversion error")]
CLValue,
}
impl From<RuntimeStackOverflow> for GetEraValidatorsError {
fn from(overflow: RuntimeStackOverflow) -> Self {
GetEraValidatorsError::Other(Error::from(overflow))
}
}
impl GetEraValidatorsError {
pub fn is_era_validators_missing(&self) -> bool {
matches!(self, GetEraValidatorsError::EraValidatorsMissing)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GetEraValidatorsRequest {
state_hash: Digest,
protocol_version: ProtocolVersion,
}
impl GetEraValidatorsRequest {
pub fn new(state_hash: Digest, protocol_version: ProtocolVersion) -> Self {
GetEraValidatorsRequest {
state_hash,
protocol_version,
}
}
pub fn state_hash(&self) -> Digest {
self.state_hash
}
pub fn protocol_version(&self) -> ProtocolVersion {
self.protocol_version
}
}