Allow single transaction lookup by full TXID

This commit is contained in:
Roman Zeyde 2018-06-02 09:04:25 +03:00
parent 3cc7625608
commit 9f8f1adf3c
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with 14 additions and 4 deletions

View File

@ -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(),

View File

@ -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()