casper_client/rpcs/v1_4_5/
list_rpcs.rs

1use schemars::{schema::Schema, Map};
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5use casper_types::ProtocolVersion;
6
7pub(crate) const LIST_RPCS_METHOD: &str = "rpc.discover";
8
9/// Contact information for the exposed API.
10#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize, Debug)]
11pub struct OpenRpcContactField {
12    /// The identifying name of the organization.
13    pub name: String,
14    /// The URL pointing to the contact information.
15    pub url: String,
16}
17
18/// License information for the exposed API.
19#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize, Debug)]
20pub struct OpenRpcLicenseField {
21    /// The license name used for the API.
22    pub name: String,
23    /// A URL to the license used for the API.
24    pub url: String,
25}
26
27/// Metadata about the API.
28#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize, Debug)]
29pub struct OpenRpcInfoField {
30    /// The version of this OpenRPC schema document.
31    pub version: String,
32    /// The title of the application.
33    pub title: String,
34    /// The description of the application.
35    pub description: String,
36    /// The contact information for the exposed API.
37    pub contact: OpenRpcContactField,
38    /// The license information for the exposed API.
39    pub license: OpenRpcLicenseField,
40}
41
42/// An object representing a Server.
43#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize, Debug)]
44pub struct OpenRpcServerEntry {
45    /// The name of the server.
46    pub name: String,
47    /// A URL to the server.
48    pub url: String,
49}
50
51/// A parameter that is applicable to a method.
52#[derive(Clone, PartialEq, Serialize, Deserialize, Debug)]
53pub struct SchemaParam {
54    /// The name of the parameter.
55    pub name: String,
56    /// The schema describing the parameter.
57    pub schema: Schema,
58    /// Whether the parameter is required or not.
59    pub required: bool,
60}
61
62/// The description of the result returned by the method.
63#[derive(Clone, PartialEq, Serialize, Deserialize, Debug)]
64pub struct ResponseResult {
65    /// Name of the response result.
66    pub name: String,
67    /// The schema describing the response result.
68    pub schema: Schema,
69}
70
71/// An example request parameter.
72#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
73pub struct ExampleParam {
74    /// Canonical name of the example parameter.
75    pub name: String,
76    /// Embedded literal example parameter.
77    pub value: Value,
78}
79
80/// An example result.
81#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
82pub struct ExampleResult {
83    /// Canonical name of the example result.
84    pub name: String,
85    /// Embedded literal example result.
86    pub value: Value,
87}
88
89/// An example pair of request parameters and response result.
90#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
91pub struct Example {
92    /// Name for the example pairing.
93    pub name: String,
94    /// Example parameters.
95    pub params: Vec<ExampleParam>,
96    /// Example result.
97    pub result: ExampleResult,
98}
99
100/// Describes the interface for the given method name.  The method name is used as the `method`
101/// field of the JSON-RPC body.
102#[derive(Clone, PartialEq, Serialize, Deserialize, Debug)]
103pub struct Method {
104    /// The method name.
105    pub name: String,
106    /// A short summary of what the method does.
107    pub summary: String,
108    /// A list of parameters that are applicable for this method.
109    pub params: Vec<SchemaParam>,
110    /// The description of the result returned by the method.
111    pub result: ResponseResult,
112    /// An array of examples.
113    pub examples: Vec<Example>,
114}
115
116/// The schema components.
117#[derive(Clone, PartialEq, Serialize, Deserialize, Debug)]
118pub struct Components {
119    /// The map of component schemas.
120    pub schemas: Map<String, Schema>,
121}
122
123/// The main schema for the casper node's RPC server, compliant with
124/// [the OpenRPC Specification](https://spec.open-rpc.org).
125#[derive(Clone, PartialEq, Serialize, Deserialize, Debug)]
126pub struct OpenRpcSchema {
127    /// The OpenRPC Standard version.
128    pub openrpc: String,
129    /// The OpenRPC info field.
130    pub info: OpenRpcInfoField,
131    /// Available servers for the `rpc.discovery` method.
132    pub servers: Vec<OpenRpcServerEntry>,
133    /// The available RPC methods.
134    pub methods: Vec<Method>,
135    /// The schema components.
136    pub components: Components,
137}
138
139/// The `result` field of a successful JSON-RPC response to a `rpc.discover` request.
140#[derive(Serialize, Deserialize, Debug)]
141#[serde(deny_unknown_fields)]
142pub struct ListRpcsResult {
143    /// The JSON-RPC server version.
144    pub api_version: ProtocolVersion,
145    /// Hard coded name: "OpenRPC Schema".
146    pub name: String,
147    /// The list of supported RPCs described in OpenRPC schema format.
148    pub schema: OpenRpcSchema,
149}