Commit 182b4468 authored by Chiguireitor's avatar Chiguireitor
Browse files

Merge branch 'master' of code.samourai.io:dojo/addrindexrs

parents 76700cc5 ade631cd
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]] [[package]]
name = "addrindexrs" name = "addrindexrs"
version = "0.3.0" version = "0.4.0"
dependencies = [ dependencies = [
"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
......
[package] [package]
name = "addrindexrs" name = "addrindexrs"
version = "0.3.0" version = "0.4.0"
authors = ["Roman Zeyde <me@romanzey.de>", "kenshin-samourai <kenshin_samourai@tutanota.com>"] authors = ["Roman Zeyde <me@romanzey.de>", "kenshin-samourai <kenshin_samourai@tutanota.com>"]
description = "An efficient address indexer in Rust" description = "An efficient address indexer in Rust"
license = "MIT" license = "MIT"
......
...@@ -3,18 +3,33 @@ ...@@ -3,18 +3,33 @@
## Releases ## ## Releases ##
- [v0.4.0](#0_4_0)
- [v0.3.0](#0_3_0) - [v0.3.0](#0_3_0)
- [v0.2.0](#0_2_0) - [v0.2.0](#0_2_0)
- [v0.1.0](#0_1_0) - [v0.1.0](#0_1_0)
<a name="0_4_0"/>
## addrindexrs v0.4.0 ##
### Change log ###
- [#mr7](https://code.samourai.io/dojo/addrindexrs/-/merge_requests/7) reactivate api endpoints
#### Credits ###
- kenshin-samourai
<a name="0_3_0"/> <a name="0_3_0"/>
## addrindexrs v0.3.0 ## ## addrindexrs v0.3.0 ##
### Change log ### ### Change log ###
- [#9](https://github.com/Samourai-Wallet/addrindexrs/pull/9) srewrite wriestore::flush() - [#9](https://github.com/Samourai-Wallet/addrindexrs/pull/9) rewrite writestore::flush()
#### Credits ### #### Credits ###
......
...@@ -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[..])?;
...@@ -95,6 +109,8 @@ impl Connection { ...@@ -95,6 +109,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),
"blockchain.scripthash.get_utxos" => self.blockchain_scripthash_get_utxos(&params), "blockchain.scripthash.get_utxos" => self.blockchain_scripthash_get_utxos(&params),
"server.ping" => Ok(Value::Null), "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