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: list block return thin block #2254

Merged
merged 2 commits into from
Mar 9, 2021
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
21 changes: 16 additions & 5 deletions rpc/api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,27 +474,38 @@ pub struct BlockView {
pub uncles: Vec<BlockHeaderView>,
}

impl TryFrom<Block> for BlockView {
type Error = anyhow::Error;

fn try_from(block: Block) -> Result<Self, Self::Error> {
impl BlockView {
pub fn try_from_block(block: Block, thin: bool) -> Result<Self, anyhow::Error> {
let (header, body) = block.into_inner();
let BlockBody {
transactions,
uncles,
} = body;
let txns_view = if thin {
BlockTransactionsView::Hashes(transactions.into_iter().map(|t| t.id()).collect())
} else {
transactions.try_into()?
};
Ok(BlockView {
header: header.into(),
uncles: uncles
.unwrap_or_default()
.into_iter()
.map(|h| h.into())
.collect(),
body: transactions.try_into()?,
body: txns_view,
})
}
}

impl TryFrom<Block> for BlockView {
type Error = anyhow::Error;

fn try_from(block: Block) -> Result<Self, Self::Error> {
Self::try_from_block(block, false)
}
}

#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct BlockSummaryView {
pub header: BlockHeaderView,
Expand Down
2 changes: 1 addition & 1 deletion rpc/server/src/module/chain_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ where

Ok(block
.into_iter()
.map(TryInto::try_into)
.map(|blk| BlockView::try_from_block(blk, true))
.collect::<Result<Vec<_>, _>>()?)
}
.map_err(map_err);
Expand Down