Derive common traits for structs and enum, make internal struct not pub

This commit is contained in:
Riccardo Casatta 2021-07-16 16:39:51 +02:00
parent 55ce3dd6ae
commit 417cfe31e3
No known key found for this signature in database
GPG Key ID: FD986A969E450397
1 changed files with 11 additions and 5 deletions

View File

@ -32,6 +32,7 @@ use {Script, Transaction, TxOut};
use prelude::*; use prelude::*;
/// Efficiently calculates signature hash message for legacy, segwit and taproot inputs. /// Efficiently calculates signature hash message for legacy, segwit and taproot inputs.
#[derive(Debug)]
pub struct SigHashCache<T: Deref<Target = Transaction>> { pub struct SigHashCache<T: Deref<Target = Transaction>> {
/// Access to transaction required for various introspection, moreover type /// Access to transaction required for various introspection, moreover type
/// `T: Deref<Target=Transaction>` allows to accept borrow and mutable borrow, the /// `T: Deref<Target=Transaction>` allows to accept borrow and mutable borrow, the
@ -49,7 +50,8 @@ pub struct SigHashCache<T: Deref<Target = Transaction>> {
} }
/// Values cached common between segwit and taproot inputs /// Values cached common between segwit and taproot inputs
pub struct CommonCache { #[derive(Debug)]
struct CommonCache {
prevouts: sha256::Hash, prevouts: sha256::Hash,
sequences: sha256::Hash, sequences: sha256::Hash,
@ -59,20 +61,23 @@ pub struct CommonCache {
} }
/// Values cached for segwit inputs, it's equal to [CommonCache] plus another round of `sha256` /// Values cached for segwit inputs, it's equal to [CommonCache] plus another round of `sha256`
pub struct SegwitCache { #[derive(Debug)]
struct SegwitCache {
prevouts: sha256d::Hash, prevouts: sha256d::Hash,
sequences: sha256d::Hash, sequences: sha256d::Hash,
outputs: sha256d::Hash, outputs: sha256d::Hash,
} }
/// Values cached for taproot inputs /// Values cached for taproot inputs
pub struct TaprootCache { #[derive(Debug)]
struct TaprootCache {
amounts: sha256::Hash, amounts: sha256::Hash,
script_pubkeys: sha256::Hash, script_pubkeys: sha256::Hash,
} }
/// Contains outputs of previous transactions. /// Contains outputs of previous transactions.
/// In the case [SigHashType] variant is `ANYONECANPAY`, [Prevouts::One] may be provided /// In the case [SigHashType] variant is `ANYONECANPAY`, [Prevouts::One] may be provided
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum Prevouts<'u> { pub enum Prevouts<'u> {
/// `One` variant allows to provide the single Prevout needed. It's useful for example /// `One` variant allows to provide the single Prevout needed. It's useful for example
/// when modifier `ANYONECANPAY` is provided, only prevout of the current input is needed. /// when modifier `ANYONECANPAY` is provided, only prevout of the current input is needed.
@ -86,6 +91,7 @@ pub enum Prevouts<'u> {
const LEAF_VERSION_TAPSCRIPT: u8 = 0xc0; const LEAF_VERSION_TAPSCRIPT: u8 = 0xc0;
/// Information related to the script path spending /// Information related to the script path spending
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct ScriptPath<'s> { pub struct ScriptPath<'s> {
script: &'s Script, script: &'s Script,
code_separator_pos: u32, code_separator_pos: u32,
@ -94,7 +100,7 @@ pub struct ScriptPath<'s> {
/// Hashtype of an input's signature, encoded in the last byte of the signature /// Hashtype of an input's signature, encoded in the last byte of the signature
/// Fixed values so they can be casted as integer types for encoding /// Fixed values so they can be casted as integer types for encoding
#[derive(PartialEq, Eq, Debug, Copy, Clone)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum SigHashType { pub enum SigHashType {
/// 0x0: Used when not explicitly specified, defaulting to [SigHashType::All] /// 0x0: Used when not explicitly specified, defaulting to [SigHashType::All]
Default = 0x00, Default = 0x00,
@ -119,7 +125,7 @@ pub enum SigHashType {
} }
/// Possible errors in computing the signature message /// Possible errors in computing the signature message
#[derive(Debug, Eq, PartialEq)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum Error { pub enum Error {
/// Should never happen since we are always encoding, thus we are avoiding wrap the IO error /// Should never happen since we are always encoding, thus we are avoiding wrap the IO error
IoError, IoError,