withdrawals_contract/
lib.rs

1pub use crate::error::Error;
2use num_enum::{IntoPrimitive, TryFromPrimitive};
3use platform_value::{Identifier, IdentifierBytes32};
4use platform_version::version::PlatformVersion;
5use serde_json::Value;
6use serde_repr::{Deserialize_repr, Serialize_repr};
7use std::fmt;
8
9mod error;
10pub mod v1;
11
12pub const ID_BYTES: [u8; 32] = [
13    54, 98, 187, 97, 225, 127, 174, 62, 162, 148, 207, 96, 49, 151, 251, 10, 171, 109, 81, 24, 11,
14    216, 182, 16, 76, 73, 68, 166, 47, 226, 217, 127,
15];
16
17pub const OWNER_ID_BYTES: [u8; 32] = [0; 32];
18
19pub const ID: Identifier = Identifier(IdentifierBytes32(ID_BYTES));
20pub const OWNER_ID: Identifier = Identifier(IdentifierBytes32(OWNER_ID_BYTES));
21
22// @append_only
23#[repr(u8)]
24#[derive(
25    Serialize_repr,
26    Deserialize_repr,
27    PartialEq,
28    Eq,
29    Clone,
30    Copy,
31    Debug,
32    TryFromPrimitive,
33    IntoPrimitive,
34)]
35pub enum WithdrawalStatus {
36    /// The documents are in the state and waiting to be processed.
37    QUEUED = 0,
38    /// Pooled happens when we are waiting for signing.
39    POOLED = 1,
40    /// We have broadcasted the transaction to core.
41    BROADCASTED = 2,
42    /// The transaction is now complete.
43    COMPLETE = 3,
44    /// We broadcasted the transaction but core never saw it or rejected it.
45    EXPIRED = 4,
46}
47
48impl fmt::Display for WithdrawalStatus {
49    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50        let status_str = match self {
51            WithdrawalStatus::QUEUED => "Queued",
52            WithdrawalStatus::POOLED => "Pooled",
53            WithdrawalStatus::BROADCASTED => "Broadcasted",
54            WithdrawalStatus::COMPLETE => "Complete",
55            WithdrawalStatus::EXPIRED => "Expired",
56        };
57        write!(f, "{}", status_str)
58    }
59}
60
61pub fn load_definitions(platform_version: &PlatformVersion) -> Result<Option<Value>, Error> {
62    match platform_version.system_data_contracts.withdrawals {
63        1 => Ok(None),
64        version => Err(Error::UnknownVersionMismatch {
65            method: "withdrawals_contract::load_definitions".to_string(),
66            known_versions: vec![1],
67            received: version,
68        }),
69    }
70}
71pub fn load_documents_schemas(platform_version: &PlatformVersion) -> Result<Value, Error> {
72    match platform_version.system_data_contracts.withdrawals {
73        1 => v1::load_documents_schemas(),
74        version => Err(Error::UnknownVersionMismatch {
75            method: "withdrawals_contract::load_documents_schemas".to_string(),
76            known_versions: vec![1],
77            received: version,
78        }),
79    }
80}