Rename `push_scriptint` and make it private
`push_scriptint` is a significant footgun with an unclear name. This renames it and unpublishes to avoid mistakes by downstream crates. Closes #1517
This commit is contained in:
parent
98203bc8b3
commit
94b678e73f
|
@ -73,8 +73,8 @@ fn bitcoin_genesis_tx() -> Transaction {
|
|||
};
|
||||
|
||||
// Inputs
|
||||
let in_script = script::Builder::new().push_scriptint(486604799)
|
||||
.push_scriptint(4)
|
||||
let in_script = script::Builder::new().push_int(486604799)
|
||||
.push_int_non_minimal(4)
|
||||
.push_slice(b"The Times 03/Jan/2009 Chancellor on brink of second bailout for banks")
|
||||
.into_script();
|
||||
ret.input.push(TxIn {
|
||||
|
|
|
@ -1757,12 +1757,13 @@ impl Builder {
|
|||
self.push_opcode(opcodes::OP_FALSE)
|
||||
}
|
||||
// Otherwise encode it as data
|
||||
else { self.push_scriptint(data) }
|
||||
else { self.push_int_non_minimal(data) }
|
||||
}
|
||||
|
||||
/// Adds instructions to push an integer onto the stack, using the explicit
|
||||
/// encoding regardless of the availability of dedicated opcodes.
|
||||
pub fn push_scriptint(self, data: i64) -> Builder {
|
||||
/// Adds instructions to push an integer onto the stack without optimization.
|
||||
///
|
||||
/// This uses the explicit encoding regardless of the availability of dedicated opcodes.
|
||||
pub(super) fn push_int_non_minimal(self, data: i64) -> Builder {
|
||||
let mut buf = [0u8; 8];
|
||||
let len = write_scriptint(&mut buf, data);
|
||||
self.push_slice(&buf[..len])
|
||||
|
@ -2029,7 +2030,7 @@ mod test {
|
|||
script = script.push_int(4); comp.push(84u8); assert_eq!(script.as_bytes(), &comp[..]);
|
||||
script = script.push_int(-1); comp.push(79u8); assert_eq!(script.as_bytes(), &comp[..]);
|
||||
// forced scriptint
|
||||
script = script.push_scriptint(4); comp.extend([1u8, 4].iter().cloned()); assert_eq!(script.as_bytes(), &comp[..]);
|
||||
script = script.push_int_non_minimal(4); comp.extend([1u8, 4].iter().cloned()); assert_eq!(script.as_bytes(), &comp[..]);
|
||||
// big ints
|
||||
script = script.push_int(17); comp.extend([1u8, 17].iter().cloned()); assert_eq!(script.as_bytes(), &comp[..]);
|
||||
script = script.push_int(10000); comp.extend([2u8, 16, 39].iter().cloned()); assert_eq!(script.as_bytes(), &comp[..]);
|
||||
|
|
Loading…
Reference in New Issue