zebra_rpc/methods/types/
z_validate_address.rs
1use derive_getters::Getters;
4use derive_new::new;
5use zebra_chain::primitives::Address;
6
7#[derive(
9 Clone, Default, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, Getters, new,
10)]
11pub struct ZValidateAddressResponse {
12 #[serde(rename = "isvalid")]
16 pub(crate) is_valid: bool,
17
18 #[serde(skip_serializing_if = "Option::is_none")]
20 pub(crate) address: Option<String>,
21
22 #[serde(skip_serializing_if = "Option::is_none")]
24 #[getter(copy)]
25 pub(crate) address_type: Option<ZValidateAddressType>,
26
27 #[serde(rename = "ismine")]
31 #[serde(skip_serializing_if = "Option::is_none")]
32 #[getter(copy)]
33 pub(crate) is_mine: Option<bool>,
34}
35
36impl ZValidateAddressResponse {
37 pub fn invalid() -> Self {
39 Self::default()
40 }
41}
42
43#[derive(Copy, Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq)]
46#[serde(rename_all = "lowercase")]
47pub enum ZValidateAddressType {
48 P2pkh,
50 P2sh,
52 Sapling,
54 Unified,
56}
57
58impl From<&Address> for ZValidateAddressType {
59 fn from(address: &Address) -> Self {
60 match address {
61 Address::Transparent(_) => {
62 if address.is_script_hash() {
63 Self::P2sh
64 } else {
65 Self::P2pkh
66 }
67 }
68 Address::Sapling { .. } => Self::Sapling,
69 Address::Unified { .. } => Self::Unified,
70 }
71 }
72}