Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate API to jsonrpsee #3219

Merged
merged 7 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
743 changes: 485 additions & 258 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions massa-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"

[dependencies]
displaydoc = "0.2"
jsonrpc-core = { git = "https://github.com/massalabs/jsonrpc" }
jsonrpc-derive = { git = "https://github.com/massalabs/jsonrpc" }
jsonrpc-http-server = { git = "https://github.com/massalabs/jsonrpc" }
jsonrpsee = { version = "0.16.1", features = ["server", "macros"] }
async-trait = "0.1.58"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.87"
thiserror = "1.0"
tokio = { version = "1.21", features = ["full"] }
tracing = "0.1"
Expand Down
23 changes: 22 additions & 1 deletion massa-api/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) 2022 MASSA LABS <[email protected]>

use jsonrpc_core::serde::Deserialize;
use massa_time::MassaTime;
use std::net::SocketAddr;
use std::path::PathBuf;

use serde::Deserialize;

/// API settings.
/// the API settings
#[derive(Debug, Deserialize, Clone)]
Expand All @@ -19,6 +20,26 @@ pub struct APIConfig {
pub max_arguments: u64,
/// openrpc specification path
pub openrpc_spec_path: PathBuf,
/// maximum size in bytes of a request.
pub max_request_body_size: u32,
/// maximum size in bytes of a response.
pub max_response_body_size: u32,
/// maximum number of incoming connections allowed.
pub max_connections: u32,
/// maximum number of subscriptions per connection.
pub max_subscriptions_per_connection: u32,
/// max length for logging for requests and responses. Logs bigger than this limit will be truncated.
pub max_log_length: u32,
/// host filtering.
pub allow_hosts: Vec<String>,
/// whether batch requests are supported by this server or not.
pub batch_requests_supported: bool,
/// the interval at which `Ping` frames are submitted.
pub ping_interval: MassaTime,
/// whether to enable HTTP.
pub enable_http: bool,
/// whether to enable WS.
pub enable_ws: bool,
/// max datastore value length
pub max_datastore_value_length: u64,
/// max op datastore entry
Expand Down
13 changes: 7 additions & 6 deletions massa-api/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright (c) 2022 MASSA LABS <[email protected]>

use displaydoc::Display;
use jsonrpsee::{
core::Error as JsonRpseeError,
types::error::{CallError, ErrorObject},
};
use massa_consensus_exports::error::ConsensusError;
use massa_execution_exports::ExecutionError;
use massa_hash::MassaHashError;
Expand Down Expand Up @@ -50,7 +54,7 @@ pub enum ApiError {
InternalServerError(String),
}

impl From<ApiError> for jsonrpc_core::Error {
impl From<ApiError> for JsonRpseeError {
fn from(err: ApiError) -> Self {
// JSON-RPC Server errors codes must be between -32099 to -32000
let code = match err {
Expand All @@ -72,10 +76,7 @@ impl From<ApiError> for jsonrpc_core::Error {
ApiError::MissingConfig(_) => -32018,
ApiError::WrongAPI => -32019,
};
jsonrpc_core::Error {
code: jsonrpc_core::ErrorCode::ServerError(code),
message: err.to_string(),
data: None,
}

CallError::Custom(ErrorObject::owned(code, err.to_string(), None::<()>)).into()
}
}
Loading