[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:
parent
eeb4655886
commit
dba71d9253
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "bitcoin"
|
name = "bitcoin"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
|
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
|
||||||
license = "CC0-1.0"
|
license = "CC0-1.0"
|
||||||
homepage = "https://github.com/apoelstra/rust-bitcoin/"
|
homepage = "https://github.com/apoelstra/rust-bitcoin/"
|
||||||
|
|
|
@ -556,12 +556,6 @@ pub enum All {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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
|
/// Classifies an Opcode into a broad class
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn classify(&self) -> Class {
|
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);
|
display_from_debug!(All);
|
||||||
|
|
||||||
impl<D: SimpleDecoder> ConsensusDecodable<D> for All {
|
impl<D: SimpleDecoder> ConsensusDecodable<D> for All {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn consensus_decode(d: &mut D) -> Result<All, D::Error> {
|
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
|
@ -148,8 +148,8 @@ impl TxIn {
|
||||||
if txo.script_pubkey.is_p2sh() && stack.len() > 0 {
|
if txo.script_pubkey.is_p2sh() && stack.len() > 0 {
|
||||||
p2sh_stack = stack.clone();
|
p2sh_stack = stack.clone();
|
||||||
p2sh_script = match p2sh_stack.pop() {
|
p2sh_script = match p2sh_stack.pop() {
|
||||||
Some(script::MaybeOwned::Owned(v)) => Script::from_vec(v),
|
Some(script::MaybeOwned::Owned(v)) => Script::from(v),
|
||||||
Some(script::MaybeOwned::Borrowed(s)) => Script::from_vec(s.to_vec()),
|
Some(script::MaybeOwned::Borrowed(s)) => Script::from(s.to_vec()),
|
||||||
None => unreachable!()
|
None => unreachable!()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -228,8 +228,8 @@ impl Transaction {
|
||||||
if txo.script_pubkey.is_p2sh() && stack.len() > 0 {
|
if txo.script_pubkey.is_p2sh() && stack.len() > 0 {
|
||||||
p2sh_stack = stack.clone();
|
p2sh_stack = stack.clone();
|
||||||
p2sh_script = match p2sh_stack.pop() {
|
p2sh_script = match p2sh_stack.pop() {
|
||||||
Some(script::MaybeOwned::Owned(v)) => Script::from_vec(v),
|
Some(script::MaybeOwned::Owned(v)) => Script::from(v),
|
||||||
Some(script::MaybeOwned::Borrowed(s)) => Script::from_vec(s.to_vec()),
|
Some(script::MaybeOwned::Borrowed(s)) => Script::from(s.to_vec()),
|
||||||
None => unreachable!()
|
None => unreachable!()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,9 +73,10 @@ macro_rules! impl_array_newtype {
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Returns the length of the object as an array
|
/// Returns the length of the object as an array
|
||||||
pub fn len(&self) -> usize { $len }
|
pub fn len(&self) -> usize { $len }
|
||||||
|
}
|
||||||
|
|
||||||
/// Constructs a new object from raw data
|
impl<'a> From<&'a [$ty]> for $thing {
|
||||||
pub fn from_slice(data: &[$ty]) -> $thing {
|
fn from(data: &'a [$ty]) -> $thing {
|
||||||
assert_eq!(data.len(), $len);
|
assert_eq!(data.len(), $len);
|
||||||
unsafe {
|
unsafe {
|
||||||
use std::intrinsics::copy_nonoverlapping;
|
use std::intrinsics::copy_nonoverlapping;
|
||||||
|
@ -113,7 +114,7 @@ macro_rules! impl_array_newtype {
|
||||||
impl Clone for $thing {
|
impl Clone for $thing {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone(&self) -> $thing {
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub fn script_find_and_remove(haystack: &mut Vec<u8>, needle: &[u8]) -> usize {
|
||||||
top = top.wrapping_sub(needle.len());
|
top = top.wrapping_sub(needle.len());
|
||||||
if overflow { break; }
|
if overflow { break; }
|
||||||
} else {
|
} 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::PushBytes(n) => n as usize + 1,
|
||||||
opcodes::Class::Ordinary(opcodes::Ordinary::OP_PUSHDATA1) => 2,
|
opcodes::Class::Ordinary(opcodes::Ordinary::OP_PUSHDATA1) => 2,
|
||||||
opcodes::Class::Ordinary(opcodes::Ordinary::OP_PUSHDATA2) => 3,
|
opcodes::Class::Ordinary(opcodes::Ordinary::OP_PUSHDATA2) => 3,
|
||||||
|
|
Loading…
Reference in New Issue