Skip to content

Commit

Permalink
[RPC API][Refactoring] - Move rpc apis to it's own package (MystenLab…
Browse files Browse the repository at this point in the history
…s#2542)

* move rpc apis to it's own package and decouple it from gateway, in preparation of creating a Sui rust SDK

* minor fixes

* fix fmt

* rename sui-rpc and sui-rpc-api to sui-json-rpc and sui-json-rpc-api
  • Loading branch information
patrickkuo authored Jun 14, 2022
1 parent d96ea49 commit b027b24
Show file tree
Hide file tree
Showing 39 changed files with 394 additions and 214 deletions.
64 changes: 61 additions & 3 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ members = [
"crates/sui-framework-build",
"crates/sui-gateway",
"crates/sui-json",
"crates/sui-json-rpc",
"crates/sui-json-rpc-api",
"crates/sui-network",
"crates/sui-node",
"crates/sui-open-rpc",
Expand Down
2 changes: 2 additions & 0 deletions crates/generate-json-rpc-spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ tempfile = "3.3.0"
tokio = { version = "1.18.2", features = ["full"] }

sui = { path = "../sui" }
sui-json-rpc = { path = "../sui-json-rpc" }
sui-json-rpc-api = { path = "../sui-json-rpc-api" }
sui-core = { path = "../sui-core" }
sui-gateway = { path = "../sui-gateway" }
sui-json = { path = "../sui-json" }
Expand Down
25 changes: 13 additions & 12 deletions crates/generate-json-rpc-spec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

use std::collections::BTreeMap;
use std::fs::File;
use std::io::Write;

use clap::ArgEnum;
use clap::Parser;
Expand All @@ -11,24 +13,23 @@ use pretty_assertions::assert_str_eq;
use serde::Serialize;
use serde_json::{json, Map, Value};

use std::fs::File;
use std::io::Write;
use sui::wallet_commands::{WalletCommandResult, WalletCommands, WalletContext};
use sui::wallet_commands::{EXAMPLE_NFT_DESCRIPTION, EXAMPLE_NFT_NAME, EXAMPLE_NFT_URL};
use sui_config::genesis_config::GenesisConfig;
use sui_config::SUI_WALLET_CONFIG;
use sui_core::gateway_types::{
use sui_json::SuiJsonValue;
use sui_json_rpc::bcs_api::BcsApiImpl;
use sui_json_rpc::gateway_api::{GatewayReadApiImpl, RpcGatewayImpl, TransactionBuilderImpl};
use sui_json_rpc::read_api::{FullNodeApi, ReadApi};
use sui_json_rpc::sui_rpc_doc;
use sui_json_rpc::SuiRpcModule;
use sui_json_rpc_api::rpc_types::{
GetObjectDataResponse, SuiObjectInfo, TransactionEffectsResponse, TransactionResponse,
};
use sui_gateway::api::RpcGatewayApiClient;
use sui_gateway::api::RpcReadApiClient;
use sui_gateway::api::RpcTransactionBuilderClient;
use sui_gateway::api::{SuiRpcModule, TransactionBytes};
use sui_gateway::bcs_api::BcsApiImpl;
use sui_gateway::json_rpc::sui_rpc_doc;
use sui_gateway::read_api::{FullNodeApi, ReadApi};
use sui_gateway::rpc_gateway::{GatewayReadApiImpl, RpcGatewayImpl, TransactionBuilderImpl};
use sui_json::SuiJsonValue;
use sui_json_rpc_api::QuorumDriverApiClient;
use sui_json_rpc_api::RpcReadApiClient;
use sui_json_rpc_api::RpcTransactionBuilderClient;
use sui_json_rpc_api::TransactionBytes;
use sui_types::base_types::{ObjectID, SuiAddress};
use sui_types::sui_serde::{Base64, Encoding};
use sui_types::SUI_FRAMEWORK_ADDRESS;
Expand Down
1 change: 1 addition & 0 deletions crates/sui-cluster-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ telemetry-subscribers = { git = "https://github.com/MystenLabs/mysten-infra", re

sui-faucet = { path = "../sui-faucet" }
sui = { path = "../sui" }
sui-json-rpc-api = { path = "../sui-json-rpc-api" }
sui-core = { path = "../sui-core" }
sui-types = { path = "../sui-types" }
sui-json = { path = "../sui-json" }
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-cluster-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use sui::{
call_move, WalletContext, EXAMPLE_NFT_DESCRIPTION, EXAMPLE_NFT_NAME, EXAMPLE_NFT_URL,
},
};
use sui_core::gateway_types::{GetObjectDataResponse, SuiExecutionStatus, TransactionResponse};
use sui_faucet::FaucetResponse;
use sui_json::SuiJsonValue;
use sui_json_rpc_api::rpc_types::{GetObjectDataResponse, SuiExecutionStatus, TransactionResponse};
use sui_types::{
base_types::{encode_bytes_hex, ObjectID, SuiAddress},
crypto::get_key_pair,
Expand Down
1 change: 1 addition & 0 deletions crates/sui-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ sui-types = { path = "../sui-types" }
sui-storage = { path = "../sui-storage" }
sui-config = { path = "../sui-config" }
sui-json = { path = "../sui-json" }
sui-json-rpc-api = { path = "../sui-json-rpc-api" }

move-binary-format = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
Expand Down
3 changes: 1 addition & 2 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
epoch::EpochInfoLocals,
event_handler::EventHandler,
execution_engine,
gateway_types::TransactionEffectsResponse,
query_helpers::QueryHelpers,
transaction_input_checker,
};
Expand Down Expand Up @@ -1101,7 +1100,7 @@ impl AuthorityState {
pub async fn get_transaction(
&self,
digest: TransactionDigest,
) -> Result<TransactionEffectsResponse, anyhow::Error> {
) -> Result<(CertifiedTransaction, TransactionEffects), anyhow::Error> {
QueryHelpers::get_transaction(&self.database, digest)
}

Expand Down
14 changes: 12 additions & 2 deletions crates/sui-core/src/gateway_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ use crate::{
query_helpers::QueryHelpers,
};
use sui_json::{resolve_move_function_args, SuiJsonCallArg, SuiJsonValue};
use sui_json_rpc_api::rpc_types::{
GetObjectDataResponse, GetRawObjectDataResponse, MergeCoinResponse, PublishResponse,
SplitCoinResponse, SuiMoveObject, SuiObject, SuiObjectInfo, TransactionEffectsResponse,
TransactionResponse,
};

use crate::gateway_types::*;
use crate::transaction_input_checker::InputObjects;

#[cfg(test)]
Expand Down Expand Up @@ -1214,6 +1218,12 @@ where
&self,
digest: TransactionDigest,
) -> Result<TransactionEffectsResponse, anyhow::Error> {
QueryHelpers::get_transaction(&self.store, digest)
let (cert, effect) = QueryHelpers::get_transaction(&self.store, digest)?;

Ok(TransactionEffectsResponse {
certificate: cert.try_into()?,
effects: effect.into(),
timestamp_ms: None,
})
}
}
1 change: 0 additions & 1 deletion crates/sui-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub mod epoch;
pub mod event_handler;
pub mod execution_engine;
pub mod gateway_state;
pub mod gateway_types;
pub mod safe_client;
pub mod streamer;
pub mod transaction_input_checker;
Expand Down
11 changes: 4 additions & 7 deletions crates/sui-core/src/query_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::{authority::SuiDataStore, gateway_types::TransactionEffectsResponse};
use crate::authority::SuiDataStore;
use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use sui_types::messages::{CertifiedTransaction, TransactionEffects};
use sui_types::{base_types::*, batch::TxSequenceNumber, error::SuiError, fp_ensure};
use tracing::debug;

Expand Down Expand Up @@ -79,14 +80,10 @@ impl<const ALL_OBJ_VER: bool, S: Eq + Serialize + for<'de> Deserialize<'de>>
pub fn get_transaction(
database: &SuiDataStore<ALL_OBJ_VER, S>,
digest: TransactionDigest,
) -> Result<TransactionEffectsResponse, anyhow::Error> {
) -> Result<(CertifiedTransaction, TransactionEffects), anyhow::Error> {
let opt = database.get_certified_transaction(&digest)?;
match opt {
Some(certificate) => Ok(TransactionEffectsResponse {
certificate: certificate.try_into()?,
effects: database.get_effects(&digest)?.into(),
timestamp_ms: None,
}),
Some(certificate) => Ok((certificate, database.get_effects(&digest)?)),
None => Err(anyhow!(SuiError::TransactionNotFound { digest })),
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/sui-faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ serde_json = "1.0.80"
tower = { version = "0.4.12", features = ["util", "timeout", "load-shed", "limit"] }

sui = { path = "../sui" }
sui-json-rpc-api = { path = "../sui-json-rpc-api" }
sui-types = { path = "../sui-types" }
sui-core = { path = "../sui-core" }
sui-config = { path = "../sui-config" }
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-faucet/src/faucet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::FaucetError;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use sui_core::gateway_types::SuiParsedObject;
use sui_json_rpc_api::rpc_types::SuiParsedObject;
use sui_types::{
base_types::{ObjectID, SuiAddress},
gas_coin::GasCoin,
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-faucet/src/faucet/simple_faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use anyhow::anyhow;
use async_trait::async_trait;
use sui::wallet_commands::WalletContext;
use sui_core::gateway_types::{SuiExecutionStatus, SuiParsedObject};
use sui_json_rpc_api::rpc_types::{SuiExecutionStatus, SuiParsedObject};
use sui_types::{
base_types::{ObjectID, SuiAddress},
gas_coin::GasCoin,
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ sui-core = { path = "../sui-core" }
sui-config = { path = "../sui-config" }
sui-types = { path = "../sui-types" }
sui-json = { path = "../sui-json" }
sui-json-rpc-api = { path = "../sui-json-rpc-api" }
sui-open-rpc = { path = "../sui-open-rpc" }
sui-open-rpc-macros = { path = "../sui-open-rpc-macros" }

move-core-types = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02", features = ["address20"] }
mysten-network = { git = "https://github.com/MystenLabs/mysten-infra", rev = "ff5c1d69057fe93be658377462ca2875a57a0223" }
Expand Down
29 changes: 24 additions & 5 deletions crates/sui-gateway/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

pub mod api;
pub mod bcs_api;
use crate::config::GatewayConfig;
use anyhow::anyhow;
use std::path::Path;
use std::sync::Arc;
use sui_config::PersistedConfig;
use sui_core::gateway_state::{GatewayClient, GatewayState};

pub mod config;
pub mod json_rpc;
pub mod read_api;
pub mod rpc_gateway;
pub mod rpc_gateway_client;

pub fn create_client(config_path: &Path) -> Result<GatewayClient, anyhow::Error> {
let config: GatewayConfig = PersistedConfig::read(config_path).map_err(|e| {
anyhow!(
"Failed to read config file at {:?}: {}. Have you run `sui genesis` first?",
config_path,
e
)
})?;
let committee = config.make_committee();
let authority_clients = config.make_authority_clients();
Ok(Arc::new(GatewayState::new(
config.db_folder_path,
committee,
authority_clients,
)?))
}
Loading

0 comments on commit b027b24

Please sign in to comment.