Skip to main content

blockchain_client/
types.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum Chain {
5    Bitcoin,
6    Litecoin,
7}
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
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: Option<String>,
22    pub label: Option<String>,
23    #[serde(rename = "scriptPubKey")]
24    pub script_pub_key: String,
25    pub amount: f64,
26    pub confirmations: u64,
27    pub spendable: bool,
28    pub solvable: bool,
29    pub descriptor: Option<String>,
30    pub safe: bool,
31}
32
33#[derive(Debug, Serialize, Deserialize)]
34pub struct TransactionListItem {
35    pub txid: String,
36    pub address: Option<String>,
37    pub category: String,
38    pub amount: f64,
39    pub label: Option<String>,
40    pub vout: Option<u32>,
41    pub confirmations: i64,
42    pub blockhash: Option<String>,
43    pub blockindex: Option<u64>,
44    pub blocktime: Option<u64>,
45    pub time: u64,
46    pub timereceived: u64,
47    pub comment: Option<String>,
48    pub otheraccount: Option<String>,
49    pub fee: Option<f64>,
50}
51
52#[derive(Debug, Serialize, Deserialize)]
53pub struct ReceivedByAddress {
54    pub address: String,
55    pub amount: f64,
56    pub confirmations: u64,
57    pub label: Option<String>,
58    #[serde(default)]
59    pub txids: Vec<String>,
60}
61
62#[derive(Debug, Serialize, Deserialize)]
63pub struct ScriptSig {
64    pub asm: String,
65    pub hex: String,
66}
67
68#[derive(Debug, Serialize, Deserialize)]
69pub struct ScriptPubKey {
70    pub asm: Option<String>,
71    pub hex: Option<String>,
72    #[serde(rename = "reqSigs")]
73    pub req_sigs: Option<u32>,
74    #[serde(rename = "type")]
75    pub type_field: Option<String>,
76    #[serde(default)]
77    pub addresses: Vec<String>,
78}
79
80#[derive(Debug, Serialize, Deserialize)]
81pub struct TxInput {
82    pub txid: Option<String>,
83    pub vout: Option<u32>,
84    #[serde(rename = "scriptSig")]
85    pub script_sig: Option<ScriptSig>,
86    pub sequence: Option<u64>,
87    pub coinbase: Option<String>,
88}
89
90#[derive(Debug, Serialize, Deserialize)]
91pub struct TxOutput {
92    pub value: f64,
93    pub n: u32,
94    #[serde(rename = "scriptPubKey")]
95    pub script_pub_key: ScriptPubKey,
96}
97
98#[derive(Debug, Serialize, Deserialize)]
99pub struct RawTransaction {
100    pub txid: String,
101    pub hash: Option<String>,
102    pub version: Option<i32>,
103    pub size: Option<u64>,
104    pub vsize: Option<u64>,
105    pub weight: Option<u64>,
106    pub locktime: Option<u64>,
107    #[serde(default)]
108    pub vin: Vec<TxInput>,
109    #[serde(default)]
110    pub vout: Vec<TxOutput>,
111}
112
113#[derive(Debug, Serialize, Deserialize)]
114pub struct BlockchainInfo {
115    pub chain: String,
116    pub blocks: u64,
117    pub headers: u64,
118    pub bestblockhash: String,
119    pub difficulty: f64,
120    pub mediantime: Option<u64>,
121    pub verificationprogress: Option<f64>,
122    pub initialblockdownload: Option<bool>,
123    pub size_on_disk: Option<u64>,
124    pub pruned: Option<bool>,
125}
126
127#[derive(Debug, Serialize, Deserialize)]
128pub struct AddressValidation {
129    pub isvalid: bool,
130    pub address: Option<String>,
131    #[serde(rename = "scriptPubKey")]
132    pub script_pub_key: Option<String>,
133    pub isscript: Option<bool>,
134    pub iswitness: Option<bool>,
135    #[serde(rename = "witness_version")]
136    pub witness_version: Option<u32>,
137    #[serde(rename = "witness_program")]
138    pub witness_program: Option<String>,
139    pub account: Option<String>,
140    pub hdkeypath: Option<String>,
141    pub ismine: Option<bool>,
142    pub iswatchonly: Option<bool>,
143}