1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! SyncState table struct.
//!
//! Maps to TS `TableSyncState` in `wallet-toolbox/src/storage/schema/tables/TableSyncState.ts`.
use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use crate::status::SyncStatus;
/// Synchronization state between wallet storage instances.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, FromRow)]
#[serde(rename_all = "camelCase")]
#[sqlx(rename_all = "camelCase")]
pub struct SyncState {
/// When this record was created.
#[sqlx(rename = "created_at")]
#[serde(
rename = "created_at",
alias = "createdAt",
with = "crate::serde_datetime"
)]
pub created_at: NaiveDateTime,
/// When this record was last updated.
#[sqlx(rename = "updated_at")]
#[serde(
rename = "updated_at",
alias = "updatedAt",
with = "crate::serde_datetime"
)]
pub updated_at: NaiveDateTime,
/// Primary key.
pub sync_state_id: i64,
/// Owning user foreign key.
pub user_id: i64,
/// Identity key of the remote storage.
pub storage_identity_key: String,
/// Name of the remote storage.
pub storage_name: String,
/// Current sync status.
pub status: SyncStatus,
/// Whether initial sync has been performed.
/// TS server may return `0`/`1` instead of `false`/`true`.
#[serde(deserialize_with = "crate::serde_helpers::bool_from_int_or_bool")]
pub init: bool,
/// Reference number for sync protocol.
pub ref_num: String,
/// JSON-encoded sync map tracking per-entity sync positions.
pub sync_map: String,
/// Timestamp of last successful sync.
#[serde(
default,
with = "crate::serde_datetime::option",
skip_serializing_if = "Option::is_none"
)]
pub when: Option<NaiveDateTime>,
/// Net satoshi delta from last sync.
#[serde(skip_serializing_if = "Option::is_none")]
pub satoshis: Option<i64>,
/// Error message from the local side, if any.
#[serde(skip_serializing_if = "Option::is_none")]
pub error_local: Option<String>,
/// Error message from the remote side, if any.
#[serde(skip_serializing_if = "Option::is_none")]
pub error_other: Option<String>,
}