Merge rust-bitcoin/rust-bitcoin#2872: Update PushBytes::read_scriptint(x) to x.read_scriptint()

e7f33a2a12 Update PushBytes::read_scriptint(x) to x.read_scriptint() (Shing Him Ng)

Pull request description:

  Fixes #2849

  There were a few other usages of PushBytes::read_scriptint(_) in the tests such as [this](406e3486ab/bitcoin/src/blockdata/script/tests.rs (L315)), but they couldn't be updated as cleanly as the changes in this PR. I wasn't sure if the intention of this issue was to fix those as well, but I can update this PR if needed

ACKs for top commit:
  tcharding:
    ACK e7f33a2a12
  Kixunil:
    ACK e7f33a2a12

Tree-SHA512: 4620f4972c40b0bf7333dbe302d1dabc5dbcb39749c734cc297a019d36983757f59659d76ae40b4a6121e51d0bde1e2b7883a0c77536be18927d1cfef53ba579
This commit is contained in:
Andrew Poelstra 2024-06-17 15:49:10 +00:00
commit 0ae6f49cea
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 3 additions and 4 deletions

View File

@ -19,7 +19,6 @@ use crate::consensus::{encode, Decodable, Encodable, Params};
use crate::internal_macros::{impl_consensus_encoding, impl_hashencode};
use crate::pow::{CompactTarget, Target, Work};
use crate::prelude::*;
use crate::script::PushBytes;
use crate::{merkle_tree, VarInt};
hashes::hash_newtype! {
@ -381,7 +380,7 @@ impl Block {
match push.map_err(|_| Bip34Error::NotPresent)? {
script::Instruction::PushBytes(b) => {
// Check that the number is encoded in the minimal way.
let h = PushBytes::read_scriptint(b)
let h = b.read_scriptint()
.map_err(|_e| Bip34Error::UnexpectedPush(b.as_bytes().to_vec()))?;
if h < 0 {
Err(Bip34Error::NegativeHeight)

View File

@ -76,7 +76,7 @@ impl<'a> Instruction<'a> {
_ => None,
}
}
Instruction::PushBytes(bytes) => match PushBytes::read_scriptint(bytes) {
Instruction::PushBytes(bytes) => match bytes.read_scriptint() {
Ok(v) => Some(v),
_ => None,
},

View File

@ -23,7 +23,7 @@ fn do_test(data: &[u8]) {
// reserialized as numbers. (For -1 through 16, this will use special ops; for
// others it'll just reserialize them as pushes.)
if bytes.len() == 1 && bytes[0] != 0x80 && bytes[0] != 0x00 {
if let Ok(num) = script::PushBytes::read_scriptint(bytes) {
if let Ok(num) = bytes.read_scriptint() {
b = b.push_int(num);
} else {
b = b.push_slice(bytes);