zilliqa_rs/providers/mod.rs
1//! Clients for interacting with zilliqa network.
2
3pub mod http;
4pub mod provider;
5
6pub use http::Http;
7pub use provider::Provider;
8
9use crate::Error;
10use async_trait::async_trait;
11use jsonrpsee::core::traits::ToRpcParams;
12use serde::de::DeserializeOwned;
13use std::fmt::Debug;
14
15/// JSON-RPC client trait
16///
17/// If a client wants to be used as a JSON-RPC client, it must implement this trait.
18#[async_trait]
19pub trait JsonRpcClient: Debug + Send + Sync {
20 async fn request<T, R>(&self, method: &str, params: T) -> Result<R, Error>
21 where
22 T: Debug + Send + Sync + ToRpcParams,
23 R: DeserializeOwned + Send;
24}
25
26pub enum RPCErrorCode {
27 // Standard JSON-RPC 2.0 errors
28 // RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400).
29 // It should not be used for application-layer errors.
30 RpcInvalidRequest = -32600,
31 // RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404).
32 // It should not be used for application-layer errors.
33 RpcMethodNotFound = -32601,
34 RpcInvalidParams = -32602,
35 // RPC_INTERNAL_ERROR should only be used for genuine errors in bitcoind
36 // (for example datadir corruption).
37 RpcInternalError = -32603,
38 RpcParseError = -32700,
39
40 // General application defined errors
41 RpcMiscError = -1, // std::exception thrown in command handling
42 RpcTypeError = -3, // Unexpected type was passed as parameter
43 RpcInvalidAddressOrKey = -5, // Invalid address or key
44 RpcInvalidParameter = -8, // Invalid, missing or duplicate parameter
45 RpcDatabaseError = -20, // Database error
46 RpcDeserializationError = -22, // Error parsing or validating structure in raw format
47 RpcVerifyError = -25, // General error during transaction or block submission
48 RpcVerifyRejected = -26, // Transaction or block was rejected by network rules
49 RpcInWarmup = -28, // Client still warming up
50 RpcMethodDeprecated = -32, // RPC method is deprecated
51}