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

[enh] add `get_written_transactions_for_bma()` and `get_pending_transactions_for_bma()` - close #1

parent c8d178fd
No related branches found
No related tags found
1 merge request!5feat(bma) add `get_written_transactions_for_bma()` and `get_pending_transactions_for_bma()` - close #1
Pipeline #31801 failed
...@@ -446,10 +446,40 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2 ...@@ -446,10 +446,40 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
gva_db_ro: &GvaDb, gva_db_ro: &GvaDb,
txs_mp_db_ro: &TxsMpDb, txs_mp_db_ro: &TxsMpDb,
pubkey: PublicKey, pubkey: PublicKey,
) -> KvResult<TxsHistory> {
// Get written TX
let TxsHistory { sent, received, .. } = get_written_transactions_for_bma(gva_db_ro, pubkey)?;
// Get pending TX
let TxsHistory {
sending, pending, ..
} = get_pending_transactions_for_bma(txs_mp_db_ro, pubkey)?;
// Return all (written + pending)
Ok(TxsHistory {
sent,
received,
sending,
pending,
})
}
// Needed for BMA only
pub fn get_written_transactions_for_bma<GvaDb: GvaV1DbReadable>(
gva_db_ro: &GvaDb,
pubkey: PublicKey,
) -> KvResult<TxsHistory> {
get_written_transactions_for_bma_with_range(gva_db_ro, pubkey, 0, u32::MAX)
}
// Needed for BMA only
pub fn get_written_transactions_for_bma_with_range<GvaDb: GvaV1DbReadable>(
gva_db_ro: &GvaDb,
pubkey: PublicKey,
start_block: u32,
end_block: u32,
) -> KvResult<TxsHistory> { ) -> KvResult<TxsHistory> {
let script_hash = Hash::compute(WalletScriptV10::single_sig(pubkey).to_string().as_bytes()); let script_hash = Hash::compute(WalletScriptV10::single_sig(pubkey).to_string().as_bytes());
let start_k = WalletHashWithBnV1Db::new(script_hash, BlockNumber(0)); let start_k = WalletHashWithBnV1Db::new(script_hash, BlockNumber(start_block));
let end_k = WalletHashWithBnV1Db::new(script_hash, BlockNumber(u32::MAX)); let end_k = WalletHashWithBnV1Db::new(script_hash, BlockNumber(end_block));
let sent = gva_db_ro let sent = gva_db_ro
.txs_by_issuer() .txs_by_issuer()
...@@ -478,6 +508,19 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2 ...@@ -478,6 +508,19 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
}) })
.flatten_ok() .flatten_ok()
.collect::<KvResult<Vec<_>>>()?; .collect::<KvResult<Vec<_>>>()?;
Ok(TxsHistory {
sent,
received,
sending: Vec::new(),
pending: Vec::new(),
})
}
// Needed for BMA only
pub fn get_pending_transactions_for_bma<TxsMpDb: TxsMpV2DbReadable>(
txs_mp_db_ro: &TxsMpDb,
pubkey: PublicKey,
) -> KvResult<TxsHistory> {
let sending = txs_mp_db_ro let sending = txs_mp_db_ro
.txs_by_issuer() .txs_by_issuer()
.get_ref_slice(&PubKeyKeyV2(pubkey), |hashs| { .get_ref_slice(&PubKeyKeyV2(pubkey), |hashs| {
...@@ -503,8 +546,8 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2 ...@@ -503,8 +546,8 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
})? })?
.unwrap_or_default(); .unwrap_or_default();
Ok(TxsHistory { Ok(TxsHistory {
sent, sent: Vec::new(),
received, received: Vec::new(),
sending, sending,
pending, pending,
}) })
......
...@@ -170,7 +170,7 @@ impl duniter_core::module::DuniterModule for GvaModule { ...@@ -170,7 +170,7 @@ impl duniter_core::module::DuniterModule for GvaModule {
} }
Ok(()) Ok(())
} }
// Needed for BMA only, will be removed when the migration is complete. // Needed for BMA only
fn get_transactions_history_for_bma( fn get_transactions_history_for_bma(
dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>, dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>,
profile_path_opt: Option<&Path>, profile_path_opt: Option<&Path>,
...@@ -216,7 +216,70 @@ impl duniter_core::module::DuniterModule for GvaModule { ...@@ -216,7 +216,70 @@ impl duniter_core::module::DuniterModule for GvaModule {
pending, pending,
})) }))
} }
// Needed for BMA only, will be removed when the migration is complete. // Needed for BMA only
fn get_written_transactions_for_bma(
profile_path_opt: Option<&Path>,
pubkey: PublicKey,
start_block: u32,
end_block: u32,
) -> KvResult<Option<duniter_core::module::TxsHistoryForBma>> {
let gva_db = get_gva_db_ro(profile_path_opt);
let duniter_gva_dbs_reader::txs_history::TxsHistory { sent, received, .. } =
duniter_gva_dbs_reader::txs_history::get_written_transactions_for_bma_with_range(
gva_db,
pubkey,
start_block,
end_block,
)?;
Ok(Some(duniter_core::module::TxsHistoryForBma {
sent: sent
.into_iter()
.map(
|GvaTxDbV1 {
tx,
written_block,
written_time,
}| (tx, written_block, written_time),
)
.collect(),
received: received
.into_iter()
.map(
|GvaTxDbV1 {
tx,
written_block,
written_time,
}| (tx, written_block, written_time),
)
.collect(),
sending: Vec::new(),
pending: Vec::new(),
}))
}
// Needed for BMA only
fn get_pending_transactions_for_bma(
dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>,
pubkey: PublicKey,
) -> KvResult<Option<duniter_core::module::TxsHistoryForBma>> {
let duniter_gva_dbs_reader::txs_history::TxsHistory {
sending, pending, ..
} = dbs_pool
.execute(move |dbs| {
duniter_gva_dbs_reader::txs_history::get_pending_transactions_for_bma(
&dbs.txs_mp_db,
pubkey,
)
})
.expect("dbs pool disconnected")?;
Ok(Some(duniter_core::module::TxsHistoryForBma {
sent: Vec::new(),
received: Vec::new(),
sending,
pending,
}))
}
// Needed for BMA only
fn get_tx_by_hash( fn get_tx_by_hash(
dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>, dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>,
hash: Hash, hash: Hash,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment