diff --git a/CHANGELOG.md b/CHANGELOG.md index b9f19532..0c68b983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ and this project adheres to Rust's notion of - Migrated to `zcash_note_encryption 0.2`. - `orchard::builder::Builder::{add_spend, add_output}` now use concrete error types instead of `&'static str`s. +- `orchard::builder::Error` is now `BuildError` to differentiate from + new error types ## [0.2.0] - 2022-06-24 ### Added diff --git a/src/builder.rs b/src/builder.rs index 90c4af75..48348e6b 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -28,7 +28,7 @@ const MIN_ACTIONS: usize = 2; /// An error type for the kinds of errors that can occur during bundle construction. #[derive(Debug)] -pub enum Error { +pub enum BuildError { /// A bundle could not be built because required signatures were missing. MissingSignatures, /// An error occurred in the process of producing a proof for a bundle. @@ -57,15 +57,15 @@ pub enum SpendError { /// The only error that can occur here is if outputs are disabled for this builder. pub type OutputsDisabled = (); -impl From for Error { +impl From for BuildError { fn from(e: halo2_proofs::plonk::Error) -> Self { - Error::Proof(e) + BuildError::Proof(e) } } -impl From for Error { +impl From for BuildError { fn from(e: value::OverflowError) -> Self { - Error::ValueSum(e) + BuildError::ValueSum(e) } } @@ -339,7 +339,7 @@ impl Builder { pub fn build>( mut self, mut rng: impl RngCore, - ) -> Result, V>, Error> { + ) -> Result, V>, BuildError> { // Pair up the spends and recipients, extending with dummy values as necessary. let pre_actions: Vec<_> = { let num_spends = self.spends.len(); @@ -384,8 +384,8 @@ impl Builder { .ok_or(OverflowError)?; let result_value_balance: V = i64::try_from(value_balance) - .map_err(Error::ValueSum) - .and_then(|i| V::try_from(i).map_err(|_| Error::ValueSum(value::OverflowError)))?; + .map_err(BuildError::ValueSum) + .and_then(|i| V::try_from(i).map_err(|_| BuildError::ValueSum(value::OverflowError)))?; // Compute the transaction binding signing key. let bsk = pre_actions @@ -460,7 +460,7 @@ impl Bundle, V> { self, pk: &ProvingKey, mut rng: impl RngCore, - ) -> Result, V>, Error> { + ) -> Result, V>, BuildError> { let instances: Vec<_> = self .actions() .iter() @@ -535,10 +535,10 @@ pub enum MaybeSigned { } impl MaybeSigned { - fn finalize(self) -> Result, Error> { + fn finalize(self) -> Result, BuildError> { match self { Self::Signature(sig) => Ok(sig), - _ => Err(Error::MissingSignatures), + _ => Err(BuildError::MissingSignatures), } } } @@ -582,7 +582,7 @@ impl Bundle, V> { mut rng: R, sighash: [u8; 32], signing_keys: &[SpendAuthorizingKey], - ) -> Result, Error> { + ) -> Result, BuildError> { signing_keys .iter() .fold(self.prepare(&mut rng, sighash), |partial, ask| { @@ -621,11 +621,14 @@ impl Bundle, V> { pub fn append_signatures( self, signatures: &[redpallas::Signature], - ) -> Result { + ) -> Result { signatures.iter().try_fold(self, Self::append_signature) } - fn append_signature(self, signature: &redpallas::Signature) -> Result { + fn append_signature( + self, + signature: &redpallas::Signature, + ) -> Result { let mut signature_valid_for = 0usize; let bundle = self.map_authorization( &mut signature_valid_for, @@ -645,9 +648,9 @@ impl Bundle, V> { |_, partial| partial, ); match signature_valid_for { - 0 => Err(Error::InvalidExternalSignature), + 0 => Err(BuildError::InvalidExternalSignature), 1 => Ok(bundle), - _ => Err(Error::DuplicateSignature), + _ => Err(BuildError::DuplicateSignature), } } } @@ -656,7 +659,7 @@ impl Bundle, V> { /// Finalizes this bundle, enabling it to be included in a transaction. /// /// Returns an error if any signatures are missing. - pub fn finalize(self) -> Result, Error> { + pub fn finalize(self) -> Result, BuildError> { self.try_map_authorization( &mut (), |_, _, maybe| maybe.finalize(),