utxo_scanner/
utxo.rs

1#[derive(Debug, Clone)]
2pub enum AddressType {
3    NonStandard,
4    P2pkh,
5    P2sh,
6    Bech32
7}
8
9#[derive(Clone, Debug)]
10pub struct Utxo {
11    pub txid: String,
12    pub vout: usize,
13    pub coinbase: u64,
14    pub height: u64,
15    pub amount: u64,
16    pub address: String,
17    pub address_type: AddressType,
18    pub sigscript: String,
19}
20
21impl Utxo {
22    pub fn new(
23        txid: String,
24        vout: usize,
25        coinbase: u64,
26        height: u64,
27        amount: u64,
28        address_type: AddressType,
29        address: String,
30        sigscript: String,
31    ) -> Self {
32        Self {
33            txid,
34            vout,
35            coinbase,
36            height,
37            amount,
38            address_type,
39            address,
40            sigscript,
41        }
42    }
43
44    pub fn get_rocksdb_line(&self) -> String {
45        let line = vec![
46            format!("{}", self.txid),
47            format!("{}", self.vout),
48            format!("{}", self.amount),
49            format!("{}", self.address),
50            format!("{}", self.sigscript),
51            format!("{}", self.height),
52            format!("{}", self.coinbase),
53        ]
54        .join(",");
55
56        line
57    }
58
59    pub fn get_csv_line(&self) -> String {
60        let line = vec![
61            format!("{}", self.txid),
62            format!("{}", self.vout),
63            format!("{}", self.amount),
64            format!("{}", self.address),
65            format!("{}", self.height),
66            format!("{}", self.coinbase),
67            format!("{}", self.sigscript),
68        ]
69        .join(",");
70
71    format!("{}\n", line)
72    }
73}