Skip to content

Commit 9787ba6

Browse files
committed
Rename Script::empty to Script::new
The `empty` constructor is mis-named for the following reasons: - Non-uniform with `ScriptBuf::new` - Non-standard with respect to stdlib which uses `Path::new` and `PathBuf::new` (on which we based the `Scritp`/`ScriptBuf`) Rename the function to `new`, put it at the top of the impl block while we are at it.
1 parent 1318ff8 commit 9787ba6

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

bitcoin/src/blockdata/script/borrowed.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ impl ToOwned for Script {
8080
}
8181

8282
impl Script {
83+
/// Creates a new empty script.
84+
#[inline]
85+
pub fn new() -> &'static Script { Script::from_bytes(&[]) }
86+
8387
/// Treat byte slice as `Script`
8488
#[inline]
8589
pub fn from_bytes(bytes: &[u8]) -> &Script {
@@ -110,10 +114,6 @@ impl Script {
110114
#[inline]
111115
pub fn as_mut_bytes(&mut self) -> &mut [u8] { &mut self.0 }
112116

113-
/// Creates a new empty script.
114-
#[inline]
115-
pub fn empty() -> &'static Script { Script::from_bytes(&[]) }
116-
117117
/// Creates a new script builder
118118
pub fn builder() -> Builder { Builder::new() }
119119

bitcoin/src/blockdata/script/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ fn script_asm() {
423423

424424
#[test]
425425
fn script_buf_collect() {
426-
assert_eq!(&core::iter::empty::<Instruction<'_>>().collect::<ScriptBuf>(), Script::empty());
426+
assert_eq!(&core::iter::empty::<Instruction<'_>>().collect::<ScriptBuf>(), Script::new());
427427
let script = ScriptBuf::from_hex("0047304402202457e78cc1b7f50d0543863c27de75d07982bde8359b9e3316adec0aec165f2f02200203fd331c4e4a4a02f48cf1c291e2c0d6b2f7078a784b5b3649fca41f8794d401004cf1552103244e602b46755f24327142a0517288cebd159eccb6ccf41ea6edf1f601e9af952103bbbacc302d19d29dbfa62d23f37944ae19853cf260c745c2bea739c95328fcb721039227e83246bd51140fe93538b2301c9048be82ef2fb3c7fc5d78426ed6f609ad210229bf310c379b90033e2ecb07f77ecf9b8d59acb623ab7be25a0caed539e2e6472103703e2ed676936f10b3ce9149fa2d4a32060fb86fa9a70a4efe3f21d7ab90611921031e9b7c6022400a6bb0424bbcde14cff6c016b91ee3803926f3440abf5c146d05210334667f975f55a8455d515a2ef1c94fdfa3315f12319a14515d2a13d82831f62f57ae").unwrap();
428428
assert_eq!(script.instructions().collect::<Result<ScriptBuf, _>>().unwrap(), script);
429429
}

bitcoin/src/crypto/sighash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ impl<R: BorrowMut<Transaction>> SighashCache<R> {
10621062
///
10631063
/// let mut sig_hasher = SighashCache::new(&mut tx_to_sign);
10641064
/// for inp in 0..input_count {
1065-
/// let prevout_script = Script::empty();
1065+
/// let prevout_script = Script::new();
10661066
/// let _sighash = sig_hasher.segwit_signature_hash(inp, prevout_script, Amount::ONE_SAT, EcdsaSighashType::All);
10671067
/// // ... sign the sighash
10681068
/// sig_hasher.witness_mut(inp).unwrap().push(&Vec::new());
@@ -1364,7 +1364,7 @@ mod tests {
13641364
})
13651365
);
13661366
assert_eq!(
1367-
c.legacy_signature_hash(10, Script::empty(), 0u32),
1367+
c.legacy_signature_hash(10, Script::new(), 0u32),
13681368
Err(Error::IndexOutOfInputsBounds {
13691369
index: 10,
13701370
inputs_size: 1

0 commit comments

Comments
 (0)