use crate::primitives::{KeyHash, ScriptHash};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct Address(pub String);
impl Address {
#[inline]
pub fn new(b32: impl Into<String>) -> Self { Self(b32.into()) }
#[inline]
pub fn as_str(&self) -> &str { &self.0 }
}
impl From<String> for Address {
fn from(s: String) -> Self { Self(s) }
}
impl From<&str> for Address {
fn from(s: &str) -> Self { Self(s.to_string()) }
}
impl std::fmt::Display for Address {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct RewardAddress(pub String);
impl RewardAddress {
#[inline]
pub fn new(b32: impl Into<String>) -> Self { Self(b32.into()) }
#[inline]
pub fn as_str(&self) -> &str { &self.0 }
}
impl From<String> for RewardAddress {
fn from(s: String) -> Self { Self(s) }
}
impl From<&str> for RewardAddress {
fn from(s: &str) -> Self { Self(s.to_string()) }
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum Credential {
KeyHash {
#[serde(rename = "keyHash")]
key_hash: KeyHash,
},
ScriptHash {
#[serde(rename = "scriptHash")]
script_hash: ScriptHash,
},
}
impl Credential {
pub fn key(h: impl Into<KeyHash>) -> Self {
Self::KeyHash { key_hash: h.into() }
}
pub fn script(h: impl Into<ScriptHash>) -> Self {
Self::ScriptHash { script_hash: h.into() }
}
}