Allow single transaction lookup by full TXID
This commit is contained in:
parent
3cc7625608
commit
9f8f1adf3c
|
@ -129,10 +129,14 @@ impl TxRow {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn filter(txid_prefix: &HashPrefix) -> Bytes {
|
||||
pub fn filter_prefix(txid_prefix: &HashPrefix) -> Bytes {
|
||||
[b"T", &txid_prefix[..]].concat()
|
||||
}
|
||||
|
||||
pub fn filter_full(txid: &Sha256dHash) -> Bytes {
|
||||
[b"T", &txid[..]].concat()
|
||||
}
|
||||
|
||||
pub fn to_row(&self) -> Row {
|
||||
Row {
|
||||
key: bincode::serialize(&self.key).unwrap(),
|
||||
|
|
12
src/query.rs
12
src/query.rs
|
@ -10,7 +10,7 @@ use std::sync::{Arc, RwLock};
|
|||
use app::App;
|
||||
use index::{compute_script_hash, TxInRow, TxOutRow, TxRow};
|
||||
use mempool::Tracker;
|
||||
use store::ReadStore;
|
||||
use store::{ReadStore, Row};
|
||||
use util::{FullHash, HashPrefix, HeaderEntry};
|
||||
|
||||
use errors::*;
|
||||
|
@ -97,10 +97,16 @@ fn merklize(left: Sha256dHash, right: Sha256dHash) -> Sha256dHash {
|
|||
Sha256dHash::from_data(&data)
|
||||
}
|
||||
|
||||
// TODO: the 3 functions below can be part of ReadStore.
|
||||
// TODO: the functions below can be part of ReadStore.
|
||||
fn txrow_by_txid(store: &ReadStore, txid: &Sha256dHash) -> Option<TxRow> {
|
||||
let key = TxRow::filter_full(&txid);
|
||||
let value = store.get(&key)?;
|
||||
Some(TxRow::from_row(&Row { key, value }))
|
||||
}
|
||||
|
||||
fn txrows_by_prefix(store: &ReadStore, txid_prefix: &HashPrefix) -> Vec<TxRow> {
|
||||
store
|
||||
.scan(&TxRow::filter(&txid_prefix))
|
||||
.scan(&TxRow::filter_prefix(&txid_prefix))
|
||||
.iter()
|
||||
.map(|row| TxRow::from_row(row))
|
||||
.collect()
|
||||
|
|
Loading…
Reference in New Issue
Block a user