casper_storage/data_access_layer/
forced_undelegate.rs1use casper_types::{
2 execution::Effects, system::auction::Error as AuctionError, BlockTime, Digest, ProtocolVersion,
3};
4use thiserror::Error;
5
6use crate::{
7 system::{runtime_native::Config, transfer::TransferError},
8 tracking_copy::TrackingCopyError,
9};
10
11#[derive(Debug, Clone, PartialEq, Eq)]
13pub struct ForcedUndelegateRequest {
14 config: Config,
15 state_hash: Digest,
16 protocol_version: ProtocolVersion,
17 block_time: BlockTime,
18}
19
20impl ForcedUndelegateRequest {
21 pub fn new(
23 config: Config,
24 state_hash: Digest,
25 protocol_version: ProtocolVersion,
26 block_time: BlockTime,
27 ) -> Self {
28 Self {
29 config,
30 state_hash,
31 protocol_version,
32 block_time,
33 }
34 }
35
36 pub fn config(&self) -> &Config {
38 &self.config
39 }
40
41 pub fn state_hash(&self) -> Digest {
43 self.state_hash
44 }
45
46 pub fn protocol_version(&self) -> ProtocolVersion {
48 self.protocol_version
49 }
50
51 pub fn block_time(&self) -> BlockTime {
53 self.block_time
54 }
55}
56
57#[derive(Clone, Error, Debug)]
59pub enum ForcedUndelegateError {
60 #[error(transparent)]
62 TrackingCopy(TrackingCopyError),
63 #[error("Registry entry not found: {0}")]
65 RegistryEntryNotFound(String),
66 #[error(transparent)]
68 Transfer(TransferError),
69 #[error("Auction error: {0}")]
71 Auction(AuctionError),
72}
73
74#[derive(Debug, Clone)]
76pub enum ForcedUndelegateResult {
77 RootNotFound,
79 Failure(ForcedUndelegateError),
81 Success {
83 post_state_hash: Digest,
85 effects: Effects,
87 },
88}
89
90impl ForcedUndelegateResult {
91 pub fn is_success(&self) -> bool {
93 matches!(self, Self::Success { .. })
94 }
95}