use enumset::EnumSet;
use serde::{Deserialize, Serialize};
use crate::kind::EventKind;
use crate::sync::SyncLifecycle;
use crate::value::{Amount, AssetId, WalletId};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum WalletEvent {
FundsReceived {
wallet_id: WalletId,
asset: Option<AssetId>,
amount: Amount,
coin_id: String,
confirmed_height: u32,
},
FundsSent {
wallet_id: WalletId,
asset: Option<AssetId>,
amount: Amount,
tx_id: String,
confirmed_height: u32,
},
CoinStateChanged {
coin_id: String,
spent: bool,
created_height: Option<u32>,
spent_height: Option<u32>,
},
Confirmation {
tx_id: String,
height: u32,
},
TransactionFailed {
tx_id: String,
error: String,
},
NewTip {
height: u32,
header_hash: String,
},
SyncProgress {
wallet_id: WalletId,
state: SyncLifecycle,
peak_height: u32,
target_height: u32,
},
CatInfo {
asset_id: AssetId,
name: Option<String>,
},
DidInfo {
launcher_id: String,
},
NftData {
launcher_id: String,
},
Derivation {
wallet_id: WalletId,
index: u32,
},
}
impl WalletEvent {
pub fn kind(&self) -> EventKind {
match self {
Self::FundsReceived { .. } => EventKind::FundsReceived,
Self::FundsSent { .. } => EventKind::FundsSent,
Self::CoinStateChanged { .. } => EventKind::CoinStateChanged,
Self::Confirmation { .. } => EventKind::Confirmation,
Self::TransactionFailed { .. } => EventKind::TransactionFailed,
Self::NewTip { .. } => EventKind::NewTip,
Self::SyncProgress { .. } => EventKind::SyncProgress,
Self::CatInfo { .. } => EventKind::CatInfo,
Self::DidInfo { .. } => EventKind::DidInfo,
Self::NftData { .. } => EventKind::NftData,
Self::Derivation { .. } => EventKind::Derivation,
}
}
pub fn matches(&self, filter: EnumSet<EventKind>) -> bool {
filter.contains(self.kind())
}
}