Pass pubkey for coinbase (#159)

* store wallet output data in hashmap
* cleanup up commented out code
* pass pubkey/identifier and not derivation around to miner etc.
* fix failing tests
This commit is contained in:
AntiochP
2017-10-07 13:38:41 -04:00
committed by Ignotus Peverell
parent c7f1ce965e
commit 3dd1dde00b
14 changed files with 249 additions and 69 deletions
+16 -10
View File
@@ -266,7 +266,7 @@ impl Block {
prev: &BlockHeader,
txs: Vec<&Transaction>,
keychain: &keychain::Keychain,
pubkey: keychain::Identifier,
pubkey: &keychain::Identifier,
) -> Result<Block, keychain::Error> {
let fees = txs.iter().map(|tx| tx.fee).sum();
@@ -469,11 +469,18 @@ impl Block {
// * That the sum of blinding factors for all coinbase-marked outputs match
// the coinbase-marked kernels.
fn verify_coinbase(&self, secp: &Secp256k1) -> Result<(), Error> {
let cb_outs = filter_map_vec!(self.outputs, |out| {
if out.features.contains(COINBASE_OUTPUT) { Some(out.commitment()) } else { None }
let cb_outs = filter_map_vec!(self.outputs, |out| if out.features.contains(
COINBASE_OUTPUT,
)
{
Some(out.commitment())
} else {
None
});
let cb_kerns = filter_map_vec!(self.kernels, |k| {
if k.features.contains(COINBASE_KERNEL) { Some(k.excess) } else { None }
let cb_kerns = filter_map_vec!(self.kernels, |k| if k.features.contains(COINBASE_KERNEL) {
Some(k.excess)
} else {
None
});
let over_commit = secp.commit_value(reward(self.total_fees()))?;
@@ -490,16 +497,15 @@ impl Block {
/// reward.
pub fn reward_output(
keychain: &keychain::Keychain,
pubkey: keychain::Identifier,
pubkey: &keychain::Identifier,
fees: u64,
) -> Result<(Output, TxKernel), keychain::Error> {
let secp = keychain.secp();
let commit = keychain.commit(reward(fees), &pubkey)?;
let commit = keychain.commit(reward(fees), pubkey)?;
// let switch_commit = keychain.switch_commit(pubkey)?;
let msg = secp::pedersen::ProofMessage::empty();
let rproof = keychain.range_proof(reward(fees), &pubkey, commit, msg)?;
let rproof = keychain.range_proof(reward(fees), pubkey, commit, msg)?;
let output = Output {
features: COINBASE_OUTPUT,
@@ -540,7 +546,7 @@ mod test {
// header
fn new_block(txs: Vec<&Transaction>, keychain: &Keychain) -> Block {
let pubkey = keychain.derive_pubkey(1).unwrap();
Block::new(&BlockHeader::default(), txs, keychain, pubkey).unwrap()
Block::new(&BlockHeader::default(), txs, keychain, &pubkey).unwrap()
}
// utility producing a transaction that spends an output with the provided
+3 -3
View File
@@ -329,7 +329,7 @@ mod test {
let keychain = new_keychain();
let pubkey = keychain.derive_pubkey(1).unwrap();
let b = Block::new(&BlockHeader::default(), vec![], &keychain, pubkey).unwrap();
let b = Block::new(&BlockHeader::default(), vec![], &keychain, &pubkey).unwrap();
b.compact().validate(&keychain.secp()).unwrap();
}
@@ -345,7 +345,7 @@ mod test {
let mut tx1 = tx2i1o();
tx1.verify_sig(keychain.secp()).unwrap();
let b = Block::new(&BlockHeader::default(), vec![&mut tx1], &keychain, pubkey).unwrap();
let b = Block::new(&BlockHeader::default(), vec![&mut tx1], &keychain, &pubkey).unwrap();
b.compact().validate(keychain.secp()).unwrap();
}
@@ -360,7 +360,7 @@ mod test {
let mut tx2 = tx1i1o();
tx2.verify_sig(keychain.secp()).unwrap();
let b = Block::new(&BlockHeader::default(), vec![&mut tx1, &mut tx2], &keychain, pubkey).unwrap();
let b = Block::new(&BlockHeader::default(), vec![&mut tx1, &mut tx2], &keychain, &pubkey).unwrap();
b.validate(keychain.secp()).unwrap();
}
+19
View File
@@ -22,6 +22,7 @@
use std::{error, fmt, cmp};
use std::io::{self, Write, Read};
use byteorder::{ByteOrder, ReadBytesExt, BigEndian};
use keychain::Identifier;
use secp::pedersen::Commitment;
use secp::pedersen::RangeProof;
use secp::constants::PEDERSEN_COMMITMENT_SIZE;
@@ -285,6 +286,19 @@ impl Writeable for Commitment {
}
}
impl Writeable for Identifier {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
writer.write_fixed_bytes(self)
}
}
impl Readable for Identifier {
fn read(reader: &mut Reader) -> Result<Identifier, Error> {
let bytes = reader.read_fixed_bytes(20)?;
Ok(Identifier::from_bytes(&bytes))
}
}
impl Writeable for RangeProof {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
writer.write_fixed_bytes(self)
@@ -511,3 +525,8 @@ impl AsFixedBytes for ::secp::pedersen::Commitment {
return PEDERSEN_COMMITMENT_SIZE;
}
}
impl AsFixedBytes for ::keychain::Identifier {
fn len(&self) -> usize {
return 20;
}
}