Commit 97a9e0fb authored by kenshin-samourai's avatar kenshin-samourai
Browse files

reactivate headers.subscribe endpoint

parent c8e19c1d
......@@ -342,6 +342,11 @@ impl Index {
*headers = read_indexed_headers(store);
}
pub fn best_header(&self) -> Option<HeaderEntry> {
let headers = self.headers.read().unwrap();
headers.header_by_blockhash(&headers.tip()).cloned()
}
pub fn get_header(&self, height: usize) -> Option<HeaderEntry> {
self.headers
.read()
......
......@@ -7,7 +7,7 @@ use crate::errors::*;
use crate::index::{TxInRow, TxOutRow, TxRow};
use crate::mempool::Tracker;
use crate::store::ReadStore;
use crate::util::HashPrefix;
use crate::util::{HashPrefix, HeaderEntry};
//
// Output of a Transaction
......@@ -246,6 +246,11 @@ impl Query {
Ok(Status { confirmed, mempool })
}
pub fn get_best_header(&self) -> Result<HeaderEntry> {
let last_header = self.app.index().best_header();
Ok(last_header.chain_err(|| "no headers indexed")?)
}
pub fn update_mempool(&self) -> Result<()> {
self.tracker.write().unwrap().update(self.app.daemon())
}
......
use bitcoin::consensus::encode::serialize;
use bitcoin_hashes::hex::{FromHex, ToHex};
use bitcoin_hashes::sha256d::Hash as Sha256dHash;
use error_chain::ChainedError;
......@@ -60,6 +61,13 @@ impl Connection {
]))
}
fn blockchain_headers_subscribe(&mut self) -> Result<Value> {
let entry = self.query.get_best_header()?;
let hex_header = hex::encode(serialize(entry.header()));
let result = json!({"hex": hex_header, "height": entry.height()});
Ok(result)
}
fn blockchain_scripthash_get_balance(&self, _params: &[Value]) -> Result<Value> {
Ok(
json!({ "confirmed": null, "unconfirmed": null }),
......@@ -80,6 +88,7 @@ impl Connection {
fn handle_command(&mut self, method: &str, params: &[Value], id: &Value) -> Result<Value> {
let result = match method {
"blockchain.headers.subscribe" => self.blockchain_headers_subscribe(),
"blockchain.scripthash.get_balance" => self.blockchain_scripthash_get_balance(&params),
"blockchain.scripthash.get_history" => self.blockchain_scripthash_get_history(&params),
"server.ping" => Ok(Value::Null),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment