Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions bitcoin/examples/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ fn main() {
// And so does `from_hex_prefixed`.
assert!(ScriptPubKeyBuf::from_hex_prefixed(&hex_lower_hex_trait).is_err());
// But we provide an explicit constructor that does not.
assert_eq!(
ScriptPubKeyBuf::from_hex_no_length_prefix(&hex_lower_hex_trait).unwrap(),
script
);
assert_eq!(ScriptPubKeyBuf::from_hex_no_length_prefix(&hex_lower_hex_trait).unwrap(), script);

// This is consensus encoding i.e., includes the length prefix.
let hex_inherent = script.to_hex_string_prefixed(); // Defined in `ScriptExt`.
Expand Down
8 changes: 4 additions & 4 deletions bitcoin/src/blockdata/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ pub use primitives::script::ScriptBufDecoderError;
#[doc(inline)]
pub use primitives::script::{
RedeemScript, RedeemScriptBuf, RedeemScriptTag, Script, ScriptBuf, ScriptBufDecoder,
ScriptEncoder, ScriptHash, ScriptHashableTag, ScriptPubKey, ScriptPubKeyBuf, ScriptPubKeyTag,
ScriptSig, ScriptSigBuf, ScriptSigTag, SignetBlockScript, SignetBlockScriptBuf,
SignetBlockScriptTag, Tag, TapScript, TapScriptBuf, TapScriptTag, WScriptHash, WitnessScript,
WitnessScriptBuf, WitnessScriptTag, ScriptCode, ScriptCodeTag,
ScriptCode, ScriptCodeTag, ScriptEncoder, ScriptHash, ScriptHashableTag, ScriptPubKey,
ScriptPubKeyBuf, ScriptPubKeyTag, ScriptSig, ScriptSigBuf, ScriptSigTag, SignetBlockScript,
SignetBlockScriptBuf, SignetBlockScriptTag, Tag, TapScript, TapScriptBuf, TapScriptTag,
WScriptHash, WitnessScript, WitnessScriptBuf, WitnessScriptTag,
};

pub(crate) use self::borrowed::ScriptExtPriv;
Expand Down
19 changes: 5 additions & 14 deletions bitcoin/src/blockdata/script/script_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ use core::ops::Deref;
use arbitrary::{Arbitrary, Unstructured};

use crate::key::WPubkeyHash;
use crate::opcodes::all::{OP_CHECKSIG, OP_DUP, OP_EQUALVERIFY, OP_HASH160, OP_PUSHBYTES_20};
use crate::script::ScriptCode;

use crate::opcodes::all::{
OP_CHECKSIG, OP_DUP, OP_EQUALVERIFY, OP_HASH160, OP_PUSHBYTES_20,
};
const P2WPKH_SCRIPT_CODE_LEN: usize = 25;

/// Owned script code used for P2WPKH sighash computation.
Expand All @@ -33,23 +30,17 @@ impl P2wpkhScriptCode {
}

/// Borrows the script code without modifyign or copying its bytes.
pub fn as_script(&self) -> &ScriptCode {
ScriptCode::from_bytes(&self.0)
}
pub fn as_script(&self) -> &ScriptCode { ScriptCode::from_bytes(&self.0) }
}

impl AsRef<ScriptCode> for P2wpkhScriptCode {
fn as_ref(&self) -> &ScriptCode {
self.as_script()
}
fn as_ref(&self) -> &ScriptCode { self.as_script() }
}

impl Deref for P2wpkhScriptCode {
type Target = ScriptCode;

fn deref(&self) -> &Self::Target {
self.as_script()
}

fn deref(&self) -> &Self::Target { self.as_script() }
}

