use casper_types::{
execution::Effects, system::auction::Error as AuctionError, BlockTime, Digest, ProtocolVersion,
};
use thiserror::Error;
use crate::{
system::{runtime_native::Config, transfer::TransferError},
tracking_copy::TrackingCopyError,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ForcedUndelegateRequest {
config: Config,
state_hash: Digest,
protocol_version: ProtocolVersion,
block_time: BlockTime,
}
impl ForcedUndelegateRequest {
pub fn new(
config: Config,
state_hash: Digest,
protocol_version: ProtocolVersion,
block_time: BlockTime,
) -> Self {
Self {
config,
state_hash,
protocol_version,
block_time,
}
}
pub fn config(&self) -> &Config {
&self.config
}
pub fn state_hash(&self) -> Digest {
self.state_hash
}
pub fn protocol_version(&self) -> ProtocolVersion {
self.protocol_version
}
pub fn block_time(&self) -> BlockTime {
self.block_time
}
}
#[derive(Clone, Error, Debug)]
pub enum ForcedUndelegateError {
#[error(transparent)]
TrackingCopy(TrackingCopyError),
#[error("Registry entry not found: {0}")]
RegistryEntryNotFound(String),
#[error(transparent)]
Transfer(TransferError),
#[error("Auction error: {0}")]
Auction(AuctionError),
}
#[derive(Debug, Clone)]
pub enum ForcedUndelegateResult {
RootNotFound,
Failure(ForcedUndelegateError),
Success {
post_state_hash: Digest,
effects: Effects,
},
}
impl ForcedUndelegateResult {
pub fn is_success(&self) -> bool {
matches!(self, Self::Success { .. })
}
}