Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruve-p committed Aug 1, 2023
2 parents 006d3d1 + cdf3e30 commit 55bf041
Show file tree
Hide file tree
Showing 26 changed files with 61 additions and 59 deletions.
2 changes: 1 addition & 1 deletion groestlcoin/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use crate::prelude::*;
use crate::taproot::TapNodeHash;

/// Address error.
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// Base58 encoding error.
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/base58.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl<T: Default + Copy> SmallVec<T> {
}

/// An error that might occur during base58 decoding.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// Invalid character encountered.
Expand Down
4 changes: 2 additions & 2 deletions groestlcoin/src/bip152.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::prelude::*;
use crate::{block, io, Block, BlockHash, Transaction};

/// A BIP-152 error
#[derive(Clone, PartialEq, Eq, Debug, Copy, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// An unknown version number was used.
Expand Down Expand Up @@ -318,7 +318,7 @@ impl Decodable for BlockTransactionsRequest {

/// A transaction index is requested that is out of range from the
/// corresponding block.
#[derive(Clone, PartialEq, Eq, Debug, Copy, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TxIndexOutOfRangeError(u64);

impl fmt::Display for TxIndexOutOfRangeError {
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl fmt::Debug for DerivationPath {
pub type KeySource = (Fingerprint, DerivationPath);

/// A BIP32 error
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// A pk->pk derivation was attempted on a hardened key
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/blockdata/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl std::error::Error for Bip34Error {
}

/// A block validation error.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ValidationError {
/// The header hash is not below the target.
BadProofOfWork,
Expand Down
4 changes: 2 additions & 2 deletions groestlcoin/src/blockdata/locktime/absolute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ impl From<ParseIntError> for Error {
}

/// An error that occurs when converting a `u32` to a lock time variant.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ConversionError {
/// The expected timelock unit, height (blocks) or time (seconds).
unit: LockTimeUnit,
Expand Down Expand Up @@ -646,7 +646,7 @@ impl fmt::Display for LockTimeUnit {
}

/// Errors than occur when operating on lock times.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum OperationError {
/// Cannot compare different lock time units (height vs time).
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/blockdata/locktime/relative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl fmt::Display for Time {
}

/// Errors related to relative lock times.
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// Input time in seconds was too large to be encoded to a 16 bit 512 second interval.
Expand Down
20 changes: 20 additions & 0 deletions groestlcoin/src/blockdata/script/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,26 @@ impl Script {
}
}

/// Computes the P2SH output corresponding to this redeem script.
pub fn to_p2sh(&self) -> ScriptBuf { ScriptBuf::new_p2sh(&self.script_hash()) }

/// Returns the script code used for spending a P2WPKH output if this script is a script pubkey
/// for a P2WPKH output. The `scriptCode` is described in [BIP143].
///
/// [BIP143]: <https://github.com/bitcoin/bips/blob/99701f68a88ce33b2d0838eb84e115cef505b4c2/bip-0143.mediawiki>
pub fn p2wpkh_script_code(&self) -> Option<ScriptBuf> {
self.v0_p2wpkh().map(|wpkh| {
Builder::new()
.push_opcode(OP_DUP)
.push_opcode(OP_HASH160)
// The `self` script is 0x00, 0x14, <pubkey_hash>
.push_slice(wpkh)
.push_opcode(OP_EQUALVERIFY)
.push_opcode(OP_CHECKSIG)
.into_script()
})
}

/// Returns the minimum value an output with this script should have in order to be
/// broadcastable on today's Bitcoin network.
pub fn dust_value(&self) -> crate::Amount {
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/blockdata/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ pub(super) fn bytes_to_asm_fmt(script: &[u8], f: &mut dyn fmt::Write) -> fmt::Re
/// Ways that a script might fail. Not everything is split up as
/// much as it could be; patches welcome if more detailed errors
/// would help you.
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// Something did a non-minimal push; for more information see
Expand Down
20 changes: 0 additions & 20 deletions groestlcoin/src/blockdata/script/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,6 @@ impl ScriptBuf {
/// This method doesn't (re)allocate.
pub fn into_bytes(self) -> Vec<u8> { self.0 }

/// Computes the P2SH output corresponding to this redeem script.
pub fn to_p2sh(&self) -> ScriptBuf { ScriptBuf::new_p2sh(&self.script_hash()) }

/// Returns the script code used for spending a P2WPKH output if this script is a script pubkey
/// for a P2WPKH output. The `scriptCode` is described in [BIP143].
///
/// [BIP143]: <https://github.com/bitcoin/bips/blob/99701f68a88ce33b2d0838eb84e115cef505b4c2/bip-0143.mediawiki>
pub fn p2wpkh_script_code(&self) -> Option<ScriptBuf> {
self.v0_p2wpkh().map(|wpkh| {
Builder::new()
.push_opcode(OP_DUP)
.push_opcode(OP_HASH160)
// The `self` script is 0x00, 0x14, <pubkey_hash>
.push_slice(wpkh)
.push_opcode(OP_EQUALVERIFY)
.push_opcode(OP_CHECKSIG)
.into_script()
})
}

/// Adds a single opcode to the script.
pub fn push_opcode(&mut self, data: opcodes::All) { self.0.push(data.to_u8()); }

Expand Down
4 changes: 2 additions & 2 deletions groestlcoin/src/blockdata/script/push_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ mod error {

/// Error returned on attempt to create too large `PushBytes`.
#[allow(unused)]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PushBytesError {
never: core::convert::Infallible,
}
Expand All @@ -391,7 +391,7 @@ mod error {
use core::fmt;

/// Error returned on attempt to create too large `PushBytes`.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PushBytesError {
/// How long the input was.
pub(super) len: usize,
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/blockdata/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl fmt::Display for OutPoint {
}

/// An error in parsing an OutPoint.
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ParseOutPointError {
/// Error in TXID part.
Expand Down
4 changes: 2 additions & 2 deletions groestlcoin/src/consensus/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ pub mod hex {
// TODO: statically prove impossible cases

/// Error returned when a hex string decoder can't be created.
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DecodeInitError(hex::HexToBytesError);

/// Error returned when a hex string contains invalid characters.
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DecodeError(hex::HexToBytesError);

/// Hex decoder state.
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/crypto/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl<'a> IntoIterator for &'a SerializedSignature {
}

/// A key-related error.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// Hex decoding error
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/crypto/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::taproot::{TapNodeHash, TapTweakHash};
use crate::{base58, io};

/// A key-related error.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// Base58 encoding error
Expand Down
4 changes: 2 additions & 2 deletions groestlcoin/src/crypto/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl str::FromStr for TapSighashType {
}

/// Possible errors in computing the signature message.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// Could happen only by using `*_encode_signing_*` methods with custom writers, engines writers
Expand Down Expand Up @@ -531,7 +531,7 @@ impl_std_error!(NonStandardSighashType);
/// Error returned for failure during parsing one of the sighash types.
///
/// This is currently returned for unrecognized sighash strings.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SighashTypeParseError {
/// The unrecognized string we attempted to parse.
pub unrecognized: String,
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/crypto/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Signature {
/// An error constructing a [`taproot::Signature`] from a byte slice.
///
/// [`taproot::Signature`]: crate::crypto::taproot::Signature
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum SigFromSliceError {
/// Invalid signature hash type.
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/merkle_tree/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ impl Decodable for PartialMerkleTree {
}

/// An error when verifying the merkle block.
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum MerkleBlockError {
/// Merkle root in the header doesn't match to the root calculated from partial merkle tree.
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/network/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl Magic {
}

/// An error in parsing magic bytes.
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseMagicError {
/// The error that occurred when parsing the string.
error: hex::HexToArrayError,
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/network/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Decodable for CommandString {
/// Error returned when a command string is invalid.
///
/// This is currently returned for command strings longer than 12.
#[derive(Clone, Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandStringError {
cow: Cow<'static, str>,
}
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::prelude::*;
/// Note that this is larger than the type from `core` so if it's passed through a deep call stack
/// in a performance-critical application you may want to box it or throw away the context by
/// converting to `core` type.
#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseIntError {
input: String,
// for displaying - see Display impl with nice error message below
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ impl<T: Into<u128>> From<T> for U256 {
}

/// Error from `TryFrom<signed type>` implementations, occurs when input is negative.
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TryFromError(i128);

impl fmt::Display for TryFromError {
Expand Down
22 changes: 12 additions & 10 deletions groestlcoin/src/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use internals::write_err;
use secp256k1::{Message, Secp256k1, Signing};

use crate::bip32::{self, ExtendedPrivKey, ExtendedPubKey, KeySource};
use crate::blockdata::script::ScriptBuf;
use crate::blockdata::transaction::{Transaction, TxOut};
use crate::crypto::ecdsa;
use crate::crypto::key::{PrivateKey, PublicKey};
Expand Down Expand Up @@ -336,16 +335,18 @@ impl Psbt {
Ok((Message::from(sighash), hash_ty))
}
Wpkh => {
let script_code = ScriptBuf::p2wpkh_script_code(spk).ok_or(SignError::NotWpkh)?;
let script_code = spk.p2wpkh_script_code().ok_or(SignError::NotWpkh)?;
let sighash =
cache.segwit_signature_hash(input_index, &script_code, utxo.value, hash_ty)?;
Ok((Message::from(sighash), hash_ty))
}
ShWpkh => {
let script_code = ScriptBuf::p2wpkh_script_code(
input.redeem_script.as_ref().expect("checked above"),
)
.ok_or(SignError::NotWpkh)?;
let script_code = input
.redeem_script
.as_ref()
.expect("checked above")
.p2wpkh_script_code()
.ok_or(SignError::NotWpkh)?;
let sighash =
cache.segwit_signature_hash(input_index, &script_code, utxo.value, hash_ty)?;
Ok((Message::from(sighash), hash_ty))
Expand Down Expand Up @@ -575,7 +576,7 @@ impl_get_key_for_map!(BTreeMap);
impl_get_key_for_map!(HashMap);

/// Errors when getting a key.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum GetKeyError {
/// A bip32 error.
Expand Down Expand Up @@ -658,7 +659,8 @@ pub enum SigningAlgorithm {
}

/// Errors encountered while calculating the sighash message.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum SignError {
/// Input index out of bounds (actual index, maximum index allowed).
IndexOutOfBounds(usize, usize),
Expand Down Expand Up @@ -695,7 +697,7 @@ impl fmt::Display for SignError {
use self::SignError::*;

match *self {
IndexOutOfBounds(ind, len) => {
IndexOutOfBounds(ref ind, ref len) => {
write!(f, "index {}, psbt input len: {}", ind, len)
}
InvalidSighashType => write!(f, "invalid sighash type"),
Expand All @@ -706,7 +708,7 @@ impl fmt::Display for SignError {
MismatchedAlgoKey => write!(f, "signing algorithm and key type does not match"),
NotEcdsa => write!(f, "attempted to ECDSA sign an non-ECDSA input"),
NotWpkh => write!(f, "the scriptPubkey is not a P2WPKH script"),
SighashComputation(e) => write!(f, "sighash: {}", e),
SighashComputation(ref e) => write!(f, "sighash: {}", e),
UnknownOutputType => write!(f, "unable to determine the output type"),
KeyNotFound => write!(f, "unable to find key"),
WrongSigningAlgorithm =>
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/sign_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod message_signing {
use crate::prelude::*;

/// An error used for dealing with Bitcoin Signed Messages.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum MessageSignatureError {
/// Signature is expected to be 65 bytes.
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub trait FromHexStr: Sized {
}

/// Hex parsing error
#[derive(Debug, Eq, PartialEq, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FromHexError<E> {
/// The input was not a valid hex string, contains the error that occurred while parsing.
ParseHex(E),
Expand Down
4 changes: 2 additions & 2 deletions groestlcoin/src/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ impl<'de> serde::Deserialize<'de> for LeafVersion {
}

/// Detailed error type for taproot builder.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum TaprootBuilderError {
/// Merkle tree depth must not be more than 128.
Expand Down Expand Up @@ -1491,7 +1491,7 @@ impl std::error::Error for TaprootBuilderError {
}

/// Detailed error type for taproot utilities.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum TaprootError {
/// Proof size must be a multiple of 32.
Expand Down

0 comments on commit 55bf041

Please sign in to comment.