Merge rust-bitcoin/rust-bitcoin#1527: Rename `push_scriptint` and make it private

94b678e73f Rename `push_scriptint` and make it private (Martin Habovstiak)

Pull request description:

  `push_scriptint` is a significant footgun with an unclear name. This renames it and unpublishes to avoid mistakes by downstream crates.

  Closes #1517

ACKs for top commit:
  apoelstra:
    ACK 94b678e73f

Tree-SHA512: 9e1772c6fb326d8b0c78d702ad9926a79a91589feb8650aed7c5e75bfbdbf0164357b4d5b190877c40b8469e0e3be3d3453fe407741b5dae0c5758176f756417
This commit is contained in:
Andrew Poelstra 2023-01-06 14:47:58 +00:00
commit 5f2beb8ae2
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 8 additions and 7 deletions

View File

@ -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 {

View File

@ -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[..]);