Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dumptxoutset #359

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,16 @@ pub trait RpcApi: Sized {
fn get_zmq_notifications(&self) -> Result<Vec<json::GetZmqNotificationsResult>> {
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<json::DumpTxOutSetResult> {
self.call("dumptxoutset", &[path.into()])
}
}

/// Client implements a JSON-RPC client for the Bitcoin Core daemon or compatible APIs.
Expand Down
8 changes: 8 additions & 0 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
extern crate lazy_static;

use std::collections::HashMap;
use std::path::PathBuf;
use std::str::FromStr;

use bitcoin::absolute::LockTime;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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());
}
18 changes: 18 additions & 0 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down