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:
AntiochP
2018-01-19 22:29:48 -05:00
committed by GitHub
parent 9085e548f7
commit ba4c450d2f
3 changed files with 136 additions and 50 deletions
+9 -2
View File
@@ -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
View File
@@ -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(),
}
}
}