mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-27 01:25:43 +01:00
Mint_Info feilds as options
This commit is contained in:
@@ -64,4 +64,39 @@ pub mod serde_public_key {
|
||||
let decoded = hex::decode(encoded).map_err(serde::de::Error::custom)?;
|
||||
PublicKey::from_sec1_bytes(&decoded).map_err(serde::de::Error::custom)
|
||||
}
|
||||
|
||||
pub mod opt {
|
||||
use k256::PublicKey;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
pub fn serialize<S>(pubkey: &Option<PublicKey>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
match pubkey {
|
||||
Some(pubkey) => {
|
||||
let encoded = hex::encode(pubkey.to_sec1_bytes());
|
||||
serializer.serialize_str(&encoded)
|
||||
}
|
||||
None => serializer.serialize_none(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<PublicKey>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let option_str: Option<String> = Option::deserialize(deserializer)?;
|
||||
|
||||
match option_str {
|
||||
Some(encoded) => {
|
||||
let bytes = hex::decode(encoded).map_err(serde::de::Error::custom)?;
|
||||
let pubkey =
|
||||
PublicKey::from_sec1_bytes(&bytes).map_err(serde::de::Error::custom)?;
|
||||
Ok(Some(pubkey))
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
src/types.rs
14
src/types.rs
@@ -270,22 +270,22 @@ impl<'de> Deserialize<'de> for MintVersion {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct MintInfo {
|
||||
/// name of the mint and should be recognizable
|
||||
pub name: String,
|
||||
pub name: Option<String>,
|
||||
/// hex pubkey of the mint
|
||||
#[serde(with = "serde_utils::serde_public_key")]
|
||||
pub pubkey: PublicKey,
|
||||
#[serde(with = "serde_utils::serde_public_key::opt")]
|
||||
pub pubkey: Option<PublicKey>,
|
||||
/// implementation name and the version running
|
||||
pub version: MintVersion,
|
||||
pub version: Option<MintVersion>,
|
||||
/// short description of the mint
|
||||
pub description: String,
|
||||
pub description: Option<String>,
|
||||
/// long description
|
||||
pub description_long: String,
|
||||
pub description_long: Option<String>,
|
||||
/// contact methods to reach the mint operator
|
||||
pub contact: Vec<Vec<String>>,
|
||||
/// shows which NUTs the mint supports
|
||||
pub nuts: Vec<String>,
|
||||
/// message of the day that the wallet must display to the user
|
||||
pub motd: String,
|
||||
pub motd: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user