Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #3 ReceiptStoreOperations.list_receipts_since returns wrong list. #6

Open
wants to merge 1 commit into
base: 0-7
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
//! Provides the list transaction receipt since operation for `DieselReceiptStore`

use std::collections::HashMap;
use std::convert::TryFrom;

use diesel::{prelude::*, sql_types::Text};
use transact::protocol::receipt::{Event, StateChange, TransactionReceipt, TransactionResult};

use crate::error::InvalidStateError;
use crate::error::InternalError;

use super::ReceiptStoreOperations;

Expand Down Expand Up @@ -63,9 +65,37 @@ where
if let Some(service_id) = &self.service_id {
query = query.filter(transaction_receipt::service_id.eq(service_id));
};
let transaction_receipt_models: Vec<TransactionReceiptModel> = match id {
Some(id) => query
.filter(transaction_receipt::transaction_id.gt(id))

let mut query2 = transaction_receipt::table.into_boxed();
if let Some(service_id) = &self.service_id {
query2 = query2.filter(transaction_receipt::service_id.eq(service_id));
};

let txn_receipts: Vec<TransactionReceiptModel> = match id {
Some(ref id) => query2
.filter(transaction_receipt::transaction_id.eq(id))
.select(transaction_receipt::all_columns)
.load(self.conn)?,
None => Vec::new(),
};

let idx = match id {
Some(_) => txn_receipts[0].idx,
None => 0
};

let index = match i64::try_from(idx) {
Ok(ind) => Some(ind),
Err(_) => {
return Err(ReceiptStoreError::InternalError(InternalError::with_message(
"Unable to convert index into i64".to_string(),
)));
}
};

let transaction_receipt_models: Vec<TransactionReceiptModel> = match index {
Some(index) => query
.filter(transaction_receipt::idx.gt(index))
.select(transaction_receipt::all_columns)
.load(self.conn)?,
None => query
Expand Down
Loading