use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use kuatia_types::{AccountId, EnvelopeId};
use crate::error::StoreError;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum LedgerEventKind {
TransferCommitted {
transfer_id: EnvelopeId,
},
AccountCreated {
account_id: AccountId,
},
AccountFrozen {
account_id: AccountId,
},
AccountUnfrozen {
account_id: AccountId,
},
AccountClosed {
account_id: AccountId,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct LedgerEvent {
pub seq: u64,
pub timestamp: i64,
pub kind: LedgerEventKind,
}
pub fn event_dedup_key(kind: &LedgerEventKind) -> Option<EnvelopeId> {
match kind {
LedgerEventKind::TransferCommitted { transfer_id } => Some(*transfer_id),
LedgerEventKind::AccountCreated { .. }
| LedgerEventKind::AccountFrozen { .. }
| LedgerEventKind::AccountUnfrozen { .. }
| LedgerEventKind::AccountClosed { .. } => None,
}
}
#[async_trait]
pub trait EventStore: Send + Sync {
async fn append_event(&self, event: &LedgerEvent) -> Result<u64, StoreError>;
async fn get_events_since(
&self,
after_seq: u64,
limit: u32,
) -> Result<Vec<LedgerEvent>, StoreError>;
}