diff --git a/core/api/src/adapter.rs b/core/api/src/adapter.rs index 1a040af6b..2fa385116 100644 --- a/core/api/src/adapter.rs +++ b/core/api/src/adapter.rs @@ -246,7 +246,7 @@ where block_number: Option, ) -> ProtocolResult { if let Some(num) = block_number { - return MetadataHandle::new(self.get_metadata_root(ctx).await?) + return MetadataHandle::new(self.get_metadata_root(ctx, Some(num)).await?) .get_metadata_by_block_number(num); } @@ -255,11 +255,12 @@ where .get_latest_block_header(ctx.clone()) .await? .number; - MetadataHandle::new(self.get_metadata_root(ctx).await?).get_metadata_by_block_number(num) + MetadataHandle::new(self.get_metadata_root(ctx, None).await?) + .get_metadata_by_block_number(num) } async fn get_ckb_related_info(&self, ctx: Context) -> ProtocolResult { - MetadataHandle::new(self.get_metadata_root(ctx).await?).get_ckb_related_info() + MetadataHandle::new(self.get_metadata_root(ctx, None).await?).get_ckb_related_info() } async fn get_image_cell_root(&self, ctx: Context) -> ProtocolResult { @@ -274,8 +275,17 @@ where .get_image_cell_root()) } - async fn get_metadata_root(&self, ctx: Context) -> ProtocolResult { - let state_root = self.storage.get_latest_block_header(ctx).await?.state_root; + async fn get_metadata_root(&self, ctx: Context, number: Option) -> ProtocolResult { + let state_root = match number { + Some(n) => { + self.storage + .get_block_header(ctx, n) + .await? + .ok_or_else(|| APIError::RequestPayload("Not found number".to_string()))? + .state_root + } + None => self.storage.get_latest_block_header(ctx).await?.state_root, + }; Ok(AxonExecutorReadOnlyAdapter::from_root( state_root, @@ -287,7 +297,7 @@ where } async fn hardfork_info(&self, ctx: Context) -> ProtocolResult { - MetadataHandle::new(self.get_metadata_root(ctx).await?).hardfork_infos() + MetadataHandle::new(self.get_metadata_root(ctx, None).await?).hardfork_infos() } async fn hardfork_proposal(&self, ctx: Context) -> ProtocolResult> { diff --git a/protocol/src/traits/api.rs b/protocol/src/traits/api.rs index c1dfcaeba..dee572f8a 100644 --- a/protocol/src/traits/api.rs +++ b/protocol/src/traits/api.rs @@ -104,7 +104,7 @@ pub trait APIAdapter: Send + Sync { async fn get_image_cell_root(&self, ctx: Context) -> ProtocolResult; - async fn get_metadata_root(&self, ctx: Context) -> ProtocolResult; + async fn get_metadata_root(&self, ctx: Context, number: Option) -> ProtocolResult; async fn hardfork_info(&self, ctx: Context) -> ProtocolResult;