Skip to content

Commit

Permalink
v0: Clean up and re-export errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharding committed Feb 1, 2024
1 parent 23fcb4d commit 6cd60cd
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/v2/map/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ impl Map for Global {
}
}

/// An error while decoding.
#[derive(Debug)]
#[non_exhaustive]
pub enum DecodeError {
Expand Down Expand Up @@ -560,7 +561,10 @@ pub enum InsertPairError {
/// PSBT_GLOBAL_PROPRIETARY: Invalid proprietary key.
InvalidProprietaryKey,
/// Key must be excluded from this version of PSBT (see consts.rs for u8 values).
ExcludedKey { key_type_value: u8 },
ExcludedKey {
/// Key type value we found.
key_type_value: u8,
},
}

impl fmt::Display for InsertPairError {
Expand Down
1 change: 1 addition & 0 deletions src/v2/map/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ impl InputBuilder {
pub fn build(self) -> Input { self.0 }
}

/// An error while decoding.
#[derive(Debug)]
#[non_exhaustive]
pub enum DecodeError {
Expand Down
12 changes: 12 additions & 0 deletions src/v2/map/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
// SPDX-License-Identifier: CC0-1.0

//! Implementation of the "maps" concept defined in BIP-174.
//!
//! > The Partially Signed Bitcoin Transaction (PSBT) format consists of key-value maps.
//! > ...
//! > <global-map> := <keypair>* 0x00
//! > <input-map> := <keypair>* 0x00
//! > <output-map> := <keypair>* 0x00
//! > ...
/// The `global-map`.
pub mod global;
/// The `input-map`.
pub mod input;
/// The `output-map`.
pub mod output;

use crate::prelude::*;
Expand Down
1 change: 1 addition & 0 deletions src/v2/map/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ impl OutputBuilder {
pub fn build(self) -> Output { self.0 }
}

/// An error while decoding.
#[derive(Debug)]
#[non_exhaustive]
pub enum DecodeError {
Expand Down
16 changes: 13 additions & 3 deletions src/v2/miniscript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::v2::map::input::Input;
use crate::v2::{DetermineLockTimeError, Psbt};

#[rustfmt::skip] // Keep public exports separate.
pub use self::finalize::{Finalizer, InputError, FinalizeError, FinalizeInputError};
pub use self::finalize::{InputError, Finalizer, FinalizeError, FinalizeInputError};

impl Psbt {
// TODO: Should this be on a Role? Finalizer/Extractor? Then we can remove the debug_assert
Expand Down Expand Up @@ -186,9 +186,19 @@ impl From<InterpreterCheckInputError> for InterpreterCheckError {
#[derive(Debug)]
pub enum InterpreterCheckInputError {
/// Failed to construct a [`miniscript::Interpreter`].
Constructor { input_index: usize, error: interpreter::Error },
Constructor {
/// Index of the input causing this error.
input_index: usize,
/// The interpreter error returned from `rust-miniscript`.
error: interpreter::Error,
},
/// Interpreter satisfaction failed for input.
Satisfaction { input_index: usize, error: interpreter::Error },
Satisfaction {
/// Index of the input causing this error.
input_index: usize,
/// The interpreter error returned from `rust-miniscript`.
error: interpreter::Error,
},
}

impl fmt::Display for InterpreterCheckInputError {
Expand Down
2 changes: 1 addition & 1 deletion src/v2/miniscript/satisfy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::v2::map::input::Input;
/// operations on this structure will panic if index is more than number of inputs in pbst
///
/// [`Satisfier`]: crate::miniscript::Satisfier
pub struct InputSatisfier<'a> {
pub(crate) struct InputSatisfier<'a> {
pub(crate) input: &'a Input,
}

Expand Down
14 changes: 10 additions & 4 deletions src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,29 @@ use crate::prelude::*;
use crate::v0;
use crate::v2::map::Map;

pub use self::error::{IndexOutOfBoundsError, SignError, PsbtNotModifiableError, NotUnsignedError, OutputsNotModifiableError, InputsNotModifiableError, DetermineLockTimeError, DeserializeError, PartialSigsSighashTypeError};

#[rustfmt::skip] // Keep public exports separate.
#[doc(inline)]
pub use self::{
error::{
DeserializeError, DetermineLockTimeError, IndexOutOfBoundsError, InputsNotModifiableError,
NotUnsignedError, OutputsNotModifiableError, PartialSigsSighashTypeError,
PsbtNotModifiableError, SignError,
},
extract::{Extractor, ExtractError, ExtractTxError, ExtractTxFeeRateError},
map::{
// We do not re-export any of the input/output/global error types, use form `input::DecodeError`.
global::{self, Global},
input::{self, Input, InputBuilder},
output::{self, Output, OutputBuilder},
},
extract::{Extractor, ExtractError, ExtractTxError, ExtractTxFeeRateError},
};
#[cfg(feature = "base64")]
pub use self::display_from_str::ParsePsbtError;
#[cfg(feature = "miniscript")]
pub use self::miniscript::{FinalizeError, FinalizeInputError, Finalizer, InputError};
pub use self::miniscript::{
FinalizeError, FinalizeInputError, Finalizer, InputError, InterpreterCheckError,
InterpreterCheckInputError,
};

/// Combines these two PSBTs as described by BIP-174 (i.e. combine is the same for BIP-370).
///
Expand Down

0 comments on commit 6cd60cd

Please sign in to comment.