Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Dojo
addrindexrs
Commits
97a9e0fb
Commit
97a9e0fb
authored
Oct 06, 2020
by
kenshin-samourai
Browse files
reactivate headers.subscribe endpoint
parent
c8e19c1d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
1 deletion
+20
-1
src/index.rs
src/index.rs
+5
-0
src/query.rs
src/query.rs
+6
-1
src/rpc.rs
src/rpc.rs
+9
-0
No files found.
src/index.rs
View file @
97a9e0fb
...
...
@@ -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
()
...
...
src/query.rs
View file @
97a9e0fb
...
...
@@ -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
())
}
...
...
src/rpc.rs
View file @
97a9e0fb
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
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment