|
| 1 | +use crate::{channel_v5::Channel, Address, BalancesMap, UnifiedNum}; |
| 2 | +use chrono::{DateTime, Utc}; |
| 3 | +use serde::{Deserialize, Serialize}; |
| 4 | + |
| 5 | +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] |
| 6 | +#[serde(rename_all = "camelCase")] |
| 7 | +pub struct Deposit { |
| 8 | + pub total: UnifiedNum, |
| 9 | + pub still_on_create2: UnifiedNum, |
| 10 | +} |
| 11 | + |
| 12 | +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] |
| 13 | +pub struct Spendable { |
| 14 | + pub spender: Address, |
| 15 | + pub channel: Channel, |
| 16 | + #[serde(flatten)] |
| 17 | + pub deposit: Deposit, |
| 18 | +} |
| 19 | + |
| 20 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 21 | +#[serde(rename_all = "camelCase")] |
| 22 | +pub struct Aggregate { |
| 23 | + pub spender: Address, |
| 24 | + pub channel: Channel, |
| 25 | + pub balances: BalancesMap, |
| 26 | + pub created: DateTime<Utc>, |
| 27 | +} |
| 28 | +#[cfg(feature = "postgres")] |
| 29 | +mod postgres { |
| 30 | + use std::convert::TryFrom; |
| 31 | + use tokio_postgres::{Error, Row}; |
| 32 | + |
| 33 | + use super::*; |
| 34 | + |
| 35 | + impl TryFrom<Row> for Spendable { |
| 36 | + type Error = Error; |
| 37 | + |
| 38 | + fn try_from(row: Row) -> Result<Self, Self::Error> { |
| 39 | + Ok(Spendable { |
| 40 | + spender: row.try_get("spender")?, |
| 41 | + channel: row.try_get("channel")?, |
| 42 | + deposit: Deposit { |
| 43 | + total: row.try_get("total")?, |
| 44 | + still_on_create2: row.try_get("still_on_create2")?, |
| 45 | + }, |
| 46 | + }) |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments