mirror of
https://github.com/romanz/electrs.git
synced 2025-02-25 07:17:41 +01:00
Retrieve blockchain state before opening the DB
This would make sure that bitcoind is up and running.
This commit is contained in:
parent
50941e7bea
commit
67ece2dd49
2 changed files with 17 additions and 1 deletions
|
@ -101,6 +101,7 @@ impl App {
|
||||||
fn run_server(config: &Config) -> Result<()> {
|
fn run_server(config: &Config) -> Result<()> {
|
||||||
let index = index::Index::new();
|
let index = index::Index::new();
|
||||||
let daemon = daemon::Daemon::new(config.network_type)?;
|
let daemon = daemon::Daemon::new(config.network_type)?;
|
||||||
|
debug!("{:?}", daemon.getblockchaininfo()?);
|
||||||
|
|
||||||
let store = store::DBStore::open(
|
let store = store::DBStore::open(
|
||||||
config.db_path,
|
config.db_path,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use bitcoin::network::serialize::BitcoinHash;
|
||||||
use bitcoin::network::serialize::{deserialize, serialize};
|
use bitcoin::network::serialize::{deserialize, serialize};
|
||||||
use bitcoin::util::hash::Sha256dHash;
|
use bitcoin::util::hash::Sha256dHash;
|
||||||
use hex;
|
use hex;
|
||||||
use serde_json::{from_str, Value};
|
use serde_json::{from_str, from_value, Value};
|
||||||
use std::env::home_dir;
|
use std::env::home_dir;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{BufRead, BufReader, Write};
|
use std::io::{BufRead, BufReader, Write};
|
||||||
|
@ -49,6 +49,16 @@ pub struct MempoolEntry {
|
||||||
fee_per_vbyte: f32,
|
fee_per_vbyte: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct BlockchainInfo {
|
||||||
|
chain: String,
|
||||||
|
blocks: usize,
|
||||||
|
headers: usize,
|
||||||
|
bestblockhash: String,
|
||||||
|
size_on_disk: usize,
|
||||||
|
pruned: bool,
|
||||||
|
}
|
||||||
|
|
||||||
impl MempoolEntry {
|
impl MempoolEntry {
|
||||||
fn new(fee: u64, vsize: u32) -> MempoolEntry {
|
fn new(fee: u64, vsize: u32) -> MempoolEntry {
|
||||||
MempoolEntry {
|
MempoolEntry {
|
||||||
|
@ -144,6 +154,11 @@ impl Daemon {
|
||||||
|
|
||||||
// bitcoind JSONRPC API:
|
// bitcoind JSONRPC API:
|
||||||
|
|
||||||
|
pub fn getblockchaininfo(&self) -> Result<BlockchainInfo> {
|
||||||
|
let info: Value = self.request("getblockchaininfo", json!([]))?;
|
||||||
|
Ok(from_value(info).chain_err(|| "invalid blockchain info")?)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn getbestblockhash(&self) -> Result<Sha256dHash> {
|
pub fn getbestblockhash(&self) -> Result<Sha256dHash> {
|
||||||
parse_hash(&self.request("getbestblockhash", json!([]))?).chain_err(|| "invalid blockhash")
|
parse_hash(&self.request("getbestblockhash", json!([]))?).chain_err(|| "invalid blockhash")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue