casper_storage/data_access_layer/
forced_undelegate.rs

1use 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/// Forced undelegate request.
12#[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    /// Ctor.
22    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    /// Returns config.
37    pub fn config(&self) -> &Config {
38        &self.config
39    }
40
41    /// Returns state_hash.
42    pub fn state_hash(&self) -> Digest {
43        self.state_hash
44    }
45
46    /// Returns protocol_version.
47    pub fn protocol_version(&self) -> ProtocolVersion {
48        self.protocol_version
49    }
50
51    /// Returns block time.
52    pub fn block_time(&self) -> BlockTime {
53        self.block_time
54    }
55}
56
57/// Forced undelegation error.
58#[derive(Clone, Error, Debug)]
59pub enum ForcedUndelegateError {
60    /// Tracking copy error.
61    #[error(transparent)]
62    TrackingCopy(TrackingCopyError),
63    /// Registry entry not found error.
64    #[error("Registry entry not found: {0}")]
65    RegistryEntryNotFound(String),
66    /// Transfer error.
67    #[error(transparent)]
68    Transfer(TransferError),
69    /// Auction error.
70    #[error("Auction error: {0}")]
71    Auction(AuctionError),
72}
73
74/// Forced undelegation result.
75#[derive(Debug, Clone)]
76pub enum ForcedUndelegateResult {
77    /// Root hash not found in global state.
78    RootNotFound,
79    /// Forced undelegation failed.
80    Failure(ForcedUndelegateError),
81    /// Forced undelegation succeeded.
82    Success {
83        /// State hash after distribution outcome is committed to the global state.
84        post_state_hash: Digest,
85        /// Effects of the distribution process.
86        effects: Effects,
87    },
88}
89
90impl ForcedUndelegateResult {
91    /// Returns true if successful, else false.
92    pub fn is_success(&self) -> bool {
93        matches!(self, Self::Success { .. })
94    }
95}