mirror of https://github.com/zcash/orchard.git
Add concrete error types for add_spend and add_output
This commit is contained in:
parent
d05b6cee9d
commit
4f27b6bac3
|
@ -26,9 +26,14 @@ and this project adheres to Rust's notion of
|
||||||
- impls of `Eq` for:
|
- impls of `Eq` for:
|
||||||
- `orchard::zip32::ChildIndex`
|
- `orchard::zip32::ChildIndex`
|
||||||
- `orchard::value::ValueSum`
|
- `orchard::value::ValueSum`
|
||||||
|
- `orchard::builder::Builder:`
|
||||||
|
- `SpendError`
|
||||||
|
- `OutputsDisabled`
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Migrated to `zcash_note_encryption 0.2`.
|
- Migrated to `zcash_note_encryption 0.2`.
|
||||||
|
- `orchard::builder::Builder::{add_spend, add_output}` now use
|
||||||
|
concrete error types instead of `&'static str`s.
|
||||||
|
|
||||||
## [0.2.0] - 2022-06-24
|
## [0.2.0] - 2022-06-24
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -43,6 +43,20 @@ pub enum Error {
|
||||||
DuplicateSignature,
|
DuplicateSignature,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An error type for adding a spend to the builder.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum SpendError {
|
||||||
|
/// Spends aren't enabled for this builder.
|
||||||
|
SpendsDisabled,
|
||||||
|
/// The anchor provided to this builder doesn't match the merkle path used to add a spend.
|
||||||
|
AnchorMismatch,
|
||||||
|
/// The full viewing key provided didn't match the note provided
|
||||||
|
FvkMismatch,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The only error that can occur here is if outputs are disabled for this builder.
|
||||||
|
pub type OutputsDisabled = ();
|
||||||
|
|
||||||
impl From<halo2_proofs::plonk::Error> for Error {
|
impl From<halo2_proofs::plonk::Error> for Error {
|
||||||
fn from(e: halo2_proofs::plonk::Error) -> Self {
|
fn from(e: halo2_proofs::plonk::Error) -> Self {
|
||||||
Error::Proof(e)
|
Error::Proof(e)
|
||||||
|
@ -243,23 +257,22 @@ impl Builder {
|
||||||
fvk: FullViewingKey,
|
fvk: FullViewingKey,
|
||||||
note: Note,
|
note: Note,
|
||||||
merkle_path: MerklePath,
|
merkle_path: MerklePath,
|
||||||
) -> Result<(), &'static str> {
|
) -> Result<(), SpendError> {
|
||||||
if !self.flags.spends_enabled() {
|
if !self.flags.spends_enabled() {
|
||||||
return Err("Spends are not enabled for this builder");
|
return Err(SpendError::SpendsDisabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Consistency check: all anchors must be equal.
|
// Consistency check: all anchors must be equal.
|
||||||
let cm = note.commitment();
|
let cm = note.commitment();
|
||||||
let path_root: Anchor =
|
let path_root = merkle_path.root(cm.into());
|
||||||
<Option<_>>::from(merkle_path.root(cm.into())).ok_or("Derived the bottom anchor")?;
|
|
||||||
if path_root != self.anchor {
|
if path_root != self.anchor {
|
||||||
return Err("All anchors must be equal.");
|
return Err(SpendError::AnchorMismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if note is internal or external.
|
// Check if note is internal or external.
|
||||||
let scope = fvk
|
let scope = fvk
|
||||||
.scope_for_address(¬e.recipient())
|
.scope_for_address(¬e.recipient())
|
||||||
.ok_or("FullViewingKey does not correspond to the given note")?;
|
.ok_or(SpendError::FvkMismatch)?;
|
||||||
|
|
||||||
self.spends.push(SpendInfo {
|
self.spends.push(SpendInfo {
|
||||||
dummy_sk: None,
|
dummy_sk: None,
|
||||||
|
@ -279,9 +292,9 @@ impl Builder {
|
||||||
recipient: Address,
|
recipient: Address,
|
||||||
value: NoteValue,
|
value: NoteValue,
|
||||||
memo: Option<[u8; 512]>,
|
memo: Option<[u8; 512]>,
|
||||||
) -> Result<(), &'static str> {
|
) -> Result<(), OutputsDisabled> {
|
||||||
if !self.flags.outputs_enabled() {
|
if !self.flags.outputs_enabled() {
|
||||||
return Err("Outputs are not enabled for this builder");
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.recipients.push(RecipientInfo {
|
self.recipients.push(RecipientInfo {
|
||||||
|
|
Loading…
Reference in New Issue