Move read_to_end out of util module

The `read_to_end` function is only used in the `psbt` module, move it
there.

Done as part of work trying to flatten the `util` module.
This commit is contained in:
Tobin C. Harding 2022-08-02 16:10:30 +10:00
parent 445b07c94c
commit 8a75ff450f
2 changed files with 15 additions and 19 deletions

View File

@ -13,24 +13,6 @@ pub mod base58;
pub mod psbt;
pub mod taproot;
use crate::prelude::*;
use crate::io;
// core2 doesn't have read_to_end
pub(crate) fn read_to_end<D: io::Read>(mut d: D) -> Result<Vec<u8>, io::Error> {
let mut result = vec![];
let mut buf = [0u8; 64];
loop {
match d.read(&mut buf) {
Ok(0) => break,
Ok(n) => result.extend_from_slice(&buf[0..n]),
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {},
Err(e) => return Err(e),
};
}
Ok(result)
}
/// The `misc` module was moved and re-named to `sign_message`.
pub mod misc {
use crate::prelude::*;

View File

@ -14,7 +14,6 @@ use crate::io;
use crate::consensus::encode::{self, ReadExt, WriteExt, Decodable, Encodable, VarInt, serialize, deserialize, MAX_VEC_SIZE};
use crate::hashes::hex;
use crate::util::psbt::Error;
use crate::util::read_to_end;
/// A PSBT key in its raw byte form.
#[derive(Debug, PartialEq, Hash, Eq, Clone, Ord, PartialOrd)]
@ -173,3 +172,18 @@ where
Ok(deserialize(&key.key)?)
}
}
// core2 doesn't have read_to_end
pub(crate) fn read_to_end<D: io::Read>(mut d: D) -> Result<Vec<u8>, io::Error> {
let mut result = vec![];
let mut buf = [0u8; 64];
loop {
match d.read(&mut buf) {
Ok(0) => break,
Ok(n) => result.extend_from_slice(&buf[0..n]),
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {},
Err(e) => return Err(e),
};
}
Ok(result)
}