[BREAKING CHANGE] Minor library updates

Breaking changes are:
    opcode::All::from_u8 is now From<u8>
    script::Builder::from_vec is now From<Vec<u8>>
    script::Script::from_vec is now From<Vec<u8>>
This commit is contained in:
Andrew Poelstra 2015-10-14 08:56:48 -05:00
parent eeb4655886
commit dba71d9253
6 changed files with 64 additions and 50 deletions

View File

@ -1,7 +1,7 @@
[package]
name = "bitcoin"
version = "0.2.0"
version = "0.3.0"
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
license = "CC0-1.0"
homepage = "https://github.com/apoelstra/rust-bitcoin/"

View File

@ -556,12 +556,6 @@ pub enum All {
}
impl All {
/// Translates a u8 to an opcode
#[inline]
pub fn from_u8(b: u8) -> All {
unsafe { transmute(b) }
}
/// Classifies an Opcode into a broad class
#[inline]
pub fn classify(&self) -> Class {
@ -602,12 +596,20 @@ impl All {
}
}
impl From<u8> for All {
#[inline]
fn from(b: u8) -> All {
unsafe { transmute(b) }
}
}
display_from_debug!(All);
impl<D: SimpleDecoder> ConsensusDecodable<D> for All {
#[inline]
fn consensus_decode(d: &mut D) -> Result<All, D::Error> {
Ok(All::from_u8(try!(d.read_u8())))
Ok(All::from(try!(d.read_u8())))
}
}

File diff suppressed because one or more lines are too long

View File

@ -148,8 +148,8 @@ impl TxIn {
if txo.script_pubkey.is_p2sh() && stack.len() > 0 {
p2sh_stack = stack.clone();
p2sh_script = match p2sh_stack.pop() {
Some(script::MaybeOwned::Owned(v)) => Script::from_vec(v),
Some(script::MaybeOwned::Borrowed(s)) => Script::from_vec(s.to_vec()),
Some(script::MaybeOwned::Owned(v)) => Script::from(v),
Some(script::MaybeOwned::Borrowed(s)) => Script::from(s.to_vec()),
None => unreachable!()
};
}
@ -228,8 +228,8 @@ impl Transaction {
if txo.script_pubkey.is_p2sh() && stack.len() > 0 {
p2sh_stack = stack.clone();
p2sh_script = match p2sh_stack.pop() {
Some(script::MaybeOwned::Owned(v)) => Script::from_vec(v),
Some(script::MaybeOwned::Borrowed(s)) => Script::from_vec(s.to_vec()),
Some(script::MaybeOwned::Owned(v)) => Script::from(v),
Some(script::MaybeOwned::Borrowed(s)) => Script::from(s.to_vec()),
None => unreachable!()
};
}

View File

@ -73,9 +73,10 @@ macro_rules! impl_array_newtype {
#[inline]
/// Returns the length of the object as an array
pub fn len(&self) -> usize { $len }
}
/// Constructs a new object from raw data
pub fn from_slice(data: &[$ty]) -> $thing {
impl<'a> From<&'a [$ty]> for $thing {
fn from(data: &'a [$ty]) -> $thing {
assert_eq!(data.len(), $len);
unsafe {
use std::intrinsics::copy_nonoverlapping;
@ -113,7 +114,7 @@ macro_rules! impl_array_newtype {
impl Clone for $thing {
#[inline]
fn clone(&self) -> $thing {
$thing::from_slice(&self[..])
$thing::from(&self[..])
}
}
@ -135,6 +136,13 @@ macro_rules! impl_array_newtype {
}
}
}
impl ::rand::Rand for $thing {
#[inline]
fn rand<R: ::rand::Rng>(r: &mut R) -> $thing {
$thing(::rand::Rand::rand(r))
}
}
}
}

View File

@ -82,7 +82,7 @@ pub fn script_find_and_remove(haystack: &mut Vec<u8>, needle: &[u8]) -> usize {
top = top.wrapping_sub(needle.len());
if overflow { break; }
} else {
i += match opcodes::All::from_u8((*haystack)[i]).classify() {
i += match opcodes::All::from((*haystack)[i]).classify() {
opcodes::Class::PushBytes(n) => n as usize + 1,
opcodes::Class::Ordinary(opcodes::Ordinary::OP_PUSHDATA1) => 2,
opcodes::Class::Ordinary(opcodes::Ordinary::OP_PUSHDATA2) => 3,