diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs index 0bd448d13..59d47e0db 100644 --- a/bitcoin/src/address/mod.rs +++ b/bitcoin/src/address/mod.rs @@ -1067,10 +1067,8 @@ mod tests { #[test] fn p2sh_parse_for_large_script() { let script = ScriptBuf::from_hex("552103a765fc35b3f210b95223846b36ef62a4e53e34e2925270c2c7906b92c9f718eb2103c327511374246759ec8d0b89fa6c6b23b33e11f92c5bc155409d86de0c79180121038cae7406af1f12f4786d820a1466eec7bc5785a1b5e4a387eca6d797753ef6db2103252bfb9dcaab0cd00353f2ac328954d791270203d66c2be8b430f115f451b8a12103e79412d42372c55dd336f2eb6eb639ef9d74a22041ba79382c74da2338fe58ad21035049459a4ebc00e876a9eef02e72a3e70202d3d1f591fc0dd542f93f642021f82102016f682920d9723c61b27f562eb530c926c00106004798b6471e8c52c60ee02057ae12123122313123123ac1231231231231313123131231231231313212313213123123552103a765fc35b3f210b95223846b36ef62a4e53e34e2925270c2c7906b92c9f718eb2103c327511374246759ec8d0b89fa6c6b23b33e11f92c5bc155409d86de0c79180121038cae7406af1f12f4786d820a1466eec7bc5785a1b5e4a387eca6d797753ef6db2103252bfb9dcaab0cd00353f2ac328954d791270203d66c2be8b430f115f451b8a12103e79412d42372c55dd336f2eb6eb639ef9d74a22041ba79382c74da2338fe58ad21035049459a4ebc00e876a9eef02e72a3e70202d3d1f591fc0dd542f93f642021f82102016f682920d9723c61b27f562eb530c926c00106004798b6471e8c52c60ee02057ae12123122313123123ac1231231231231313123131231231231313212313213123123552103a765fc35b3f210b95223846b36ef62a4e53e34e2925270c2c7906b92c9f718eb2103c327511374246759ec8d0b89fa6c6b23b33e11f92c5bc155409d86de0c79180121038cae7406af1f12f4786d820a1466eec7bc5785a1b5e4a387eca6d797753ef6db2103252bfb9dcaab0cd00353f2ac328954d791270203d66c2be8b430f115f451b8a12103e79412d42372c55dd336f2eb6eb639ef9d74a22041ba79382c74da2338fe58ad21035049459a4ebc00e876a9eef02e72a3e70202d3d1f591fc0dd542f93f642021f82102016f682920d9723c61b27f562eb530c926c00106004798b6471e8c52c60ee02057ae12123122313123123ac1231231231231313123131231231231313212313213123123").unwrap(); - assert_eq!( - Address::p2sh(&script, NetworkKind::Test), - Err(RedeemScriptSizeError { size: script.len() }) - ); + let res = Address::p2sh(&script, NetworkKind::Test); + assert_eq!(res.unwrap_err().invalid_size(), script.len()) } #[test] diff --git a/primitives/src/locktime/relative.rs b/primitives/src/locktime/relative.rs index 663223efe..5acd78169 100644 --- a/primitives/src/locktime/relative.rs +++ b/primitives/src/locktime/relative.rs @@ -401,12 +401,19 @@ impl std::error::Error for DisabledLockTimeError {} /// Tried to satisfy a lock-by-blocktime lock using a height value. #[derive(Debug, Clone, PartialEq, Eq)] -#[non_exhaustive] pub struct IncompatibleHeightError { /// Attempted to satisfy a lock-by-blocktime lock with this height. - pub height: Height, + height: Height, /// The inner time value of the lock-by-blocktime lock. - pub time: Time, + time: Time, +} + +impl IncompatibleHeightError { + /// Returns the height that was erroneously used to try and satisfy a lock-by-blocktime lock. + pub fn incompatible(&self) -> Height { self.height } + + /// Returns the time value of the lock-by-blocktime lock. + pub fn expected(&self) -> Time { self.time } } impl fmt::Display for IncompatibleHeightError { @@ -424,12 +431,19 @@ impl std::error::Error for IncompatibleHeightError {} /// Tried to satisfy a lock-by-blockheight lock using a time value. #[derive(Debug, Clone, PartialEq, Eq)] -#[non_exhaustive] pub struct IncompatibleTimeError { /// Attempted to satisfy a lock-by-blockheight lock with this time. - pub time: Time, + time: Time, /// The inner height value of the lock-by-blockheight lock. - pub height: Height, + height: Height, +} + +impl IncompatibleTimeError { + /// Returns the time that was erroneously used to try and satisfy a lock-by-blockheight lock. + pub fn incompatible(&self) -> Time { self.time } + + /// Returns the height value of the lock-by-blockheight lock. + pub fn expected(&self) -> Height { self.height } } impl fmt::Display for IncompatibleTimeError { diff --git a/primitives/src/script/mod.rs b/primitives/src/script/mod.rs index 7832ecfef..db5fff808 100644 --- a/primitives/src/script/mod.rs +++ b/primitives/src/script/mod.rs @@ -174,7 +174,12 @@ impl TryFrom<&Script> for WScriptHash { #[derive(Debug, Clone, PartialEq, Eq)] pub struct RedeemScriptSizeError { /// Invalid redeem script size (cannot exceed 520 bytes). - pub size: usize, + size: usize, +} + +impl RedeemScriptSizeError { + /// Returns the invalid redeem script size. + pub fn invalid_size(&self) -> usize { self.size } } impl From for RedeemScriptSizeError { @@ -196,7 +201,12 @@ impl std::error::Error for RedeemScriptSizeError {} #[derive(Debug, Clone, PartialEq, Eq)] pub struct WitnessScriptSizeError { /// Invalid witness script size (cannot exceed 10,000 bytes). - pub size: usize, + size: usize, +} + +impl WitnessScriptSizeError { + /// Returns the invalid witness script size. + pub fn invalid_size(&self) -> usize { self.size } } impl From for WitnessScriptSizeError {