|
1 | 1 | mod bitcoin_primitives; |
2 | 2 | mod bitcoin_serialization; |
| 3 | +mod utils; |
3 | 4 |
|
4 | 5 | mod cli; |
5 | 6 |
|
6 | 7 | use anyhow::{Context, Result}; |
7 | 8 | use bitcoin::hashes::Hash; |
8 | 9 | use clap::Parser; |
9 | 10 | use rocksdb::{DB, IteratorMode, Options}; |
10 | | -use std::{ |
11 | | - fs::File, |
12 | | - io::{BufReader, BufWriter}, |
13 | | -}; |
14 | 11 |
|
15 | 12 | use bitcoin::hashes::sha256; |
16 | 13 |
|
17 | 14 | use crate::{ |
18 | 15 | bitcoin_primitives::{CoinKey, CoinValue}, |
19 | 16 | bitcoin_serialization::deobfuscate, |
| 17 | + utils::{P2PKH_UTXO_SIZE, load_utxos, save_utxos}, |
20 | 18 | }; |
21 | 19 |
|
22 | 20 | const OBFUSCATION_KEY_DB_KEY: &[u8] = b"\x0e\x00obfuscate_key"; |
23 | | -const P2PKH_UTXO_SIZE: usize = 8 + 25; // 8 bytes for amount, 25 bytes for P2PKH scriptPubKey |
24 | 21 |
|
25 | 22 | fn main() -> Result<()> { |
26 | 23 | let cli = cli::Cli::parse(); |
@@ -120,17 +117,3 @@ fn run_build_merkle_root(utxo_index_path: &str) -> Result<()> { |
120 | 117 |
|
121 | 118 | Ok(()) |
122 | 119 | } |
123 | | - |
124 | | -fn save_utxos(utxos: &Vec<[u8; P2PKH_UTXO_SIZE]>, path: &str) -> Result<()> { |
125 | | - let file = File::create(path)?; |
126 | | - let mut writer = BufWriter::new(file); |
127 | | - bincode::encode_into_std_write(utxos, &mut writer, bincode::config::standard())?; |
128 | | - Ok(()) |
129 | | -} |
130 | | - |
131 | | -fn load_utxos(path: &str) -> Result<Vec<[u8; P2PKH_UTXO_SIZE]>> { |
132 | | - let file = File::open(path)?; |
133 | | - let mut reader = BufReader::new(file); |
134 | | - let utxos = bincode::decode_from_std_read(&mut reader, bincode::config::standard())?; |
135 | | - Ok(utxos) |
136 | | -} |
0 commit comments