Skip to content

Commit

Permalink
[RPC API] - add raw BCS API for RPC (MystenLabs#2376)
Browse files Browse the repository at this point in the history
* add raw bcs get object endpoint

* encode bcs bytes in b64

* fixup after rebase

* fixup after rebase
  • Loading branch information
patrickkuo authored Jun 6, 2022
1 parent 50300a4 commit 6f36055
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 100 deletions.
2 changes: 2 additions & 0 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 crates/generate-json-rpc-spec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use sui_core::gateway_types::{
GetObjectDataResponse, SuiObjectInfo, TransactionEffectsResponse, TransactionResponse,
};
use sui_gateway::api::SuiRpcModule;
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};
Expand Down Expand Up @@ -66,6 +67,7 @@ async fn main() {
open_rpc.add_module(GatewayReadApiImpl::rpc_doc_module());
open_rpc.add_module(ReadApi::rpc_doc_module());
open_rpc.add_module(FullNodeApi::rpc_doc_module());
open_rpc.add_module(BcsApiImpl::rpc_doc_module());

match options.action {
Action::Print => {
Expand Down
3 changes: 2 additions & 1 deletion crates/sui-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ ed25519-dalek = "1.0.1"
scopeguard = "1.1.0"
clap = { version = "3.1.17", features = ["derive"] }
bincode = "1.3.3"
schemars = "0.8.10"
schemars = {version = "0.8.10", features = ["either"]}
either = "1.6.1"
multiaddr = "0.14.0"
mysten-network = { git = "https://github.com/MystenLabs/mysten-infra", rev = "ff5c1d69057fe93be658377462ca2875a57a0223" }
prometheus_exporter = "0.8.4"
Expand Down
26 changes: 23 additions & 3 deletions crates/sui-core/src/gateway_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ pub trait GatewayAPI {
async fn get_object(&self, object_id: ObjectID)
-> Result<GetObjectDataResponse, anyhow::Error>;

/// Get the object data
async fn get_raw_object(
&self,
object_id: ObjectID,
) -> Result<GetRawObjectDataResponse, anyhow::Error>;

/// Get refs of all objects we own from local cache.
async fn get_objects_owned_by_address(
&self,
Expand Down Expand Up @@ -366,15 +372,21 @@ where
})
}

async fn get_sui_object(&self, object_id: &ObjectID) -> Result<SuiObject, anyhow::Error> {
async fn get_sui_object<T: SuiMoveObject>(
&self,
object_id: &ObjectID,
) -> Result<SuiObject<T>, anyhow::Error> {
let object = self.get_object_internal(object_id).await?;
self.to_sui_object(object)
}

fn to_sui_object(&self, object: Object) -> Result<SuiObject, anyhow::Error> {
fn to_sui_object<T: SuiMoveObject>(
&self,
object: Object,
) -> Result<SuiObject<T>, anyhow::Error> {
let cache = ModuleCache::new(&*self.store);
let layout = object.get_layout(ObjectFormatOptions::default(), &cache)?;
SuiObject::try_from(object, layout)
SuiObject::<T>::try_from(object, layout)
}

async fn get_object_ref(&self, object_id: &ObjectID) -> SuiResult<ObjectRef> {
Expand Down Expand Up @@ -1111,6 +1123,14 @@ where
Ok(result.try_into()?)
}

async fn get_raw_object(
&self,
object_id: ObjectID,
) -> Result<GetRawObjectDataResponse, anyhow::Error> {
let result = self.download_object_from_authorities(object_id).await?;
Ok(result.try_into()?)
}

async fn get_objects_owned_by_address(
&self,
account_addr: SuiAddress,
Expand Down
Loading

0 comments on commit 6f36055

Please sign in to comment.