Skip to content

Commit

Permalink
(#78) Network Viewer - Add versioning mechanism to JSON-RPC responses
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Oct 5, 2023
1 parent e491530 commit 9f4c3c7
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 51 deletions.
2 changes: 1 addition & 1 deletion rust/demo-app/move/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[move]
version = 0
manifest_digest = "C7E0EBC4DD41B277F44A5FA805716E002069FC359A3BE24E541A14E868DA561C"
deps_digest = "112928C94A84031C09CD9B9D1D44B149B73FC0EEA5FA8D8B2D7CA4D91936335A"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"

dependencies = [
{ name = "Sui" },
Expand Down
2 changes: 2 additions & 0 deletions rust/suibase/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.'cfg(all())']
rustflags = ["--cfg", "uuid_unstable"]
3 changes: 3 additions & 0 deletions rust/suibase/rustfmt.toml → rust/suibase/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
edition = "2021"
use_field_init_shorthand = true
tab_spaces = 4
max_width = 100
hard_tabs = false
32 changes: 30 additions & 2 deletions rust/suibase/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rust/suibase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ tower-http = { version = "0.3.4", features = [
"propagate-header",
] }

uuid = { version = "1.4.1", features = ["v4","v7","fast-rng"] }
uuid7 = { version= "0.7.0", features = [ "uuid" ] }

anyhow = { version = "1.0.71", features = ["backtrace"] }
thiserror = "1.0"

Expand Down
3 changes: 3 additions & 0 deletions rust/suibase/crates/suibase-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mime = "0.3.16"

memchr = "2.5.0"


tokio.workspace = true
tokio-graceful-shutdown.workspace = true

Expand All @@ -27,6 +28,8 @@ notify = { version = "6.0", default-features = false, features = [
"macos_kqueue",
] }

uuid.workspace = true
uuid7.workspace = true
anyhow.workspace = true

clap.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion rust/suibase/crates/suibase-daemon/src/api/api_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl JSONRPCServer {
}

async fn run_server(self, _subsys: &SubsystemHandle) -> Result<()> {
// Refrence:
// Reference:
// https://github.com/paritytech/jsonrpsee/blob/master/examples/examples/cors_server.rs
let cors = CorsLayer::new()
// Allow `POST` when accessing the resource
Expand Down
39 changes: 39 additions & 0 deletions rust/suibase/crates/suibase-daemon/src/api/json_rpc_api.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use hyper::header;
// Defines the JSON-RPC API.
//
// Intended Design (WIP)
Expand All @@ -11,13 +12,46 @@
// emit a message toward the AdminController describing the action needed. The AdminController perform the
// modification and provides the response with a returning tokio OneShot channel.
//
// All *successful" JSON responses have a required "header" section.
//
use jsonrpsee::core::RpcResult;
use jsonrpsee_proc_macros::rpc;

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;

#[serde_as]
#[derive(Clone, Default, Debug, JsonSchema, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Header {
// Header fields
// =============
// - method:
// A string echoing the method of the request.
//
// - key:
// A string echoing one of the "key" parameter of the request (e.g. the workdir requested).
// This field is optional and its interpretation depends on the method.
//
// - data_uuid:
// A sortable hex 64 bytes (UUID v7). Increments with every data modification.
//
// - server_uuid:
// A hex 64 bytes that changes every time the server detects that
// a data_uuid is unexpectedly lower than the previous one (e.g. system
// time went backward) or the PID of the process changes. This is to
// complement data_version for added reliability.
//
pub method: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub server_uuid: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub data_uuid: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub key: Option<String>,
}

#[serde_as]
#[derive(Clone, Default, Debug, JsonSchema, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -75,6 +109,8 @@ impl LinksSummary {
#[derive(Clone, Debug, JsonSchema, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct LinksResponse {
pub header: Header,

pub status: String, // This is a single word combined "Multi-Link status". Either "OK" or "DOWN".

pub info: String, // More details about the status (e.g. '50% degraded', 'all servers down', etc...)
Expand All @@ -100,6 +136,7 @@ pub struct LinksResponse {
impl LinksResponse {
pub fn new() -> Self {
Self {
header: Header::default(),
status: "DISABLED".to_string(),
info: "INITIALIZING".to_string(),
summary: None,
Expand All @@ -114,12 +151,14 @@ impl LinksResponse {
#[derive(Clone, Debug, JsonSchema, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct InfoResponse {
pub header: Header,
pub info: String, // "Success" or info on failure.
}

impl InfoResponse {
pub fn new() -> Self {
Self {
header: Header::default(),
info: "Unknown Error".to_string(),
}
}
Expand Down
Loading

0 comments on commit 9f4c3c7

Please sign in to comment.