mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-07-30 20:11:23 +00:00
Correcting some trivial Rust option/iterator warts
This commit is contained in:
@@ -255,18 +255,18 @@ fn tree_validator(p: &Params, state: &Blake2bState, indices: &[u32]) -> Option<N
|
||||
if indices.len() > 1 {
|
||||
let end = indices.len();
|
||||
let mid = end / 2;
|
||||
match tree_validator(p, state, &indices[0..mid]) {
|
||||
Some(a) => match tree_validator(p, state, &indices[mid..end]) {
|
||||
Some(b) => {
|
||||
if validate_subtrees(p, &a, &b) {
|
||||
Some(Node::from_children(a, b, p.collision_byte_length()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
match (
|
||||
tree_validator(p, state, &indices[0..mid]),
|
||||
tree_validator(p, state, &indices[mid..end]),
|
||||
) {
|
||||
(Some(a), Some(b)) => {
|
||||
if validate_subtrees(p, &a, &b) {
|
||||
Some(Node::from_children(a, b, p.collision_byte_length()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
Some(Node::new(&p, &state, indices[0]))
|
||||
|
@@ -89,10 +89,8 @@ impl<E: JubjubEngine> Point<E, Unknown> {
|
||||
y_repr.as_mut()[3] &= 0x7fffffffffffffff;
|
||||
|
||||
match E::Fr::from_repr(y_repr) {
|
||||
Ok(y) => match Self::get_for_y(y, x_sign, params) {
|
||||
Some(p) => Ok(p),
|
||||
None => Err(io::Error::new(io::ErrorKind::InvalidInput, "not on curve")),
|
||||
},
|
||||
Ok(y) => Self::get_for_y(y, x_sign, params)
|
||||
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "not on curve")),
|
||||
Err(_) => Err(io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"y is not in field",
|
||||
|
@@ -164,14 +164,8 @@ impl<Node: Hashable> CommitmentTree<Node> {
|
||||
// - Empty leaves are used as needed.
|
||||
let leaf_root = Node::combine(
|
||||
0,
|
||||
&match self.left {
|
||||
Some(node) => node,
|
||||
None => filler.next(0),
|
||||
},
|
||||
&match self.right {
|
||||
Some(node) => node,
|
||||
None => filler.next(0),
|
||||
},
|
||||
&self.left.unwrap_or_else(|| filler.next(0)),
|
||||
&self.right.unwrap_or_else(|| filler.next(0)),
|
||||
);
|
||||
|
||||
// 2) Hash in parents up to the currently-filled depth.
|
||||
|
@@ -14,13 +14,8 @@ fn read_scalar<E: JubjubEngine, R: Read>(reader: R) -> io::Result<E::Fs> {
|
||||
let mut s_repr = <E::Fs as PrimeField>::Repr::default();
|
||||
s_repr.read_le(reader)?;
|
||||
|
||||
match E::Fs::from_repr(s_repr) {
|
||||
Ok(s) => Ok(s),
|
||||
Err(_) => Err(io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"scalar is not in field",
|
||||
)),
|
||||
}
|
||||
E::Fs::from_repr(s_repr)
|
||||
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "scalar is not in field"))
|
||||
}
|
||||
|
||||
fn write_scalar<E: JubjubEngine, W: Write>(s: &E::Fs, writer: W) -> io::Result<()> {
|
||||
|
@@ -75,15 +75,13 @@ mod data;
|
||||
fn zip_0143() {
|
||||
for tv in self::data::zip_0143::make_test_vectors() {
|
||||
let tx = Transaction::read(&tv.tx[..]).unwrap();
|
||||
let transparent_input = if let Some(n) = tv.transparent_input {
|
||||
Some((
|
||||
let transparent_input = tv.transparent_input.map(|n| {
|
||||
(
|
||||
n as usize,
|
||||
&tv.script_code,
|
||||
Amount::from_nonnegative_i64(tv.amount).unwrap(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
)
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
signature_hash(&tx, tv.consensus_branch_id, tv.hash_type, transparent_input),
|
||||
@@ -96,15 +94,13 @@ fn zip_0143() {
|
||||
fn zip_0243() {
|
||||
for tv in self::data::zip_0243::make_test_vectors() {
|
||||
let tx = Transaction::read(&tv.tx[..]).unwrap();
|
||||
let transparent_input = if let Some(n) = tv.transparent_input {
|
||||
Some((
|
||||
let transparent_input = tv.transparent_input.map(|n| {
|
||||
(
|
||||
n as usize,
|
||||
&tv.script_code,
|
||||
Amount::from_nonnegative_i64(tv.amount).unwrap(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
)
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
signature_hash(&tx, tv.consensus_branch_id, tv.hash_type, transparent_input),
|
||||
|
Reference in New Issue
Block a user