nautilus_model/defi/rpc.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3// https://poseitrader.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use serde::{Deserialize, de::DeserializeOwned};
17
18/// A response structure received from a WebSocket JSON-RPC blockchain node subscription.
19#[derive(Debug, Deserialize)]
20pub struct RpcNodeWssResponse<T>
21where
22 T: DeserializeOwned,
23{
24 /// JSON-RPC version identifier.
25 pub jsonrpc: String,
26 /// Name of the RPC method that was called.
27 pub method: String,
28 /// Parameters containing subscription information and the deserialized result.
29 #[serde(bound(deserialize = ""))]
30 pub params: RpcNodeSubscriptionResponse<T>,
31}
32
33/// Container for subscription data within an RPC response, holding the subscription ID and the deserialized result.
34#[derive(Debug, Deserialize)]
35pub struct RpcNodeSubscriptionResponse<T>
36where
37 T: DeserializeOwned,
38{
39 /// ID of the subscription associated with the RPC response.
40 pub subscription: String,
41 /// Deserialized result.
42 #[serde(bound(deserialize = ""))]
43 pub result: T,
44}
45
46/// A response structure received from an HTTP JSON-RPC blockchain node request.
47#[derive(Debug, Deserialize)]
48pub struct RpcNodeHttpResponse<T>
49where
50 T: DeserializeOwned,
51{
52 /// JSON-RPC version identifier.
53 pub jsonrpc: String,
54 /// Request identifier returned by the server.
55 pub id: u64,
56 /// Deserialized result.
57 #[serde(bound(deserialize = ""))]
58 pub result: T,
59}