[1.1.0] CbData Serialization change + reward output test mode (#2710)

* cb serialization and coinbase test mode

* rustfmt
This commit is contained in:
Yeastplume
2019-03-26 12:26:03 +00:00
committed by GitHub
parent c2638844b2
commit 9fab8ee3fb
12 changed files with 56 additions and 37 deletions
+4 -3
View File
@@ -251,7 +251,7 @@ pub fn verify_partial_sig(
/// let msg = kernel_sig_msg(0, height, KernelFeatures::HeightLocked).unwrap();
/// let excess = secp.commit_sum(vec![out_commit], vec![over_commit]).unwrap();
/// let pubkey = excess.to_pubkey(&secp).unwrap();
/// let sig = aggsig::sign_from_key_id(&secp, &keychain, &msg, value, &key_id, Some(&pubkey)).unwrap();
/// let sig = aggsig::sign_from_key_id(&secp, &keychain, &msg, value, &key_id, None, Some(&pubkey)).unwrap();
/// ```
pub fn sign_from_key_id<K>(
@@ -260,13 +260,14 @@ pub fn sign_from_key_id<K>(
msg: &Message,
value: u64,
key_id: &Identifier,
s_nonce: Option<&SecretKey>,
blind_sum: Option<&PublicKey>,
) -> Result<Signature, Error>
where
K: Keychain,
{
let skey = k.derive_key(value, key_id)?;
let sig = aggsig::sign_single(secp, &msg, &skey, None, None, None, blind_sum, None)?;
let sig = aggsig::sign_single(secp, &msg, &skey, s_nonce, None, None, blind_sum, None)?;
Ok(sig)
}
@@ -316,7 +317,7 @@ where
/// let msg = kernel_sig_msg(0, height, KernelFeatures::HeightLocked).unwrap();
/// let excess = secp.commit_sum(vec![out_commit], vec![over_commit]).unwrap();
/// let pubkey = excess.to_pubkey(&secp).unwrap();
/// let sig = aggsig::sign_from_key_id(&secp, &keychain, &msg, value, &key_id, Some(&pubkey)).unwrap();
/// let sig = aggsig::sign_from_key_id(&secp, &keychain, &msg, value, &key_id, None, Some(&pubkey)).unwrap();
///
/// // Verify the signature from the excess commit
/// let sig_verifies =
+24 -3
View File
@@ -20,10 +20,15 @@ use crate::core::{KernelFeatures, Output, OutputFeatures, TxKernel};
use crate::keychain::{Identifier, Keychain};
use crate::libtx::error::Error;
use crate::libtx::{aggsig, proof};
use crate::util::static_secp_instance;
use crate::util::{secp, static_secp_instance};
/// output a reward output
pub fn output<K>(keychain: &K, key_id: &Identifier, fees: u64) -> Result<(Output, TxKernel), Error>
pub fn output<K>(
keychain: &K,
key_id: &Identifier,
fees: u64,
test_mode: bool,
) -> Result<(Output, TxKernel), Error>
where
K: Keychain,
{
@@ -50,7 +55,23 @@ where
// NOTE: Remember we sign the fee *and* the lock_height.
// For a coinbase output the fee is 0 and the lock_height is 0
let msg = kernel_sig_msg(0, 0, KernelFeatures::Coinbase)?;
let sig = aggsig::sign_from_key_id(&secp, keychain, &msg, value, &key_id, Some(&pubkey))?;
let sig = match test_mode {
true => {
let test_nonce = secp::key::SecretKey::from_slice(&secp, &[0u8; 32])?;
aggsig::sign_from_key_id(
&secp,
keychain,
&msg,
value,
&key_id,
Some(&test_nonce),
Some(&pubkey),
)?
}
false => {
aggsig::sign_from_key_id(&secp, keychain, &msg, value, &key_id, None, Some(&pubkey))?
}
};
let proof = TxKernel {
features: KernelFeatures::Coinbase,