kaspa_rpc_core/api/
ops.rs

1//!
2//! RPC Operations used to identify RPC methods during transport and in various RPC-related macros.
3//!
4
5use borsh::{BorshDeserialize, BorshSerialize};
6use kaspa_notify::events::EventType;
7use serde::{Deserialize, Serialize};
8use workflow_core::enums::Describe;
9
10/// API version. Change in this value should result
11/// in the client refusing to connect.
12pub const RPC_API_VERSION: u16 = 1;
13/// API revision. Change in this value denotes
14/// backwards-compatible changes.
15pub const RPC_API_REVISION: u16 = 0;
16
17#[derive(Describe, Clone, Copy, Debug, PartialEq, Eq, Hash, BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
18#[serde(rename_all = "camelCase")]
19#[borsh(use_discriminant = true)]
20pub enum RpcApiOps {
21    NoOp = 0,
22
23    // connection control (provisional)
24    Connect = 1,
25    Disconnect = 2,
26
27    // subscription management
28    Subscribe = 3,
29    Unsubscribe = 4,
30
31    // ~~~
32
33    // Subscription commands for starting/stopping notifications
34    NotifyBlockAdded = 10,
35    NotifyNewBlockTemplate = 11,
36    NotifyUtxosChanged = 12,
37    NotifyPruningPointUtxoSetOverride = 13,
38    NotifyFinalityConflict = 14,
39    NotifyFinalityConflictResolved = 15, // for uniformity purpose only since subscribing to NotifyFinalityConflict means receiving both FinalityConflict and FinalityConflictResolved
40    NotifyVirtualDaaScoreChanged = 16,
41    NotifyVirtualChainChanged = 17,
42    NotifySinkBlueScoreChanged = 18,
43
44    // Notification ops required by wRPC
45
46    // TODO: Remove these ops and use EventType as NotificationOps when workflow_rpc::server::interface::Interface
47    //       will be generic over a MethodOps and NotificationOps instead of a single Ops param.
48    BlockAddedNotification = 60,
49    VirtualChainChangedNotification = 61,
50    FinalityConflictNotification = 62,
51    FinalityConflictResolvedNotification = 63,
52    UtxosChangedNotification = 64,
53    SinkBlueScoreChangedNotification = 65,
54    VirtualDaaScoreChangedNotification = 66,
55    PruningPointUtxoSetOverrideNotification = 67,
56    NewBlockTemplateNotification = 68,
57
58    // RPC methods
59    /// Ping the node to check if connection is alive
60    Ping = 110,
61    /// Get metrics for consensus information and node performance
62    GetMetrics = 111,
63    /// Get system information (RAM available, number of cores, available file descriptors)
64    GetSystemInfo = 112,
65    /// Get current number of active TCP connections
66    GetConnections = 113,
67    /// Get state information on the node
68    GetServerInfo = 114,
69    /// Get the current sync status of the node
70    GetSyncStatus = 115,
71    /// Returns the network this Kaspad is connected to (Mainnet, Testnet)
72    GetCurrentNetwork = 116,
73    /// Extracts a block out of the request message and attempts to add it to the DAG Returns an empty response or an error message
74    SubmitBlock = 117,
75    /// Returns a "template" by which a miner can mine a new block
76    GetBlockTemplate = 118,
77    /// Returns a list of all the addresses (IP, port) this Kaspad knows and a list of all addresses that are currently banned by this Kaspad
78    GetPeerAddresses = 119,
79    /// Returns the hash of the current selected tip block of the DAG
80    GetSink = 120,
81    /// Get information about an entry in the node's mempool
82    GetMempoolEntry = 121,
83    /// Get a snapshot of the node's mempool
84    GetMempoolEntries = 122,
85    /// Returns a list of the peers currently connected to this Kaspad, along with some statistics on them
86    GetConnectedPeerInfo = 123,
87    /// Instructs Kaspad to connect to a given IP address.
88    AddPeer = 124,
89    /// Extracts a transaction out of the request message and attempts to add it to the mempool Returns an empty response or an error message
90    SubmitTransaction = 125,
91    /// Requests info on a block corresponding to a given block hash Returns block info if the block is known.
92    GetBlock = 126,
93    //
94    GetSubnetwork = 127,
95    //
96    GetVirtualChainFromBlock = 128,
97    //
98    GetBlocks = 129,
99    /// Returns the amount of blocks in the DAG
100    GetBlockCount = 130,
101    /// Returns info on the current state of the DAG
102    GetBlockDagInfo = 131,
103    //
104    ResolveFinalityConflict = 132,
105    /// Instructs this node to shut down Returns an empty response or an error message
106    Shutdown = 133,
107    //
108    GetHeaders = 134,
109    /// Get a list of available UTXOs for a given address
110    GetUtxosByAddresses = 135,
111    /// Get a balance for a given address
112    GetBalanceByAddress = 136,
113    /// Get a balance for a number of addresses
114    GetBalancesByAddresses = 137,
115    // ?
116    GetSinkBlueScore = 138,
117    /// Ban a specific peer by it's IP address
118    Ban = 139,
119    /// Unban a specific peer by it's IP address
120    Unban = 140,
121    /// Get generic node information
122    GetInfo = 141,
123    //
124    EstimateNetworkHashesPerSecond = 142,
125    /// Get a list of mempool entries that belong to a specific address
126    GetMempoolEntriesByAddresses = 143,
127    /// Get current issuance supply
128    GetCoinSupply = 144,
129    /// Get DAA Score timestamp estimate
130    GetDaaScoreTimestampEstimate = 145,
131    /// Extracts a transaction out of the request message and attempts to replace a matching transaction in the mempool with it, applying a mandatory Replace by Fee policy
132    SubmitTransactionReplacement = 146,
133    /// Fee estimation
134    GetFeeEstimate = 147,
135    /// Fee estimation (experimental)
136    GetFeeEstimateExperimental = 148,
137    /// Block color determination by iterating DAG.
138    GetCurrentBlockColor = 149,
139}
140
141impl RpcApiOps {
142    pub fn is_subscription(&self) -> bool {
143        matches!(
144            self,
145            RpcApiOps::NotifyBlockAdded
146                | RpcApiOps::NotifyNewBlockTemplate
147                | RpcApiOps::NotifyUtxosChanged
148                | RpcApiOps::NotifyVirtualChainChanged
149                | RpcApiOps::NotifyPruningPointUtxoSetOverride
150                | RpcApiOps::NotifyFinalityConflict
151                | RpcApiOps::NotifyFinalityConflictResolved
152                | RpcApiOps::NotifySinkBlueScoreChanged
153                | RpcApiOps::NotifyVirtualDaaScoreChanged
154                | RpcApiOps::Subscribe
155                | RpcApiOps::Unsubscribe
156        )
157    }
158}
159
160impl From<RpcApiOps> for u32 {
161    fn from(item: RpcApiOps) -> Self {
162        item as u32
163    }
164}
165
166// TODO: Remove this conversion when workflow_rpc::server::interface::Interface
167//       will be generic over a MethodOps and NotificationOps instead of a single Ops param.
168impl From<EventType> for RpcApiOps {
169    fn from(item: EventType) -> Self {
170        match item {
171            EventType::BlockAdded => RpcApiOps::BlockAddedNotification,
172            EventType::VirtualChainChanged => RpcApiOps::VirtualChainChangedNotification,
173            EventType::FinalityConflict => RpcApiOps::FinalityConflictNotification,
174            EventType::FinalityConflictResolved => RpcApiOps::FinalityConflictResolvedNotification,
175            EventType::UtxosChanged => RpcApiOps::UtxosChangedNotification,
176            EventType::SinkBlueScoreChanged => RpcApiOps::SinkBlueScoreChangedNotification,
177            EventType::VirtualDaaScoreChanged => RpcApiOps::VirtualDaaScoreChangedNotification,
178            EventType::PruningPointUtxoSetOverride => RpcApiOps::PruningPointUtxoSetOverrideNotification,
179            EventType::NewBlockTemplate => RpcApiOps::NewBlockTemplateNotification,
180        }
181    }
182}