Consolidate validation in Block and Transaction (#1354)

* Consolidate validation in Block and Transaction

Introduce TransactionBody which is included into block and tx.
Fixes #1333
This commit is contained in:
hashmap
2018-08-15 23:14:48 +02:00
committed by GitHub
parent 37fa413329
commit 99a66c1960
20 changed files with 570 additions and 476 deletions
+13 -8
View File
@@ -134,7 +134,7 @@ impl OutputHandler {
// in the period between accepting the block and refreshing the wallet
if let Ok(block) = w(&self.chain).get_block(&header.hash()) {
let outputs = block
.outputs
.outputs()
.iter()
.filter(|output| commitments.is_empty() || commitments.contains(&output.commit))
.map(|output| {
@@ -226,7 +226,8 @@ impl OutputHandler {
impl Handler for OutputHandler {
fn get(&self, req: Request<Body>) -> ResponseFuture {
match req.uri()
match req
.uri()
.path()
.trim_right_matches("/")
.rsplit("/")
@@ -362,7 +363,8 @@ impl Handler for TxHashSetHandler {
}
}
}
match req.uri()
match req
.uri()
.path()
.trim_right()
.trim_right_matches("/")
@@ -418,7 +420,8 @@ pub struct PeerHandler {
impl Handler for PeerHandler {
fn get(&self, req: Request<Body>) -> ResponseFuture {
if let Ok(addr) = req.uri()
if let Ok(addr) = req
.uri()
.path()
.trim_right_matches("/")
.rsplit("/")
@@ -604,7 +607,8 @@ fn check_block_param(input: &String) -> Result<(), Error> {
impl Handler for BlockHandler {
fn get(&self, req: Request<Body>) -> ResponseFuture {
let el = req.uri()
let el = req
.uri()
.path()
.trim_right_matches("/")
.rsplit("/")
@@ -649,7 +653,8 @@ impl Handler for BlockHandler {
impl Handler for HeaderHandler {
fn get(&self, req: Request<Body>) -> ResponseFuture {
let el = req.uri()
let el = req
.uri()
.path()
.trim_right_matches("/")
.rsplit("/")
@@ -736,8 +741,8 @@ where
info!(
LOGGER,
"Pushing transaction with {} inputs and {} outputs to pool.",
tx.inputs.len(),
tx.outputs.len()
tx.inputs().len(),
tx.outputs().len()
);
// Push to tx pool.
+9 -6
View File
@@ -292,7 +292,8 @@ impl OutputPrintable {
}
pub fn range_proof(&self) -> Result<pedersen::RangeProof, ser::Error> {
let proof_str = self.proof
let proof_str = self
.proof
.clone()
.ok_or_else(|| ser::Error::HexError(format!("output range_proof missing")))
.unwrap();
@@ -531,12 +532,12 @@ impl BlockPrintable {
include_proof: bool,
) -> BlockPrintable {
let inputs = block
.inputs
.inputs()
.iter()
.map(|x| util::to_hex(x.commitment().0.to_vec()))
.collect();
let outputs = block
.outputs
.outputs()
.iter()
.map(|output| {
OutputPrintable::from_output(
@@ -548,7 +549,7 @@ impl BlockPrintable {
})
.collect();
let kernels = block
.kernels
.kernels()
.iter()
.map(|kernel| TxKernelPrintable::from_txkernel(kernel))
.collect();
@@ -581,11 +582,13 @@ impl CompactBlockPrintable {
chain: Arc<chain::Chain>,
) -> CompactBlockPrintable {
let block = chain.get_block(&cb.hash()).unwrap();
let out_full = cb.out_full
let out_full = cb
.out_full
.iter()
.map(|x| OutputPrintable::from_output(x, chain.clone(), Some(&block.header), false))
.collect();
let kern_full = cb.kern_full
let kern_full = cb
.kern_full
.iter()
.map(|x| TxKernelPrintable::from_txkernel(x))
.collect();