diem_json_rpc_types/
lib.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4pub mod stream;
5
6pub mod errors;
7pub mod request;
8pub mod response;
9pub mod views;
10
11use serde::{Deserialize, Serialize};
12
13#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
14pub enum JsonRpcVersion {
15    #[serde(rename = "2.0")]
16    V2,
17}
18
19#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
20#[serde(deny_unknown_fields)]
21#[serde(untagged)]
22pub enum Id {
23    /// Numeric id
24    Number(u64),
25    /// String id
26    String(Box<str>),
27}
28
29impl std::fmt::Display for Id {
30    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
31        match self {
32            Id::Number(ref v) => std::fmt::Debug::fmt(v, f),
33            Id::String(ref v) => std::fmt::Debug::fmt(v, f),
34        }
35    }
36}
37
38#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Deserialize, Serialize)]
39#[serde(rename_all = "snake_case")]
40pub enum Method {
41    Submit,
42    GetMetadata,
43    GetAccount,
44    GetTransactions,
45    GetAccountTransaction,
46    GetAccountTransactions,
47    GetEvents,
48    GetCurrencies,
49    GetNetworkStatus,
50
51    //
52    // Experimental APIs
53    //
54    GetResources,
55    GetStateProof,
56    GetAccumulatorConsistencyProof,
57    GetAccountStateWithProof,
58    GetTransactionsWithProofs,
59    GetAccountTransactionsWithProofs,
60    GetEventsWithProofs,
61    GetEventByVersionWithProof,
62}
63
64impl Method {
65    pub fn as_str(&self) -> &str {
66        match self {
67            Method::Submit => "submit",
68            Method::GetMetadata => "get_metadata",
69            Method::GetAccount => "get_account",
70            Method::GetTransactions => "get_transactions",
71            Method::GetAccountTransaction => "get_account_transaction",
72            Method::GetAccountTransactions => "get_account_transactions",
73            Method::GetEvents => "get_events",
74            Method::GetCurrencies => "get_currencies",
75            Method::GetNetworkStatus => "get_network_status",
76            Method::GetResources => "get_resources",
77            Method::GetStateProof => "get_state_proof",
78            Method::GetAccumulatorConsistencyProof => "get_accumulator_consistency_proof",
79            Method::GetAccountStateWithProof => "get_account_state_with_proof",
80            Method::GetTransactionsWithProofs => "get_transactions_with_proofs",
81            Method::GetAccountTransactionsWithProofs => "get_account_transactions_with_proofs",
82            Method::GetEventsWithProofs => "get_events_with_proofs",
83            Method::GetEventByVersionWithProof => "get_event_by_version_with_proof",
84        }
85    }
86}