Skip to content
Snippets Groups Projects
Commit 4f26e9e6 authored by Éloïs's avatar Éloïs
Browse files

feat(dbs): txs mempool: store received time in each tx

parent 895fee13
No related branches found
No related tags found
No related merge requests found
Pipeline #12188 passed
......@@ -111,7 +111,13 @@ pub fn add_pending_tx<
outputs_by_script.upsert(script, script_outputs);
}
// Insert tx itself
txs.upsert(HashKeyV2(tx_hash), PendingTxDbV2(tx.into_owned()));
txs.upsert(
HashKeyV2(tx_hash),
PendingTxDbV2 {
doc: tx.into_owned(),
received_time,
},
);
Ok(())
},
)
......@@ -177,7 +183,7 @@ fn remove_one_pending_tx<B: Backend>(txs_mp_db: &TxsMpV2Db<B>, tx_hash: Hash) ->
mut outputs_by_script,
)| {
// Remove tx inputs in cols `uds_ids` and `utxos_ids`
for input in tx.0.get_inputs() {
for input in tx.doc.get_inputs() {
match input.id {
SourceIdV10::Ud(UdSourceIdV10 {
issuer,
......@@ -191,14 +197,14 @@ fn remove_one_pending_tx<B: Backend>(txs_mp_db: &TxsMpV2Db<B>, tx_hash: Hash) ->
}
}
// Remove tx hash in col `txs_by_issuer`
for pubkey in tx.0.issuers() {
for pubkey in tx.doc.issuers() {
let mut hashs_ =
txs_by_issuer.get(&PubKeyKeyV2(pubkey))?.unwrap_or_default();
hashs_.remove(&tx_hash);
txs_by_issuer.upsert(PubKeyKeyV2(pubkey), hashs_)
}
// Remove tx hash in col `txs_by_recipient`
for pubkey in tx.0.recipients_keys() {
for pubkey in tx.doc.recipients_keys() {
let mut hashs_ = txs_by_recipient
.get(&PubKeyKeyV2(pubkey))?
.unwrap_or_default();
......@@ -206,7 +212,7 @@ fn remove_one_pending_tx<B: Backend>(txs_mp_db: &TxsMpV2Db<B>, tx_hash: Hash) ->
txs_by_recipient.upsert(PubKeyKeyV2(pubkey), hashs_)
}
// Remove tx outputs in col `outputs`
for (output_index, output) in tx.0.get_outputs().iter().enumerate() {
for (output_index, output) in tx.doc.get_outputs().iter().enumerate() {
let script = WalletConditionsV2(output.conditions.script.to_owned());
let utxo = UtxoValV2::new(output.amount, tx_hash, output_index as u32);
let mut script_outputs =
......
......@@ -17,7 +17,10 @@ use crate::*;
use dubp::documents::transaction::TransactionDocumentV10;
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct PendingTxDbV2(pub TransactionDocumentV10);
pub struct PendingTxDbV2 {
pub doc: TransactionDocumentV10,
pub received_time: i64,
}
impl AsBytes for PendingTxDbV2 {
fn as_bytes<T, F: FnMut(&[u8]) -> T>(&self, mut f: F) -> T {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment