Update bitflags to ^0.1 (#682)
* Removed unused crates * Add listconnectedpeers in grin client * Update bitflags to ^0.1 globally
This commit is contained in:
committed by
Ignotus Peverell
parent
1f7dd4eb73
commit
8a7eb94759
+24
-24
@@ -29,8 +29,8 @@ use core::{
|
||||
Proof,
|
||||
TxKernel,
|
||||
Transaction,
|
||||
COINBASE_KERNEL,
|
||||
COINBASE_OUTPUT
|
||||
OutputFeatures,
|
||||
KernelFeatures
|
||||
};
|
||||
use consensus;
|
||||
use consensus::{exceeds_weight, reward, REWARD, VerifySortOrder};
|
||||
@@ -452,18 +452,18 @@ impl Block {
|
||||
|
||||
let mut out_full = self.outputs
|
||||
.iter()
|
||||
.filter(|x| x.features.contains(COINBASE_OUTPUT))
|
||||
.filter(|x| x.features.contains(OutputFeatures::COINBASE_OUTPUT))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let mut kern_full = self.kernels
|
||||
.iter()
|
||||
.filter(|x| x.features.contains(COINBASE_KERNEL))
|
||||
.filter(|x| x.features.contains(KernelFeatures::COINBASE_KERNEL))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut kern_ids = self.kernels
|
||||
.iter()
|
||||
.filter(|x| !x.features.contains(COINBASE_KERNEL))
|
||||
.filter(|x| !x.features.contains(KernelFeatures::COINBASE_KERNEL))
|
||||
.map(|x| x.short_id(&block_hash))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -570,7 +570,7 @@ impl Block {
|
||||
|
||||
let out_set = self.outputs
|
||||
.iter()
|
||||
.filter(|out| !out.features.contains(COINBASE_OUTPUT))
|
||||
.filter(|out| !out.features.contains(OutputFeatures::COINBASE_OUTPUT))
|
||||
.map(|out| out.commitment())
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
@@ -679,13 +679,13 @@ impl Block {
|
||||
fn verify_coinbase(&self) -> Result<(), Error> {
|
||||
let cb_outs = self.outputs
|
||||
.iter()
|
||||
.filter(|out| out.features.contains(COINBASE_OUTPUT))
|
||||
.filter(|out| out.features.contains(OutputFeatures::COINBASE_OUTPUT))
|
||||
.cloned()
|
||||
.collect::<Vec<Output>>();
|
||||
|
||||
let cb_kerns = self.kernels
|
||||
.iter()
|
||||
.filter(|kernel| kernel.features.contains(COINBASE_KERNEL))
|
||||
.filter(|kernel| kernel.features.contains(KernelFeatures::COINBASE_KERNEL))
|
||||
.cloned()
|
||||
.collect::<Vec<TxKernel>>();
|
||||
|
||||
@@ -738,7 +738,7 @@ impl Block {
|
||||
// _and_ that we trust this claim.
|
||||
// We should have already confirmed the entry from the MMR exists
|
||||
// and has the expected hash.
|
||||
assert!(output.features.contains(COINBASE_OUTPUT));
|
||||
assert!(output.features.contains(OutputFeatures::COINBASE_OUTPUT));
|
||||
|
||||
if let Some(_) = self.outputs
|
||||
.iter()
|
||||
@@ -788,7 +788,7 @@ impl Block {
|
||||
let rproof = keychain.range_proof(reward(fees), key_id, commit, msg)?;
|
||||
|
||||
let output = Output {
|
||||
features: COINBASE_OUTPUT,
|
||||
features: OutputFeatures::COINBASE_OUTPUT,
|
||||
commit: commit,
|
||||
switch_commit_hash: switch_commit_hash,
|
||||
proof: rproof,
|
||||
@@ -809,7 +809,7 @@ impl Block {
|
||||
let sig = keychain.aggsig_sign_from_key_id(&msg, &key_id)?;
|
||||
|
||||
let proof = TxKernel {
|
||||
features: COINBASE_KERNEL,
|
||||
features: KernelFeatures::COINBASE_KERNEL,
|
||||
excess: excess,
|
||||
excess_sig: sig,
|
||||
fee: 0,
|
||||
@@ -945,14 +945,14 @@ mod test {
|
||||
|
||||
let coinbase_outputs = b.outputs
|
||||
.iter()
|
||||
.filter(|out| out.features.contains(COINBASE_OUTPUT))
|
||||
.filter(|out| out.features.contains(OutputFeatures::COINBASE_OUTPUT))
|
||||
.map(|o| o.clone())
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(coinbase_outputs.len(), 1);
|
||||
|
||||
let coinbase_kernels = b.kernels
|
||||
.iter()
|
||||
.filter(|out| out.features.contains(COINBASE_KERNEL))
|
||||
.filter(|out| out.features.contains(KernelFeatures::COINBASE_KERNEL))
|
||||
.map(|o| o.clone())
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(coinbase_kernels.len(), 1);
|
||||
@@ -970,8 +970,8 @@ mod test {
|
||||
let keychain = Keychain::from_random_seed().unwrap();
|
||||
let mut b = new_block(vec![], &keychain);
|
||||
|
||||
assert!(b.outputs[0].features.contains(COINBASE_OUTPUT));
|
||||
b.outputs[0].features.remove(COINBASE_OUTPUT);
|
||||
assert!(b.outputs[0].features.contains(OutputFeatures::COINBASE_OUTPUT));
|
||||
b.outputs[0].features.remove(OutputFeatures::COINBASE_OUTPUT);
|
||||
|
||||
assert_eq!(
|
||||
b.verify_coinbase(),
|
||||
@@ -992,8 +992,8 @@ mod test {
|
||||
let keychain = Keychain::from_random_seed().unwrap();
|
||||
let mut b = new_block(vec![], &keychain);
|
||||
|
||||
assert!(b.kernels[0].features.contains(COINBASE_KERNEL));
|
||||
b.kernels[0].features.remove(COINBASE_KERNEL);
|
||||
assert!(b.kernels[0].features.contains(KernelFeatures::COINBASE_KERNEL));
|
||||
b.kernels[0].features.remove(KernelFeatures::COINBASE_KERNEL);
|
||||
|
||||
assert_eq!(
|
||||
b.verify_coinbase(),
|
||||
@@ -1029,7 +1029,7 @@ mod test {
|
||||
ser::serialize(&mut vec, &b).expect("serialization failed");
|
||||
assert_eq!(
|
||||
vec.len(),
|
||||
5_676,
|
||||
5_676
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1042,7 +1042,7 @@ mod test {
|
||||
ser::serialize(&mut vec, &b).expect("serialization failed");
|
||||
assert_eq!(
|
||||
vec.len(),
|
||||
16_224,
|
||||
16_224
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1054,7 +1054,7 @@ mod test {
|
||||
ser::serialize(&mut vec, &b.as_compact_block()).expect("serialization failed");
|
||||
assert_eq!(
|
||||
vec.len(),
|
||||
5_662,
|
||||
5_662
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1067,7 +1067,7 @@ mod test {
|
||||
ser::serialize(&mut vec, &b.as_compact_block()).expect("serialization failed");
|
||||
assert_eq!(
|
||||
vec.len(),
|
||||
5_668,
|
||||
5_668
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1089,7 +1089,7 @@ mod test {
|
||||
ser::serialize(&mut vec, &b).expect("serialization failed");
|
||||
assert_eq!(
|
||||
vec.len(),
|
||||
111_156,
|
||||
111_156
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1111,7 +1111,7 @@ mod test {
|
||||
ser::serialize(&mut vec, &b.as_compact_block()).expect("serialization failed");
|
||||
assert_eq!(
|
||||
vec.len(),
|
||||
5_722,
|
||||
5_722
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1131,7 +1131,7 @@ mod test {
|
||||
cb.kern_ids[0],
|
||||
b.kernels
|
||||
.iter()
|
||||
.find(|x| !x.features.contains(COINBASE_KERNEL))
|
||||
.find(|x| !x.features.contains(KernelFeatures::COINBASE_KERNEL))
|
||||
.unwrap()
|
||||
.short_id(&b.hash())
|
||||
);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
use util::{secp, kernel_sig_msg};
|
||||
|
||||
use core::{Transaction, Input, Output, OutputFeatures, SwitchCommitHash, COINBASE_OUTPUT, DEFAULT_OUTPUT};
|
||||
use core::{Transaction, Input, Output, OutputFeatures, SwitchCommitHash};
|
||||
use core::hash::Hash;
|
||||
use keychain;
|
||||
use keychain::{Keychain, BlindSum, BlindingFactor, Identifier};
|
||||
@@ -69,7 +69,7 @@ pub fn input(
|
||||
key_id: Identifier,
|
||||
) -> Box<Append> {
|
||||
debug!(LOGGER, "Building input (spending regular output): {}, {}", value, key_id);
|
||||
build_input(value, DEFAULT_OUTPUT, Some(out_block), key_id)
|
||||
build_input(value, OutputFeatures::DEFAULT_OUTPUT, Some(out_block), key_id)
|
||||
}
|
||||
|
||||
/// Adds a coinbase input spending a coinbase output.
|
||||
@@ -80,7 +80,7 @@ pub fn coinbase_input(
|
||||
key_id: Identifier,
|
||||
) -> Box<Append> {
|
||||
debug!(LOGGER, "Building input (spending coinbase): {}, {}", value, key_id);
|
||||
build_input(value, COINBASE_OUTPUT, Some(out_block), key_id)
|
||||
build_input(value, OutputFeatures::COINBASE_OUTPUT, Some(out_block), key_id)
|
||||
}
|
||||
|
||||
/// Adds an output with the provided value and key identifier from the
|
||||
@@ -120,7 +120,7 @@ pub fn output(value: u64, key_id: Identifier) -> Box<Append> {
|
||||
|
||||
(
|
||||
tx.with_output(Output {
|
||||
features: DEFAULT_OUTPUT,
|
||||
features: OutputFeatures::DEFAULT_OUTPUT,
|
||||
commit: commit,
|
||||
switch_commit_hash: switch_commit_hash,
|
||||
proof: rproof,
|
||||
|
||||
@@ -319,7 +319,7 @@ mod test {
|
||||
let tx_kernel = tx.build_kernel(excess);
|
||||
let _ = tx_kernel.verify().unwrap();
|
||||
|
||||
assert_eq!(tx_kernel.features, DEFAULT_KERNEL);
|
||||
assert_eq!(tx_kernel.features, KernelFeatures::DEFAULT_KERNEL);
|
||||
assert_eq!(tx_kernel.fee, tx.fee);
|
||||
assert_eq!(tx_kernel.excess, excess);
|
||||
}
|
||||
|
||||
@@ -38,11 +38,11 @@ pub const SWITCH_COMMIT_KEY_SIZE: usize = 32;
|
||||
|
||||
bitflags! {
|
||||
/// Options for a kernel's structure or use
|
||||
pub flags KernelFeatures: u8 {
|
||||
pub struct KernelFeatures: u8 {
|
||||
/// No flags
|
||||
const DEFAULT_KERNEL = 0b00000000,
|
||||
const DEFAULT_KERNEL = 0b00000000;
|
||||
/// Kernel matching a coinbase output
|
||||
const COINBASE_KERNEL = 0b00000001,
|
||||
const COINBASE_KERNEL = 0b00000001;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ impl Transaction {
|
||||
/// Builds a transaction kernel
|
||||
pub fn build_kernel(&self, excess: Commitment) -> TxKernel {
|
||||
TxKernel {
|
||||
features: DEFAULT_KERNEL,
|
||||
features: KernelFeatures::DEFAULT_KERNEL,
|
||||
excess: excess,
|
||||
excess_sig: self.excess_sig.clone(),
|
||||
fee: self.fee,
|
||||
@@ -408,7 +408,7 @@ impl Writeable for Input {
|
||||
writer.write_u8(self.features.bits())?;
|
||||
writer.write_fixed_bytes(&self.commit)?;
|
||||
|
||||
if self.features.contains(COINBASE_OUTPUT) {
|
||||
if self.features.contains(OutputFeatures::COINBASE_OUTPUT) {
|
||||
writer.write_fixed_bytes(&self.out_block.unwrap_or(ZERO_HASH))?;
|
||||
}
|
||||
|
||||
@@ -426,7 +426,7 @@ impl Readable for Input {
|
||||
|
||||
let commit = Commitment::read(reader)?;
|
||||
|
||||
let out_block = if features.contains(COINBASE_OUTPUT) {
|
||||
let out_block = if features.contains(OutputFeatures::COINBASE_OUTPUT) {
|
||||
Some(Hash::read(reader)?)
|
||||
} else {
|
||||
None
|
||||
@@ -469,11 +469,11 @@ impl Input {
|
||||
bitflags! {
|
||||
/// Options for block validation
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub flags OutputFeatures: u8 {
|
||||
pub struct OutputFeatures: u8 {
|
||||
/// No flags
|
||||
const DEFAULT_OUTPUT = 0b00000000,
|
||||
const DEFAULT_OUTPUT = 0b00000000;
|
||||
/// Output is a coinbase output, must not be spent until maturity
|
||||
const COINBASE_OUTPUT = 0b00000001,
|
||||
const COINBASE_OUTPUT = 0b00000001;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -920,7 +920,7 @@ mod test {
|
||||
let sig = secp::Signature::from_raw_data(&[0;64]).unwrap();
|
||||
|
||||
let kernel = TxKernel {
|
||||
features: DEFAULT_KERNEL,
|
||||
features: KernelFeatures::DEFAULT_KERNEL,
|
||||
lock_height: 0,
|
||||
excess: commit,
|
||||
excess_sig: sig.clone(),
|
||||
@@ -930,7 +930,7 @@ mod test {
|
||||
let mut vec = vec![];
|
||||
ser::serialize(&mut vec, &kernel).expect("serialized failed");
|
||||
let kernel2: TxKernel = ser::deserialize(&mut &vec[..]).unwrap();
|
||||
assert_eq!(kernel2.features, DEFAULT_KERNEL);
|
||||
assert_eq!(kernel2.features, KernelFeatures::DEFAULT_KERNEL);
|
||||
assert_eq!(kernel2.lock_height, 0);
|
||||
assert_eq!(kernel2.excess, commit);
|
||||
assert_eq!(kernel2.excess_sig, sig.clone());
|
||||
@@ -938,7 +938,7 @@ mod test {
|
||||
|
||||
// now check a kernel with lock_height serializes/deserializes correctly
|
||||
let kernel = TxKernel {
|
||||
features: DEFAULT_KERNEL,
|
||||
features: KernelFeatures::DEFAULT_KERNEL,
|
||||
lock_height: 100,
|
||||
excess: commit,
|
||||
excess_sig: sig.clone(),
|
||||
@@ -948,7 +948,7 @@ mod test {
|
||||
let mut vec = vec![];
|
||||
ser::serialize(&mut vec, &kernel).expect("serialized failed");
|
||||
let kernel2: TxKernel = ser::deserialize(&mut &vec[..]).unwrap();
|
||||
assert_eq!(kernel2.features, DEFAULT_KERNEL);
|
||||
assert_eq!(kernel2.features, KernelFeatures::DEFAULT_KERNEL);
|
||||
assert_eq!(kernel2.lock_height, 100);
|
||||
assert_eq!(kernel2.excess, commit);
|
||||
assert_eq!(kernel2.excess_sig, sig.clone());
|
||||
@@ -970,7 +970,7 @@ mod test {
|
||||
let proof = keychain.range_proof(5, &key_id, commit, msg).unwrap();
|
||||
|
||||
let out = Output {
|
||||
features: DEFAULT_OUTPUT,
|
||||
features: OutputFeatures::DEFAULT_OUTPUT,
|
||||
commit: commit,
|
||||
switch_commit_hash: switch_commit_hash,
|
||||
proof: proof,
|
||||
@@ -980,7 +980,7 @@ mod test {
|
||||
ser::serialize(&mut vec, &out).expect("serialized failed");
|
||||
let dout: Output = ser::deserialize(&mut &vec[..]).unwrap();
|
||||
|
||||
assert_eq!(dout.features, DEFAULT_OUTPUT);
|
||||
assert_eq!(dout.features, OutputFeatures::DEFAULT_OUTPUT);
|
||||
assert_eq!(dout.commit, out.commit);
|
||||
assert_eq!(dout.proof, out.proof);
|
||||
}
|
||||
@@ -1001,7 +1001,7 @@ mod test {
|
||||
let proof = keychain.range_proof(1003, &key_id, commit, msg).unwrap();
|
||||
|
||||
let output = Output {
|
||||
features: DEFAULT_OUTPUT,
|
||||
features: OutputFeatures::DEFAULT_OUTPUT,
|
||||
commit: commit,
|
||||
switch_commit_hash: switch_commit_hash,
|
||||
proof: proof,
|
||||
@@ -1047,7 +1047,7 @@ mod test {
|
||||
let commit = keychain.commit(5, &key_id).unwrap();
|
||||
|
||||
let input = Input {
|
||||
features: DEFAULT_OUTPUT,
|
||||
features: OutputFeatures::DEFAULT_OUTPUT,
|
||||
commit: commit,
|
||||
out_block: None,
|
||||
};
|
||||
@@ -1062,7 +1062,7 @@ mod test {
|
||||
// now generate the short_id for a *very* similar output (single feature flag different)
|
||||
// and check it generates a different short_id
|
||||
let input = Input {
|
||||
features: COINBASE_OUTPUT,
|
||||
features: OutputFeatures::COINBASE_OUTPUT,
|
||||
commit: commit,
|
||||
out_block: None,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user