Skip to main content

blockchain_client/
types.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4pub enum Chain {
5    Bitcoin,
6    Litecoin,
7}
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
10pub enum Network {
11    Mainnet,
12    Testnet,
13    Regtest,
14    Signet,
15}
16
17#[derive(Debug, Serialize, Deserialize)]
18pub struct Utxo {
19    pub txid: String,
20    pub vout: u32,
21    pub address: String,
22    pub label: String,
23    #[serde(rename = "scriptPubKey")]
24    pub script_pub_key: String,
25    pub amount: f64,
26    pub confirmations: u64,
27    #[serde(rename = "redeemScript")]
28    pub redeem_script: Option<String>,
29    #[serde(rename = "witnessScript")]
30    pub witness_script: Option<String>,
31    pub spendable: bool,
32    pub solvable: bool,
33    pub reused: Option<bool>,
34    #[serde(rename = "desc")]
35    pub descriptor: Option<String>,
36    pub safe: bool,
37}
38
39#[derive(Debug, Serialize, Deserialize)]
40pub struct TransactionListItem {
41    pub txid: String,
42    pub address: String,
43    pub category: String,
44    pub amount: f64,
45    pub label: String,
46    pub vout: u32,
47    pub fee: Option<f64>,
48    pub confirmations: i64,
49    pub generated: Option<bool>,
50    pub trusted: Option<bool>,
51    pub blockhash: String,
52    pub blockheight: u64,
53    pub blockindex: u64,
54    pub blocktime: u64,
55    pub time: u64,
56    pub timereceived: u64,
57    pub comment: Option<String>,
58    #[serde(rename = "bip125-replaceable")]
59    pub bip125_replaceable: String,
60    pub abandoned: Option<bool>,
61    #[serde(rename = "involvesWatchonly")]
62    pub involves_watchonly: Option<bool>,
63}
64
65#[derive(Debug, Serialize, Deserialize)]
66pub struct ReceivedByAddress {
67    pub address: String,
68    pub amount: f64,
69    pub confirmations: u64,
70    pub label: Option<String>,
71    #[serde(default)]
72    pub txids: Vec<String>,
73}
74
75#[derive(Debug, Serialize, Deserialize)]
76pub struct ScriptSig {
77    pub asm: String,
78    pub hex: String,
79}
80
81#[derive(Debug, Serialize, Deserialize)]
82pub struct ScriptPubKey {
83    pub asm: String,
84    pub hex: String,
85    #[serde(rename = "reqSigs")]
86    pub req_sigs: Option<u32>,
87    #[serde(rename = "type")]
88    pub type_field: String,
89    #[serde(default)]
90    pub addresses: Vec<String>,
91}
92
93#[derive(Debug, Serialize, Deserialize)]
94pub struct TxInput {
95    pub txid: Option<String>,
96    pub vout: Option<u32>,
97    #[serde(rename = "scriptSig")]
98    pub script_sig: Option<ScriptSig>,
99    pub sequence: u64,
100    pub coinbase: Option<String>,
101    #[serde(rename = "txinwitness")]
102    pub txin_witness: Option<Vec<String>>,
103}
104
105#[derive(Debug, Serialize, Deserialize)]
106pub struct TxOutput {
107    pub value: f64,
108    pub n: u32,
109    #[serde(rename = "scriptPubKey")]
110    pub script_pub_key: ScriptPubKey,
111}
112
113#[derive(Debug, Serialize, Deserialize)]
114pub struct RawTransaction {
115    pub txid: String,
116    pub hash: String,
117    pub version: i32,
118    pub size: u64,
119    pub vsize: u64,
120    pub weight: u64,
121    pub locktime: u64,
122
123    #[serde(default)]
124    pub vin: Vec<TxInput>,
125    #[serde(default)]
126    pub vout: Vec<TxOutput>,
127
128    pub in_active_chain: Option<bool>,
129    pub blockhash: Option<String>,
130    pub confirmations: Option<u64>,
131    pub blocktime: Option<u64>,
132    pub time: Option<u64>,
133}
134
135#[derive(Debug, Serialize, Deserialize)]
136pub struct BlockchainInfo {
137    pub chain: String,
138    pub blocks: u64,
139    pub headers: u64,
140    pub bestblockhash: String,
141    pub difficulty: f64,
142    pub mediantime: u64,
143    pub verificationprogress: f64,
144    pub initialblockdownload: bool,
145    pub chainwork: String,
146    pub size_on_disk: u64,
147    pub pruned: bool,
148
149    pub pruneheight: Option<u64>,
150    pub automatic_pruning: Option<bool>,
151    pub prune_target_size: Option<u64>,
152
153    pub softforks: serde_json::Value,
154    pub warnings: String,
155}
156
157#[derive(Debug, Serialize, Deserialize)]
158pub struct AddressValidation {
159    pub isvalid: bool,
160    pub address: Option<String>,
161    #[serde(rename = "scriptPubKey")]
162    pub script_pub_key: Option<String>,
163
164    pub isscript: Option<bool>,
165    pub iswitness: Option<bool>,
166    #[serde(rename = "witness_version")]
167    pub witness_version: Option<u32>,
168    #[serde(rename = "witness_program")]
169    pub witness_program: Option<String>,
170
171    pub ismine: Option<bool>,
172    pub iswatchonly: Option<bool>,
173    pub solvable: Option<bool>,
174    pub desc: Option<String>,
175    pub pubkey: Option<String>,
176    pub iscompressed: Option<bool>,
177    pub labels: Option<Vec<String>>,
178
179    pub hdkeypath: Option<String>,
180
181    pub error: Option<String>,
182    pub error_locations: Option<Vec<usize>>,
183}
184
185// implementations
186
187impl TransactionListItem {
188    pub fn is_send(&self) -> bool {
189        self.category == "send"
190    }
191}