Skip to content
Snippets Groups Projects
Commit 085e5020 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[enh] rename BMA tx history functions

parent 43c25ea4
Branches
No related tags found
1 merge request!5feat(bma) add `get_written_transactions_for_bma()` and `get_pending_transactions_for_bma()` - close #1
Pipeline #31887 failed
...@@ -449,7 +449,7 @@ pub fn get_txs_history_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2DbReadable>( ...@@ -449,7 +449,7 @@ pub fn get_txs_history_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2DbReadable>(
) -> KvResult<TxsHistory> { ) -> KvResult<TxsHistory> {
// Get written TX // Get written TX
let TxsHistory { sent, received, .. } = let TxsHistory { sent, received, .. } =
get_tx_history_bma_by_blocks(gva_db_ro, pubkey, None, None)?; get_txs_history_bma_by_blocks(gva_db_ro, pubkey, None, None)?;
// Get pending TX // Get pending TX
let TxsHistory { let TxsHistory {
sending, pending, .. sending, pending, ..
...@@ -464,7 +464,7 @@ pub fn get_txs_history_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2DbReadable>( ...@@ -464,7 +464,7 @@ pub fn get_txs_history_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2DbReadable>(
} }
/// Get TX history of a pubkey from a block range. Needed for BMA only /// Get TX history of a pubkey from a block range. Needed for BMA only
pub fn get_tx_history_bma_by_blocks<GvaDb: GvaV1DbReadable>( pub fn get_txs_history_bma_by_blocks<GvaDb: GvaV1DbReadable>(
gva_db_ro: &GvaDb, gva_db_ro: &GvaDb,
pubkey: PublicKey, pubkey: PublicKey,
from: Option<u32>, from: Option<u32>,
...@@ -512,7 +512,7 @@ pub fn get_tx_history_bma_by_blocks<GvaDb: GvaV1DbReadable>( ...@@ -512,7 +512,7 @@ pub fn get_tx_history_bma_by_blocks<GvaDb: GvaV1DbReadable>(
} }
/// Get TX history of a pubkey from a median_time range. Needed for BMA only /// Get TX history of a pubkey from a median_time range. Needed for BMA only
pub fn get_tx_history_bma_by_times<GvaDb: GvaV1DbReadable>( pub fn get_txs_history_bma_by_times<GvaDb: GvaV1DbReadable>(
gva_db_ro: &GvaDb, gva_db_ro: &GvaDb,
pubkey: PublicKey, pubkey: PublicKey,
from: Option<u64>, from: Option<u64>,
...@@ -521,26 +521,29 @@ pub fn get_tx_history_bma_by_times<GvaDb: GvaV1DbReadable>( ...@@ -521,26 +521,29 @@ pub fn get_tx_history_bma_by_times<GvaDb: GvaV1DbReadable>(
let from_block = match from { let from_block = match from {
Some(from_time) => gva_db_ro Some(from_time) => gva_db_ro
.blocks_by_common_time() .blocks_by_common_time()
.iter(U64BE(from_time)..) .iter(U64BE(from_time).., |it| it.values().next_res())?
.values()
.next_res()?
.unwrap_or(u32::MAX), .unwrap_or(u32::MAX),
None => 0, None => 0,
}; };
let to_block = match to { let to_block = match to {
Some(to_time) => gva_db_ro Some(to_time) => gva_db_ro
.blocks_by_common_time() .blocks_by_common_time()
.iter_rev(..U64BE(to_time)) .iter_rev(..U64BE(to_time), |it| it.values().next_res())?
.values() .unwrap_or(u32::MAX),
.next_res()?
.unwrap_or(0),
None => u32::MAX, None => u32::MAX,
}; };
get_tx_history_bma_by_blocks(gva_db_ro, pubkey, Some(from_block), Some(to_block)) let TxsHistory { sent, received, .. } =
get_txs_history_bma_by_blocks(gva_db_ro, pubkey, Some(from_block), Some(to_block))?;
Ok(TxsHistory {
sent,
received,
sending: Vec::new(),
pending: Vec::new(),
})
} }
/// Get mempool TX of a pubkey. Needed for BMA only /// Get mempool TX of a pubkey. Needed for BMA only
pub fn get_mempool_tx_bma<TxsMpDb: TxsMpV2DbReadable>( pub fn get_txs_history_bma_mempool<TxsMpDb: TxsMpV2DbReadable>(
txs_mp_db_ro: &TxsMpDb, txs_mp_db_ro: &TxsMpDb,
pubkey: PublicKey, pubkey: PublicKey,
) -> KvResult<TxsHistory> { ) -> KvResult<TxsHistory> {
...@@ -578,17 +581,19 @@ pub fn get_mempool_tx_bma<TxsMpDb: TxsMpV2DbReadable>( ...@@ -578,17 +581,19 @@ pub fn get_mempool_tx_bma<TxsMpDb: TxsMpV2DbReadable>(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*;
use duniter_core::{ use duniter_core::{
common::prelude::{BlockHash, Blockstamp}, common::prelude::{BlockHash, Blockstamp},
crypto::keys::ed25519::PublicKey, crypto::keys::ed25519::PublicKey,
documents::transaction::{TransactionDocumentV10, TransactionDocumentV10Stringified}, documents::transaction::{TransactionDocumentV10, TransactionDocumentV10Stringified},
documents_parser::prelude::FromStringObject, documents_parser::prelude::FromStringObject,
}; };
use duniter_gva_db::GvaV1DbWritable;
use maplit::btreeset; use maplit::btreeset;
use unwrap::unwrap; use unwrap::unwrap;
use duniter_gva_db::GvaV1DbWritable;
use super::*;
fn gen_tx(hash: Hash, written_block_number: BlockNumber) -> GvaTxDbV1 { fn gen_tx(hash: Hash, written_block_number: BlockNumber) -> GvaTxDbV1 {
GvaTxDbV1 { GvaTxDbV1 {
tx: unwrap!(TransactionDocumentV10::from_string_object( tx: unwrap!(TransactionDocumentV10::from_string_object(
......
...@@ -217,7 +217,7 @@ impl duniter_core::module::DuniterModule for GvaModule { ...@@ -217,7 +217,7 @@ impl duniter_core::module::DuniterModule for GvaModule {
})) }))
} }
// Needed for BMA only // Needed for BMA only
fn get_tx_history_bma_by_blocks( fn get_txs_history_bma_by_blocks(
profile_path_opt: Option<&Path>, profile_path_opt: Option<&Path>,
pubkey: PublicKey, pubkey: PublicKey,
from: Option<u32>, from: Option<u32>,
...@@ -225,7 +225,7 @@ impl duniter_core::module::DuniterModule for GvaModule { ...@@ -225,7 +225,7 @@ impl duniter_core::module::DuniterModule for GvaModule {
) -> KvResult<Option<duniter_core::module::TxsHistoryForBma>> { ) -> KvResult<Option<duniter_core::module::TxsHistoryForBma>> {
let gva_db = get_gva_db_ro(profile_path_opt); let gva_db = get_gva_db_ro(profile_path_opt);
let duniter_gva_dbs_reader::txs_history::TxsHistory { sent, received, .. } = let duniter_gva_dbs_reader::txs_history::TxsHistory { sent, received, .. } =
duniter_gva_dbs_reader::txs_history::get_tx_history_bma_by_blocks( duniter_gva_dbs_reader::txs_history::get_txs_history_bma_by_blocks(
gva_db, pubkey, from, to, gva_db, pubkey, from, to,
)?; )?;
Ok(Some(duniter_core::module::TxsHistoryForBma { Ok(Some(duniter_core::module::TxsHistoryForBma {
...@@ -255,7 +255,7 @@ impl duniter_core::module::DuniterModule for GvaModule { ...@@ -255,7 +255,7 @@ impl duniter_core::module::DuniterModule for GvaModule {
})) }))
} }
// Needed for BMA only // Needed for BMA only
fn get_tx_history_bma_by_times( fn get_txs_history_bma_by_times(
profile_path_opt: Option<&Path>, profile_path_opt: Option<&Path>,
pubkey: PublicKey, pubkey: PublicKey,
from: Option<u64>, from: Option<u64>,
...@@ -263,7 +263,7 @@ impl duniter_core::module::DuniterModule for GvaModule { ...@@ -263,7 +263,7 @@ impl duniter_core::module::DuniterModule for GvaModule {
) -> KvResult<Option<duniter_core::module::TxsHistoryForBma>> { ) -> KvResult<Option<duniter_core::module::TxsHistoryForBma>> {
let gva_db = get_gva_db_ro(profile_path_opt); let gva_db = get_gva_db_ro(profile_path_opt);
let duniter_gva_dbs_reader::txs_history::TxsHistory { sent, received, .. } = let duniter_gva_dbs_reader::txs_history::TxsHistory { sent, received, .. } =
duniter_gva_dbs_reader::txs_history::get_tx_history_bma_by_times( duniter_gva_dbs_reader::txs_history::get_txs_history_bma_by_times(
gva_db, pubkey, from, to, gva_db, pubkey, from, to,
)?; )?;
Ok(Some(duniter_core::module::TxsHistoryForBma { Ok(Some(duniter_core::module::TxsHistoryForBma {
...@@ -293,7 +293,7 @@ impl duniter_core::module::DuniterModule for GvaModule { ...@@ -293,7 +293,7 @@ impl duniter_core::module::DuniterModule for GvaModule {
})) }))
} }
// Needed for BMA only // Needed for BMA only
fn get_mempool_tx_bma( fn get_txs_history_bma_mempool(
dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>, dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>,
pubkey: PublicKey, pubkey: PublicKey,
) -> KvResult<Option<duniter_core::module::TxsHistoryForBma>> { ) -> KvResult<Option<duniter_core::module::TxsHistoryForBma>> {
...@@ -301,7 +301,10 @@ impl duniter_core::module::DuniterModule for GvaModule { ...@@ -301,7 +301,10 @@ impl duniter_core::module::DuniterModule for GvaModule {
sending, pending, .. sending, pending, ..
} = dbs_pool } = dbs_pool
.execute(move |dbs| { .execute(move |dbs| {
duniter_gva_dbs_reader::txs_history::get_mempool_tx_bma(&dbs.txs_mp_db, pubkey) duniter_gva_dbs_reader::txs_history::get_txs_history_bma_mempool(
&dbs.txs_mp_db,
pubkey,
)
}) })
.expect("dbs pool disconnected")?; .expect("dbs pool disconnected")?;
Ok(Some(duniter_core::module::TxsHistoryForBma { Ok(Some(duniter_core::module::TxsHistoryForBma {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment