What changed, and why it matters
This commit is a straightforward internal rename in the rust-bitcoin library. It changes the names 'GenericScript' and 'GenericScriptBuf' to the simpler 'Script' and 'ScriptBuf' across many files. There are no changes to how the code behaves, no bug fixes, and no security-related changes.
No security action needed. Treat as a normal API refactoring commit. Review downstream code only if it imports the old names directly, since the public names have changed.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit performs a large-scale identifier rename: GenericScript -> Script, GenericScriptBuf -> ScriptBuf, GenericScriptExt -> ScriptExt, GenericScriptBufExt -> ScriptBufExt, and corresponding private traits. Type aliases such as RedeemScript, ScriptPubKey, etc., are updated to point to the renamed base types. The diff is purely mechanical refactoring with no logic, validation, serialization, or API behavior changes.
Changed components
bitcoin/src/blockdata/script/*bitcoin/src/address/mod.rsbitcoin/src/crypto/sighash.rsbitcoin/src/psbt/*bitcoin/src/taproot/mod.rsprimitives/src/script/*Inspect captured patch +204 / −218
diff --git a/bitcoin/examples/script.rs b/bitcoin/examples/script.rs
index 36b7b11f..2a4b0492 100644
--- a/bitcoin/examples/script.rs
+++ b/bitcoin/examples/script.rs
@@ -9,7 +9,7 @@
use bitcoin::consensus::encode;
use bitcoin::key::WPubkeyHash;
-use bitcoin::script::{self, GenericScriptBufExt as _, GenericScriptExt as _};
+use bitcoin::script::{self, ScriptBufExt as _, ScriptExt as _};
use bitcoin::WitnessScriptBuf;
fn main() {
diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs
index af262d55..001445fd 100644
--- a/bitcoin/src/address/mod.rs
+++ b/bitcoin/src/address/mod.rs
@@ -64,10 +64,9 @@ use crate::prelude::{String, ToOwned};
use crate::script::witness_program::WitnessProgram;
use crate::script::witness_version::WitnessVersion;
use crate::script::{
- self, GenericScript, GenericScriptExt as _, RedeemScriptSizeError, ScriptHash,
- ScriptHashableTag, ScriptPubKey, ScriptPubKeyBuf, ScriptPubKeyBufExt as _,
- ScriptPubKeyExt as _, WScriptHash, WitnessScript, WitnessScriptExt as _,
- WitnessScriptSizeError,
+ self, RedeemScriptSizeError, Script, ScriptExt as _, ScriptHash, ScriptHashableTag,
+ ScriptPubKey, ScriptPubKeyBuf, ScriptPubKeyBufExt as _, ScriptPubKeyExt as _, WScriptHash,
+ WitnessScript, WitnessScriptExt as _, WitnessScriptSizeError,
};
use crate::taproot::TapNodeHash;
@@ -508,7 +507,7 @@ impl Address {
/// these days.
#[inline]
pub fn p2sh<T: ScriptHashableTag>(
- redeem_script: &GenericScript<T>,
+ redeem_script: &Script<T>,
network: impl Into<NetworkKind>,
) -> Result<Address, RedeemScriptSizeError> {
let hash = redeem_script.script_hash()?;
@@ -1022,7 +1021,7 @@ mod tests {
use super::*;
use crate::network::Network::{Bitcoin, Testnet};
use crate::network::{params, TestnetVersion};
- use crate::script::{GenericScriptBufExt as _, RedeemScriptBuf, WitnessScriptBuf};
+ use crate::script::{RedeemScriptBuf, ScriptBufExt as _, WitnessScriptBuf};
fn roundtrips(addr: &Address, network: Network) {
assert_eq!(
diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs
index daf8aa79..b6e06425 100644
--- a/bitcoin/src/blockdata/block.rs
+++ b/bitcoin/src/blockdata/block.rs
@@ -22,7 +22,7 @@ use crate::merkle_tree::{MerkleNode as _, TxMerkleNode, WitnessMerkleNode};
use crate::network::Params;
use crate::pow::{Target, Work};
use crate::prelude::Vec;
-use crate::script::{self, GenericScriptExt as _};
+use crate::script::{self, ScriptExt as _};
use crate::transaction::{Transaction, TransactionExt as _, Wtxid};
use crate::{internal_macros, BlockTime};
diff --git a/bitcoin/src/blockdata/script/borrowed.rs b/bitcoin/src/blockdata/script/borrowed.rs
index be5205d2..ecace353 100644
--- a/bitcoin/src/blockdata/script/borrowed.rs
+++ b/bitcoin/src/blockdata/script/borrowed.rs
@@ -9,9 +9,9 @@ use secp256k1::{Secp256k1, Verification};
use super::witness_version::WitnessVersion;
use super::{
- Builder, GenericScript, Instruction, InstructionIndices, Instructions, PushBytes, RedeemScript,
- RedeemScriptSizeError, ScriptHash, ScriptHashableTag, ScriptPubKey, ScriptSig, TapScript,
- WScriptHash, WitnessScript, WitnessScriptSizeError,
+ Builder, Instruction, InstructionIndices, Instructions, PushBytes, RedeemScript,
+ RedeemScriptSizeError, Script, ScriptHash, ScriptHashableTag, ScriptPubKey, ScriptSig,
+ TapScript, WScriptHash, WitnessScript, WitnessScriptSizeError,
};
use crate::consensus::{self, Encodable};
use crate::key::{PublicKey, UntweakedPublicKey, WPubkeyHash};
@@ -24,8 +24,8 @@ use crate::taproot::{LeafVersion, TapLeafHash, TapNodeHash};
use crate::{internal_macros, Amount, FeeRate, ScriptPubKeyBuf, WitnessScriptBuf};
internal_macros::define_extension_trait! {
- /// Extension functionality for the [`GenericScript`] type.
- pub trait GenericScriptExt<T> impl<T> for GenericScript<T> {
+ /// Extension functionality for the [`Script`] type.
+ pub trait ScriptExt<T> impl<T> for Script<T> {
/// Constructs a new script builder
fn builder() -> Builder<T> { Builder::new() }
@@ -472,11 +472,11 @@ internal_macros::define_extension_trait! {
mod sealed {
pub trait Sealed {}
- impl<T> Sealed for super::GenericScript<T> {}
+ impl<T> Sealed for super::Script<T> {}
}
internal_macros::define_extension_trait! {
- pub(crate) trait GenericScriptExtPriv<T> impl<T> for GenericScript<T> {
+ pub(crate) trait ScriptExtPriv<T> impl<T> for Script<T> {
fn count_sigops_internal(&self, accurate: bool) -> usize {
let mut n = 0;
let mut pushnum_cache = None;
diff --git a/bitcoin/src/blockdata/script/builder.rs b/bitcoin/src/blockdata/script/builder.rs
index 68f532e5..1a3109f6 100644
--- a/bitcoin/src/blockdata/script/builder.rs
+++ b/bitcoin/src/blockdata/script/builder.rs
@@ -2,31 +2,27 @@
use core::fmt;
-use super::{opcode_to_verify, write_scriptint, Error, GenericScript, GenericScriptBuf, PushBytes};
+use super::{opcode_to_verify, write_scriptint, Error, PushBytes, Script, ScriptBuf};
use crate::key::{PublicKey, XOnlyPublicKey};
use crate::locktime::absolute;
use crate::opcodes::all::*;
use crate::opcodes::Opcode;
use crate::prelude::Vec;
-use crate::script::{
- GenericScriptBufExt as _, GenericScriptBufExtPriv as _, GenericScriptExtPriv as _,
-};
+use crate::script::{ScriptBufExt as _, ScriptBufExtPriv as _, ScriptExtPriv as _};
use crate::{relative, Sequence};
/// An Object which can be used to construct a script piece by piece.
#[derive(PartialEq, Eq, Clone)]
-pub struct Builder<T>(GenericScriptBuf<T>, Option<Opcode>);
+pub struct Builder<T>(ScriptBuf<T>, Option<Opcode>);
impl<T> Builder<T> {
/// Constructs a new empty script.
#[inline]
- pub const fn new() -> Self { Self(GenericScriptBuf::new(), None) }
+ pub const fn new() -> Self { Self(ScriptBuf::new(), None) }
/// Constructs a new empty script builder with at least the specified capacity.
#[inline]
- pub fn with_capacity(capacity: usize) -> Self {
- Self(GenericScriptBuf::with_capacity(capacity), None)
- }
+ pub fn with_capacity(capacity: usize) -> Self { Self(ScriptBuf::with_capacity(capacity), None) }
/// Returns the length in bytes of the script.
pub fn len(&self) -> usize { self.0.len() }
@@ -182,13 +178,13 @@ impl<T> Builder<T> {
}
/// Converts the `Builder` into `ScriptBuf`.
- pub fn into_script(self) -> GenericScriptBuf<T> { self.0 }
+ pub fn into_script(self) -> ScriptBuf<T> { self.0 }
/// Converts the `Builder` into script bytes
pub fn into_bytes(self) -> Vec<u8> { self.0.into() }
/// Returns the internal script
- pub fn as_script(&self) -> &GenericScript<T> { &self.0 }
+ pub fn as_script(&self) -> &Script<T> { &self.0 }
/// Returns script bytes
pub fn as_bytes(&self) -> &[u8] { self.0.as_bytes() }
@@ -201,7 +197,7 @@ impl<T> Default for Builder<T> {
/// Constructs a new builder from an existing vector.
impl<T> From<Vec<u8>> for Builder<T> {
fn from(v: Vec<u8>) -> Self {
- let script = GenericScriptBuf::from(v);
+ let script = ScriptBuf::from(v);
let last_op = script.last_opcode();
Self(script, last_op)
}
diff --git a/bitcoin/src/blockdata/script/instruction.rs b/bitcoin/src/blockdata/script/instruction.rs
index 66566967..05605ac1 100644
--- a/bitcoin/src/blockdata/script/instruction.rs
+++ b/bitcoin/src/blockdata/script/instruction.rs
@@ -2,10 +2,10 @@
use internals::script::{self, PushDataLenLen};
-use super::{Error, GenericScript, GenericScriptBufExtPriv as _, PushBytes};
+use super::{Error, PushBytes, Script, ScriptBufExtPriv as _};
use crate::opcodes::{self, Opcode};
-/// A "parsed opcode" which allows iterating over a [`GenericScript`] in a more sensible way.
+/// A "parsed opcode" which allows iterating over a [`Script`] in a more sensible way.
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum Instruction<'a> {
/// Push a bunch of data.
@@ -93,9 +93,7 @@ impl<'a> Instructions<'a> {
/// Views the remaining script as a slice.
///
/// This is analogous to what [`core::str::Chars::as_str`] does.
- pub fn as_script<T>(&self) -> &'a GenericScript<T> {
- GenericScript::from_bytes(self.data.as_slice())
- }
+ pub fn as_script<T>(&self) -> &'a Script<T> { Script::from_bytes(self.data.as_slice()) }
/// The number of remaining bytes in the script.
fn remaining_bytes(&self) -> usize { self.data.as_slice().len() }
@@ -205,7 +203,7 @@ impl core::iter::FusedIterator for Instructions<'_> {}
/// Iterator over script instructions with their positions.
///
-/// The returned indices can be used for slicing [`GenericScript`] [safely](GenericScript#slicing-safety).
+/// The returned indices can be used for slicing [`Script`] [safely](Script#slicing-safety).
///
/// This is analogous to [`core::str::CharIndices`].
#[derive(Debug, Clone)]
@@ -219,7 +217,7 @@ impl<'a> InstructionIndices<'a> {
///
/// This is analogous to what [`core::str::Chars::as_str`] does.
#[inline]
- pub fn as_script<T>(&self) -> &'a GenericScript<T> { self.instructions.as_script() }
+ pub fn as_script<T>(&self) -> &'a Script<T> { self.instructions.as_script() }
/// Constructs a new `Self` setting `pos` to 0.
pub(super) fn from_instructions(instructions: Instructions<'a>) -> Self {
diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs
index 34b54d56..065e4324 100644
--- a/bitcoin/src/blockdata/script/mod.rs
+++ b/bitcoin/src/blockdata/script/mod.rs
@@ -72,22 +72,22 @@ use crate::OutPoint;
#[rustfmt::skip] // Keep public re-exports separate.
#[doc(inline)]
pub use self::{
- borrowed::{GenericScriptExt, TapScriptExt, ScriptPubKeyExt, WitnessScriptExt, ScriptSigExt},
+ borrowed::{ScriptExt, TapScriptExt, ScriptPubKeyExt, WitnessScriptExt, ScriptSigExt},
builder::Builder,
instruction::{Instruction, Instructions, InstructionIndices},
- owned::{GenericScriptBufExt, ScriptPubKeyBufExt},
+ owned::{ScriptBufExt, ScriptPubKeyBufExt},
push_bytes::{PushBytes, PushBytesBuf, PushBytesError, PushBytesErrorReport},
};
#[doc(inline)]
pub use primitives::script::{
- GenericScript, GenericScriptBuf, RedeemScript, RedeemScriptBuf, RedeemScriptSizeError,
- RedeemScriptTag, ScriptHash, ScriptHashableTag, ScriptPubKey, ScriptPubKeyBuf, ScriptPubKeyTag,
- ScriptSig, ScriptSigBuf, ScriptSigTag, Tag, TapScript, TapScriptBuf, WScriptHash,
- WitnessScript, WitnessScriptBuf, WitnessScriptSizeError, WitnessScriptTag,
+ RedeemScript, RedeemScriptBuf, RedeemScriptSizeError, RedeemScriptTag, Script, ScriptBuf,
+ ScriptHash, ScriptHashableTag, ScriptPubKey, ScriptPubKeyBuf, ScriptPubKeyTag, ScriptSig,
+ ScriptSigBuf, ScriptSigTag, Tag, TapScript, TapScriptBuf, WScriptHash, WitnessScript,
+ WitnessScriptBuf, WitnessScriptSizeError, WitnessScriptTag,
};
-pub(crate) use self::borrowed::GenericScriptExtPriv;
-pub(crate) use self::owned::GenericScriptBufExtPriv;
+pub(crate) use self::borrowed::ScriptExtPriv;
+pub(crate) use self::owned::ScriptBufExtPriv;
impl_asref_push_bytes!(ScriptHash, WScriptHash);
@@ -205,7 +205,7 @@ fn opcode_to_verify(opcode: Option<Opcode>) -> Option<Opcode> {
pub(crate) fn new_witness_program_unchecked<T: AsRef<PushBytes>, Tg>(
version: WitnessVersion,
program: T,
-) -> GenericScriptBuf<Tg> {
+) -> ScriptBuf<Tg> {
let program = program.as_ref();
debug_assert!(program.len() >= 2 && program.len() <= 40);
// In SegWit v0, the program must be either 20 bytes (P2WPKH) or 32 bytes (P2WSH) long.
@@ -213,21 +213,21 @@ pub(crate) fn new_witness_program_unchecked<T: AsRef<PushBytes>, Tg>(
Builder::new().push_opcode(version.into()).push_slice(program).into_script()
}
-impl<T> Encodable for GenericScript<T> {
+impl<T> Encodable for Script<T> {
#[inline]
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
crate::consensus::encode::consensus_encode_with_size(self.as_bytes(), w)
}
}
-impl<T> Encodable for GenericScriptBuf<T> {
+impl<T> Encodable for ScriptBuf<T> {
#[inline]
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
self.as_script().consensus_encode(w)
}
}
-impl<T> Decodable for GenericScriptBuf<T> {
+impl<T> Decodable for ScriptBuf<T> {
#[inline]
fn consensus_decode_from_finite_reader<R: BufRead + ?Sized>(
r: &mut R,
diff --git a/bitcoin/src/blockdata/script/owned.rs b/bitcoin/src/blockdata/script/owned.rs
index 0d8d7d50..b359182b 100644
--- a/bitcoin/src/blockdata/script/owned.rs
+++ b/bitcoin/src/blockdata/script/owned.rs
@@ -8,7 +8,7 @@ use internals::ToU64 as _;
use secp256k1::{Secp256k1, Verification};
use super::{
- opcode_to_verify, Builder, GenericScriptBuf, GenericScriptExtPriv as _, Instruction, PushBytes,
+ opcode_to_verify, Builder, Instruction, PushBytes, ScriptBuf, ScriptExtPriv as _,
ScriptPubKeyBuf,
};
use crate::key::{
@@ -24,8 +24,8 @@ use crate::taproot::TapNodeHash;
use crate::{consensus, internal_macros};
internal_macros::define_extension_trait! {
- /// Extension functionality for the [`GenericScriptBuf`] type.
- pub trait GenericScriptBufExt<T> impl<T> for GenericScriptBuf<T> {
+ /// Extension functionality for the [`ScriptBuf`] type.
+ pub trait ScriptBufExt<T> impl<T> for ScriptBuf<T> {
/// Constructs a new script builder
fn builder() -> Builder<T> { Builder::new() }
@@ -95,7 +95,7 @@ internal_macros::define_extension_trait! {
/// multiple times.
fn scan_and_push_verify(&mut self) { self.push_verify(self.last_opcode()); }
- /// Constructs a new [`GenericScriptBuf`] from a hex string.
+ /// Constructs a new [`ScriptBuf`] from a hex string.
///
/// The input string is expected to be consensus encoded i.e., includes the length prefix.
fn from_hex_prefixed(s: &str) -> Result<Self, consensus::FromHexError>
@@ -104,7 +104,7 @@ internal_macros::define_extension_trait! {
consensus::encode::deserialize_hex(s)
}
- /// Constructs a new [`GenericScriptBuf`] from a hex string.
+ /// Constructs a new [`ScriptBuf`] from a hex string.
#[deprecated(since = "TBD", note = "use `from_hex_string_no_length_prefix()` instead")]
fn from_hex(s: &str) -> Result<Self, hex::HexToBytesError>
where Self: Sized
@@ -112,10 +112,10 @@ internal_macros::define_extension_trait! {
Self::from_hex_no_length_prefix(s)
}
- /// Constructs a new [`GenericScriptBuf`] from a hex string.
+ /// Constructs a new [`ScriptBuf`] from a hex string.
///
/// This is **not** consensus encoding. If your hex string is a consensus encoded script
- /// then use `GenericScriptBuf::from_hex_prefixed`.
+ /// then use `ScriptBuf::from_hex_prefixed`.
fn from_hex_no_length_prefix(s: &str) -> Result<Self, hex::HexToBytesError>
where Self: Sized
{
@@ -208,11 +208,11 @@ crate::internal_macros::define_extension_trait! {
mod sealed {
pub trait Sealed {}
- impl<T> Sealed for super::GenericScriptBuf<T> {}
+ impl<T> Sealed for super::ScriptBuf<T> {}
}
internal_macros::define_extension_trait! {
- pub(crate) trait GenericScriptBufExtPriv<T> impl<T> for GenericScriptBuf<T> {
+ pub(crate) trait ScriptBufExtPriv<T> impl<T> for ScriptBuf<T> {
/// Pretends to convert `&mut ScriptBuf` to `&mut Vec<u8>` so that it can be modified.
///
/// Note: if the returned value leaks the original `ScriptBuf` will become empty.
@@ -278,7 +278,7 @@ internal_macros::define_extension_trait! {
}
}
-impl<'a, Tg> core::iter::FromIterator<Instruction<'a>> for GenericScriptBuf<Tg> {
+impl<'a, Tg> core::iter::FromIterator<Instruction<'a>> for ScriptBuf<Tg> {
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item = Instruction<'a>>,
@@ -289,7 +289,7 @@ impl<'a, Tg> core::iter::FromIterator<Instruction<'a>> for GenericScriptBuf<Tg>
}
}
-impl<'a, Tg> Extend<Instruction<'a>> for GenericScriptBuf<Tg> {
+impl<'a, Tg> Extend<Instruction<'a>> for ScriptBuf<Tg> {
fn extend<T>(&mut self, iter: T)
where
T: IntoIterator<Item = Instruction<'a>>,
@@ -330,7 +330,7 @@ impl<'a, Tg> Extend<Instruction<'a>> for GenericScriptBuf<Tg> {
/// In reality the backing `Vec<u8>` is swapped with an empty one and this is holding both the
/// reference and the vec. The vec is put back when this drops so it also covers panics. (But not
/// leaks, which is OK since we never leak.)
-pub(crate) struct ScriptBufAsVec<'a, T>(&'a mut GenericScriptBuf<T>, Vec<u8>);
+pub(crate) struct ScriptBufAsVec<'a, T>(&'a mut ScriptBuf<T>, Vec<u8>);
impl<T> core::ops::Deref for ScriptBufAsVec<'_, T> {
type Target = Vec<u8>;
@@ -345,6 +345,6 @@ impl<T> core::ops::DerefMut for ScriptBufAsVec<'_, T> {
impl<T> Drop for ScriptBufAsVec<'_, T> {
fn drop(&mut self) {
let vec = core::mem::take(&mut self.1);
- *(self.0) = GenericScriptBuf::from_bytes(vec);
+ *(self.0) = ScriptBuf::from_bytes(vec);
}
}
diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs
index 3049c86c..318d9fa7 100644
--- a/bitcoin/src/blockdata/transaction.rs
+++ b/bitcoin/src/blockdata/transaction.rs
@@ -22,7 +22,7 @@ use crate::consensus::{self, encode, Decodable, Encodable};
use crate::locktime::absolute::{self, Height, MedianTimePast};
use crate::prelude::{Borrow, Vec};
use crate::script::{
- GenericScriptExt as _, GenericScriptExtPriv as _, RedeemScript, ScriptPubKey, ScriptPubKeyBuf,
+ RedeemScript, ScriptExt as _, ScriptExtPriv as _, ScriptPubKey, ScriptPubKeyBuf,
ScriptPubKeyExt as _, WitnessScript,
};
#[cfg(doc)]
diff --git a/bitcoin/src/blockdata/witness.rs b/bitcoin/src/blockdata/witness.rs
index 43ef966b..2034aa55 100644
--- a/bitcoin/src/blockdata/witness.rs
+++ b/bitcoin/src/blockdata/witness.rs
@@ -207,7 +207,7 @@ internal_macros::define_extension_trait! {
/// Unlike the Taproot case, we do no validation to determine whether this is a
/// witness script: it may be a Taproot control block, annex, or some other kind
/// of object. If you are not certain whether the output being spent is Segwit v0,
- /// use [`crate::script::GenericScriptExt::is_p2wsh`] on the output's script.
+ /// use [`crate::script::ScriptExt::is_p2wsh`] on the output's script.
fn witness_script(&self) -> Option<&WitnessScript> { self.last().map(WitnessScript::from_bytes) }
}
}
diff --git a/bitcoin/src/crypto/ecdsa.rs b/bitcoin/src/crypto/ecdsa.rs
index 62be3299..64bdd5ff 100644
--- a/bitcoin/src/crypto/ecdsa.rs
+++ b/bitcoin/src/crypto/ecdsa.rs
@@ -102,7 +102,7 @@ impl FromStr for Signature {
/// expect and has familiar methods.
///
/// However, the usual use case is to push it into a script. This can be done directly passing it
-/// into [`push_slice`](crate::script::GenericScriptBufExt::push_slice).
+/// into [`push_slice`](crate::script::ScriptBufExt::push_slice).
#[derive(Copy, Clone)]
pub struct SerializedSignature {
data: [u8; MAX_SIG_LEN],
diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs
index e223a749..bad17a7c 100644
--- a/bitcoin/src/crypto/sighash.rs
+++ b/bitcoin/src/crypto/sighash.rs
@@ -22,7 +22,7 @@ use io::Write;
use crate::consensus::{encode, Encodable};
use crate::prelude::{Borrow, BorrowMut, String, ToOwned};
-use crate::script::{GenericScriptExt as _, ScriptHashableTag};
+use crate::script::{ScriptExt as _, ScriptHashableTag};
use crate::taproot::{LeafVersion, TapLeafHash, TapLeafTag, TAPROOT_ANNEX_PREFIX};
use crate::transaction::TransactionExt as _;
use crate::witness::Witness;
@@ -878,7 +878,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
pub fn p2wpkh_signature_hash<T: ScriptHashableTag>(
&mut self,
input_index: usize,
- script_pubkey: &crate::script::GenericScript<T>,
+ script_pubkey: &crate::script::Script<T>,
value: Amount,
sighash_type: EcdsaSighashType,
) -> Result<SegwitV0Sighash, P2wpkhError> {
@@ -945,7 +945,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
&self,
writer: &mut W,
input_index: usize,
- script_pubkey: &crate::script::GenericScript<T>,
+ script_pubkey: &crate::script::Script<T>,
sighash_type: U,
) -> EncodeSigningDataResult<SigningDataError<transaction::InputsIndexError>> {
// Validate input_index.
@@ -970,7 +970,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
self_: &Transaction,
writer: &mut W,
input_index: usize,
- script_pubkey: &crate::script::GenericScript<T>,
+ script_pubkey: &crate::script::Script<T>,
sighash_type: u32,
) -> Result<(), io::Error> {
use crate::consensus::encode::WriteExt;
@@ -1065,7 +1065,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
pub fn legacy_signature_hash<T: ScriptHashableTag>(
&self,
input_index: usize,
- script_pubkey: &crate::script::GenericScript<T>,
+ script_pubkey: &crate::script::Script<T>,
sighash_type: u32,
) -> Result<LegacySighash, transaction::InputsIndexError> {
let mut engine = LegacySighash::engine();
@@ -1542,7 +1542,7 @@ mod tests {
use crate::consensus::deserialize;
use crate::locktime::absolute;
use crate::script::{
- GenericScriptBufExt as _, ScriptPubKey, ScriptPubKeyBuf, TapScriptBuf, WitnessScriptBuf,
+ ScriptBufExt as _, ScriptPubKey, ScriptPubKeyBuf, TapScriptBuf, WitnessScriptBuf,
};
use crate::TxIn;
diff --git a/bitcoin/src/lib.rs b/bitcoin/src/lib.rs
index 6b824a41..ecb3fca0 100644
--- a/bitcoin/src/lib.rs
+++ b/bitcoin/src/lib.rs
@@ -114,7 +114,7 @@ pub mod ext {
pub use crate::{
block::{BlockUncheckedExt as _, BlockCheckedExt as _, HeaderExt as _},
pow::CompactTargetExt as _,
- script::{GenericScriptExt as _, GenericScriptBufExt as _, TapScriptExt as _, ScriptPubKeyExt as _, ScriptPubKeyBufExt as _, WitnessScriptExt as _, ScriptSigExt as _},
+ script::{ScriptExt as _, ScriptBufExt as _, TapScriptExt as _, ScriptPubKeyExt as _, ScriptPubKeyBufExt as _, WitnessScriptExt as _, ScriptSigExt as _},
transaction::{TxidExt as _, WtxidExt as _, OutPointExt as _, TxInExt as _, TxOutExt as _, TransactionExt as _},
witness::WitnessExt as _,
};
diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs
index a3641a6c..6dc89a99 100644
--- a/bitcoin/src/psbt/mod.rs
+++ b/bitcoin/src/psbt/mod.rs
@@ -26,7 +26,7 @@ use crate::crypto::key::{PrivateKey, PublicKey};
use crate::crypto::{ecdsa, taproot};
use crate::key::{TapTweak, XOnlyPublicKey};
use crate::prelude::{btree_map, BTreeMap, BTreeSet, Borrow, Box, Vec};
-use crate::script::{GenericScriptExt as _, ScriptPubKeyExt as _};
+use crate::script::{ScriptExt as _, ScriptPubKeyExt as _};
use crate::sighash::{self, EcdsaSighashType, Prevouts, SighashCache};
use crate::transaction::{self, Transaction, TransactionExt as _, TxOut};
use crate::{Amount, FeeRate, TapLeafHash, TapSighash, TapSighashType};
@@ -1344,7 +1344,7 @@ mod tests {
use crate::network::NetworkKind;
use crate::psbt::serialize::{Deserialize, Serialize};
use crate::script::{
- GenericScriptBufExt as _, RedeemScriptBuf, ScriptPubKeyBuf, ScriptSigBuf, WitnessScriptBuf,
+ RedeemScriptBuf, ScriptBufExt as _, ScriptPubKeyBuf, ScriptSigBuf, WitnessScriptBuf,
};
use crate::transaction::{self, OutPoint, TxIn};
use crate::witness::Witness;
diff --git a/bitcoin/src/psbt/serialize.rs b/bitcoin/src/psbt/serialize.rs
index 6804cc26..457dc73d 100644
--- a/bitcoin/src/psbt/serialize.rs
+++ b/bitcoin/src/psbt/serialize.rs
@@ -18,7 +18,7 @@ use crate::crypto::{ecdsa, taproot};
use crate::io::Write;
use crate::prelude::{DisplayHex, String, Vec};
use crate::psbt::{Error, Psbt};
-use crate::script::GenericScriptBuf;
+use crate::script::ScriptBuf;
use crate::taproot::{
ControlBlock, LeafVersion, TapLeafHash, TapNodeHash, TapTree, TaprootBuilder,
};
@@ -152,11 +152,11 @@ impl_psbt_hash_de_serialize!(sha256d::Hash);
// Taproot
impl_psbt_de_serialize!(Vec<TapLeafHash>);
-impl<T> Serialize for GenericScriptBuf<T> {
+impl<T> Serialize for ScriptBuf<T> {
fn serialize(&self) -> Vec<u8> { self.to_vec() }
}
-impl<T> Deserialize for GenericScriptBuf<T> {
+impl<T> Deserialize for ScriptBuf<T> {
fn deserialize(bytes: &[u8]) -> Result<Self, Error> { Ok(Self::from(bytes.to_vec())) }
}
@@ -346,7 +346,7 @@ impl Deserialize for ControlBlock {
}
// Versioned ScriptBuf
-impl<T> Serialize for (GenericScriptBuf<T>, LeafVersion) {
+impl<T> Serialize for (ScriptBuf<T>, LeafVersion) {
fn serialize(&self) -> Vec<u8> {
let mut buf = Vec::with_capacity(self.0.len() + 1);
buf.extend(self.0.as_bytes());
@@ -355,13 +355,13 @@ impl<T> Serialize for (GenericScriptBuf<T>, LeafVersion) {
}
}
-impl<T> Deserialize for (GenericScriptBuf<T>, LeafVersion) {
+impl<T> Deserialize for (ScriptBuf<T>, LeafVersion) {
fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
if bytes.is_empty() {
return Err(io::Error::from(io::ErrorKind::UnexpectedEof).into());
}
// The last byte is LeafVersion.
- let script = GenericScriptBuf::deserialize(&bytes[..bytes.len() - 1])?;
+ let script = ScriptBuf::deserialize(&bytes[..bytes.len() - 1])?;
let leaf_ver = LeafVersion::from_consensus(bytes[bytes.len() - 1])
.map_err(|_| Error::InvalidLeafVersion)?;
Ok((script, leaf_ver))
@@ -415,8 +415,7 @@ impl Deserialize for TapTree {
let mut bytes_iter = bytes.iter();
while let Some(depth) = bytes_iter.next() {
let version = bytes_iter.next().ok_or(Error::Taproot("invalid Taproot Builder"))?;
- let (script, consumed) =
- deserialize_partial::<GenericScriptBuf<_>>(bytes_iter.as_slice())?;
+ let (script, consumed) = deserialize_partial::<ScriptBuf<_>>(bytes_iter.as_slice())?;
if consumed > 0 {
bytes_iter.nth(consumed - 1);
}
@@ -436,7 +435,7 @@ fn key_source_len(key_source: &KeySource) -> usize { 4 + 4 * (key_source.1).as_r
#[cfg(test)]
mod tests {
use super::*;
- use crate::script::GenericScriptBufExt as _;
+ use crate::script::ScriptBufExt as _;
use crate::TapScriptBuf;
// Composes tree matching a given depth map, filled with dumb script leafs,
diff --git a/bitcoin/src/taproot/mod.rs b/bitcoin/src/taproot/mod.rs
index 18b37a9e..52b854f2 100644
--- a/bitcoin/src/taproot/mod.rs
+++ b/bitcoin/src/taproot/mod.rs
@@ -1693,7 +1693,7 @@ mod test {
use secp256k1::VerifyOnly;
use super::*;
- use crate::script::GenericScriptBufExt as _;
+ use crate::script::ScriptBufExt as _;
use crate::sighash::TapSighashTag;
use crate::{Address, KnownHrp, ScriptPubKeyBuf};
extern crate serde_json;
diff --git a/bitcoin/tests/bip_174.rs b/bitcoin/tests/bip_174.rs
index f99f94e0..69168ee7 100644
--- a/bitcoin/tests/bip_174.rs
+++ b/bitcoin/tests/bip_174.rs
@@ -9,7 +9,7 @@ use bitcoin::consensus::encode::{deserialize, serialize_hex};
use bitcoin::hex::FromHex;
use bitcoin::opcodes::OP_0;
use bitcoin::psbt::{Psbt, PsbtSighashType};
-use bitcoin::script::{GenericScriptBuf, GenericScriptBufExt as _, PushBytes};
+use bitcoin::script::{PushBytes, ScriptBuf, ScriptBufExt as _};
use bitcoin::secp256k1::Secp256k1;
use bitcoin::{
absolute, script, transaction, NetworkKind, OutPoint, PrivateKey, PublicKey, ScriptPubKeyBuf,
@@ -23,8 +23,8 @@ fn hex_psbt(s: &str) -> Psbt {
}
#[track_caller]
-fn hex_script<T>(s: &str) -> GenericScriptBuf<T> {
- GenericScriptBuf::from_hex_no_length_prefix(s).expect("valid hex digits")
+fn hex_script<T>(s: &str) -> ScriptBuf<T> {
+ ScriptBuf::from_hex_no_length_prefix(s).expect("valid hex digits")
}
#[test]
diff --git a/bitcoin/tests/serde.rs b/bitcoin/tests/serde.rs
index a81602ee..0d4eeaa8 100644
--- a/bitcoin/tests/serde.rs
+++ b/bitcoin/tests/serde.rs
@@ -27,7 +27,7 @@ use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d};
use bitcoin::hex::FromHex;
use bitcoin::locktime::{absolute, relative};
use bitcoin::psbt::{raw, Input, Output, Psbt, PsbtSighashType};
-use bitcoin::script::GenericScriptBufExt as _;
+use bitcoin::script::ScriptBufExt as _;
use bitcoin::sighash::{EcdsaSighashType, TapSighashType};
use bitcoin::taproot::{self, ControlBlock, LeafVersion, TapTree, TaprootBuilder};
use bitcoin::witness::Witness;
diff --git a/fuzz/fuzz_targets/bitcoin/deserialize_script.rs b/fuzz/fuzz_targets/bitcoin/deserialize_script.rs
index d42b5914..c3a553ea 100644
--- a/fuzz/fuzz_targets/bitcoin/deserialize_script.rs
+++ b/fuzz/fuzz_targets/bitcoin/deserialize_script.rs
@@ -1,6 +1,6 @@
use bitcoin::address::Address;
use bitcoin::consensus::encode;
-use bitcoin::script::{self, GenericScriptExt as _, ScriptPubKeyExt as _};
+use bitcoin::script::{self, ScriptExt as _, ScriptPubKeyExt as _};
use bitcoin::{FeeRate, Network};
use bitcoin_fuzz::fuzz_utils::{consume_random_bytes, consume_u32};
use honggfuzz::fuzz;
diff --git a/primitives/src/script/borrowed.rs b/primitives/src/script/borrowed.rs
index 96e0ceed..22028875 100644
--- a/primitives/src/script/borrowed.rs
+++ b/primitives/src/script/borrowed.rs
@@ -8,7 +8,7 @@ use core::ops::{
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
-use super::GenericScriptBuf;
+use super::ScriptBuf;
use crate::prelude::{Box, ToOwned, Vec};
internals::transparent_newtype! {
@@ -16,13 +16,13 @@ internals::transparent_newtype! {
///
/// *[See also the `bitcoin::script` module](super).*
///
- /// `GenericScript` is a script slice, the most primitive script type. It's usually seen in its borrowed
- /// form `&GenericScript`. It is always encoded as a series of bytes representing the opcodes and data
+ /// `Script` is a script slice, the most primitive script type. It's usually seen in its borrowed
+ /// form `&Script`. It is always encoded as a series of bytes representing the opcodes and data
/// pushes.
///
/// # Validity
///
- /// `GenericScript` does not have any validity invariants - it's essentially just a marked slice of
+ /// `Script` does not have any validity invariants - it's essentially just a marked slice of
/// bytes. This is similar to [`Path`](std::path::Path) vs [`OsStr`](std::ffi::OsStr) where they
/// are trivially cast-able to each-other and `Path` doesn't guarantee being a usable FS path but
/// having a newtype still has value because of added methods, readability and basic type checking.
@@ -63,13 +63,13 @@ internals::transparent_newtype! {
/// * [CScript definition](https://github.com/bitcoin/bitcoin/blob/d492dc1cdaabdc52b0766bf4cba4bd73178325d0/src/script/script.h#L410)
///
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
- pub struct GenericScript<T>(PhantomData<T>, [u8]);
+ pub struct Script<T>(PhantomData<T>, [u8]);
- impl<T> GenericScript<T> {
- /// Treat byte slice as `GenericScript`
+ impl<T> Script<T> {
+ /// Treat byte slice as `Script`
pub const fn from_bytes(bytes: &_) -> &Self;
- /// Treat mutable byte slice as `GenericScript`
+ /// Treat mutable byte slice as `Script`
pub fn from_bytes_mut(bytes: &mut _) -> &mut Self;
pub(crate) fn from_boxed_bytes(bytes: Box<_>) -> Box<Self>;
@@ -78,19 +78,19 @@ internals::transparent_newtype! {
}
}
-impl<T: 'static> Default for &GenericScript<T> {
+impl<T: 'static> Default for &Script<T> {
#[inline]
- fn default() -> Self { GenericScript::new() }
+ fn default() -> Self { Script::new() }
}
-impl<T> ToOwned for GenericScript<T> {
- type Owned = GenericScriptBuf<T>;
+impl<T> ToOwned for Script<T> {
+ type Owned = ScriptBuf<T>;
#[inline]
- fn to_owned(&self) -> Self::Owned { GenericScriptBuf::from_bytes(self.to_vec()) }
+ fn to_owned(&self) -> Self::Owned { ScriptBuf::from_bytes(self.to_vec()) }
}
-impl<T> GenericScript<T> {
+impl<T> Script<T> {
/// Constructs a new empty script.
#[inline]
pub const fn new() -> &'static Self { Self::from_bytes(&[]) }
@@ -126,17 +126,17 @@ impl<T> GenericScript<T> {
#[inline]
pub const fn is_empty(&self) -> bool { self.as_bytes().is_empty() }
- /// Converts a [`Box<GenericScript>`](Box) into a [`GenericScriptBuf`] without copying or allocating.
+ /// Converts a [`Box<Script>`](Box) into a [`ScriptBuf`] without copying or allocating.
#[must_use]
#[inline]
- pub fn into_script_buf(self: Box<Self>) -> GenericScriptBuf<T> {
+ pub fn into_script_buf(self: Box<Self>) -> ScriptBuf<T> {
let rw = Box::into_raw(self) as *mut [u8];
// SAFETY: copied from `std`
// The pointer was just created from a box without deallocating
// Casting a transparent struct wrapping a slice to the slice pointer is sound (same
// layout).
let inner = unsafe { Box::from_raw(rw) };
- GenericScriptBuf::from_bytes(Vec::from(inner))
+ ScriptBuf::from_bytes(Vec::from(inner))
}
/// Gets the hex representation of this script.
@@ -153,19 +153,19 @@ impl<T> GenericScript<T> {
}
#[cfg(feature = "arbitrary")]
-impl<'a, T> Arbitrary<'a> for &'a GenericScript<T> {
+impl<'a, T> Arbitrary<'a> for &'a Script<T> {
#[inline]
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let v = <&'a [u8]>::arbitrary(u)?;
- Ok(GenericScript::from_bytes(v))
+ Ok(Script::from_bytes(v))
}
}
macro_rules! delegate_index {
($($type:ty),* $(,)?) => {
$(
- /// [`GenericScript`] subslicing operation - read [slicing safety](#slicing-safety)!
- impl<T> Index<$type> for GenericScript<T> {
+ /// Script subslicing operation - read [slicing safety](#slicing-safety)!
+ impl<T> Index<$type> for Script<T> {
type Output = Self;
#[inline]
diff --git a/primitives/src/script/mod.rs b/primitives/src/script/mod.rs
index e49c085b..f7517b2a 100644
--- a/primitives/src/script/mod.rs
+++ b/primitives/src/script/mod.rs
@@ -28,40 +28,40 @@ use crate::prelude::{Borrow, BorrowMut, Box, Cow, ToOwned, Vec};
#[rustfmt::skip] // Keep public re-exports separate.
#[doc(inline)]
pub use self::{
- borrowed::GenericScript,
- owned::GenericScriptBuf,
+ borrowed::Script,
+ owned::ScriptBuf,
tag::{Tag, RedeemScriptTag, ScriptPubKeyTag, ScriptSigTag, TapScriptTag, WitnessScriptTag},
};
/// A P2SH redeem script.
-pub type RedeemScriptBuf = GenericScriptBuf<RedeemScriptTag>;
+pub type RedeemScriptBuf = ScriptBuf<RedeemScriptTag>;
/// A reference to a P2SH redeem script.
-pub type RedeemScript = GenericScript<RedeemScriptTag>;
+pub type RedeemScript = Script<RedeemScriptTag>;
/// A reference to a script public key (scriptPubKey).
-pub type ScriptPubKey = GenericScript<ScriptPubKeyTag>;
+pub type ScriptPubKey = Script<ScriptPubKeyTag>;
/// A reference to a script signature (scriptSig).
-pub type ScriptSig = GenericScript<ScriptSigTag>;
+pub type ScriptSig = Script<ScriptSigTag>;
/// A script public key (scriptPubKey).
-pub type ScriptPubKeyBuf = GenericScriptBuf<ScriptPubKeyTag>;
+pub type ScriptPubKeyBuf = ScriptBuf<ScriptPubKeyTag>;
/// A script signature (scriptSig).
-pub type ScriptSigBuf = GenericScriptBuf<ScriptSigTag>;
+pub type ScriptSigBuf = ScriptBuf<ScriptSigTag>;
/// A Segwit v1 Taproot script.
-pub type TapScriptBuf = GenericScriptBuf<TapScriptTag>;
+pub type TapScriptBuf = ScriptBuf<TapScriptTag>;
/// A reference to a Segwit v1 Taproot script.
-pub type TapScript = GenericScript<TapScriptTag>;
+pub type TapScript = Script<TapScriptTag>;
/// A Segwit v0 witness script.
-pub type WitnessScriptBuf = GenericScriptBuf<WitnessScriptTag>;
+pub type WitnessScriptBuf = ScriptBuf<WitnessScriptTag>;
/// A reference to a Segwit v0 witness script.
-pub type WitnessScript = GenericScript<WitnessScriptTag>;
+pub type WitnessScript = Script<WitnessScriptTag>;
/// The maximum allowed redeem script size for a P2SH output.
pub const MAX_REDEEM_SCRIPT_SIZE: usize = 520;
@@ -69,14 +69,14 @@ pub const MAX_REDEEM_SCRIPT_SIZE: usize = 520;
pub const MAX_WITNESS_SCRIPT_SIZE: usize = 10_000;
hashes::hash_newtype! {
- /// A 160-bit hash of Bitcoin GenericScript bytecode.
+ /// A 160-bit hash of Bitcoin Script bytecode.
///
/// Note: there is another "script hash" object in bitcoin ecosystem (Electrum protocol) that
/// uses 256-bit hash and hashes a semantically different script. Thus, this type cannot
/// represent it.
pub struct ScriptHash(hash160::Hash);
- /// SegWit (256-bit) version of a Bitcoin GenericScript bytecode hash.
+ /// SegWit (256-bit) version of a Bitcoin Script bytecode hash.
///
/// Note: there is another "script hash" object in bitcoin ecosystem (Electrum protocol) that
/// looks similar to this one also being SHA256, however, they hash semantically different
@@ -124,7 +124,7 @@ impl ScriptHash {
///
/// ref: [BIP-16](https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#user-content-520byte_limitation_on_serialized_script_size)
#[inline]
- pub fn from_script<T>(redeem_script: &GenericScript<T>) -> Result<Self, RedeemScriptSizeError>
+ pub fn from_script<T>(redeem_script: &Script<T>) -> Result<Self, RedeemScriptSizeError>
where
T: ScriptHashableTag,
{
@@ -143,7 +143,7 @@ impl ScriptHash {
///
/// [BIP-16]: <https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#user-content-520byte_limitation_on_serialized_script_size>
#[inline]
- pub fn from_script_unchecked<T>(script: &GenericScript<T>) -> Self {
+ pub fn from_script_unchecked<T>(script: &Script<T>) -> Self {
ScriptHash(hash160::Hash::hash(script.as_bytes()))
}
}
@@ -179,29 +179,29 @@ impl WScriptHash {
}
}
-impl<T: ScriptHashableTag> TryFrom<GenericScriptBuf<T>> for ScriptHash {
+impl<T: ScriptHashableTag> TryFrom<ScriptBuf<T>> for ScriptHash {
type Error = RedeemScriptSizeError;
#[inline]
- fn try_from(redeem_script: GenericScriptBuf<T>) -> Result<Self, Self::Error> {
+ fn try_from(redeem_script: ScriptBuf<T>) -> Result<Self, Self::Error> {
Self::from_script(&redeem_script)
}
}
-impl<T: ScriptHashableTag> TryFrom<&GenericScriptBuf<T>> for ScriptHash {
+impl<T: ScriptHashableTag> TryFrom<&ScriptBuf<T>> for ScriptHash {
type Error = RedeemScriptSizeError;
#[inline]
- fn try_from(redeem_script: &GenericScriptBuf<T>) -> Result<Self, Self::Error> {
+ fn try_from(redeem_script: &ScriptBuf<T>) -> Result<Self, Self::Error> {
Self::from_script(redeem_script)
}
}
-impl<T: ScriptHashableTag> TryFrom<&GenericScript<T>> for ScriptHash {
+impl<T: ScriptHashableTag> TryFrom<&Script<T>> for ScriptHash {
type Error = RedeemScriptSizeError;
#[inline]
- fn try_from(redeem_script: &GenericScript<T>) -> Result<Self, Self::Error> {
+ fn try_from(redeem_script: &Script<T>) -> Result<Self, Self::Error> {
Self::from_script(redeem_script)
}
}
@@ -287,21 +287,21 @@ impl fmt::Display for WitnessScriptSizeError {
#[cfg(feature = "std")]
impl std::error::Error for WitnessScriptSizeError {}
-// We keep all the `GenericScript` and `GenericScriptBuf` impls together since it's easier to see side-by-side.
+// We keep all the `Script` and `ScriptBuf` impls together since it's easier to see side-by-side.
-impl<T> From<GenericScriptBuf<T>> for Box<GenericScript<T>> {
+impl<T> From<ScriptBuf<T>> for Box<Script<T>> {
#[inline]
- fn from(v: GenericScriptBuf<T>) -> Self { v.into_boxed_script() }
+ fn from(v: ScriptBuf<T>) -> Self { v.into_boxed_script() }
}
-impl<T> From<GenericScriptBuf<T>> for Cow<'_, GenericScript<T>> {
+impl<T> From<ScriptBuf<T>> for Cow<'_, Script<T>> {
#[inline]
- fn from(value: GenericScriptBuf<T>) -> Self { Cow::Owned(value) }
+ fn from(value: ScriptBuf<T>) -> Self { Cow::Owned(value) }
}
-impl<'a, T> From<Cow<'a, GenericScript<T>>> for GenericScriptBuf<T> {
+impl<'a, T> From<Cow<'a, Script<T>>> for ScriptBuf<T> {
#[inline]
- fn from(value: Cow<'a, GenericScript<T>>) -> Self {
+ fn from(value: Cow<'a, Script<T>>) -> Self {
match value {
Cow::Owned(owned) => owned,
Cow::Borrowed(borrowed) => borrowed.into(),
@@ -309,9 +309,9 @@ impl<'a, T> From<Cow<'a, GenericScript<T>>> for GenericScriptBuf<T> {
}
}
-impl<'a, T> From<Cow<'a, GenericScript<T>>> for Box<GenericScript<T>> {
+impl<'a, T> From<Cow<'a, Script<T>>> for Box<Script<T>> {
#[inline]
- fn from(value: Cow<'a, GenericScript<T>>) -> Self {
+ fn from(value: Cow<'a, Script<T>>) -> Self {
match value {
Cow::Owned(owned) => owned.into(),
Cow::Borrowed(borrowed) => borrowed.into(),
@@ -319,101 +319,97 @@ impl<'a, T> From<Cow<'a, GenericScript<T>>> for Box<GenericScript<T>> {
}
}
-impl<'a, T> From<&'a GenericScript<T>> for Box<GenericScript<T>> {
+impl<'a, T> From<&'a Script<T>> for Box<Script<T>> {
#[inline]
- fn from(value: &'a GenericScript<T>) -> Self { value.to_owned().into() }
+ fn from(value: &'a Script<T>) -> Self { value.to_owned().into() }
}
-impl<'a, T> From<&'a GenericScript<T>> for GenericScriptBuf<T> {
+impl<'a, T> From<&'a Script<T>> for ScriptBuf<T> {
#[inline]
- fn from(value: &'a GenericScript<T>) -> Self { value.to_owned() }
+ fn from(value: &'a Script<T>) -> Self { value.to_owned() }
}
-impl<'a, T> From<&'a GenericScript<T>> for Cow<'a, GenericScript<T>> {
+impl<'a, T> From<&'a Script<T>> for Cow<'a, Script<T>> {
#[inline]
- fn from(value: &'a GenericScript<T>) -> Self { Cow::Borrowed(value) }
+ fn from(value: &'a Script<T>) -> Self { Cow::Borrowed(value) }
}
/// Note: This will fail to compile on old Rust for targets that don't support atomics
#[cfg(target_has_atomic = "ptr")]
-impl<'a, T> From<&'a GenericScript<T>> for Arc<GenericScript<T>> {
+impl<'a, T> From<&'a Script<T>> for Arc<Script<T>> {
#[inline]
- fn from(value: &'a GenericScript<T>) -> Self {
- GenericScript::from_arc_bytes(Arc::from(value.as_bytes()))
- }
+ fn from(value: &'a Script<T>) -> Self { Script::from_arc_bytes(Arc::from(value.as_bytes())) }
}
-impl<'a, T> From<&'a GenericScript<T>> for Rc<GenericScript<T>> {
+impl<'a, T> From<&'a Script<T>> for Rc<Script<T>> {
#[inline]
- fn from(value: &'a GenericScript<T>) -> Self {
- GenericScript::from_rc_bytes(Rc::from(value.as_bytes()))
- }
+ fn from(value: &'a Script<T>) -> Self { Script::from_rc_bytes(Rc::from(value.as_bytes())) }
}
-impl<T> From<Vec<u8>> for GenericScriptBuf<T> {
+impl<T> From<Vec<u8>> for ScriptBuf<T> {
#[inline]
fn from(v: Vec<u8>) -> Self { Self::from_bytes(v) }
}
-impl<T> From<GenericScriptBuf<T>> for Vec<u8> {
+impl<T> From<ScriptBuf<T>> for Vec<u8> {
#[inline]
- fn from(v: GenericScriptBuf<T>) -> Self { v.into_bytes() }
+ fn from(v: ScriptBuf<T>) -> Self { v.into_bytes() }
}
-impl<T> AsRef<GenericScript<T>> for GenericScript<T> {
+impl<T> AsRef<Script<T>> for Script<T> {
#[inline]
fn as_ref(&self) -> &Self { self }
}
-impl<T> AsRef<GenericScript<T>> for GenericScriptBuf<T> {
+impl<T> AsRef<Script<T>> for ScriptBuf<T> {
#[inline]
- fn as_ref(&self) -> &GenericScript<T> { self }
+ fn as_ref(&self) -> &Script<T> { self }
}
-impl<T> AsRef<[u8]> for GenericScript<T> {
+impl<T> AsRef<[u8]> for Script<T> {
#[inline]
fn as_ref(&self) -> &[u8] { self.as_bytes() }
}
-impl<T> AsRef<[u8]> for GenericScriptBuf<T> {
+impl<T> AsRef<[u8]> for ScriptBuf<T> {
#[inline]
fn as_ref(&self) -> &[u8] { self.as_bytes() }
}
-impl<T> AsMut<GenericScript<T>> for GenericScript<T> {
+impl<T> AsMut<Script<T>> for Script<T> {
#[inline]
fn as_mut(&mut self) -> &mut Self { self }
}
-impl<T> AsMut<GenericScript<T>> for GenericScriptBuf<T> {
+impl<T> AsMut<Script<T>> for ScriptBuf<T> {
#[inline]
- fn as_mut(&mut self) -> &mut GenericScript<T> { self }
+ fn as_mut(&mut self) -> &mut Script<T> { self }
}
-impl<T> AsMut<[u8]> for GenericScript<T> {
+impl<T> AsMut<[u8]> for Script<T> {
#[inline]
fn as_mut(&mut self) -> &mut [u8] { self.as_mut_bytes() }
}
-impl<T> AsMut<[u8]> for GenericScriptBuf<T> {
+impl<T> AsMut<[u8]> for ScriptBuf<T> {
#[inline]
fn as_mut(&mut self) -> &mut [u8] { self.as_mut_bytes() }
}
-impl<T> fmt::Debug for GenericScript<T> {
+impl<T> fmt::Debug for Script<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.write_str("GenericScript(")?;
+ f.write_str("Script(")?;
fmt::Display::fmt(self, f)?;
f.write_str(")")
}
}
-impl<T> fmt::Debug for GenericScriptBuf<T> {
+impl<T> fmt::Debug for ScriptBuf<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(self.as_script(), f) }
}
-impl<T> fmt::Display for GenericScript<T> {
+impl<T> fmt::Display for Script<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// This has to be a macro because it needs to break the loop
macro_rules! read_push_data_len {
@@ -486,13 +482,13 @@ impl<T> fmt::Display for GenericScript<T> {
}
}
-impl<T> fmt::Display for GenericScriptBuf<T> {
+impl<T> fmt::Display for ScriptBuf<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(self.as_script(), f) }
}
#[cfg(feature = "hex")]
-impl<T> fmt::LowerHex for GenericScript<T> {
+impl<T> fmt::LowerHex for Script<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::LowerHex::fmt(&self.as_bytes().as_hex(), f)
@@ -500,13 +496,13 @@ impl<T> fmt::LowerHex for GenericScript<T> {
}
#[cfg(feature = "hex")]
-impl<T> fmt::LowerHex for GenericScriptBuf<T> {
+impl<T> fmt::LowerHex for ScriptBuf<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(self.as_script(), f) }
}
#[cfg(feature = "hex")]
-impl<T> fmt::UpperHex for GenericScript<T> {
+impl<T> fmt::UpperHex for Script<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::UpperHex::fmt(&self.as_bytes().as_hex(), f)
@@ -514,48 +510,48 @@ impl<T> fmt::UpperHex for GenericScript<T> {
}
#[cfg(feature = "hex")]
-impl<T> fmt::UpperHex for GenericScriptBuf<T> {
+impl<T> fmt::UpperHex for ScriptBuf<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::UpperHex::fmt(self.as_script(), f) }
}
-impl<T> Borrow<GenericScript<T>> for GenericScriptBuf<T> {
+impl<T> Borrow<Script<T>> for ScriptBuf<T> {
#[inline]
- fn borrow(&self) -> &GenericScript<T> { self }
+ fn borrow(&self) -> &Script<T> { self }
}
-impl<T> BorrowMut<GenericScript<T>> for GenericScriptBuf<T> {
+impl<T> BorrowMut<Script<T>> for ScriptBuf<T> {
#[inline]
- fn borrow_mut(&mut self) -> &mut GenericScript<T> { self }
+ fn borrow_mut(&mut self) -> &mut Script<T> { self }
}
-impl<T: PartialEq> PartialEq<GenericScriptBuf<T>> for GenericScript<T> {
+impl<T: PartialEq> PartialEq<ScriptBuf<T>> for Script<T> {
#[inline]
- fn eq(&self, other: &GenericScriptBuf<T>) -> bool { self.eq(other.as_script()) }
+ fn eq(&self, other: &ScriptBuf<T>) -> bool { self.eq(other.as_script()) }
}
-impl<T: PartialEq> PartialEq<GenericScript<T>> for GenericScriptBuf<T> {
+impl<T: PartialEq> PartialEq<Script<T>> for ScriptBuf<T> {
#[inline]
- fn eq(&self, other: &GenericScript<T>) -> bool { self.as_script().eq(other) }
+ fn eq(&self, other: &Script<T>) -> bool { self.as_script().eq(other) }
}
-impl<T: PartialOrd> PartialOrd<GenericScript<T>> for GenericScriptBuf<T> {
+impl<T: PartialOrd> PartialOrd<Script<T>> for ScriptBuf<T> {
#[inline]
- fn partial_cmp(&self, other: &GenericScript<T>) -> Option<Ordering> {
+ fn partial_cmp(&self, other: &Script<T>) -> Option<Ordering> {
self.as_script().partial_cmp(other)
}
}
-impl<T: PartialOrd> PartialOrd<GenericScriptBuf<T>> for GenericScript<T> {
+impl<T: PartialOrd> PartialOrd<ScriptBuf<T>> for Script<T> {
#[inline]
- fn partial_cmp(&self, other: &GenericScriptBuf<T>) -> Option<Ordering> {
+ fn partial_cmp(&self, other: &ScriptBuf<T>) -> Option<Ordering> {
self.partial_cmp(other.as_script())
}
}
#[cfg(feature = "serde")]
-impl<T> serde::Serialize for GenericScript<T> {
- /// User-facing serialization for `GenericScript`.
+impl<T> serde::Serialize for Script<T> {
+ /// User-facing serialization for `Script`.
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
@@ -570,14 +566,14 @@ impl<T> serde::Serialize for GenericScript<T> {
/// Can only deserialize borrowed bytes.
#[cfg(feature = "serde")]
-impl<'de, T> serde::Deserialize<'de> for &'de GenericScript<T> {
+impl<'de, T> serde::Deserialize<'de> for &'de Script<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
struct Visitor<T>(PhantomData<T>);
impl<'de, T: 'de> serde::de::Visitor<'de> for Visitor<T> {
- type Value = &'de GenericScript<T>;
+ type Value = &'de Script<T>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("borrowed bytes")
@@ -587,7 +583,7 @@ impl<'de, T> serde::Deserialize<'de> for &'de GenericScript<T> {
where
E: serde::de::Error,
{
- Ok(GenericScript::from_bytes(v))
+ Ok(Script::from_bytes(v))
}
}
@@ -595,7 +591,7 @@ impl<'de, T> serde::Deserialize<'de> for &'de GenericScript<T> {
use crate::serde::de::Error;
return Err(D::Error::custom(
- "deserialization of `&GenericScript` from human-readable formats is not possible",
+ "deserialization of `&Script` from human-readable formats is not possible",
));
}
@@ -604,8 +600,8 @@ impl<'de, T> serde::Deserialize<'de> for &'de GenericScript<T> {
}
#[cfg(feature = "serde")]
-impl<T> serde::Serialize for GenericScriptBuf<T> {
- /// User-facing serialization for `GenericScript`.
+impl<T> serde::Serialize for ScriptBuf<T> {
+ /// User-facing serialization for `Script`.
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
@@ -615,7 +611,7 @@ impl<T> serde::Serialize for GenericScriptBuf<T> {
}
#[cfg(feature = "serde")]
-impl<'de, T> serde::Deserialize<'de> for GenericScriptBuf<T> {
+impl<'de, T> serde::Deserialize<'de> for ScriptBuf<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
@@ -627,7 +623,7 @@ impl<'de, T> serde::Deserialize<'de> for GenericScriptBuf<T> {
if deserializer.is_human_readable() {
struct Visitor<T>(PhantomData<T>);
impl<T> serde::de::Visitor<'_> for Visitor<T> {
- type Value = GenericScriptBuf<T>;
+ type Value = ScriptBuf<T>;
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
formatter.write_str("a script hex")
@@ -638,7 +634,7 @@ impl<'de, T> serde::Deserialize<'de> for GenericScriptBuf<T> {
E: serde::de::Error,
{
let v = Vec::from_hex(v).map_err(E::custom)?;
- Ok(GenericScriptBuf::from(v))
+ Ok(ScriptBuf::from(v))
}
}
deserializer.deserialize_str(Visitor(PhantomData))
@@ -646,7 +642,7 @@ impl<'de, T> serde::Deserialize<'de> for GenericScriptBuf<T> {
struct BytesVisitor<T>(PhantomData<T>);
impl<T> serde::de::Visitor<'_> for BytesVisitor<T> {
- type Value = GenericScriptBuf<T>;
+ type Value = ScriptBuf<T>;
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
formatter.write_str("a script Vec<u8>")
@@ -656,14 +652,14 @@ impl<'de, T> serde::Deserialize<'de> for GenericScriptBuf<T> {
where
E: serde::de::Error,
{
- Ok(GenericScriptBuf::from(v.to_vec()))
+ Ok(ScriptBuf::from(v.to_vec()))
}
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
- Ok(GenericScriptBuf::from(v))
+ Ok(ScriptBuf::from(v))
}
}
deserializer.deserialize_byte_buf(BytesVisitor(PhantomData))
diff --git a/primitives/src/script/owned.rs b/primitives/src/script/owned.rs
index daa7aeb3..45e289c9 100644
--- a/primitives/src/script/owned.rs
+++ b/primitives/src/script/owned.rs
@@ -6,16 +6,16 @@ use core::ops::{Deref, DerefMut};
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
-use super::GenericScript;
+use super::Script;
use crate::prelude::{Box, Vec};
/// An owned, growable script.
///
-/// `GenericScriptBuf` is the most common script type that has the ownership over the contents of the
-/// script. It has a close relationship with its borrowed counterpart, [`GenericScript`].
+/// `ScriptBuf` is the most common script type that has the ownership over the contents of the
+/// script. It has a close relationship with its borrowed counterpart, [`Script`].
///
/// Just as other similar types, this implements [`Deref`], so [deref coercions] apply. Also note
-/// that all the safety/validity restrictions that apply to [`GenericScript`] apply to `GenericScriptBuf` as well.
+/// that all the safety/validity restrictions that apply to [`Script`] apply to `ScriptBuf` as well.
///
/// # Hexadecimal strings
///
@@ -28,9 +28,9 @@ use crate::prelude::{Box, Vec};
/// [`examples/script.rs`]: <https://github.com/rust-bitcoin/rust-bitcoin/blob/master/bitcoin/examples/script.rs>
/// [deref coercions]: https://doc.rust-lang.org/std/ops/trait.Deref.html#more-on-deref-coercion
#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
-pub struct GenericScriptBuf<T>(PhantomData<T>, Vec<u8>);
+pub struct ScriptBuf<T>(PhantomData<T>, Vec<u8>);
-impl<T> GenericScriptBuf<T> {
+impl<T> ScriptBuf<T> {
/// Constructs a new empty script.
#[inline]
pub const fn new() -> Self { Self::from_bytes(Vec::new()) }
@@ -44,13 +44,11 @@ impl<T> GenericScriptBuf<T> {
/// Returns a reference to unsized script.
#[inline]
- pub fn as_script(&self) -> &GenericScript<T> { GenericScript::from_bytes(&self.1) }
+ pub fn as_script(&self) -> &Script<T> { Script::from_bytes(&self.1) }
/// Returns a mutable reference to unsized script.
#[inline]
- pub fn as_mut_script(&mut self) -> &mut GenericScript<T> {
- GenericScript::from_bytes_mut(&mut self.1)
- }
+ pub fn as_mut_script(&mut self) -> &mut Script<T> { Script::from_bytes_mut(&mut self.1) }
/// Converts the script into a byte vector.
///
@@ -62,7 +60,7 @@ impl<T> GenericScriptBuf<T> {
#[inline]
pub fn into_bytes(self) -> Vec<u8> { self.1 }
- /// Converts this `GenericScriptBuf` into a [boxed](Box) [`GenericScript`].
+ /// Converts this `ScriptBuf` into a [boxed](Box) [`Script`].
///
/// This method reallocates if the capacity is greater than length of the script but should not
/// when they are equal. If you know beforehand that you need to create a script of exact size
@@ -70,8 +68,8 @@ impl<T> GenericScriptBuf<T> {
/// reallocation can be avoided.
#[must_use]
#[inline]
- pub fn into_boxed_script(self) -> Box<GenericScript<T>> {
- GenericScript::from_boxed_bytes(self.into_bytes().into_boxed_slice())
+ pub fn into_boxed_script(self) -> Box<Script<T>> {
+ Script::from_boxed_bytes(self.into_bytes().into_boxed_slice())
}
/// Constructs a new empty script with at least the specified capacity.
@@ -127,24 +125,24 @@ impl<T> GenericScriptBuf<T> {
}
// Cannot derive due to generics.
-impl<T> Default for GenericScriptBuf<T> {
+impl<T> Default for ScriptBuf<T> {
fn default() -> Self { Self(PhantomData, Vec::new()) }
}
-impl<T> Deref for GenericScriptBuf<T> {
- type Target = GenericScript<T>;
+impl<T> Deref for ScriptBuf<T> {
+ type Target = Script<T>;
#[inline]
fn deref(&self) -> &Self::Target { self.as_script() }
}
-impl<T> DerefMut for GenericScriptBuf<T> {
+impl<T> DerefMut for ScriptBuf<T> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target { self.as_mut_script() }
}
#[cfg(feature = "arbitrary")]
-impl<'a, T> Arbitrary<'a> for GenericScriptBuf<T> {
+impl<'a, T> Arbitrary<'a> for ScriptBuf<T> {
#[inline]
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let v = Vec::<u8>::arbitrary(u)?;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.