Deprecate Script::fmt_asm and to_asm_str
The `Script::fmt_asm` function is a legacy from days yore before `Display` printed asm. We no longer need it. Deprecate `Script::fmt_asm` and use the private `bytes_to_asm_fmt` or `Display` impls.
This commit is contained in:
parent
6fac593ec9
commit
374c6118dc
|
@ -481,14 +481,16 @@ crate::internal_macros::define_extension_trait! {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes the human-readable assembly representation of the script to the formatter.
|
/// Writes the human-readable assembly representation of the script to the formatter.
|
||||||
|
#[deprecated(since = "TBD", note = "use the script's Display impl instead")]
|
||||||
fn fmt_asm(&self, f: &mut dyn fmt::Write) -> fmt::Result {
|
fn fmt_asm(&self, f: &mut dyn fmt::Write) -> fmt::Result {
|
||||||
bytes_to_asm_fmt(self.as_ref(), f)
|
bytes_to_asm_fmt(self.as_ref(), f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the human-readable assembly representation of the script.
|
/// Returns the human-readable assembly representation of the script.
|
||||||
|
#[deprecated(since = "TBD", note = "use `to_string()` instead")]
|
||||||
fn to_asm_string(&self) -> String {
|
fn to_asm_string(&self) -> String {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
self.fmt_asm(&mut buf).unwrap();
|
bytes_to_asm_fmt(self.as_ref(), &mut buf).expect("in-memory writers don't fail");
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::locktime::absolute;
|
||||||
use crate::opcodes::all::*;
|
use crate::opcodes::all::*;
|
||||||
use crate::opcodes::{self, Opcode};
|
use crate::opcodes::{self, Opcode};
|
||||||
use crate::prelude::Vec;
|
use crate::prelude::Vec;
|
||||||
use crate::script::{ScriptBufExt as _, ScriptExt as _, ScriptExtPriv as _};
|
use crate::script::{ScriptBufExt as _, ScriptExtPriv as _};
|
||||||
use crate::Sequence;
|
use crate::Sequence;
|
||||||
|
|
||||||
/// An Object which can be used to construct a script piece by piece.
|
/// An Object which can be used to construct a script piece by piece.
|
||||||
|
@ -126,7 +126,7 @@ impl From<Vec<u8>> for Builder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Builder {
|
impl fmt::Display for Builder {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.fmt_asm(f) }
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) }
|
||||||
}
|
}
|
||||||
|
|
||||||
internals::debug_from_display!(Builder);
|
internals::debug_from_display!(Builder);
|
||||||
|
|
|
@ -415,7 +415,7 @@ impl AsMut<[u8]> for ScriptBuf {
|
||||||
impl fmt::Debug for Script {
|
impl fmt::Debug for Script {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.write_str("Script(")?;
|
f.write_str("Script(")?;
|
||||||
self.fmt_asm(f)?;
|
bytes_to_asm_fmt(self.as_ref(), f)?;
|
||||||
f.write_str(")")
|
f.write_str(")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -426,7 +426,7 @@ impl fmt::Debug for ScriptBuf {
|
||||||
|
|
||||||
impl fmt::Display for Script {
|
impl fmt::Display for Script {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_asm(f) }
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { bytes_to_asm_fmt(self.as_ref(), f) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ScriptBuf {
|
impl fmt::Display for ScriptBuf {
|
||||||
|
|
|
@ -483,40 +483,40 @@ fn script_json_serialize() {
|
||||||
#[test]
|
#[test]
|
||||||
fn script_asm() {
|
fn script_asm() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ScriptBuf::from_hex("6363636363686868686800").unwrap().to_asm_string(),
|
ScriptBuf::from_hex("6363636363686868686800").unwrap().to_string(),
|
||||||
"OP_IF OP_IF OP_IF OP_IF OP_IF OP_ENDIF OP_ENDIF OP_ENDIF OP_ENDIF OP_ENDIF OP_0"
|
"OP_IF OP_IF OP_IF OP_IF OP_IF OP_ENDIF OP_ENDIF OP_ENDIF OP_ENDIF OP_ENDIF OP_0"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ScriptBuf::from_hex("6363636363686868686800").unwrap().to_asm_string(),
|
ScriptBuf::from_hex("6363636363686868686800").unwrap().to_string(),
|
||||||
"OP_IF OP_IF OP_IF OP_IF OP_IF OP_ENDIF OP_ENDIF OP_ENDIF OP_ENDIF OP_ENDIF OP_0"
|
"OP_IF OP_IF OP_IF OP_IF OP_IF OP_ENDIF OP_ENDIF OP_ENDIF OP_ENDIF OP_ENDIF OP_0"
|
||||||
);
|
);
|
||||||
assert_eq!(ScriptBuf::from_hex("2102715e91d37d239dea832f1460e91e368115d8ca6cc23a7da966795abad9e3b699ac").unwrap().to_asm_string(),
|
assert_eq!(ScriptBuf::from_hex("2102715e91d37d239dea832f1460e91e368115d8ca6cc23a7da966795abad9e3b699ac").unwrap().to_string(),
|
||||||
"OP_PUSHBYTES_33 02715e91d37d239dea832f1460e91e368115d8ca6cc23a7da966795abad9e3b699 OP_CHECKSIG");
|
"OP_PUSHBYTES_33 02715e91d37d239dea832f1460e91e368115d8ca6cc23a7da966795abad9e3b699 OP_CHECKSIG");
|
||||||
// Elements Alpha peg-out transaction with some signatures removed for brevity. Mainly to test PUSHDATA1
|
// Elements Alpha peg-out transaction with some signatures removed for brevity. Mainly to test PUSHDATA1
|
||||||
assert_eq!(ScriptBuf::from_hex("0047304402202457e78cc1b7f50d0543863c27de75d07982bde8359b9e3316adec0aec165f2f02200203fd331c4e4a4a02f48cf1c291e2c0d6b2f7078a784b5b3649fca41f8794d401004cf1552103244e602b46755f24327142a0517288cebd159eccb6ccf41ea6edf1f601e9af952103bbbacc302d19d29dbfa62d23f37944ae19853cf260c745c2bea739c95328fcb721039227e83246bd51140fe93538b2301c9048be82ef2fb3c7fc5d78426ed6f609ad210229bf310c379b90033e2ecb07f77ecf9b8d59acb623ab7be25a0caed539e2e6472103703e2ed676936f10b3ce9149fa2d4a32060fb86fa9a70a4efe3f21d7ab90611921031e9b7c6022400a6bb0424bbcde14cff6c016b91ee3803926f3440abf5c146d05210334667f975f55a8455d515a2ef1c94fdfa3315f12319a14515d2a13d82831f62f57ae").unwrap().to_asm_string(),
|
assert_eq!(ScriptBuf::from_hex("0047304402202457e78cc1b7f50d0543863c27de75d07982bde8359b9e3316adec0aec165f2f02200203fd331c4e4a4a02f48cf1c291e2c0d6b2f7078a784b5b3649fca41f8794d401004cf1552103244e602b46755f24327142a0517288cebd159eccb6ccf41ea6edf1f601e9af952103bbbacc302d19d29dbfa62d23f37944ae19853cf260c745c2bea739c95328fcb721039227e83246bd51140fe93538b2301c9048be82ef2fb3c7fc5d78426ed6f609ad210229bf310c379b90033e2ecb07f77ecf9b8d59acb623ab7be25a0caed539e2e6472103703e2ed676936f10b3ce9149fa2d4a32060fb86fa9a70a4efe3f21d7ab90611921031e9b7c6022400a6bb0424bbcde14cff6c016b91ee3803926f3440abf5c146d05210334667f975f55a8455d515a2ef1c94fdfa3315f12319a14515d2a13d82831f62f57ae").unwrap().to_string(),
|
||||||
"OP_0 OP_PUSHBYTES_71 304402202457e78cc1b7f50d0543863c27de75d07982bde8359b9e3316adec0aec165f2f02200203fd331c4e4a4a02f48cf1c291e2c0d6b2f7078a784b5b3649fca41f8794d401 OP_0 OP_PUSHDATA1 552103244e602b46755f24327142a0517288cebd159eccb6ccf41ea6edf1f601e9af952103bbbacc302d19d29dbfa62d23f37944ae19853cf260c745c2bea739c95328fcb721039227e83246bd51140fe93538b2301c9048be82ef2fb3c7fc5d78426ed6f609ad210229bf310c379b90033e2ecb07f77ecf9b8d59acb623ab7be25a0caed539e2e6472103703e2ed676936f10b3ce9149fa2d4a32060fb86fa9a70a4efe3f21d7ab90611921031e9b7c6022400a6bb0424bbcde14cff6c016b91ee3803926f3440abf5c146d05210334667f975f55a8455d515a2ef1c94fdfa3315f12319a14515d2a13d82831f62f57ae");
|
"OP_0 OP_PUSHBYTES_71 304402202457e78cc1b7f50d0543863c27de75d07982bde8359b9e3316adec0aec165f2f02200203fd331c4e4a4a02f48cf1c291e2c0d6b2f7078a784b5b3649fca41f8794d401 OP_0 OP_PUSHDATA1 552103244e602b46755f24327142a0517288cebd159eccb6ccf41ea6edf1f601e9af952103bbbacc302d19d29dbfa62d23f37944ae19853cf260c745c2bea739c95328fcb721039227e83246bd51140fe93538b2301c9048be82ef2fb3c7fc5d78426ed6f609ad210229bf310c379b90033e2ecb07f77ecf9b8d59acb623ab7be25a0caed539e2e6472103703e2ed676936f10b3ce9149fa2d4a32060fb86fa9a70a4efe3f21d7ab90611921031e9b7c6022400a6bb0424bbcde14cff6c016b91ee3803926f3440abf5c146d05210334667f975f55a8455d515a2ef1c94fdfa3315f12319a14515d2a13d82831f62f57ae");
|
||||||
// Various weird scripts found in transaction 6d7ed9914625c73c0288694a6819196a27ef6c08f98e1270d975a8e65a3dc09a
|
// Various weird scripts found in transaction 6d7ed9914625c73c0288694a6819196a27ef6c08f98e1270d975a8e65a3dc09a
|
||||||
// which triggerred overflow bugs on 32-bit machines in script formatting in the past.
|
// which triggerred overflow bugs on 32-bit machines in script formatting in the past.
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ScriptBuf::from_hex("01").unwrap().to_asm_string(),
|
ScriptBuf::from_hex("01").unwrap().to_string(),
|
||||||
"OP_PUSHBYTES_1 <push past end>"
|
"OP_PUSHBYTES_1 <push past end>"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ScriptBuf::from_hex("0201").unwrap().to_asm_string(),
|
ScriptBuf::from_hex("0201").unwrap().to_string(),
|
||||||
"OP_PUSHBYTES_2 <push past end>"
|
"OP_PUSHBYTES_2 <push past end>"
|
||||||
);
|
);
|
||||||
assert_eq!(ScriptBuf::from_hex("4c").unwrap().to_asm_string(), "<unexpected end>");
|
assert_eq!(ScriptBuf::from_hex("4c").unwrap().to_string(), "<unexpected end>");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ScriptBuf::from_hex("4c0201").unwrap().to_asm_string(),
|
ScriptBuf::from_hex("4c0201").unwrap().to_string(),
|
||||||
"OP_PUSHDATA1 <push past end>"
|
"OP_PUSHDATA1 <push past end>"
|
||||||
);
|
);
|
||||||
assert_eq!(ScriptBuf::from_hex("4d").unwrap().to_asm_string(), "<unexpected end>");
|
assert_eq!(ScriptBuf::from_hex("4d").unwrap().to_string(), "<unexpected end>");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ScriptBuf::from_hex("4dffff01").unwrap().to_asm_string(),
|
ScriptBuf::from_hex("4dffff01").unwrap().to_string(),
|
||||||
"OP_PUSHDATA2 <push past end>"
|
"OP_PUSHDATA2 <push past end>"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ScriptBuf::from_hex("4effffffff01").unwrap().to_asm_string(),
|
ScriptBuf::from_hex("4effffffff01").unwrap().to_string(),
|
||||||
"OP_PUSHDATA4 <push past end>"
|
"OP_PUSHDATA4 <push past end>"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue