diff --git a/Cargo.lock b/Cargo.lock index 463051df1..473d1e140 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4962,6 +4962,7 @@ dependencies = [ "lazy_static", "log", "num-traits", + "num_enum", "serde", "serde_json", "serde_tuple", diff --git a/Cargo.toml b/Cargo.toml index 63c00a2cb..9559999dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,6 +116,7 @@ multihash = { version = "0.18.1", default-features = false, features = [ num-bigint = "0.4" num-derive = "0.3" num-traits = "0.2" +num_enum = "0.7.2" paste = "1" pin-project = "1.1.2" prometheus = "0.13" diff --git a/ipc/api/Cargo.toml b/ipc/api/Cargo.toml index 4ba9a8f2a..011c8e99d 100644 --- a/ipc/api/Cargo.toml +++ b/ipc/api/Cargo.toml @@ -20,6 +20,7 @@ lazy_static = { workspace = true } log = { workspace = true } cid = { workspace = true } num-traits = { workspace = true } +num_enum = { workspace = true } serde = { workspace = true } serde_tuple = { workspace = true } strum = { workspace = true } diff --git a/ipc/api/src/staking.rs b/ipc/api/src/staking.rs index 70aeb68c6..e49f1e2ab 100644 --- a/ipc/api/src/staking.rs +++ b/ipc/api/src/staking.rs @@ -12,21 +12,14 @@ use std::fmt::{Display, Formatter}; pub type ConfigurationNumber = u64; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, num_enum::TryFromPrimitive)] +#[non_exhaustive] +#[repr(u8)] pub enum StakingOperation { - Deposit, - Withdraw, - SetMetadata, -} - -impl From for StakingOperation { - fn from(value: u8) -> Self { - match value { - 0 => Self::Deposit, - 1 => Self::Withdraw, - _ => Self::SetMetadata, - } - } + Deposit = 0, + Withdraw = 1, + SetMetadata = 2, + SetFederatedPower = 3, } #[derive(Clone, Debug)] @@ -52,7 +45,7 @@ impl TryFrom for StakingC Ok(Self { configuration_number: value.configuration_number, change: StakingChange { - op: StakingOperation::from(value.op), + op: StakingOperation::try_from(value.op)?, payload: value.payload.to_vec(), validator: ethers_address_to_fil_address(&value.validator)?, },