Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RPC] Make event rpc page view no nullable #972

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/check_build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ jobs:
- name: Check code format
run: cargo fmt -- --check
- name: Lint rust sources
#FIXME mkdir is a workaroud solution for https://github.com/rooch-network/rooch/issues/968
run: mkdir -p crates/rooch/public/dashboard/ && ./scripts/pr.sh -c
run: ./scripts/pr.sh -c
- name: Build
run: cargo build
- name: Execute rust tests
Expand Down
42 changes: 18 additions & 24 deletions crates/rooch-executor/src/actor/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl Handler<GetEventsByEventHandleMessage> for ExecutorActor {
&mut self,
msg: GetEventsByEventHandleMessage,
_ctx: &mut ActorContext,
) -> Result<Vec<Option<AnnotatedMoveOSEvent>>> {
) -> Result<Vec<AnnotatedMoveOSEvent>> {
let GetEventsByEventHandleMessage {
event_handle_type,
cursor,
Expand All @@ -397,24 +397,20 @@ impl Handler<GetEventsByEventHandleMessage> for ExecutorActor {
let event_handle_id = EventHandle::derive_event_handle_id(event_handle_type.clone());
let events = event_store.get_events_by_event_handle_id(&event_handle_id, cursor, limit)?;

// for ev in events
let result = events
events
.into_iter()
// .enumerate()
.map(|event| {
let state = State::new(event.event_data.clone(), event.type_tag.clone());
let annotated_event_data = MoveValueAnnotator::new(resolver)
.view_resource(&event_handle_type, state.value.as_slice())
.unwrap();
Some(AnnotatedMoveOSEvent::new(
.view_resource(&event_handle_type, state.value.as_slice())?;
Ok(AnnotatedMoveOSEvent::new(
event,
annotated_event_data,
None,
None,
))
})
.collect();
Ok(result)
.collect::<Result<Vec<_>>>()
}
}

Expand All @@ -424,29 +420,27 @@ impl Handler<GetEventsMessage> for ExecutorActor {
&mut self,
msg: GetEventsMessage,
_ctx: &mut ActorContext,
) -> Result<Vec<Option<AnnotatedMoveOSEvent>>> {
) -> Result<Vec<AnnotatedMoveOSEvent>> {
let GetEventsMessage { filter } = msg;
let event_store = self.moveos.event_store();
let resolver = self.moveos.moveos_resolver();
//TODO handle tx hash
let mut result: Vec<Option<AnnotatedMoveOSEvent>> = Vec::new();

let events = event_store.get_events_with_filter(filter)?;
for ev in events
events
.into_iter()
.enumerate()
.map(|(_i, event)| {
.map(|event| {
let state = State::new(event.event_data.clone(), event.type_tag.clone());
let struct_tag = as_struct_tag(event.type_tag.clone()).unwrap();
let struct_tag = as_struct_tag(event.type_tag.clone())?;
let annotated_event_data = MoveValueAnnotator::new(resolver)
.view_resource(&struct_tag, state.value.as_slice())
.unwrap();
AnnotatedMoveOSEvent::new(event, annotated_event_data, None, None)
.view_resource(&struct_tag, state.value.as_slice())?;
Ok(AnnotatedMoveOSEvent::new(
event,
annotated_event_data,
None,
None,
))
})
.collect::<Vec<_>>()
{
result.push(Some(ev));
}
Ok(result)
.collect::<Result<Vec<_>>>()
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/rooch-executor/src/actor/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub struct GetEventsByEventHandleMessage {
}

impl Message for GetEventsByEventHandleMessage {
type Result = Result<Vec<Option<AnnotatedMoveOSEvent>>>;
type Result = Result<Vec<AnnotatedMoveOSEvent>>;
}

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -121,7 +121,7 @@ pub struct GetEventsMessage {
}

impl Message for GetEventsMessage {
type Result = Result<Vec<Option<AnnotatedMoveOSEvent>>>;
type Result = Result<Vec<AnnotatedMoveOSEvent>>;
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
7 changes: 2 additions & 5 deletions crates/rooch-executor/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl ExecutorProxy {
event_handle_type: StructTag,
cursor: Option<u64>,
limit: u64,
) -> Result<Vec<Option<AnnotatedMoveOSEvent>>> {
) -> Result<Vec<AnnotatedMoveOSEvent>> {
self.actor
.send(GetEventsByEventHandleMessage {
event_handle_type,
Expand All @@ -127,10 +127,7 @@ impl ExecutorProxy {
.await?
}

pub async fn get_events(
&self,
filter: EventFilter,
) -> Result<Vec<Option<AnnotatedMoveOSEvent>>> {
pub async fn get_events(&self, filter: EventFilter) -> Result<Vec<AnnotatedMoveOSEvent>> {
self.actor.send(GetEventsMessage { filter }).await?
}

Expand Down
49 changes: 21 additions & 28 deletions crates/rooch-open-rpc-spec/schemas/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
"name": "EventPageView",
"required": true,
"schema": {
"$ref": "#/components/schemas/PageView_for_Nullable_AnnotatedEventView_and_uint64"
"$ref": "#/components/schemas/PageView_for_AnnotatedEventView_and_uint64"
}
}
},
Expand Down Expand Up @@ -939,7 +939,7 @@
}
]
},
"PageView_for_AnnotatedStateView_and_alloc::vec::Vec<u8>": {
"PageView_for_AnnotatedEventView_and_uint64": {
"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 @@ -950,25 +950,23 @@
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/AnnotatedStateView"
"$ref": "#/components/schemas/AnnotatedEventView"
}
},
"has_next_page": {
"type": "boolean"
},
"next_cursor": {
"anyOf": [
{
"$ref": "#/components/schemas/alloc::vec::Vec<u8>"
},
{
"type": "null"
}
]
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
}
},
"PageView_for_BalanceInfoView_and_alloc::vec::Vec<u8>": {
"PageView_for_AnnotatedStateView_and_alloc::vec::Vec<u8>": {
"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 @@ -979,7 +977,7 @@
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BalanceInfoView"
"$ref": "#/components/schemas/AnnotatedStateView"
}
},
"has_next_page": {
Expand All @@ -997,7 +995,7 @@
}
}
},
"PageView_for_Nullable_AnnotatedEventView_and_uint64": {
"PageView_for_BalanceInfoView_and_alloc::vec::Vec<u8>": {
"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 @@ -1008,26 +1006,21 @@
"data": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/AnnotatedEventView"
},
{
"type": "null"
}
]
"$ref": "#/components/schemas/BalanceInfoView"
}
},
"has_next_page": {
"type": "boolean"
},
"next_cursor": {
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
"anyOf": [
{
"$ref": "#/components/schemas/alloc::vec::Vec<u8>"
},
{
"type": "null"
}
]
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::string::String;

pub type EventPageView = PageView<Option<AnnotatedEventView>, u64>;
pub type EventPageView = PageView<AnnotatedEventView, u64>;
pub type TransactionWithInfoPageView = PageView<TransactionWithInfoView, u128>;
pub type StatesPageView = PageView<StateView, StrView<Vec<u8>>>;
pub type AnnotatedStatesPageView = PageView<AnnotatedStateView, StrView<Vec<u8>>>;
Expand Down
10 changes: 5 additions & 5 deletions crates/rooch-rpc-server/src/server/rooch_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,19 @@ impl RoochAPIServer for RoochServer {
) -> RpcResult<EventPageView> {
// NOTE: fetch one more object to check if there is next page
let limit_of = min(limit.unwrap_or(DEFAULT_RESULT_LIMIT), MAX_RESULT_LIMIT);
let mut data: Vec<Option<AnnotatedEventView>> = self
let mut data: Vec<AnnotatedEventView> = self
.rpc_service
.get_events_by_event_handle(event_handle_type.into(), cursor, limit_of + 1)
.await?
.into_iter()
.map(|event| event.map(AnnotatedEventView::from))
.map(AnnotatedEventView::from)
.collect();

let has_next_page = (data.len() as u64) > limit_of;
data.truncate(limit_of as usize);
let next_cursor = data.last().map_or(cursor, |event| {
Some(event.clone().unwrap().event.event_id.event_seq)
});
let next_cursor = data
.last()
.map_or(cursor, |event| Some(event.event.event_id.event_seq));

Ok(EventPageView {
data,
Expand Down
7 changes: 2 additions & 5 deletions crates/rooch-rpc-server/src/service/rpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,15 @@ impl RpcService {
event_handle_type: StructTag,
cursor: Option<u64>,
limit: u64,
) -> Result<Vec<Option<AnnotatedMoveOSEvent>>> {
) -> Result<Vec<AnnotatedMoveOSEvent>> {
let resp = self
.executor
.get_events_by_event_handle(event_handle_type, cursor, limit)
.await?;
Ok(resp)
}

pub async fn get_events(
&self,
filter: EventFilter,
) -> Result<Vec<Option<AnnotatedMoveOSEvent>>> {
pub async fn get_events(&self, filter: EventFilter) -> Result<Vec<AnnotatedMoveOSEvent>> {
let resp = self.executor.get_events(filter).await?;
Ok(resp)
}
Expand Down
4 changes: 0 additions & 4 deletions crates/rooch/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"moveos_types_move_types_FunctionId": "RoochFunctionId",
"PageView_for_TransactionWithInfoView_and_uint128": "TransactionWithInfoPageView",
"PageView_for_AnnotatedStateView_and_alloc_vec_Vec_U8Array": "AnnotatedStatePageView",
"PageView_for_Nullable_AnnotatedEventView_and_uint64": "AnnotatedEventPageView",
"PageView_for_AnnotatedEventView_and_uint64": "AnnotatedEventPageView",
"PageView_for_StateView_and_alloc_vec_Vec_U8Array": "StatePageView"
}
Loading