12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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<B, I>
- where
- B: Batch,
- I: TryStreamExt<Ok = (PaymentId, AmountCents), Error = Error> + Unpin,
- {
- async fn get_payment(&self, id: PaymentId) -> Result<Payment, Error>;
- async fn begin(&self) -> Result<B, Error>;
- async fn get_balance(&self, account: AccountId) -> Result<Vec<(AssetId, AmountCents)>, Error>;
- async fn get_unspend_payments(&self, account: AccountId, asset: AssetId) -> Result<I, Error>;
- }
|