Skip to main content

vrsc_rpc_json/
identity.rs

1use std::{collections::HashMap, str::FromStr};
2
3use bitcoin::{
4    hashes::{ripemd160::Hash as hash160, sha256::Hash as hash256},
5    BlockHash, Txid,
6};
7use serde::de::{Deserialize, Deserializer};
8use vrsc::Address;
9
10#[derive(Clone, Debug, Deserialize, Serialize)]
11pub struct IdentityHistory {
12    pub fullyqualifiedname: String,
13    pub status: String,
14    pub canspendfor: bool,
15    pub cansignfor: bool,
16    pub blockheight: i64,
17    pub txid: Txid, // TODO hash
18    pub vout: u32,
19    pub history: Vec<IdentityHistoryObject>,
20}
21
22#[derive(Clone, Debug, Deserialize, Serialize)]
23pub struct IdentityHistoryObject {
24    pub identity: IdentityPrimary,
25    pub blockhash: BlockHash,
26    pub height: u64,
27    pub output: InnerIdentityTxOut,
28}
29
30#[derive(Clone, Debug, Deserialize, Serialize)]
31pub struct Identity {
32    pub fullyqualifiedname: String,
33    pub identity: IdentityPrimary,
34    pub status: String,
35    pub canspendfor: bool,
36    pub cansignfor: bool,
37    pub blockheight: i64,
38    pub txid: Txid, // TODO hash
39    pub vout: u32,
40}
41
42#[derive(Clone, Debug, Deserialize, Serialize)]
43pub struct IdentityPrimary {
44    pub version: u16,
45    pub flags: u16,
46    pub primaryaddresses: Vec<Address>,
47    pub minimumsignatures: u16,
48    pub name: String,
49    pub identityaddress: Address,
50    pub parent: Address,
51    pub systemid: Address,
52    pub contentmap: serde_json::Value,
53    pub revocationauthority: Address,
54    pub recoveryauthority: Address,
55    pub privateaddress: Option<String>,
56    pub timelock: u64,
57    pub txout: Option<InnerIdentityTxOut>,
58}
59
60#[derive(Clone, Debug, Deserialize, Serialize)]
61pub struct InnerIdentityTxOut {
62    pub txid: Txid,
63    pub voutnum: u16,
64}
65
66#[derive(Clone, Debug, Deserialize, Serialize)]
67pub struct NameCommitment {
68    pub txid: Txid,
69    pub namereservation: NameReservation,
70}
71
72#[derive(Clone, Debug, Deserialize, Serialize)]
73pub struct NameReservation {
74    pub name: String,
75    pub salt: String,
76    pub version: u8,
77    // if no refferal was given, the response is an empty string.
78    #[serde(deserialize_with = "object_empty_as_none")]
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub referral: Option<Address>,
81    pub parent: String,
82    pub nameid: Address,
83}
84
85pub fn object_empty_as_none<'de, D>(deserializer: D) -> Result<Option<Address>, D::Error>
86where
87    D: Deserializer<'de>,
88{
89    let s = String::deserialize(deserializer)?;
90    if s.is_empty() {
91        return Ok(None);
92    } else {
93        return Ok(Some(
94            Address::from_str(&s).expect("a valid Verus i, b, or R address"),
95        ));
96    }
97}
98
99#[derive(Clone, Debug, Deserialize, Serialize)]
100pub struct MarketplaceOffer {
101    pub identityid: Address,
102    pub price: f64,
103    pub offer: Offer,
104}
105
106#[derive(Clone, Debug, Deserialize, Serialize)]
107pub struct Offer {
108    pub accept: OfferVariant,
109    pub offer: OfferVariant,
110    pub blockexpiry: u64,
111    pub txid: Txid,
112}
113
114#[derive(Clone, Debug, Deserialize, Serialize)]
115#[serde(untagged)]
116pub enum OfferVariant {
117    CurrencyOffer(HashMap<String, f64>),
118    IdentityOffer(IdentityPrimary),
119}
120
121#[derive(Clone, Debug, Deserialize, Serialize)]
122pub struct IdentityOffer {
123    pub name: String,
124    pub identityid: Address,
125    pub systemid: Address,
126    pub original: u8,
127}
128
129// #[derive(Clone, Debug, Deserialize, Serialize)]
130pub type IdentitiesWithAddressResult = Vec<IdentityPrimary>;
131
132#[derive(Clone, Debug, Deserialize, Serialize)]
133pub struct GetVDXFIdResult {
134    pub vdxfid: Address,
135    pub hash160result: hash160,
136    pub qualifiedname: Option<QualifiedName>,
137    pub bounddata: Option<BoundData>,
138}
139
140#[derive(Clone, Debug, Deserialize, Serialize)]
141pub struct QualifiedName {
142    pub name: String,
143    pub parentid: Option<String>,
144    pub namespace: Option<String>,
145}
146
147#[derive(Clone, Debug, Deserialize, Serialize)]
148pub struct BoundData {
149    pub vdxfkey: Address,
150    pub uint256: hash256,
151    pub indexnum: u32,
152}