use ic_kit::RejectionCode;
use thiserror::Error;
use crate::Transaction;
mod query;
pub use query::get_transaction_page;
mod stream;
pub use stream::{get_transactions, get_user_transactions};
mod user_query;
pub use user_query::get_user_transactions_page;
#[derive(Debug, Clone)]
pub struct GetTransactionsResponse {
transactions: Vec<Transaction>,
next_page: u32,
}
impl GetTransactionsResponse {
#[inline(always)]
pub fn transactions(&self) -> &Vec<Transaction> {
&self.transactions
}
#[inline(always)]
pub fn next_page(&self) -> u32 {
self.next_page
}
#[inline(always)]
pub fn into_transactions(self) -> Vec<Transaction> {
self.into()
}
}
impl Into<Vec<Transaction>> for GetTransactionsResponse {
fn into(self) -> Vec<Transaction> {
self.transactions
}
}
pub trait AsTransactionsPage: Copy + Sized {
fn page(self) -> Option<u32>;
}
impl AsTransactionsPage for Option<u32> {
fn page(self) -> Option<u32> {
self
}
}
impl AsTransactionsPage for &GetTransactionsResponse {
fn page(self) -> Option<u32> {
Some(self.next_page)
}
}
#[derive(Error, Debug)]
pub enum GetTransactionsError {
#[error("the query was rejected")]
Unexpected(RejectionCode, String),
#[error("no transaction found with the given id")]
InvalidId,
}