#[cfg(feature = "arbitrary")]
Expand Down
9 changes: 2 additions & 7 deletions bitcoin/src/blockdata/script/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,16 +1038,11 @@ fn instruction_indices_nth_extended() {

#[test]
fn p2wpkh_script_code() {
let wpkh = WPubkeyHash::from_byte_array(
hex!("1d0f172a0ecb48aee1be1f2687d2963ae33f71a1"),
);
let wpkh = WPubkeyHash::from_byte_array(hex!("1d0f172a0ecb48aee1be1f2687d2963ae33f71a1"));
let owned = P2wpkhScriptCode::new_p2wpkh(wpkh);
let script_code: &ScriptCode = &owned;

assert_eq!(
script_code.as_bytes(),
&hex!("76a9141d0f172a0ecb48aee1be1f2687d2963ae33f71a188ac"),
);
assert_eq!(script_code.as_bytes(), &hex!("76a9141d0f172a0ecb48aee1be1f2687d2963ae33f71a188ac"),);

// Check that encoding includes the CompactSize prefix.
assert_eq!(
Expand Down
7 changes: 3 additions & 4 deletions bitcoin/src/crypto/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ use crate::transaction::TransactionExt as _;
use crate::witness::Witness;
#[cfg(doc)]
use crate::ScriptPubKey;
use crate::{
transaction, Amount, Sequence, TapScript, Transaction, TxOut, ScriptCode
};
use crate::{transaction, Amount, ScriptCode, Sequence, TapScript, Transaction, TxOut};

#[rustfmt::skip] // Keep public re-exports separate.
#[doc(no_inline)]
Expand Down Expand Up @@ -1397,7 +1395,8 @@ pub mod error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Io(error) => write_err!(f, "failed to write sighash data"; error),
Self::Sighash(error) => write_err_unchecked_source!(f, "failed to compute sighash data"; error),
Self::Sighash(error) =>
write_err_unchecked_source!(f, "failed to compute sighash data"; error),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions bitcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ pub use primitives::{
},
merkle_tree::{TxMerkleNode, WitnessMerkleNode},
script::{
RedeemScript, RedeemScriptBuf, RedeemScriptTag, ScriptHashableTag, ScriptPubKey,
ScriptPubKeyBuf, ScriptPubKeyTag, ScriptSig, ScriptSigBuf, ScriptSigTag, SignetBlockScript,
SignetBlockScriptBuf, SignetBlockScriptTag, Tag, TapScript, TapScriptBuf, TapScriptTag,
WitnessScript, WitnessScriptBuf, WitnessScriptTag, ScriptCode, ScriptCodeTag,
RedeemScript, RedeemScriptBuf, RedeemScriptTag, ScriptCode, ScriptCodeTag,
ScriptHashableTag, ScriptPubKey, ScriptPubKeyBuf, ScriptPubKeyTag, ScriptSig, ScriptSigBuf,
ScriptSigTag, SignetBlockScript, SignetBlockScriptBuf, SignetBlockScriptTag, Tag,
TapScript, TapScriptBuf, TapScriptTag, WitnessScript, WitnessScriptBuf, WitnessScriptTag,
},
transaction::{OutPoint, Transaction, TxIn, TxOut, Txid, Version as TransactionVersion, Wtxid},
witness::Witness,
Expand Down Expand Up @@ -202,9 +202,9 @@ pub use crate::{
blockdata::opcodes::{self, Opcode},
blockdata::script::witness_program::{self, WitnessProgram},
blockdata::script::witness_version::{self, WitnessVersion},
blockdata::script::P2wpkhScriptCode,
// These modules also re-export all the respective `primitives` types.
blockdata::{block, constants, fee_rate, locktime, script, transaction, weight, witness},
blockdata::script::P2wpkhScriptCode,
};

#[rustfmt::skip]
Expand Down
2 changes: 1 addition & 1 deletion internals/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait ErrorExt: std::error::Error + 'static {

#[doc(hidden)]
#[cfg(feature = "std")]
impl<T: std::error::Error + 'static> ErrorExt for T { }
impl<T: std::error::Error + 'static> ErrorExt for T {}

/// Formats error.
///
Expand Down
6 changes: 3 additions & 3 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ pub use self::{
Block, Checked as BlockChecked, Unchecked as BlockUnchecked, Validation as BlockValidation,
},
script::{
RedeemScript, RedeemScriptBuf, ScriptPubKey, ScriptPubKeyBuf, ScriptSig, ScriptSigBuf,
SignetBlockScript, SignetBlockScriptBuf, TapScript, TapScriptBuf, WitnessScript,
WitnessScriptBuf, ScriptCode,
RedeemScript, RedeemScriptBuf, ScriptCode, ScriptPubKey, ScriptPubKeyBuf, ScriptSig,
ScriptSigBuf, SignetBlockScript, SignetBlockScriptBuf, TapScript, TapScriptBuf,
WitnessScript, WitnessScriptBuf,
},
transaction::{Transaction, TxIn, TxOut},
witness::Witness,
Expand Down
12 changes: 3 additions & 9 deletions primitives/src/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ impl TryFrom<&WitnessScript> for WScriptHash {

/// Borrows `WitnessScript` as `ScriptCode` without modifying its bytes.
impl AsRef<ScriptCode> for WitnessScript {
fn as_ref(&self) -> &ScriptCode {
ScriptCode::from_bytes(self.as_bytes())
}
fn as_ref(&self) -> &ScriptCode { ScriptCode::from_bytes(self.as_bytes()) }
}

impl AsRef<ScriptCode> for WitnessScriptBuf {
Expand All @@ -239,9 +237,7 @@ impl AsRef<ScriptCode> for WitnessScriptBuf {

/// Borrows `RedeemScript` as `ScriptCode` without modifying its bytes.
impl AsRef<ScriptCode> for RedeemScript {
fn as_ref(&self) -> &ScriptCode {
ScriptCode::from_bytes(self.as_bytes())
}
fn as_ref(&self) -> &ScriptCode { ScriptCode::from_bytes(self.as_bytes()) }
}

impl AsRef<ScriptCode> for RedeemScriptBuf {
Expand All @@ -253,9 +249,7 @@ impl AsRef<ScriptCode> for RedeemScriptBuf {

/// Borrows `ScriptPubKey` as `ScriptCode` without modifying its bytes.
impl AsRef<ScriptCode> for ScriptPubKey {
fn as_ref(&self) -> &ScriptCode {
ScriptCode::from_bytes(self.as_bytes())
}
fn as_ref(&self) -> &ScriptCode { ScriptCode::from_bytes(self.as_bytes()) }
}

impl AsRef<ScriptCode> for ScriptPubKeyBuf {
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/script/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ impl Tag for WitnessScriptTag {}
/// A script code (scriptCode) used in sighash computation.
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub enum ScriptCodeTag {}
impl Tag for ScriptCodeTag {}
impl Tag for ScriptCodeTag {}
3 changes: 1 addition & 2 deletions primitives/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,7 @@ pub mod error {
match self.0 {
E::LengthPrefixDecode(ref e) =>
write_err!(f, "failed to decode witness length prefix"; e),
E::UnexpectedEof(ref e) =>
write_err!(f, "failed to decode witness"; e),
E::UnexpectedEof(ref e) => write_err!(f, "failed to decode witness"; e),
E::WitnessTooLarge(size) => write!(
f,
"serialized witness size of {} bytes exceeds the maximum of {}",
Expand Down
11 changes: 4 additions & 7 deletions units/src/amount/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
#[cfg(feature = "alloc")]
use core::fmt;

use sealed::Token;

#[cfg(feature = "alloc")]
use super::ParseAmountError;
use crate::{Amount, SignedAmount};
use sealed::Token;

#[cfg(feature = "alloc")]
struct DisplayFullError(ParseAmountError);
Expand Down Expand Up @@ -71,15 +72,11 @@ mod sealed {
}

impl AmountOps for Amount {
fn is_signed(_: Token) -> bool {
false
}
fn is_signed(_: Token) -> bool { false }
}

impl AmountOps for SignedAmount {
fn is_signed(_: Token) -> bool {
true
}
fn is_signed(_: Token) -> bool { true }
}

#[doc(hidden)]
Expand Down