diff --git a/Cargo.lock b/Cargo.lock index c7c6483128f99..1ab01346a43e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2038,6 +2038,8 @@ dependencies = [ "sui-core", "sui-gateway", "sui-json", + "sui-json-rpc", + "sui-json-rpc-api", "sui-types", "tempfile", "test-utils", @@ -5841,6 +5843,8 @@ dependencies = [ "sui-framework", "sui-gateway", "sui-json", + "sui-json-rpc", + "sui-json-rpc-api", "sui-network", "sui-node", "sui-open-rpc", @@ -5908,6 +5912,7 @@ dependencies = [ "sui-core", "sui-faucet", "sui-json", + "sui-json-rpc-api", "sui-types", "telemetry-subscribers", "tempfile", @@ -5990,6 +5995,7 @@ dependencies = [ "sui-config", "sui-framework", "sui-json", + "sui-json-rpc-api", "sui-network", "sui-storage", "sui-types", @@ -6022,6 +6028,7 @@ dependencies = [ "sui", "sui-config", "sui-core", + "sui-json-rpc-api", "sui-types", "tempfile", "test-utils", @@ -6093,8 +6100,8 @@ dependencies = [ "sui-config", "sui-core", "sui-json", + "sui-json-rpc-api", "sui-open-rpc", - "sui-open-rpc-macros", "sui-types", "tokio", "tracing", @@ -6121,6 +6128,52 @@ dependencies = [ "workspace-hack", ] +[[package]] +name = "sui-json-rpc" +version = "0.0.0" +dependencies = [ + "anyhow", + "async-trait", + "ed25519-dalek", + "jsonrpsee", + "jsonrpsee-core", + "once_cell", + "prometheus_exporter", + "sui-core", + "sui-json", + "sui-json-rpc-api", + "sui-open-rpc", + "sui-types", + "tracing", + "workspace-hack", +] + +[[package]] +name = "sui-json-rpc-api" +version = "0.0.0" +dependencies = [ + "anyhow", + "async-trait", + "colored", + "either", + "itertools", + "jsonrpsee", + "jsonrpsee-core", + "jsonrpsee-proc-macros", + "move-core-types", + "once_cell", + "schemars", + "serde 1.0.137", + "serde_json", + "serde_with", + "sui-json", + "sui-open-rpc", + "sui-open-rpc-macros", + "sui-types", + "tracing", + "workspace-hack", +] + [[package]] name = "sui-network" version = "0.0.0" @@ -6144,19 +6197,22 @@ name = "sui-node" version = "0.0.0" dependencies = [ "anyhow", + "async-trait", "clap 3.1.18", "futures", "jsonrpsee", + "jsonrpsee-core", "multiaddr", "mysten-network 0.1.0 (git+https://github.com/MystenLabs/mysten-infra?rev=ff5c1d69057fe93be658377462ca2875a57a0223)", "parking_lot 0.12.1", "prometheus_exporter", "sui-config", "sui-core", - "sui-gateway", + "sui-json-rpc", "sui-network", - "sui-quorum-driver", + "sui-open-rpc", "sui-storage", + "sui-types", "telemetry-subscribers", "tokio", "tracing", @@ -6555,6 +6611,8 @@ dependencies = [ "sui-core", "sui-framework", "sui-gateway", + "sui-json-rpc", + "sui-json-rpc-api", "sui-network", "sui-node", "sui-swarm", diff --git a/Cargo.toml b/Cargo.toml index 0262b54aab7e5..21d4bfe061965 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/crates/generate-json-rpc-spec/Cargo.toml b/crates/generate-json-rpc-spec/Cargo.toml index 686ac7e9a1601..82f1c18575288 100644 --- a/crates/generate-json-rpc-spec/Cargo.toml +++ b/crates/generate-json-rpc-spec/Cargo.toml @@ -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" } diff --git a/crates/generate-json-rpc-spec/src/main.rs b/crates/generate-json-rpc-spec/src/main.rs index 73709bde1a250..77462af4eb59e 100644 --- a/crates/generate-json-rpc-spec/src/main.rs +++ b/crates/generate-json-rpc-spec/src/main.rs @@ -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; @@ -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; diff --git a/crates/sui-cluster-test/Cargo.toml b/crates/sui-cluster-test/Cargo.toml index 8d424cd68ef13..51495ea046827 100644 --- a/crates/sui-cluster-test/Cargo.toml +++ b/crates/sui-cluster-test/Cargo.toml @@ -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" } diff --git a/crates/sui-cluster-test/src/main.rs b/crates/sui-cluster-test/src/main.rs index e31272aa273c2..d18255ac24b1e 100644 --- a/crates/sui-cluster-test/src/main.rs +++ b/crates/sui-cluster-test/src/main.rs @@ -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, diff --git a/crates/sui-core/Cargo.toml b/crates/sui-core/Cargo.toml index 013fe9fdbd8ad..6480e1a6b684f 100644 --- a/crates/sui-core/Cargo.toml +++ b/crates/sui-core/Cargo.toml @@ -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" } diff --git a/crates/sui-core/src/authority.rs b/crates/sui-core/src/authority.rs index fb03433fcb869..ea762c489c1c1 100644 --- a/crates/sui-core/src/authority.rs +++ b/crates/sui-core/src/authority.rs @@ -9,7 +9,6 @@ use crate::{ epoch::EpochInfoLocals, event_handler::EventHandler, execution_engine, - gateway_types::TransactionEffectsResponse, query_helpers::QueryHelpers, transaction_input_checker, }; @@ -1101,7 +1100,7 @@ impl AuthorityState { pub async fn get_transaction( &self, digest: TransactionDigest, - ) -> Result { + ) -> Result<(CertifiedTransaction, TransactionEffects), anyhow::Error> { QueryHelpers::get_transaction(&self.database, digest) } diff --git a/crates/sui-core/src/gateway_state.rs b/crates/sui-core/src/gateway_state.rs index 29732475c3cd3..34ed09ca1bd9a 100644 --- a/crates/sui-core/src/gateway_state.rs +++ b/crates/sui-core/src/gateway_state.rs @@ -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)] @@ -1214,6 +1218,12 @@ where &self, digest: TransactionDigest, ) -> Result { - 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, + }) } } diff --git a/crates/sui-core/src/lib.rs b/crates/sui-core/src/lib.rs index f894b99e1d37c..955e162324e6a 100644 --- a/crates/sui-core/src/lib.rs +++ b/crates/sui-core/src/lib.rs @@ -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; diff --git a/crates/sui-core/src/query_helpers.rs b/crates/sui-core/src/query_helpers.rs index aea47eebdccf8..9b61309a1c10a 100644 --- a/crates/sui-core/src/query_helpers.rs +++ b/crates/sui-core/src/query_helpers.rs @@ -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; @@ -79,14 +80,10 @@ impl Deserialize<'de>> pub fn get_transaction( database: &SuiDataStore, digest: TransactionDigest, - ) -> Result { + ) -> 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 })), } } diff --git a/crates/sui-faucet/Cargo.toml b/crates/sui-faucet/Cargo.toml index 62502656a64ef..440cb5677c994 100644 --- a/crates/sui-faucet/Cargo.toml +++ b/crates/sui-faucet/Cargo.toml @@ -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" } diff --git a/crates/sui-faucet/src/faucet/mod.rs b/crates/sui-faucet/src/faucet/mod.rs index 8ef7b442b9c1f..5ad13200b0a5c 100644 --- a/crates/sui-faucet/src/faucet/mod.rs +++ b/crates/sui-faucet/src/faucet/mod.rs @@ -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, diff --git a/crates/sui-faucet/src/faucet/simple_faucet.rs b/crates/sui-faucet/src/faucet/simple_faucet.rs index b1d68c39d9967..91a0cf6a3218d 100644 --- a/crates/sui-faucet/src/faucet/simple_faucet.rs +++ b/crates/sui-faucet/src/faucet/simple_faucet.rs @@ -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, diff --git a/crates/sui-gateway/Cargo.toml b/crates/sui-gateway/Cargo.toml index fcb69e708d762..a44f17db6f553 100644 --- a/crates/sui-gateway/Cargo.toml +++ b/crates/sui-gateway/Cargo.toml @@ -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" } diff --git a/crates/sui-gateway/src/lib.rs b/crates/sui-gateway/src/lib.rs index 56519bda56185..b2dac75045740 100644 --- a/crates/sui-gateway/src/lib.rs +++ b/crates/sui-gateway/src/lib.rs @@ -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 { + 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, + )?)) +} diff --git a/crates/sui-gateway/src/rpc_gateway/responses.rs b/crates/sui-gateway/src/rpc_gateway/responses.rs deleted file mode 100644 index 91207a0c11c1d..0000000000000 --- a/crates/sui-gateway/src/rpc_gateway/responses.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -use move_core_types::language_storage::TypeTag; -use move_core_types::parser::parse_type_tag; -use schemars::JsonSchema; -use serde::Deserialize; -use serde::Serialize; -use sui_core::gateway_types::{SuiData, SuiObjectRef, SuiParsedMoveObject}; - -use sui_types::base_types::TransactionDigest; -use sui_types::object::Owner; - -#[derive(Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub struct ObjectExistsResponse { - object_ref: SuiObjectRef, - owner: Owner, - previous_transaction: TransactionDigest, - data: SuiData, -} - -#[derive(Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub struct ObjectNotExistsResponse { - object_id: String, -} - -#[derive(Serialize, Deserialize, JsonSchema)] -#[serde(rename = "TypeTag")] -pub struct SuiTypeTag(String); - -impl TryInto for SuiTypeTag { - type Error = anyhow::Error; - fn try_into(self) -> Result { - parse_type_tag(&self.0) - } -} - -impl From for SuiTypeTag { - fn from(tag: TypeTag) -> Self { - Self(format!("{}", tag)) - } -} diff --git a/crates/sui-gateway/src/rpc_gateway_client.rs b/crates/sui-gateway/src/rpc_gateway_client.rs index 2bacb29bd12e4..b90e58012a2cf 100644 --- a/crates/sui-gateway/src/rpc_gateway_client.rs +++ b/crates/sui-gateway/src/rpc_gateway_client.rs @@ -3,33 +3,32 @@ use anyhow::Error; use async_trait::async_trait; -use jsonrpsee::http_client::{HttpClient, HttpClientBuilder}; use move_core_types::language_storage::TypeTag; use tokio::runtime::Handle; use sui_core::gateway_state::{GatewayAPI, GatewayTxSeqNumber}; -use sui_core::gateway_types::{ +use sui_json::SuiJsonValue; +use sui_json_rpc_api::client::SuiRpcClient; +use sui_json_rpc_api::rpc_types::{ GetObjectDataResponse, GetRawObjectDataResponse, SuiObjectInfo, TransactionEffectsResponse, TransactionResponse, }; -use sui_json::SuiJsonValue; +use sui_json_rpc_api::QuorumDriverApiClient; +use sui_json_rpc_api::RpcBcsApiClient; +use sui_json_rpc_api::RpcTransactionBuilderClient; +use sui_json_rpc_api::TransactionBytes; use sui_types::base_types::{ObjectID, SuiAddress, TransactionDigest}; use sui_types::messages::{Transaction, TransactionData}; use sui_types::sui_serde::Base64; - -use crate::api::RpcBcsApiClient; -use crate::api::RpcReadApiClient; -use crate::api::RpcTransactionBuilderClient; -use crate::api::{RpcGatewayApiClient, TransactionBytes}; - pub struct RpcGatewayClient { - client: HttpClient, + client: SuiRpcClient, } - +use sui_json_rpc_api::RpcReadApiClient; impl RpcGatewayClient { pub fn new(server_url: String) -> Result { - let client = HttpClientBuilder::default().build(&server_url)?; - Ok(Self { client }) + Ok(Self { + client: SuiRpcClient::new(&server_url)?, + }) } } @@ -43,6 +42,7 @@ impl GatewayAPI for RpcGatewayClient { Ok(self .client + .quorum_driver() .execute_transaction(tx_bytes, signature_bytes, pub_key) .await?) } @@ -57,6 +57,7 @@ impl GatewayAPI for RpcGatewayClient { ) -> Result { let bytes: TransactionBytes = self .client + .transaction_builder() .transfer_coin(signer, object_id, gas, gas_budget, recipient) .await?; bytes.to_data() @@ -72,13 +73,17 @@ impl GatewayAPI for RpcGatewayClient { ) -> Result { let bytes: TransactionBytes = self .client + .transaction_builder() .transfer_sui(signer, sui_object_id, gas_budget, recipient, amount) .await?; bytes.to_data() } async fn sync_account_state(&self, account_addr: SuiAddress) -> Result<(), Error> { - self.client.sync_account_state(account_addr).await?; + self.client + .quorum_driver() + .sync_account_state(account_addr) + .await?; Ok(()) } @@ -95,6 +100,7 @@ impl GatewayAPI for RpcGatewayClient { ) -> Result { let bytes: TransactionBytes = self .client + .transaction_builder() .move_call( signer, package_object_id, @@ -125,6 +131,7 @@ impl GatewayAPI for RpcGatewayClient { .collect(); let bytes: TransactionBytes = self .client + .transaction_builder() .publish(signer, package_bytes, gas, gas_budget) .await?; bytes.to_data() @@ -140,6 +147,7 @@ impl GatewayAPI for RpcGatewayClient { ) -> Result { let bytes: TransactionBytes = self .client + .transaction_builder() .split_coin(signer, coin_object_id, split_amounts, gas, gas_budget) .await?; bytes.to_data() @@ -155,38 +163,47 @@ impl GatewayAPI for RpcGatewayClient { ) -> Result { let bytes: TransactionBytes = self .client + .transaction_builder() .merge_coin(signer, primary_coin, coin_to_merge, gas, gas_budget) .await?; bytes.to_data() } async fn get_object(&self, object_id: ObjectID) -> Result { - Ok(self.client.get_object(object_id).await?) + Ok(self.client.read_api().get_object(object_id).await?) } async fn get_raw_object(&self, object_id: ObjectID) -> Result { - Ok(self.client.get_raw_object(object_id).await?) + Ok(self.client.read_api().get_raw_object(object_id).await?) } async fn get_objects_owned_by_address( &self, address: SuiAddress, ) -> Result, Error> { - Ok(self.client.get_objects_owned_by_address(address).await?) + Ok(self + .client + .read_api() + .get_objects_owned_by_address(address) + .await?) } async fn get_objects_owned_by_object( &self, object_id: ObjectID, ) -> Result, Error> { - Ok(self.client.get_objects_owned_by_object(object_id).await?) + Ok(self + .client + .read_api() + .get_objects_owned_by_object(object_id) + .await?) } fn get_total_transaction_number(&self) -> Result { let handle = Handle::current(); let _ = handle.enter(); Ok(futures::executor::block_on( - self.client.get_total_transaction_number(), + self.client.read_api().get_total_transaction_number(), )?) } @@ -198,7 +215,7 @@ impl GatewayAPI for RpcGatewayClient { let handle = Handle::current(); let _ = handle.enter(); Ok(futures::executor::block_on( - self.client.get_transactions_in_range(start, end), + self.client.read_api().get_transactions_in_range(start, end), )?) } @@ -209,7 +226,7 @@ impl GatewayAPI for RpcGatewayClient { let handle = Handle::current(); let _ = handle.enter(); Ok(futures::executor::block_on( - self.client.get_recent_transactions(count), + self.client.read_api().get_recent_transactions(count), )?) } @@ -217,6 +234,6 @@ impl GatewayAPI for RpcGatewayClient { &self, digest: TransactionDigest, ) -> Result { - Ok(self.client.get_transaction(digest).await?) + Ok(self.client.read_api().get_transaction(digest).await?) } } diff --git a/crates/sui-json-rpc-api/Cargo.toml b/crates/sui-json-rpc-api/Cargo.toml new file mode 100644 index 0000000000000..767f598f415b3 --- /dev/null +++ b/crates/sui-json-rpc-api/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "sui-json-rpc-api" +version = "0.0.0" +authors = ["Mysten Labs "] +license = "Apache-2.0" +publish = false +edition = "2021" + +[dependencies] +async-trait = "0.1.53" +anyhow = "1.0.57" +schemars = "0.8.8" +jsonrpsee = { version = "0.13.1", features = ["full"] } +jsonrpsee-proc-macros = "0.13.1" +jsonrpsee-core = "0.13.1" +once_cell = "1.12.0" +tracing = "0.1.34" +serde = { version = "1.0.137", features = ["derive"] } +serde_json = "1.0.80" +serde_with = { version = "1.14.0", features = ["hex"] } +colored = "2.0.0" +either = "1.6.1" +move-core-types = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02", features = ["address20"] } +itertools = "0.10.3" + +sui-types = { path = "../sui-types" } +sui-json = { path = "../sui-json" } +sui-open-rpc = { path = "../sui-open-rpc" } +sui-open-rpc-macros = { path = "../sui-open-rpc-macros" } + +workspace-hack = { path = "../workspace-hack"} diff --git a/crates/sui-json-rpc-api/src/client.rs b/crates/sui-json-rpc-api/src/client.rs new file mode 100644 index 0000000000000..36b53c7a620a9 --- /dev/null +++ b/crates/sui-json-rpc-api/src/client.rs @@ -0,0 +1,33 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +use jsonrpsee::http_client::{HttpClient, HttpClientBuilder}; + +use crate::QuorumDriverApiClient; +use crate::RpcFullNodeReadApiClient; +use crate::RpcReadApiClient; +use crate::RpcTransactionBuilderClient; + +pub struct SuiRpcClient { + client: HttpClient, +} + +impl SuiRpcClient { + pub fn new(server_url: &str) -> Result { + let client = HttpClientBuilder::default().build(server_url)?; + Ok(Self { client }) + } + + pub fn read_api(&self) -> &impl RpcReadApiClient { + &self.client + } + pub fn quorum_driver(&self) -> &impl QuorumDriverApiClient { + &self.client + } + pub fn full_node_read_api(&self) -> &impl RpcFullNodeReadApiClient { + &self.client + } + pub fn transaction_builder(&self) -> &impl RpcTransactionBuilderClient { + &self.client + } +} diff --git a/crates/sui-gateway/src/api.rs b/crates/sui-json-rpc-api/src/lib.rs similarity index 93% rename from crates/sui-gateway/src/api.rs rename to crates/sui-json-rpc-api/src/lib.rs index 3a1698ce9c221..20baea24d9d48 100644 --- a/crates/sui-gateway/src/api.rs +++ b/crates/sui-json-rpc-api/src/lib.rs @@ -2,18 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 use jsonrpsee::core::RpcResult; -use jsonrpsee_core::server::rpc_module::RpcModule; use jsonrpsee_proc_macros::rpc; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use serde_with::serde_as; -use sui_core::gateway_state::GatewayTxSeqNumber; -use sui_core::gateway_types::{ - GetObjectDataResponse, GetRawObjectDataResponse, SuiInputObjectKind, SuiObjectInfo, - SuiObjectRef, -}; -use sui_core::gateway_types::{TransactionEffectsResponse, TransactionResponse}; use sui_json::SuiJsonValue; use sui_open_rpc::Module; use sui_open_rpc_macros::open_rpc; @@ -24,11 +17,20 @@ use sui_types::{ messages::TransactionData, }; -use crate::rpc_gateway::responses::SuiTypeTag; +use crate::rpc_types::SuiTypeTag; +use crate::rpc_types::{ + GetObjectDataResponse, GetRawObjectDataResponse, SuiInputObjectKind, SuiObjectInfo, + SuiObjectRef, TransactionEffectsResponse, TransactionResponse, +}; + +pub mod client; +pub mod rpc_types; + +type GatewayTxSeqNumber = u64; -#[open_rpc(namespace = "sui", tag = "Gateway API")] +#[open_rpc(namespace = "sui", tag = "Quorum Driver API")] #[rpc(server, client, namespace = "sui")] -pub trait RpcGatewayApi { +pub trait QuorumDriverApi { /// Execute the transaction using the transaction data, signature and public key. #[method(name = "executeTransaction")] async fn execute_transaction( @@ -218,11 +220,3 @@ impl TransactionBytes { TransactionData::from_signable_bytes(&self.tx_bytes.to_vec()?) } } - -pub trait SuiRpcModule -where - Self: Sized, -{ - fn rpc(self) -> RpcModule; - fn rpc_doc_module() -> Module; -} diff --git a/crates/sui-core/src/gateway_types.rs b/crates/sui-json-rpc-api/src/rpc_types.rs similarity index 98% rename from crates/sui-core/src/gateway_types.rs rename to crates/sui-json-rpc-api/src/rpc_types.rs index 07afdc2f8c55d..b23c11cbab220 100644 --- a/crates/sui-core/src/gateway_types.rs +++ b/crates/sui-json-rpc-api/src/rpc_types.rs @@ -13,7 +13,7 @@ use colored::Colorize; use either::Either; use itertools::Itertools; use move_core_types::identifier::Identifier; -use move_core_types::language_storage::StructTag; +use move_core_types::language_storage::{StructTag, TypeTag}; use move_core_types::value::{MoveStruct, MoveStructLayout, MoveValue}; use schemars::JsonSchema; use serde::ser::Error; @@ -21,6 +21,7 @@ use serde::Deserialize; use serde::Serialize; use serde_json::Value; +use move_core_types::parser::parse_type_tag; use serde_with::serde_as; use sui_json::SuiJsonValue; use sui_types::base_types::{ @@ -1259,3 +1260,35 @@ impl From for SuiObjectInfo { } } } + +#[derive(Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "camelCase")] +pub struct ObjectExistsResponse { + object_ref: SuiObjectRef, + owner: Owner, + previous_transaction: TransactionDigest, + data: SuiData, +} + +#[derive(Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "camelCase")] +pub struct ObjectNotExistsResponse { + object_id: String, +} + +#[derive(Serialize, Deserialize, JsonSchema)] +#[serde(rename = "TypeTag")] +pub struct SuiTypeTag(String); + +impl TryInto for SuiTypeTag { + type Error = anyhow::Error; + fn try_into(self) -> Result { + parse_type_tag(&self.0) + } +} + +impl From for SuiTypeTag { + fn from(tag: TypeTag) -> Self { + Self(format!("{}", tag)) + } +} diff --git a/crates/sui-core/src/unit_tests/gateway_types_tests.rs b/crates/sui-json-rpc-api/src/unit_tests/gateway_types_tests.rs similarity index 98% rename from crates/sui-core/src/unit_tests/gateway_types_tests.rs rename to crates/sui-json-rpc-api/src/unit_tests/gateway_types_tests.rs index 6d9a3c507ab9c..147789781aca4 100644 --- a/crates/sui-core/src/unit_tests/gateway_types_tests.rs +++ b/crates/sui-json-rpc-api/src/unit_tests/gateway_types_tests.rs @@ -6,6 +6,7 @@ use move_core_types::ident_str; use move_core_types::language_storage::StructTag; use move_core_types::value::{MoveStruct, MoveValue}; +use crate::rpc_types::{SuiMoveStruct, SuiMoveValue}; use sui_types::base_types::SequenceNumber; use sui_types::base_types::{ObjectID, SuiAddress}; use sui_types::gas_coin::GasCoin; @@ -13,8 +14,6 @@ use sui_types::object::MoveObject; use sui_types::sui_serde::Base64; use sui_types::SUI_FRAMEWORK_ADDRESS; -use crate::gateway_types::{SuiMoveStruct, SuiMoveValue}; - #[test] fn test_move_value_to_sui_bytearray() { let move_value = MoveValue::Vector(vec![ diff --git a/crates/sui-json-rpc/Cargo.toml b/crates/sui-json-rpc/Cargo.toml new file mode 100644 index 0000000000000..181d4ea88f1ae --- /dev/null +++ b/crates/sui-json-rpc/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "sui-json-rpc" +version = "0.0.0" +authors = ["Mysten Labs "] +license = "Apache-2.0" +publish = false +edition = "2021" + +[dependencies] +sui-json-rpc-api = { path = "../sui-json-rpc-api" } +jsonrpsee = { version = "0.13.1", features = ["full"] } +jsonrpsee-core = "0.13.1" +once_cell = "1.12.0" +prometheus_exporter = "0.8.4" +anyhow = "1.0.57" +sui-open-rpc = { path = "../sui-open-rpc" } +tracing = "0.1.34" +async-trait = "0.1.53" +ed25519-dalek = { version = "1.0.1", features = ["batch", "serde"] } + +sui-core = { path = "../sui-core" } +sui-types = { path = "../sui-types" } +sui-json = { path = "../sui-json" } + +workspace-hack = { path = "../workspace-hack"} diff --git a/crates/sui-gateway/src/bcs_api.rs b/crates/sui-json-rpc/src/bcs_api.rs similarity index 86% rename from crates/sui-gateway/src/bcs_api.rs rename to crates/sui-json-rpc/src/bcs_api.rs index 34cfa0a7ed5e7..dcd1aabc422e2 100644 --- a/crates/sui-gateway/src/bcs_api.rs +++ b/crates/sui-json-rpc/src/bcs_api.rs @@ -5,17 +5,17 @@ use std::sync::Arc; use anyhow::anyhow; use async_trait::async_trait; -use jsonrpsee_core::server::rpc_module::RpcModule; -use jsonrpsee_core::RpcResult; +use jsonrpsee::core::RpcResult; +use jsonrpsee::RpcModule; use sui_core::authority::AuthorityState; use sui_core::gateway_state::GatewayClient; -use sui_core::gateway_types::GetRawObjectDataResponse; use sui_open_rpc::Module; use sui_types::base_types::ObjectID; -use crate::api::RpcBcsApiServer; -use crate::api::SuiRpcModule; +use crate::SuiRpcModule; +use sui_json_rpc_api::rpc_types::GetRawObjectDataResponse; +use sui_json_rpc_api::RpcBcsApiServer; pub struct BcsApiImpl { client: ClientStateAdaptor, @@ -69,6 +69,6 @@ impl SuiRpcModule for BcsApiImpl { } fn rpc_doc_module() -> Module { - crate::api::RpcBcsApiOpenRpc::module_doc() + sui_json_rpc_api::RpcBcsApiOpenRpc::module_doc() } } diff --git a/crates/sui-gateway/src/rpc_gateway.rs b/crates/sui-json-rpc/src/gateway_api.rs similarity index 85% rename from crates/sui-gateway/src/rpc_gateway.rs rename to crates/sui-json-rpc/src/gateway_api.rs index 2df3e01e8b908..7d5fe6850b7d3 100644 --- a/crates/sui-gateway/src/rpc_gateway.rs +++ b/crates/sui-json-rpc/src/gateway_api.rs @@ -1,9 +1,6 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -use std::path::Path; -use std::sync::Arc; - use anyhow::anyhow; use async_trait::async_trait; use ed25519_dalek::ed25519::signature::Signature; @@ -11,20 +8,16 @@ use jsonrpsee::core::RpcResult; use jsonrpsee_core::server::rpc_module::RpcModule; use tracing::debug; -use crate::rpc_gateway::responses::SuiTypeTag; -use crate::{ - api::{ - RpcGatewayApiServer, RpcReadApiServer, RpcTransactionBuilderServer, SuiRpcModule, - TransactionBytes, - }, - config::GatewayConfig, -}; -use sui_config::PersistedConfig; -use sui_core::gateway_state::{GatewayClient, GatewayState, GatewayTxSeqNumber}; -use sui_core::gateway_types::{ +use crate::SuiRpcModule; +use sui_core::gateway_state::{GatewayClient, GatewayTxSeqNumber}; +use sui_json::SuiJsonValue; +use sui_json_rpc_api::rpc_types::SuiTypeTag; +use sui_json_rpc_api::rpc_types::{ GetObjectDataResponse, SuiObjectInfo, TransactionEffectsResponse, TransactionResponse, }; -use sui_json::SuiJsonValue; +use sui_json_rpc_api::{ + QuorumDriverApiServer, RpcReadApiServer, RpcTransactionBuilderServer, TransactionBytes, +}; use sui_open_rpc::Module; use sui_types::sui_serde::Base64; use sui_types::{ @@ -34,8 +27,6 @@ use sui_types::{ messages::{Transaction, TransactionData}, }; -pub mod responses; - pub struct RpcGatewayImpl { client: GatewayClient, } @@ -64,25 +55,8 @@ impl TransactionBuilderImpl { } } -pub fn create_client(config_path: &Path) -> Result { - 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, - )?)) -} - #[async_trait] -impl RpcGatewayApiServer for RpcGatewayImpl { +impl QuorumDriverApiServer for RpcGatewayImpl { async fn execute_transaction( &self, tx_bytes: Base64, @@ -113,7 +87,7 @@ impl SuiRpcModule for RpcGatewayImpl { } fn rpc_doc_module() -> Module { - crate::api::RpcGatewayApiOpenRpc::module_doc() + sui_json_rpc_api::QuorumDriverApiOpenRpc::module_doc() } } @@ -172,7 +146,7 @@ impl SuiRpcModule for GatewayReadApiImpl { } fn rpc_doc_module() -> Module { - crate::api::RpcReadApiOpenRpc::module_doc() + sui_json_rpc_api::RpcReadApiOpenRpc::module_doc() } } @@ -296,6 +270,6 @@ impl SuiRpcModule for TransactionBuilderImpl { } fn rpc_doc_module() -> Module { - crate::api::RpcTransactionBuilderOpenRpc::module_doc() + sui_json_rpc_api::RpcTransactionBuilderOpenRpc::module_doc() } } diff --git a/crates/sui-gateway/src/json_rpc.rs b/crates/sui-json-rpc/src/lib.rs similarity index 86% rename from crates/sui-gateway/src/json_rpc.rs rename to crates/sui-json-rpc/src/lib.rs index b2b54e71b926c..8ee417a09d3f5 100644 --- a/crates/sui-gateway/src/json_rpc.rs +++ b/crates/sui-json-rpc/src/lib.rs @@ -1,21 +1,24 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -use crate::api::SuiRpcModule; -use anyhow::Result; -use jsonrpsee::{ - http_server::{AccessControlBuilder, HttpServerBuilder, HttpServerHandle}, - RpcModule, -}; +use jsonrpsee::http_server::{AccessControlBuilder, HttpServerBuilder, HttpServerHandle}; use jsonrpsee_core::middleware::Middleware; +use jsonrpsee_core::server::rpc_module::RpcModule; + use once_cell::sync::Lazy; use prometheus_exporter::prometheus::{ register_histogram_vec, register_int_counter_vec, HistogramVec, IntCounterVec, }; -use std::{env, net::SocketAddr, time::Instant}; -use sui_open_rpc::Project; +use std::env; +use std::net::SocketAddr; +use std::time::Instant; +use sui_open_rpc::{Module, Project}; use tracing::info; +pub mod bcs_api; +pub mod gateway_api; +pub mod read_api; + pub struct JsonRpcServerBuilder { module: RpcModule<()>, server_builder: HttpServerBuilder, @@ -35,7 +38,7 @@ pub fn sui_rpc_doc() -> Project { } impl JsonRpcServerBuilder { - pub fn new() -> Result { + pub fn new() -> anyhow::Result { let mut ac_builder = AccessControlBuilder::default(); if let Ok(value) = env::var("ACCESS_CONTROL_ALLOW_ORIGIN") { @@ -60,12 +63,15 @@ impl JsonRpcServerBuilder { }) } - pub fn register_module(&mut self, module: T) -> Result<()> { + pub fn register_module(&mut self, module: T) -> Result<(), anyhow::Error> { self.rpc_doc.add_module(T::rpc_doc_module()); self.module.merge(module.rpc()).map_err(Into::into) } - pub async fn start(mut self, listen_address: SocketAddr) -> Result { + pub async fn start( + mut self, + listen_address: SocketAddr, + ) -> Result { self.module .register_method("rpc.discover", move |_, _| Ok(self.rpc_doc.clone()))?; @@ -137,3 +143,11 @@ impl Middleware for JsonRpcMetrics { } } } + +pub trait SuiRpcModule +where + Self: Sized, +{ + fn rpc(self) -> RpcModule; + fn rpc_doc_module() -> Module; +} diff --git a/crates/sui-gateway/src/read_api.rs b/crates/sui-json-rpc/src/read_api.rs similarity index 88% rename from crates/sui-gateway/src/read_api.rs rename to crates/sui-json-rpc/src/read_api.rs index cc61a65b65c22..591ffdb27dafa 100644 --- a/crates/sui-gateway/src/read_api.rs +++ b/crates/sui-json-rpc/src/read_api.rs @@ -1,19 +1,19 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -use crate::api::RpcReadApiServer; -use crate::api::{RpcFullNodeReadApiServer, SuiRpcModule}; +use crate::SuiRpcModule; use anyhow::anyhow; use async_trait::async_trait; use jsonrpsee::core::RpcResult; use jsonrpsee_core::server::rpc_module::RpcModule; use std::sync::Arc; +use sui_core::authority::AuthorityState; use sui_core::gateway_state::GatewayTxSeqNumber; -use sui_core::gateway_types::SuiObjectInfo; -use sui_core::{ - authority::AuthorityState, - gateway_types::{GetObjectDataResponse, TransactionEffectsResponse}, +use sui_json_rpc_api::rpc_types::{ + GetObjectDataResponse, SuiObjectInfo, TransactionEffectsResponse, }; +use sui_json_rpc_api::RpcFullNodeReadApiServer; +use sui_json_rpc_api::RpcReadApiServer; use sui_open_rpc::Module; use sui_types::base_types::{ObjectID, SuiAddress, TransactionDigest}; use sui_types::object::Owner; @@ -100,9 +100,11 @@ impl RpcReadApiServer for ReadApi { &self, digest: TransactionDigest, ) -> RpcResult { + let (cert, effects) = self.state.get_transaction(digest).await?; Ok(TransactionEffectsResponse { + certificate: cert.try_into()?, + effects: effects.into(), timestamp_ms: self.state.get_timestamp_ms(&digest).await?, - ..self.state.get_transaction(digest).await? }) } } @@ -113,7 +115,7 @@ impl SuiRpcModule for ReadApi { } fn rpc_doc_module() -> Module { - crate::api::RpcReadApiOpenRpc::module_doc() + sui_json_rpc_api::RpcReadApiOpenRpc::module_doc() } } @@ -157,6 +159,6 @@ impl SuiRpcModule for FullNodeApi { } fn rpc_doc_module() -> Module { - crate::api::RpcFullNodeReadApiOpenRpc::module_doc() + sui_json_rpc_api::RpcFullNodeReadApiOpenRpc::module_doc() } } diff --git a/crates/sui-node/Cargo.toml b/crates/sui-node/Cargo.toml index ed8f674a45d85..3ece92336ef6b 100644 --- a/crates/sui-node/Cargo.toml +++ b/crates/sui-node/Cargo.toml @@ -16,13 +16,16 @@ tracing = "0.1.34" parking_lot = "0.12.1" futures = "0.3.21" jsonrpsee = { version = "0.13.1", features = ["full"] } +jsonrpsee-core = "0.13.1" +async-trait = "0.1.53" sui-config = { path = "../sui-config" } sui-core = { path = "../sui-core" } sui-storage = { path = "../sui-storage" } -sui-gateway = { path = "../sui-gateway" } sui-network = { path = "../sui-network" } -sui-quorum-driver = { path = "../sui-quorum-driver" } +sui-json-rpc = { path = "../sui-json-rpc" } +sui-open-rpc = { path = "../sui-open-rpc" } +sui-types = { path = "../sui-types" } telemetry-subscribers = { git = "https://github.com/MystenLabs/mysten-infra", rev = "ff5c1d69057fe93be658377462ca2875a57a0223" } mysten-network = { git = "https://github.com/MystenLabs/mysten-infra", rev = "ff5c1d69057fe93be658377462ca2875a57a0223" } diff --git a/crates/sui-node/src/lib.rs b/crates/sui-node/src/lib.rs index 1c2e29746d6b2..bfc1abd0dd144 100644 --- a/crates/sui-node/src/lib.rs +++ b/crates/sui-node/src/lib.rs @@ -13,13 +13,15 @@ use sui_core::{ authority_client::NetworkAuthorityClient, checkpoints::CheckpointStore, }; -use sui_gateway::bcs_api::BcsApiImpl; -use sui_gateway::json_rpc::JsonRpcServerBuilder; -use sui_gateway::read_api::{FullNodeApi, ReadApi}; +use sui_json_rpc::bcs_api::BcsApiImpl; +use sui_json_rpc::JsonRpcServerBuilder; use sui_network::api::ValidatorServer; use sui_storage::{follower_store::FollowerStore, IndexStore}; use tracing::info; +use sui_json_rpc::read_api::FullNodeApi; +use sui_json_rpc::read_api::ReadApi; + pub struct SuiNode { grpc_server: tokio::task::JoinHandle>, _json_rpc_service: Option, diff --git a/crates/sui-open-rpc/spec/openrpc.json b/crates/sui-open-rpc/spec/openrpc.json index c7a4a9e6fb166..43b80284ab803 100644 --- a/crates/sui-open-rpc/spec/openrpc.json +++ b/crates/sui-open-rpc/spec/openrpc.json @@ -19,7 +19,7 @@ "name": "sui_executeTransaction", "tags": [ { - "name": "Gateway API" + "name": "Quorum Driver API" } ], "description": "Execute the transaction using the transaction data, signature and public key.", @@ -907,7 +907,7 @@ "name": "sui_syncAccountState", "tags": [ { - "name": "Gateway API" + "name": "Quorum Driver API" } ], "description": "Synchronize client state with validators.", diff --git a/crates/sui/Cargo.toml b/crates/sui/Cargo.toml index 56b6867e8f6ca..06a3d5363f773 100644 --- a/crates/sui/Cargo.toml +++ b/crates/sui/Cargo.toml @@ -52,8 +52,9 @@ sui-open-rpc-macros = { path = "../sui-open-rpc-macros" } sui-json = { path = "../sui-json" } sui-gateway = { path = "../sui-gateway" } sui-node = { path = "../sui-node" } -sui-quorum-driver = { path = "../sui-quorum-driver" } sui-swarm = { path = "../sui-swarm" } +sui-json-rpc = { path = "../sui-json-rpc" } +sui-json-rpc-api = { path = "../sui-json-rpc-api" } rustyline = "9.1.2" rustyline-derive = "0.6.0" @@ -83,6 +84,7 @@ pretty_assertions = "1.2.0" tokio-util = { version = "0.7.2", features = ["codec"] } typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "ff5c1d69057fe93be658377462ca2875a57a0223"} test-utils = { path = "../test-utils" } +sui-quorum-driver = { path = "../sui-quorum-driver" } [features] benchmark = ["narwhal-node/benchmark"] diff --git a/crates/sui/src/bin/rpc-server.rs b/crates/sui/src/bin/rpc-server.rs index 44666d4db32e0..eff196ec3c416 100644 --- a/crates/sui/src/bin/rpc-server.rs +++ b/crates/sui/src/bin/rpc-server.rs @@ -8,9 +8,11 @@ use std::{ }; use sui_config::sui_config_dir; use sui_config::SUI_GATEWAY_CONFIG; -use sui_gateway::bcs_api::BcsApiImpl; -use sui_gateway::rpc_gateway::{create_client, GatewayReadApiImpl, TransactionBuilderImpl}; -use sui_gateway::{json_rpc::JsonRpcServerBuilder, rpc_gateway::RpcGatewayImpl}; +use sui_gateway::create_client; +use sui_json_rpc::bcs_api::BcsApiImpl; +use sui_json_rpc::gateway_api::RpcGatewayImpl; +use sui_json_rpc::gateway_api::{GatewayReadApiImpl, TransactionBuilderImpl}; +use sui_json_rpc::JsonRpcServerBuilder; use tracing::info; const DEFAULT_RPC_SERVER_PORT: &str = "5001"; diff --git a/crates/sui/src/bin/wallet.rs b/crates/sui/src/bin/wallet.rs index 45412f7dd9542..7431ec3a2ae0b 100644 --- a/crates/sui/src/bin/wallet.rs +++ b/crates/sui/src/bin/wallet.rs @@ -33,7 +33,7 @@ const SUI: &str = " _____ _ _ __ ____ __ #[derive(Parser)] #[clap( - name = "wallet", + name = "sui-cli", about = "A Byzantine fault tolerant chain with low-latency finality and high throughput", rename_all = "kebab-case" )] @@ -138,7 +138,7 @@ async fn try_main() -> Result<(), anyhow::Error> { version.push('-'); version.push_str(git_rev); } - writeln!(out, "--- sui wallet {version} ---")?; + writeln!(out, "--- Sui CLI {version} ---")?; writeln!(out)?; writeln!(out, "{}", context.config.deref())?; writeln!(out, "Welcome to the Sui interactive shell.")?; diff --git a/crates/sui/src/unit_tests/cli_tests.rs b/crates/sui/src/unit_tests/cli_tests.rs index b85b394bcc239..124b13d2d38e4 100644 --- a/crates/sui/src/unit_tests/cli_tests.rs +++ b/crates/sui/src/unit_tests/cli_tests.rs @@ -18,8 +18,8 @@ use sui_config::{ Config, NetworkConfig, PersistedConfig, SUI_FULLNODE_CONFIG, SUI_GATEWAY_CONFIG, SUI_GENESIS_FILENAME, SUI_NETWORK_CONFIG, SUI_WALLET_CONFIG, }; -use sui_core::gateway_types::{GetObjectDataResponse, SuiParsedObject, SuiTransactionEffects}; use sui_json::SuiJsonValue; +use sui_json_rpc_api::rpc_types::{GetObjectDataResponse, SuiParsedObject, SuiTransactionEffects}; use sui_types::{ base_types::{ObjectID, SuiAddress}, crypto::get_key_pair, diff --git a/crates/sui/src/unit_tests/rpc_server_tests.rs b/crates/sui/src/unit_tests/rpc_server_tests.rs index 8c51b1d85df8c..514258c6e4367 100644 --- a/crates/sui/src/unit_tests/rpc_server_tests.rs +++ b/crates/sui/src/unit_tests/rpc_server_tests.rs @@ -4,14 +4,14 @@ use std::{path::Path, str::FromStr}; use sui::keystore::{Keystore, SuiKeystore}; use sui_core::gateway_state::GatewayTxSeqNumber; -use sui_core::gateway_types::{ +use sui_framework::build_move_package_to_bytes; +use sui_json::SuiJsonValue; +use sui_json_rpc_api::rpc_types::{ GetObjectDataResponse, TransactionEffectsResponse, TransactionResponse, }; -use sui_framework::build_move_package_to_bytes; -use sui_gateway::api::{ - RpcGatewayApiClient, RpcReadApiClient, RpcTransactionBuilderClient, TransactionBytes, +use sui_json_rpc_api::{ + QuorumDriverApiClient, RpcReadApiClient, RpcTransactionBuilderClient, TransactionBytes, }; -use sui_json::SuiJsonValue; use sui_types::sui_serde::Base64; use sui_types::{ base_types::{ObjectID, TransactionDigest}, diff --git a/crates/sui/src/wallet_commands.rs b/crates/sui/src/wallet_commands.rs index dfb5a55865927..607e02b967558 100644 --- a/crates/sui/src/wallet_commands.rs +++ b/crates/sui/src/wallet_commands.rs @@ -15,16 +15,18 @@ use colored::Colorize; use move_core_types::{language_storage::TypeTag, parser::parse_type_tag}; use serde::Serialize; use serde_json::json; -use sui_core::gateway_types::{ +use sui_json_rpc_api::rpc_types::{ GetObjectDataResponse, MergeCoinResponse, PublishResponse, SplitCoinResponse, SuiObjectInfo, SuiParsedObject, }; use tracing::info; use sui_core::gateway_state::GatewayClient; -use sui_core::gateway_types::{SuiCertifiedTransaction, SuiExecutionStatus, SuiTransactionEffects}; use sui_framework::build_move_package_to_bytes; use sui_json::SuiJsonValue; +use sui_json_rpc_api::rpc_types::{ + SuiCertifiedTransaction, SuiExecutionStatus, SuiTransactionEffects, +}; use sui_types::object::Owner; use sui_types::sui_serde::{Base64, Encoding}; use sui_types::{ diff --git a/crates/test-utils/Cargo.toml b/crates/test-utils/Cargo.toml index c42a55696e978..791a9affc9005 100644 --- a/crates/test-utils/Cargo.toml +++ b/crates/test-utils/Cargo.toml @@ -36,4 +36,6 @@ sui-network = { path = "../sui-network" } sui-node = { path = "../sui-node" } sui-swarm = { path = "../sui-swarm" } sui = { path = "../sui" } +sui-json-rpc = { path = "../sui-json-rpc" } +sui-json-rpc-api = { path = "../sui-json-rpc-api" } workspace-hack = { path = "../workspace-hack"} diff --git a/crates/test-utils/src/network.rs b/crates/test-utils/src/network.rs index 8e4b0cb83a573..c6d1b397dd4c8 100644 --- a/crates/test-utils/src/network.rs +++ b/crates/test-utils/src/network.rs @@ -14,12 +14,11 @@ use sui::{ use sui_config::genesis_config::GenesisConfig; use sui_config::PersistedConfig; use sui_config::{Config, SUI_GATEWAY_CONFIG, SUI_NETWORK_CONFIG, SUI_WALLET_CONFIG}; -use sui_gateway::api::RpcGatewayApiServer; -use sui_gateway::api::RpcReadApiServer; -use sui_gateway::api::RpcTransactionBuilderServer; -use sui_gateway::rpc_gateway::{ - create_client, GatewayReadApiImpl, RpcGatewayImpl, TransactionBuilderImpl, -}; +use sui_gateway::create_client; +use sui_json_rpc::gateway_api::{GatewayReadApiImpl, RpcGatewayImpl, TransactionBuilderImpl}; +use sui_json_rpc_api::QuorumDriverApiServer; +use sui_json_rpc_api::RpcReadApiServer; +use sui_json_rpc_api::RpcTransactionBuilderServer; use sui_swarm::memory::Swarm; use sui_types::base_types::SuiAddress; const NUM_VALIDAOTR: usize = 4;