addition of tx statuses to sort fields, fixes to total amount queries, inclusion of bigint, addition of unit tests to exercise filtering

This commit is contained in:
Yeastplume
2022-11-28 15:10:29 +00:00
parent d29b64248a
commit 13b1fc8e01
5 changed files with 259 additions and 9 deletions
+1
View File
@@ -34,6 +34,7 @@ curve25519-dalek = "2.1"
secrecy = "0.6"
bech32 = "0.7"
byteorder = "1.3"
num-bigint = "0.2"
grin_wallet_util = { path = "../util", version = "5.2.0-alpha.1" }
grin_wallet_config = { path = "../config", version = "5.2.0-alpha.1" }
+12
View File
@@ -194,6 +194,14 @@ pub struct RetrieveTxQueryArgs {
pub include_outstanding_only: Option<bool>,
/// whether to only consider confirmed-only transactions
pub include_confirmed_only: Option<bool>,
/// whether to only consider sent transactions
pub include_sent_only: Option<bool>,
/// whether to only consider received transactions
pub include_received_only: Option<bool>,
/// whether to only consider coinbase transactions
pub include_coinbase_only: Option<bool>,
/// whether to only consider reverted transactions
pub include_reverted_only: Option<bool>,
/// lower bound on the total amount (amount_credited - amount_debited), inclusive
pub min_amount_inc: Option<u64>,
/// higher bound on the total amount (amount_credited - amount_debited), inclusive
@@ -222,6 +230,10 @@ impl Default for RetrieveTxQueryArgs {
exclude_cancelled: Some(false),
include_outstanding_only: Some(false),
include_confirmed_only: Some(false),
include_sent_only: Some(false),
include_received_only: Some(false),
include_coinbase_only: Some(false),
include_reverted_only: Some(false),
min_amount_inc: None,
max_amount_inc: None,
min_creation_timestamp_inc: None,
+79 -6
View File
@@ -38,6 +38,8 @@ use crate::{
RetrieveTxQuerySortOrder,
};
use num_bigint::BigInt;
/// Retrieve all of the outputs (doesn't attempt to update from node)
pub fn retrieve_outputs<'a, T: ?Sized, C, K>(
wallet: &mut T,
@@ -121,9 +123,6 @@ where
if let Some(v) = query_args.include_outstanding_only {
if v {
!tx_entry.confirmed
&& (tx_entry.tx_type == TxLogEntryType::TxReceived
|| tx_entry.tx_type == TxLogEntryType::TxSent
|| tx_entry.tx_type == TxLogEntryType::TxReverted)
} else {
true
}
@@ -142,6 +141,52 @@ where
true
}
})
.filter(|tx_entry| {
if let Some(v) = query_args.include_sent_only {
if v {
tx_entry.tx_type == TxLogEntryType::TxSent
|| tx_entry.tx_type == TxLogEntryType::TxSentCancelled
} else {
true
}
} else {
true
}
})
.filter(|tx_entry| {
if let Some(v) = query_args.include_received_only {
if v {
tx_entry.tx_type == TxLogEntryType::TxReceived
|| tx_entry.tx_type == TxLogEntryType::TxReceivedCancelled
} else {
true
}
} else {
true
}
})
.filter(|tx_entry| {
if let Some(v) = query_args.include_coinbase_only {
if v {
tx_entry.tx_type == TxLogEntryType::ConfirmedCoinbase
} else {
true
}
} else {
true
}
})
.filter(|tx_entry| {
if let Some(v) = query_args.include_reverted_only {
if v {
tx_entry.tx_type == TxLogEntryType::TxReverted
} else {
true
}
} else {
true
}
})
.filter(|tx_entry| {
if let Some(v) = query_args.min_id_inc {
tx_entry.id >= v
@@ -158,14 +203,34 @@ where
})
.filter(|tx_entry| {
if let Some(v) = query_args.min_amount_inc {
v >= tx_entry.amount_credited - tx_entry.amount_debited
if tx_entry.tx_type == TxLogEntryType::TxSent
|| tx_entry.tx_type == TxLogEntryType::TxSentCancelled
{
BigInt::from(tx_entry.amount_debited)
- BigInt::from(tx_entry.amount_credited)
>= BigInt::from(v)
} else {
BigInt::from(tx_entry.amount_credited)
- BigInt::from(tx_entry.amount_debited)
>= BigInt::from(v)
}
} else {
true
}
})
.filter(|tx_entry| {
if let Some(v) = query_args.max_amount_inc {
v <= tx_entry.amount_credited - tx_entry.amount_debited
if tx_entry.tx_type == TxLogEntryType::TxSent
|| tx_entry.tx_type == TxLogEntryType::TxSentCancelled
{
BigInt::from(tx_entry.amount_debited)
- BigInt::from(tx_entry.amount_credited)
<= BigInt::from(v)
} else {
BigInt::from(tx_entry.amount_credited)
- BigInt::from(tx_entry.amount_debited)
<= BigInt::from(v)
}
} else {
true
}
@@ -228,7 +293,15 @@ where
return_txs.sort_by_key(|tx| tx.confirmation_ts);
}
RetrieveTxQuerySortField::TotalAmount => {
return_txs.sort_by_key(|tx| tx.amount_credited - tx.amount_debited);
return_txs.sort_by_key(|tx| {
if tx.tx_type == TxLogEntryType::TxSent
|| tx.tx_type == TxLogEntryType::TxSentCancelled
{
BigInt::from(tx.amount_debited) - BigInt::from(tx.amount_credited)
} else {
BigInt::from(tx.amount_credited) - BigInt::from(tx.amount_debited)
}
});
}
RetrieveTxQuerySortField::AmountCredited => {
return_txs.sort_by_key(|tx| tx.amount_credited);