1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-24 06:57:53 +01:00

Add blockchain.transaction.get_confirmed_blockhash

This adds a new RPC method that enables users to fetch the block hash
for given txid. It can thus be used to emulate `txindex=1` as explained
in the related issue.

Closes #287
This commit is contained in:
Martin Habovstiak 2020-08-04 13:21:30 +02:00
parent 39111665d0
commit a0a3d4f939
2 changed files with 11 additions and 0 deletions

View file

@ -431,6 +431,11 @@ impl Query {
.gettransaction_raw(tx_hash, blockhash, verbose)
}
pub fn get_confirmed_blockhash(&self, tx_hash: &Txid) -> Result<Value> {
let blockhash = self.lookup_confirmed_blockhash(tx_hash, None)?;
Ok(json!({ "block_hash": blockhash }))
}
pub fn get_headers(&self, heights: &[usize]) -> Vec<HeaderEntry> {
let _timer = self
.duration

View file

@ -267,6 +267,11 @@ impl Connection {
Ok(self.query.get_transaction(&tx_hash, verbose)?)
}
fn blockchain_transaction_get_confirmed_blockhash(&self, params: &[Value]) -> Result<Value> {
let tx_hash = hash_from_value(params.get(0)).chain_err(|| "bad tx_hash")?;
self.query.get_confirmed_blockhash(&tx_hash)
}
fn blockchain_transaction_get_merkle(&self, params: &[Value]) -> Result<Value> {
let tx_hash = hash_from_value(params.get(0)).chain_err(|| "bad tx_hash")?;
let height = usize_from_value(params.get(1), "height")?;
@ -318,6 +323,7 @@ impl Connection {
"blockchain.transaction.broadcast" => self.blockchain_transaction_broadcast(&params),
"blockchain.transaction.get" => self.blockchain_transaction_get(&params),
"blockchain.transaction.get_merkle" => self.blockchain_transaction_get_merkle(&params),
"blockchain.transaction.get_confirmed_blockhash" => self.blockchain_transaction_get_confirmed_blockhash(&params),
"blockchain.transaction.id_from_pos" => {
self.blockchain_transaction_id_from_pos(&params)
}