From 7cf8a79869aa4f1b5d848d1ef1bc8e5270c6bd10 Mon Sep 17 00:00:00 2001 From: NTL-68 Date: Tue, 4 Jun 2024 09:29:42 +0330 Subject: [PATCH 1/3] added DumpTxOutResult --- json/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/json/src/lib.rs b/json/src/lib.rs index 25f3508e..c57b6ea8 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -2160,6 +2160,24 @@ pub struct GetZmqNotificationsResult { pub hwm: u64, } +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] +pub struct DumpTxOutSetResult { + /// The number of coins written in the snapshot + pub coins_written: u64, + /// The hash of the base of the snapshot + pub base_hash: bitcoin::BlockHash, + /// The height of the base of the snapshot + pub base_height: u64, + /// The absolute path that the snapshot was written to + pub path: String, + /// The hash of the UTXO set contents + #[serde(rename = "txoutset_hash")] + pub tx_out_set_hash: sha256::Hash, + /// The number of transactions in the chain up to and including the base block + #[serde(rename = "nchaintx")] + pub number_chain_tx: u64, +} + impl<'a> serde::Serialize for PubKeyOrAddress<'a> { fn serialize(&self, serializer: S) -> Result where From c8ab32ebeafcd6cfefd472aa7e786a34f7ab66a4 Mon Sep 17 00:00:00 2001 From: NTL-68 Date: Tue, 4 Jun 2024 09:31:50 +0330 Subject: [PATCH 2/3] added dump_tx_out_set --- client/src/client.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/client/src/client.rs b/client/src/client.rs index 2f809a79..98dee0bd 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1267,6 +1267,16 @@ pub trait RpcApi: Sized { fn get_zmq_notifications(&self) -> Result> { self.call("getzmqnotifications", &[]) } + + /// Write the serialized UTXO set to a file. + /// If used to dump the UTXO set of the mainnet, make sure you create a client through + /// bitcoincore_rpc::jsonrpc::simple_http::Builder, so that the timeout can be set to a + /// higher level compared to the default value. Since it takes a considerable time for + /// bitcoincore to dump the UTXO set, if bitcoincore_rpc::Client::new is used, you will + /// encounter a timeout error. + fn dump_tx_out_set(&self, path: &str) -> Result { + self.call("dumptxoutset", &[path.into()]) + } } /// Client implements a JSON-RPC client for the Bitcoin Core daemon or compatible APIs. From 478b9872bcc60620f1e053569ec2143a910e2737 Mon Sep 17 00:00:00 2001 From: NTL-68 Date: Tue, 4 Jun 2024 09:53:06 +0330 Subject: [PATCH 3/3] added test_dump_tx_out_set --- integration_test/src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index c3236bb9..70ba3f7d 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -14,6 +14,7 @@ extern crate lazy_static; use std::collections::HashMap; +use std::path::PathBuf; use std::str::FromStr; use bitcoin::absolute::LockTime; @@ -227,6 +228,7 @@ fn main() { test_set_network_active(&cl); test_get_index_info(&cl); test_get_zmq_notifications(&cl); + test_dump_tx_out_set(&cl); test_stop(cl); } @@ -1459,6 +1461,12 @@ fn test_get_zmq_notifications(cl: &Client) { ); } +fn test_dump_tx_out_set(cl: &Client) { + let dump_file_path = format!("{}/utxo_dump.dat", get_testdir()); + let _dump_result = cl.dump_tx_out_set(&dump_file_path).unwrap(); + assert!(PathBuf::from_str(&dump_file_path).unwrap().exists()) +} + fn test_stop(cl: Client) { println!("Stopping: '{}'", cl.stop().unwrap()); }