Commit db0d007e authored by kenshin-samourai's avatar kenshin-samourai
Browse files

Merge branch 'feat_reactivate_endpoints' into 'develop_dojo'

reactivate api endpoints

See merge request dojo/addrindexrs!7
parents 745d51ee 97a9e0fb
...@@ -342,6 +342,11 @@ impl Index { ...@@ -342,6 +342,11 @@ impl Index {
*headers = read_indexed_headers(store); *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> { pub fn get_header(&self, height: usize) -> Option<HeaderEntry> {
self.headers self.headers
.read() .read()
......
...@@ -7,7 +7,7 @@ use crate::errors::*; ...@@ -7,7 +7,7 @@ use crate::errors::*;
use crate::index::{TxInRow, TxOutRow, TxRow}; use crate::index::{TxInRow, TxOutRow, TxRow};
use crate::mempool::Tracker; use crate::mempool::Tracker;
use crate::store::ReadStore; use crate::store::ReadStore;
use crate::util::HashPrefix; use crate::util::{HashPrefix, HeaderEntry};
// //
// Output of a Transaction // Output of a Transaction
...@@ -246,6 +246,11 @@ impl Query { ...@@ -246,6 +246,11 @@ impl Query {
Ok(Status { confirmed, mempool }) 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<()> { pub fn update_mempool(&self) -> Result<()> {
self.tracker.write().unwrap().update(self.app.daemon()) self.tracker.write().unwrap().update(self.app.daemon())
} }
......
use bitcoin::consensus::encode::serialize;
use bitcoin_hashes::hex::{FromHex, ToHex}; use bitcoin_hashes::hex::{FromHex, ToHex};
use bitcoin_hashes::sha256d::Hash as Sha256dHash; use bitcoin_hashes::sha256d::Hash as Sha256dHash;
use error_chain::ChainedError; use error_chain::ChainedError;
...@@ -60,6 +61,19 @@ impl Connection { ...@@ -60,6 +61,19 @@ 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 }),
)
}
fn blockchain_scripthash_get_history(&self, params: &[Value]) -> Result<Value> { fn blockchain_scripthash_get_history(&self, params: &[Value]) -> Result<Value> {
let script_hash = hash_from_value(params.get(0)).chain_err(|| "bad script_hash")?; let script_hash = hash_from_value(params.get(0)).chain_err(|| "bad script_hash")?;
let status = self.query.status(&script_hash[..])?; let status = self.query.status(&script_hash[..])?;
...@@ -74,6 +88,8 @@ impl Connection { ...@@ -74,6 +88,8 @@ impl Connection {
fn handle_command(&mut self, method: &str, params: &[Value], id: &Value) -> Result<Value> { fn handle_command(&mut self, method: &str, params: &[Value], id: &Value) -> Result<Value> {
let result = match method { 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), "blockchain.scripthash.get_history" => self.blockchain_scripthash_get_history(&params),
"server.ping" => Ok(Value::Null), "server.ping" => Ok(Value::Null),
"server.version" => self.server_version(), "server.version" => self.server_version(),
......
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