radiusxyz / cluster-manager

1 stars 0 forks source link

`sdk/signature`: Support `ChainType` deserialization from `String`. #138

Closed Kanet1105 closed 2 hours ago

Kanet1105 commented 2 hours ago

Describe the feature

Enable ChainType deserialization from snake case String.

Solution

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
#[serde(try_from = "String")]
pub enum ChainType {
    Ethereum,
}

impl TryFrom<String> for ChainType {
    type Error = SignatureError;

    fn try_from(value: String) -> Result<Self, Self::Error> {
        match value.as_str() {
            "ethereum" => Ok(Self::Ethereum),
            _others => Err(SignatureError::UnsupportedChainType(value)),
        }
    }
}
Kanet1105 commented 2 hours ago

closed by: d5dea4d83feade6651feeb19e190185e281caa66