forked from kaspanet/rusty-kaspa
-
Notifications
You must be signed in to change notification settings - Fork 5
/
events.rs
143 lines (139 loc) · 4.49 KB
/
events.rs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use crate::imports::*;
use crate::runtime::Balance;
use crate::storage::Hint;
use crate::storage::TransactionRecord;
use crate::utxo::context::UtxoContextId;
/// Sync state of the kaspad node
#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "kebab-case")]
#[serde(tag = "sync", content = "state")]
pub enum SyncState {
Proof {
level: u64,
},
Headers {
headers: u64,
progress: u64,
},
Blocks {
blocks: u64,
progress: u64,
},
UtxoSync {
chunks: u64,
total: u64,
},
TrustSync {
processed: u64,
total: u64,
},
UtxoResync,
/// General cases when the node is waiting
/// for information from peers or waiting to
/// connect to peers.
NotSynced,
/// Node is fully synced with the network.
Synced,
}
impl SyncState {
pub fn is_synced(&self) -> bool {
matches!(self, SyncState::Synced)
}
}
/// Events emitted by the wallet framework
#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "kebab-case")]
#[serde(tag = "event", content = "data")]
pub enum Events {
/// Successful RPC connection
Connect {
#[serde(rename = "networkId")]
network_id: NetworkId,
/// Kaspa node RPC url on which connection
/// has been established
url: String,
},
/// RPC disconnection
Disconnect {
#[serde(rename = "networkId")]
network_id: NetworkId,
url: String,
},
/// A special event emitted if the connected node
/// does not have UTXO index enabled
UtxoIndexNotEnabled,
/// [`SyncState`] notification posted
/// when the node sync state changes
SyncState(SyncState),
/// Emitted after the wallet has loaded and
/// contains anti-phishing 'hint' set by the user.
WalletHint { hint: Option<Hint> },
/// Wallet has opened
WalletOpen,
/// Wallet reload initiated (development only)
WalletReload,
/// Wallet has been closed
WalletClose,
/// Emitted after successful RPC connection
/// after the initial state negotiation.
ServerStatus {
#[serde(rename = "networkId")]
network_id: NetworkId,
#[serde(rename = "serverVersion")]
server_version: String,
#[serde(rename = "isSynced")]
is_synced: bool,
/// Kaspa node RPC url on which connection
/// has been established
url: String,
},
/// Successful start of [`UtxoProcessor`](crate::utxo::processor::UtxoProcessor).
/// This event signifies that the application can
/// start interfacing with the UTXO processor.
UtxoProcStart,
/// [`UtxoProcessor`](crate::utxo::processor::UtxoProcessor) has shut down.
UtxoProcStop,
/// Occurs when UtxoProcessor has failed to connect to the node
/// for an unknown reason. (general error trap)
UtxoProcError(String),
/// DAA score change
DAAScoreChange(u64),
/// New incoming pending UTXO/transaction
Pending {
record: TransactionRecord,
/// `true` if the transaction is a result of an earlier
/// created outgoing transaction. (such as a UTXO returning
/// change to the account)
is_outgoing: bool,
},
/// Pending UTXO has been removed (reorg)
Reorg { record: TransactionRecord },
/// UtxoProcessor has received a foreign unknown transaction
/// withdrawing funds from the wallet. This occurs when another
/// instance of the wallet creates an outgoing transaction.
External { record: TransactionRecord },
/// Transaction has been confirmed
Maturity {
record: TransactionRecord,
/// `true` if the transaction is a result of an earlier
/// created outgoing transaction. (such as a UTXO returning
/// change to the account)
is_outgoing: bool,
},
/// Emitted when a transaction has been created and broadcasted
/// by the Transaction [`Generator`](crate::tx::generator::Generator)
Outgoing { record: TransactionRecord },
/// UtxoContext (Account) balance update. Emitted for each
/// balance change within the UtxoContext.
Balance {
#[serde(rename = "matureUtxoSize")]
mature_utxo_size: usize,
#[serde(rename = "pendingUtxoSize")]
pending_utxo_size: usize,
balance: Option<Balance>,
/// If UtxoContext is bound to a Runtime Account, this
/// field will contain the account id. Otherwise, it will
/// contain a developer-assigned internal id.
id: UtxoContextId,
},
}