zebra_rpc/methods/types/
z_validate_address.rs
1use zebra_chain::primitives::Address;
4
5#[derive(Clone, Default, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
7pub struct Response {
8 #[serde(rename = "isvalid")]
12 pub is_valid: bool,
13
14 #[serde(skip_serializing_if = "Option::is_none")]
16 pub address: Option<String>,
17
18 #[serde(skip_serializing_if = "Option::is_none")]
20 pub address_type: Option<AddressType>,
21
22 #[serde(rename = "ismine")]
26 #[serde(skip_serializing_if = "Option::is_none")]
27 pub is_mine: Option<bool>,
28}
29
30impl Response {
31 pub fn invalid() -> Self {
33 Self::default()
34 }
35}
36
37#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq)]
40#[serde(rename_all = "lowercase")]
41pub enum AddressType {
42 P2pkh,
44 P2sh,
46 Sapling,
48 Unified,
50}
51
52impl From<&Address> for AddressType {
53 fn from(address: &Address) -> Self {
54 match address {
55 Address::Transparent(_) => {
56 if address.is_script_hash() {
57 Self::P2sh
58 } else {
59 Self::P2pkh
60 }
61 }
62 Address::Sapling { .. } => Self::Sapling,
63 Address::Unified { .. } => Self::Unified,
64 }
65 }
66}