coinbase output(s) and kernel(s) always full in compact block (#641)
all other tx inputs/outputs/kernels can be reduced to their short_ids
This commit is contained in:
+9
-2
@@ -399,12 +399,19 @@ pub struct BlockHandler {
|
||||
impl BlockHandler {
|
||||
fn get_block(&self, h: &Hash) -> Result<BlockPrintable, Error> {
|
||||
let block = self.chain.clone().get_block(h).map_err(|_| Error::NotFound)?;
|
||||
Ok(BlockPrintable::from_block(&block, self.chain.clone(), false))
|
||||
Ok(BlockPrintable::from_block(
|
||||
&block,
|
||||
self.chain.clone(),
|
||||
false,
|
||||
))
|
||||
}
|
||||
|
||||
fn get_compact_block(&self, h: &Hash) -> Result<CompactBlockPrintable, Error> {
|
||||
let block = self.chain.clone().get_block(h).map_err(|_| Error::NotFound)?;
|
||||
Ok(CompactBlockPrintable::from_compact_block(&block.as_compact_block()))
|
||||
Ok(CompactBlockPrintable::from_compact_block(
|
||||
&block.as_compact_block(),
|
||||
self.chain.clone(),
|
||||
))
|
||||
}
|
||||
|
||||
// Try to decode the string as a height or a hash.
|
||||
|
||||
+26
-7
@@ -371,22 +371,41 @@ impl BlockPrintable {
|
||||
pub struct CompactBlockPrintable {
|
||||
/// The block header
|
||||
pub header: BlockHeaderPrintable,
|
||||
/// Full outputs, specifically coinbase output(s)
|
||||
pub out_full: Vec<OutputPrintable>,
|
||||
/// Full kernels, specifically coinbase kernel(s)
|
||||
pub kern_full: Vec<TxKernelPrintable>,
|
||||
/// Inputs (hex short_ids)
|
||||
pub inputs: Vec<String>,
|
||||
pub in_ids: Vec<String>,
|
||||
/// Outputs (hex short_ids)
|
||||
pub outputs: Vec<String>,
|
||||
pub out_ids: Vec<String>,
|
||||
/// Kernels (hex short_ids)
|
||||
pub kernels: Vec<String>,
|
||||
pub kern_ids: Vec<String>,
|
||||
}
|
||||
|
||||
impl CompactBlockPrintable {
|
||||
/// Convert a compact block into a printable representation suitable for api response
|
||||
pub fn from_compact_block(cb: &core::CompactBlock) -> CompactBlockPrintable {
|
||||
pub fn from_compact_block(
|
||||
cb: &core::CompactBlock,
|
||||
chain: Arc<chain::Chain>,
|
||||
) -> CompactBlockPrintable {
|
||||
let out_full = cb
|
||||
.out_full
|
||||
.iter()
|
||||
.map(|x| OutputPrintable::from_output(x, chain.clone(), false))
|
||||
.collect();
|
||||
let kern_full = cb
|
||||
.kern_full
|
||||
.iter()
|
||||
.map(|x| TxKernelPrintable::from_txkernel(x))
|
||||
.collect();
|
||||
CompactBlockPrintable {
|
||||
header: BlockHeaderPrintable::from_header(&cb.header),
|
||||
inputs: cb.inputs.iter().map(|x| x.to_hex()).collect(),
|
||||
outputs: cb.outputs.iter().map(|x| x.to_hex()).collect(),
|
||||
kernels: cb.kernels.iter().map(|x| x.to_hex()).collect(),
|
||||
out_full,
|
||||
kern_full,
|
||||
in_ids: cb.in_ids.iter().map(|x| x.to_hex()).collect(),
|
||||
out_ids: cb.out_ids.iter().map(|x| x.to_hex()).collect(),
|
||||
kern_ids: cb.kern_ids.iter().map(|x| x.to_hex()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user