Enum bitcoin::sighash::EncodeSigningDataResult
source · pub enum EncodeSigningDataResult<E> {
SighashSingleBug,
WriteResult(Result<(), E>),
}
Expand description
Result of SighashCache::legacy_encode_signing_data_to
.
This type forces the caller to handle SIGHASH_SINGLE bug case.
This corner case can’t be expressed using standard Result
,
in a way that is both convenient and not-prone to accidental
mistakes (like calling .expect("writer never fails")
).
Variants§
SighashSingleBug
Input data is an instance of SIGHASH_SINGLE
bug
WriteResult(Result<(), E>)
Operation performed normally.
Implementations§
source§impl<E> EncodeSigningDataResult<E>
impl<E> EncodeSigningDataResult<E>
sourcepub fn is_sighash_single_bug(self) -> Result<bool, E>
pub fn is_sighash_single_bug(self) -> Result<bool, E>
Checks for SIGHASH_SINGLE bug returning error if the writer failed.
This method is provided for easy and correct handling of the result because SIGHASH_SINGLE bug is a special case that must not be ignored nor cause panicking. Since the data is usually written directly into a hasher which never fails, the recommended pattern to handle this is:
let cache = SighashCache::new(&tx);
if cache.legacy_encode_signing_data_to(&mut writer, input_index, &script_pubkey, sighash_u32)
.is_sighash_single_bug()
.expect("writer can't fail") {
// use a hash value of "1", instead of computing the actual hash due to SIGHASH_SINGLE bug
}
sourcepub fn map_err<E2, F>(self, f: F) -> EncodeSigningDataResult<E2>where
F: FnOnce(E) -> E2,
pub fn map_err<E2, F>(self, f: F) -> EncodeSigningDataResult<E2>where F: FnOnce(E) -> E2,
Maps a Result<T, E>
to Result<T, F>
by applying a function to a
contained Err
value, leaving an Ok
value untouched.
Like Result::map_err
.