Skip to content

Commit

Permalink
Feature/open rpc (rooch-network#275)
Browse files Browse the repository at this point in the history
* rooch api open rpc done

* fix merge conflict
  • Loading branch information
wow-sven authored Jun 13, 2023
1 parent ee98712 commit 6d3f1d1
Show file tree
Hide file tree
Showing 26 changed files with 2,873 additions and 112 deletions.
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
too-many-arguments-threshold = 10
22 changes: 17 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ members = [
"crates/rooch-sequencer",
"crates/rooch-executor",
"crates/rooch-proposer",
"crates/rooch-open-rpc",
"crates/rooch-open-rpc-macros"
]

default-members = [
Expand Down Expand Up @@ -68,10 +70,12 @@ rooch-genesis = { path = "crates/rooch-genesis" }
rooch-server = { path = "crates/rooch-server" }
rooch-client = { path = "crates/rooch-client" }
rooch-testsuite = { path = "crates/testsuite" }
rooch-config = {path = "crates/rooch-config"}
rooch-sequencer = {path = "crates/rooch-sequencer"}
rooch-executor = {path = "crates/rooch-executor"}
rooch-proposer = {path = "crates/rooch-proposer"}
rooch-config = { path = "crates/rooch-config" }
rooch-sequencer = { path = "crates/rooch-sequencer" }
rooch-executor = { path = "crates/rooch-executor" }
rooch-proposer = { path = "crates/rooch-proposer" }
rooch-open-rpc = { path = "crates/rooch-open-rpc" }
rooch-open-rpc-macros = { path = "crates/rooch-open-rpc-macros" }

# External crate dependencies.
# Please do not add any test features here: they should be declared by the individual crate.
Expand Down Expand Up @@ -101,7 +105,7 @@ fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "c27e87fb
futures = "0.3"
hex = "0.4.3"
rustc-hex = "1.0"
itertools = "0.10.3"
itertools = "0.10.5"
jsonrpsee = { version = "0.16", features = ["full"] }
jpst = "0.1.1"
lazy_static = "1.4.0"
Expand Down Expand Up @@ -145,6 +149,14 @@ tracing = "0.1"
tracing-subscriber = "0.3"
codespan-reporting = "0.11.1"
termcolor = "1.1.2"
versions = "4.1.0"
pretty_assertions = "1.2.0"
syn = { version = "1.0.104", features = ["full", "extra-traits"] }
quote = "1.0"
proc-macro2 = "1.0"
derive-syn-parse = "0.1.5"
unescape = "0.1.0"


# Note: the BEGIN and END comments below are required for external tooling. Do not remove.
# BEGIN MOVE DEPENDENCIES
Expand Down
16 changes: 11 additions & 5 deletions crates/rooch-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rooch_types::{address::RoochAddress, transaction::rooch::RoochTransaction, H

pub mod client_config;
pub mod wallet_context;
use rooch_server::jsonrpc_types::{EventPage, StructTagView};
use rooch_server::jsonrpc_types::{EventPageView, StructTagView};
use std::sync::Arc;
use std::time::Duration;

Expand Down Expand Up @@ -82,6 +82,8 @@ pub struct Client {
rpc: Arc<RpcClient>,
}

// TODO: call args are uniformly defined in jsonrpc types?
// example execute_view_function get_events_by_event_handle
impl Client {
pub async fn execute_tx(&self, tx: RoochTransaction) -> Result<ExecuteTransactionResponseView> {
let tx_payload = bcs::to_bytes(&tx)?;
Expand All @@ -104,18 +106,22 @@ impl Client {
}

pub async fn get_states(&self, access_path: AccessPath) -> Result<Vec<Option<StateView>>> {
Ok(self.rpc.http.get_states(access_path).await?)
Ok(self.rpc.http.get_states(access_path.into()).await?)
}

pub async fn get_annotated_states(
&self,
access_path: AccessPath,
) -> Result<Vec<Option<AnnotatedStateView>>> {
Ok(self.rpc.http.get_annotated_states(access_path).await?)
Ok(self
.rpc
.http
.get_annotated_states(access_path.into())
.await?)
}

pub async fn get_transaction_by_hash(&self, hash: H256) -> Result<Option<TransactionView>> {
Ok(self.rpc.http.get_transaction_by_hash(hash).await?)
Ok(self.rpc.http.get_transaction_by_hash(hash.into()).await?)
}

pub async fn get_transaction_by_index(
Expand All @@ -139,7 +145,7 @@ impl Client {
event_handle_type: StructTagView,
cursor: Option<u64>,
limit: Option<u64>,
) -> Result<EventPage> {
) -> Result<EventPageView> {
let s = self
.rpc
.http
Expand Down
24 changes: 24 additions & 0 deletions crates/rooch-open-rpc-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "rooch-open-rpc-macros"
version = "0.1.0"

# Workspace inherited keys
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
publish = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
proc-macro = true

[dependencies]
syn = { workspace = true , features = ["full", "extra-traits"] }
quote = { workspace = true }
proc-macro2 = { workspace = true }
itertools = { workspace = true }
derive-syn-parse = { workspace = true }
unescape = { workspace = true }
Loading

0 comments on commit 6d3f1d1

Please sign in to comment.