pub enum EncodeSigningDataResult<E> {
    SighashSingleBug,
    WriteResult(Result<(), E>),
}
Expand description

Result of Transaction::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

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:

if tx.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
}

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.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.