Skip to content

Commit

Permalink
unify and rename for RPC and store (#817)
Browse files Browse the repository at this point in the history
* unify and rename for RPC and store

* handle rpc error
  • Loading branch information
baichuan3 authored Sep 15, 2023
1 parent ac6a11c commit 2d678a5
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 290 deletions.
211 changes: 5 additions & 206 deletions crates/rooch-open-rpc-spec/schemas/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,36 +136,6 @@
}
}
},
{
"name": "rooch_getEvents",
"description": "Get the events by event filter",
"params": [
{
"name": "filter",
"required": true,
"schema": {
"$ref": "#/components/schemas/EventFilterView"
}
}
],
"result": {
"name": "Vec<Option<AnnotatedEventView>>",
"required": true,
"schema": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/AnnotatedEventView"
},
{
"type": "null"
}
]
}
}
}
},
{
"name": "rooch_getEventsByEventHandle",
"description": "Get the events by event handle id",
Expand Down Expand Up @@ -303,10 +273,10 @@
}
],
"result": {
"name": "TransactionReturnPageView",
"name": "TransactionResultPageView",
"required": true,
"schema": {
"$ref": "#/components/schemas/PageView_for_TransactionReturnView_and_uint128"
"$ref": "#/components/schemas/PageView_for_TransactionResultView_and_uint128"
}
}
},
Expand Down Expand Up @@ -606,177 +576,6 @@
}
}
},
"EventFilterView": {
"oneOf": [
{
"description": "Query by sender address.",
"type": "object",
"required": [
"Sender"
],
"properties": {
"Sender": {
"$ref": "#/components/schemas/move_core_types::account_address::AccountAddress"
}
},
"additionalProperties": false
},
{
"description": "Return events emitted by the given transaction.",
"type": "object",
"required": [
"Transaction"
],
"properties": {
"Transaction": {
"$ref": "#/components/schemas/H256View"
}
},
"additionalProperties": false
},
{
"description": "Return events with the given move event struct name",
"type": "object",
"required": [
"MoveEventType"
],
"properties": {
"MoveEventType": {
"$ref": "#/components/schemas/move_core_types::language_storage::TypeTag"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"MoveEventField"
],
"properties": {
"MoveEventField": {
"type": "object",
"required": [
"path",
"value"
],
"properties": {
"path": {
"type": "string"
},
"value": true
}
}
},
"additionalProperties": false
},
{
"description": "Return events emitted in [start_time, end_time) interval",
"type": "object",
"required": [
"TimeRange"
],
"properties": {
"TimeRange": {
"type": "object",
"required": [
"end_time",
"start_time"
],
"properties": {
"end_time": {
"description": "right endpoint of time interval, milliseconds since epoch, exclusive",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"start_time": {
"description": "left endpoint of time interval, milliseconds since epoch, inclusive",
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
}
},
"additionalProperties": false
},
{
"description": "Return events emitted in [from_block, to_block) interval",
"type": "object",
"required": [
"All"
],
"properties": {
"All": {
"type": "array",
"items": {
"$ref": "#/components/schemas/EventFilterView"
}
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"Any"
],
"properties": {
"Any": {
"type": "array",
"items": {
"$ref": "#/components/schemas/EventFilterView"
}
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"And"
],
"properties": {
"And": {
"type": "array",
"items": [
{
"$ref": "#/components/schemas/EventFilterView"
},
{
"$ref": "#/components/schemas/EventFilterView"
}
],
"maxItems": 2,
"minItems": 2
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"Or"
],
"properties": {
"Or": {
"type": "array",
"items": [
{
"$ref": "#/components/schemas/EventFilterView"
},
{
"$ref": "#/components/schemas/EventFilterView"
}
],
"maxItems": 2,
"minItems": 2
}
},
"additionalProperties": false
}
]
},
"EventID": {
"description": "A struct that represents a globally unique id for an Event stream that a user can listen to. the Unique ID is a combination of event handle id and event seq number. the ID is local to this particular fullnode and will be different from other fullnode.",
"type": "object",
Expand Down Expand Up @@ -1271,7 +1070,7 @@
}
}
},
"PageView_for_TransactionReturnView_and_uint128": {
"PageView_for_TransactionResultView_and_uint128": {
"description": "`next_cursor` points to the last item in the page; Reading with `next_cursor` will start from the next item after `next_cursor` if `next_cursor` is `Some`, otherwise it will start from the first item.",
"type": "object",
"required": [
Expand All @@ -1282,7 +1081,7 @@
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TransactionReturnView"
"$ref": "#/components/schemas/TransactionResultView"
}
},
"has_next_page": {
Expand Down Expand Up @@ -1463,7 +1262,7 @@
}
}
},
"TransactionReturnView": {
"TransactionResultView": {
"type": "object",
"required": [
"execution_info",
Expand Down
24 changes: 12 additions & 12 deletions crates/rooch-rpc-api/src/api/rooch_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

use crate::jsonrpc_types::{
AccessPathView, AccountAddressView, AnnotatedEventView, AnnotatedFunctionResultView,
AnnotatedStateView, EventFilterView, EventPageView, ExecuteTransactionResponseView,
FunctionCallView, H256View, ListAnnotatedStatesPageView, ListBalanceInfoPageView,
ListStatesPageView, StateView, StrView, StructTagView, TransactionReturnPageView,
TransactionView,
AccessPathView, AccountAddressView, AnnotatedFunctionResultView, AnnotatedStateView,
EventPageView, ExecuteTransactionResponseView, FunctionCallView, H256View,
ListAnnotatedStatesPageView, ListBalanceInfoPageView, ListStatesPageView, StateView, StrView,
StructTagView, TransactionResultPageView, TransactionView,
};
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;
Expand Down Expand Up @@ -79,12 +78,13 @@ pub trait RoochAPI {
limit: Option<u64>,
) -> RpcResult<EventPageView>;

/// Get the events by event filter
#[method(name = "getEvents")]
async fn get_events(
&self,
filter: EventFilterView,
) -> RpcResult<Vec<Option<AnnotatedEventView>>>;
// The current scenario of querying events can be satisfied by getEventsByEventHandle. GetEvents by EventFilter will be enabled after Indexer is supported.
// /// Get the events by event filter
// #[method(name = "getEvents")]
// async fn get_events(
// &self,
// filter: EventFilterView,
// ) -> RpcResult<Vec<Option<AnnotatedEventView>>>;

#[method(name = "getTransactionByHash")]
async fn get_transaction_by_hash(&self, hash: H256View) -> RpcResult<Option<TransactionView>>;
Expand All @@ -100,7 +100,7 @@ pub trait RoochAPI {
&self,
cursor: Option<u128>,
limit: Option<u64>,
) -> RpcResult<TransactionReturnPageView>;
) -> RpcResult<TransactionResultPageView>;

/// get account balances by AccountAddress
#[method(name = "getBalances")]
Expand Down
4 changes: 2 additions & 2 deletions crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::jsonrpc_types::account_view::BalanceInfoView;
use crate::jsonrpc_types::transaction_view::TransactionReturnView;
use crate::jsonrpc_types::transaction_view::TransactionResultView;
use crate::jsonrpc_types::{
move_types::{MoveActionTypeView, MoveActionView},
AnnotatedMoveStructView, AnnotatedStateView, EventView, H256View, StateView, StrView,
Expand All @@ -22,7 +22,7 @@ use std::string::String;
use super::AccountAddressView;

pub type EventPageView = PageView<Option<AnnotatedEventView>, u64>;
pub type TransactionReturnPageView = PageView<TransactionReturnView, u128>;
pub type TransactionResultPageView = PageView<TransactionResultView, u128>;
pub type ListStatesPageView = PageView<Option<StateView>, StrView<Vec<u8>>>;
pub type ListAnnotatedStatesPageView = PageView<Option<AnnotatedStateView>, StrView<Vec<u8>>>;
pub type ListBalanceInfoPageView = PageView<Option<BalanceInfoView>, StrView<Vec<u8>>>;
Expand Down
8 changes: 4 additions & 4 deletions crates/rooch-rpc-api/src/jsonrpc_types/transaction_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone)]
pub struct TransactionReturn {
pub struct TransactionResult {
pub transaction: TypedTransaction,
pub sequence_info: TransactionSequenceInfo,
pub execution_info: TransactionExecutionInfo,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct TransactionReturnView {
pub struct TransactionResultView {
pub transaction: TransactionView,
pub sequence_info: TransactionSequenceInfoView,
pub execution_info: TransactionExecutionInfoView,
}

impl From<TransactionReturn> for TransactionReturnView {
fn from(tx: TransactionReturn) -> Self {
impl From<TransactionResult> for TransactionResultView {
fn from(tx: TransactionResult) -> Self {
Self {
transaction: tx.transaction.into(),
sequence_info: tx.sequence_info.into(),
Expand Down
Loading

0 comments on commit 2d678a5

Please sign in to comment.