diff --git a/.github/workflows/check_build_test.yml b/.github/workflows/check_build_test.yml index 70851ad678..8a9da7e471 100644 --- a/.github/workflows/check_build_test.yml +++ b/.github/workflows/check_build_test.yml @@ -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 diff --git a/crates/rooch-executor/src/actor/executor.rs b/crates/rooch-executor/src/actor/executor.rs index 6a6ce3a8ee..2714b3eaa4 100644 --- a/crates/rooch-executor/src/actor/executor.rs +++ b/crates/rooch-executor/src/actor/executor.rs @@ -385,7 +385,7 @@ impl Handler for ExecutorActor { &mut self, msg: GetEventsByEventHandleMessage, _ctx: &mut ActorContext, - ) -> Result>> { + ) -> Result> { let GetEventsByEventHandleMessage { event_handle_type, cursor, @@ -397,24 +397,20 @@ impl Handler 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::>>() } } @@ -424,29 +420,27 @@ impl Handler for ExecutorActor { &mut self, msg: GetEventsMessage, _ctx: &mut ActorContext, - ) -> Result>> { + ) -> Result> { 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> = 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::>() - { - result.push(Some(ev)); - } - Ok(result) + .collect::>>() } } diff --git a/crates/rooch-executor/src/actor/messages.rs b/crates/rooch-executor/src/actor/messages.rs index 8b35e59080..73fc773b79 100644 --- a/crates/rooch-executor/src/actor/messages.rs +++ b/crates/rooch-executor/src/actor/messages.rs @@ -112,7 +112,7 @@ pub struct GetEventsByEventHandleMessage { } impl Message for GetEventsByEventHandleMessage { - type Result = Result>>; + type Result = Result>; } #[derive(Debug, Serialize, Deserialize)] @@ -121,7 +121,7 @@ pub struct GetEventsMessage { } impl Message for GetEventsMessage { - type Result = Result>>; + type Result = Result>; } #[derive(Debug, Serialize, Deserialize)] diff --git a/crates/rooch-executor/src/proxy/mod.rs b/crates/rooch-executor/src/proxy/mod.rs index dbf3621a0c..1c5cb7928b 100644 --- a/crates/rooch-executor/src/proxy/mod.rs +++ b/crates/rooch-executor/src/proxy/mod.rs @@ -117,7 +117,7 @@ impl ExecutorProxy { event_handle_type: StructTag, cursor: Option, limit: u64, - ) -> Result>> { + ) -> Result> { self.actor .send(GetEventsByEventHandleMessage { event_handle_type, @@ -127,10 +127,7 @@ impl ExecutorProxy { .await? } - pub async fn get_events( - &self, - filter: EventFilter, - ) -> Result>> { + pub async fn get_events(&self, filter: EventFilter) -> Result> { self.actor.send(GetEventsMessage { filter }).await? } diff --git a/crates/rooch-open-rpc-spec/schemas/openrpc.json b/crates/rooch-open-rpc-spec/schemas/openrpc.json index 524e0320cd..ab8027b909 100644 --- a/crates/rooch-open-rpc-spec/schemas/openrpc.json +++ b/crates/rooch-open-rpc-spec/schemas/openrpc.json @@ -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" } } }, @@ -939,7 +939,7 @@ } ] }, - "PageView_for_AnnotatedStateView_and_alloc::vec::Vec": { + "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": [ @@ -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" - }, - { - "type": "null" - } - ] + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 } } }, - "PageView_for_BalanceInfoView_and_alloc::vec::Vec": { + "PageView_for_AnnotatedStateView_and_alloc::vec::Vec": { "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": [ @@ -979,7 +977,7 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/BalanceInfoView" + "$ref": "#/components/schemas/AnnotatedStateView" } }, "has_next_page": { @@ -997,7 +995,7 @@ } } }, - "PageView_for_Nullable_AnnotatedEventView_and_uint64": { + "PageView_for_BalanceInfoView_and_alloc::vec::Vec": { "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": [ @@ -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" + }, + { + "type": "null" + } + ] } } }, diff --git a/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs b/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs index 3959d9f8ce..2a62900efe 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs @@ -17,7 +17,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::string::String; -pub type EventPageView = PageView, u64>; +pub type EventPageView = PageView; pub type TransactionWithInfoPageView = PageView; pub type StatesPageView = PageView>>; pub type AnnotatedStatesPageView = PageView>>; diff --git a/crates/rooch-rpc-server/src/server/rooch_server.rs b/crates/rooch-rpc-server/src/server/rooch_server.rs index dac109af3c..49ac8ffd77 100644 --- a/crates/rooch-rpc-server/src/server/rooch_server.rs +++ b/crates/rooch-rpc-server/src/server/rooch_server.rs @@ -180,19 +180,19 @@ impl RoochAPIServer for RoochServer { ) -> RpcResult { // 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> = self + let mut data: Vec = 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, diff --git a/crates/rooch-rpc-server/src/service/rpc_service.rs b/crates/rooch-rpc-server/src/service/rpc_service.rs index 8b6e270678..c81ca22d90 100644 --- a/crates/rooch-rpc-server/src/service/rpc_service.rs +++ b/crates/rooch-rpc-server/src/service/rpc_service.rs @@ -133,7 +133,7 @@ impl RpcService { event_handle_type: StructTag, cursor: Option, limit: u64, - ) -> Result>> { + ) -> Result> { let resp = self .executor .get_events_by_event_handle(event_handle_type, cursor, limit) @@ -141,10 +141,7 @@ impl RpcService { Ok(resp) } - pub async fn get_events( - &self, - filter: EventFilter, - ) -> Result>> { + pub async fn get_events(&self, filter: EventFilter) -> Result> { let resp = self.executor.get_events(filter).await?; Ok(resp) } diff --git a/crates/rooch/.gitignore b/crates/rooch/.gitignore deleted file mode 100644 index 0ee4b50bf5..0000000000 --- a/crates/rooch/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. - -# dashboard -/public diff --git a/sdk/typescript/tools/generator/template/name_mapping.json b/sdk/typescript/tools/generator/template/name_mapping.json index 500b0a2d71..6f3a16cd73 100644 --- a/sdk/typescript/tools/generator/template/name_mapping.json +++ b/sdk/typescript/tools/generator/template/name_mapping.json @@ -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" }