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

fix: fix get metadata by number #1483

Merged
merged 1 commit into from
Oct 18, 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
22 changes: 16 additions & 6 deletions core/api/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ where
block_number: Option<u64>,
) -> ProtocolResult<Metadata> {
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);
}

Expand All @@ -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<CkbRelatedInfo> {
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<H256> {
Expand All @@ -274,8 +275,17 @@ where
.get_image_cell_root())
}

async fn get_metadata_root(&self, ctx: Context) -> ProtocolResult<H256> {
let state_root = self.storage.get_latest_block_header(ctx).await?.state_root;
async fn get_metadata_root(&self, ctx: Context, number: Option<u64>) -> ProtocolResult<H256> {
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,
Expand All @@ -287,7 +297,7 @@ where
}

async fn hardfork_info(&self, ctx: Context) -> ProtocolResult<HardforkInfo> {
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<Option<HardforkInfoInner>> {
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/traits/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub trait APIAdapter: Send + Sync {

async fn get_image_cell_root(&self, ctx: Context) -> ProtocolResult<H256>;

async fn get_metadata_root(&self, ctx: Context) -> ProtocolResult<H256>;
async fn get_metadata_root(&self, ctx: Context, number: Option<u64>) -> ProtocolResult<H256>;

async fn hardfork_info(&self, ctx: Context) -> ProtocolResult<HardforkInfo>;

Expand Down
Loading