nomy_data_models/models/
wallet_state.rs1#![allow(clippy::too_many_arguments, unused_imports, non_camel_case_types)]
2use serde::{Deserialize, Serialize};
8
9use chrono::{DateTime, Utc};
11use rust_decimal::Decimal;
12use serde_json::Value as JsonValue;
13use uuid::Uuid;
14
15use crate::enums::SyncState;
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct WalletState {
21 pub wallet_address: String,
22 pub chain_id: i32,
23 pub data_states: JsonValue,
24 pub sync_state: String,
25 pub id: Uuid,
26 pub created_at: DateTime<Utc>,
27 pub updated_at: DateTime<Utc>,
28 pub created_by: Option<String>,
29 pub updated_by: Option<String>,
30}
31
32impl WalletState {
33 pub fn new(
35 wallet_address: String,
36 chain_id: i32,
37 data_states: JsonValue,
38 sync_state: String,
39 id: Uuid,
40 created_at: DateTime<Utc>,
41 updated_at: DateTime<Utc>,
42 created_by: String,
43 updated_by: String,
44 ) -> Self {
45 Self {
46 wallet_address,
47 chain_id,
48 data_states,
49 sync_state,
50 id,
51 created_at,
52 updated_at,
53 created_by: Some(created_by),
54 updated_by: Some(updated_by),
55 }
56 }
57
58 pub fn to_json(&self) -> Result<String, serde_json::Error> {
60 serde_json::to_string(self)
61 }
62
63 pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
65 serde_json::from_str(json)
66 }
67
68 pub fn to_dict(&self) -> serde_json::Map<String, serde_json::Value> {
70 let json = serde_json::to_value(self).unwrap_or(serde_json::Value::Null);
71 if let serde_json::Value::Object(map) = json {
72 map
73 } else {
74 serde_json::Map::new()
75 }
76 }
77}