use crate::{amount::AmountCents, asset::AssetId, AccountId, Payment, PaymentId}; use futures::TryStreamExt; #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Storage error: {0}")] Storage(String), #[error("No storage update when expecting")] NoUpdate, } #[async_trait::async_trait] pub trait Batch { async fn spend_payment( &mut self, payment_id: PaymentId, transaction_id: AccountId, ) -> Result<(), Error>; async fn rollback(self) -> Result<(), Error>; async fn commit(self) -> Result<(), Error>; async fn store_new_payments(&mut self, outputs: &[Payment]) -> Result<(), Error>; async fn store_transaction(&mut self) -> Result<(), Error>; } #[async_trait::async_trait] pub trait Storage where B: Batch, I: TryStreamExt + Unpin, { async fn get_payment(&self, id: PaymentId) -> Result; async fn begin(&self) -> Result; async fn get_balance(&self, account: AccountId) -> Result, Error>; async fn get_unspend_payments(&self, account: AccountId, asset: AssetId) -> Result; }