Minor code changes for new rustc/clippy. No effects. Update minor version number
This commit is contained in:
parent
5f308887c9
commit
f18157e774
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "bitcoin"
|
name = "bitcoin"
|
||||||
version = "0.5.3"
|
version = "0.5.4"
|
||||||
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/"
|
||||||
|
|
|
@ -547,7 +547,7 @@ impl Blockchain {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator over all blocks in the chain starting from `start_hash`
|
/// An iterator over all blocks in the chain starting from `start_hash`
|
||||||
pub fn iter<'a>(&'a self, start_hash: Sha256dHash) -> BlockIter<'a> {
|
pub fn iter(&self, start_hash: Sha256dHash) -> BlockIter {
|
||||||
let start = match self.tree.lookup(&start_hash.into_le(), 256) {
|
let start = match self.tree.lookup(&start_hash.into_le(), 256) {
|
||||||
Some(boxptr) => &**boxptr as NodePtr,
|
Some(boxptr) => &**boxptr as NodePtr,
|
||||||
None => ptr::null()
|
None => ptr::null()
|
||||||
|
@ -559,7 +559,7 @@ impl Blockchain {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator over all blocks in reverse order to the genesis, starting with `start_hash`
|
/// An iterator over all blocks in reverse order to the genesis, starting with `start_hash`
|
||||||
pub fn rev_iter<'a>(&'a self, start_hash: Sha256dHash) -> RevBlockIter<'a> {
|
pub fn rev_iter(&self, start_hash: Sha256dHash) -> RevBlockIter {
|
||||||
let start = match self.tree.lookup(&start_hash.into_le(), 256) {
|
let start = match self.tree.lookup(&start_hash.into_le(), 256) {
|
||||||
Some(boxptr) => &**boxptr as NodePtr,
|
Some(boxptr) => &**boxptr as NodePtr,
|
||||||
None => ptr::null()
|
None => ptr::null()
|
||||||
|
@ -571,7 +571,7 @@ impl Blockchain {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator over all blocks -not- in the best chain, in reverse order, starting from `start_hash`
|
/// An iterator over all blocks -not- in the best chain, in reverse order, starting from `start_hash`
|
||||||
pub fn rev_stale_iter<'a>(&'a self, start_hash: Sha256dHash) -> RevStaleBlockIter<'a> {
|
pub fn rev_stale_iter(&self, start_hash: Sha256dHash) -> RevStaleBlockIter {
|
||||||
let start = match self.tree.lookup(&start_hash.into_le(), 256) {
|
let start = match self.tree.lookup(&start_hash.into_le(), 256) {
|
||||||
Some(boxptr) => {
|
Some(boxptr) => {
|
||||||
// If we are already on the main chain, we have a dead iterator
|
// If we are already on the main chain, we have a dead iterator
|
||||||
|
|
|
@ -67,7 +67,7 @@ fn bitcoin_genesis_tx() -> Transaction {
|
||||||
// Inputs
|
// Inputs
|
||||||
let in_script = script::Builder::new().push_scriptint(486604799)
|
let in_script = script::Builder::new().push_scriptint(486604799)
|
||||||
.push_scriptint(4)
|
.push_scriptint(4)
|
||||||
.push_slice("The Times 03/Jan/2009 Chancellor on brink of second bailout for banks".as_bytes())
|
.push_slice(b"The Times 03/Jan/2009 Chancellor on brink of second bailout for banks")
|
||||||
.into_script();
|
.into_script();
|
||||||
ret.input.push(TxIn {
|
ret.input.push(TxIn {
|
||||||
prev_hash: Default::default(),
|
prev_hash: Default::default(),
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
//! This module provides the structures and functions needed to support scripts.
|
//! This module provides the structures and functions needed to support scripts.
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use std::hash;
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::{error, fmt, ops};
|
use std::{error, fmt, ops};
|
||||||
use serialize::hex::ToHex;
|
use serialize::hex::ToHex;
|
||||||
|
@ -44,7 +43,7 @@ use network::serialize::{SimpleDecoder, SimpleEncoder, serialize};
|
||||||
use util::hash::Sha256dHash;
|
use util::hash::Sha256dHash;
|
||||||
use util::misc::script_find_and_remove;
|
use util::misc::script_find_and_remove;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||||
/// A Bitcoin script
|
/// A Bitcoin script
|
||||||
pub struct Script(Box<[u8]>);
|
pub struct Script(Box<[u8]>);
|
||||||
|
|
||||||
|
@ -126,12 +125,6 @@ impl fmt::Display for Script {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for Script {
|
|
||||||
fn clone(&self) -> Script {
|
|
||||||
Script(self.0.to_vec().into_boxed_slice())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::LowerHex for Script {
|
impl fmt::LowerHex for Script {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
for &ch in self.0.iter() {
|
for &ch in self.0.iter() {
|
||||||
|
@ -155,24 +148,6 @@ impl fmt::UpperHex for Script {
|
||||||
pub struct Builder(Vec<u8>);
|
pub struct Builder(Vec<u8>);
|
||||||
display_from_debug!(Builder);
|
display_from_debug!(Builder);
|
||||||
|
|
||||||
impl hash::Hash for Script {
|
|
||||||
#[inline]
|
|
||||||
fn hash<H>(&self, state: &mut H)
|
|
||||||
where H: hash::Hasher
|
|
||||||
{
|
|
||||||
(&self.0[..]).hash(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn hash_slice<H>(data: &[Script], state: &mut H)
|
|
||||||
where H: hash::Hasher
|
|
||||||
{
|
|
||||||
for s in data.iter() {
|
|
||||||
(&s.0[..]).hash(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ways that a script might fail. Not everything is split up as
|
/// Ways that a script might fail. Not everything is split up as
|
||||||
/// much as it could be; patches welcome if more detailed errors
|
/// much as it could be; patches welcome if more detailed errors
|
||||||
/// would help you.
|
/// would help you.
|
||||||
|
@ -1083,13 +1058,10 @@ impl AbstractStackElem {
|
||||||
try!(self.set_len_lo(val.len()));
|
try!(self.set_len_lo(val.len()));
|
||||||
try!(self.set_len_hi(val.len()));
|
try!(self.set_len_hi(val.len()));
|
||||||
try!(self.set_bool_value(read_scriptbool(val)));
|
try!(self.set_bool_value(read_scriptbool(val)));
|
||||||
match read_scriptint(val) {
|
if let Ok(n) = read_scriptint(val) {
|
||||||
Ok(n) => {
|
|
||||||
try!(self.set_num_lo(n));
|
try!(self.set_num_lo(n));
|
||||||
try!(self.set_num_hi(n));
|
try!(self.set_num_hi(n));
|
||||||
}
|
}
|
||||||
Err(_) => {}
|
|
||||||
}
|
|
||||||
try!(self.set_bool_value(read_scriptbool(val)));
|
try!(self.set_bool_value(read_scriptbool(val)));
|
||||||
self.raw = Some(val.to_vec());
|
self.raw = Some(val.to_vec());
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1645,8 +1617,8 @@ pub fn read_uint(data: &[u8], size: usize) -> Result<usize, Error> {
|
||||||
Err(Error::EarlyEndOfScript)
|
Err(Error::EarlyEndOfScript)
|
||||||
} else {
|
} else {
|
||||||
let mut ret = 0;
|
let mut ret = 0;
|
||||||
for i in 0..size {
|
for (i, item) in data.iter().take(size).enumerate() {
|
||||||
ret += (data[i] as usize) << (i * 8);
|
ret += (*item as usize) << (i * 8);
|
||||||
}
|
}
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
@ -1763,41 +1735,40 @@ fn check_signature(secp: &Secp256k1, sig_slice: &[u8], pk_slice: &[u8], script:
|
||||||
// always come first and `drop` should always come last, to avoid
|
// always come first and `drop` should always come last, to avoid
|
||||||
// surprises.
|
// surprises.
|
||||||
macro_rules! stack_opcode {
|
macro_rules! stack_opcode {
|
||||||
($stack:ident($min:expr): $($cmd:ident $args:tt);*) => ({
|
($stack:ident: $($cmd:ident $args:tt);*) => ({
|
||||||
$(stack_opcode_internal!($cmd: $stack, $min, $args);)*
|
// Record top
|
||||||
|
let mut top = $stack.len();
|
||||||
|
&mut top; // shut up warnings in case top is either unread or unmutated
|
||||||
|
$(stack_opcode_internal!($cmd: $stack, top, $args);)*
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// The actual commands available to the above macro
|
// The actual commands available to the above macro
|
||||||
macro_rules! stack_opcode_internal {
|
macro_rules! stack_opcode_internal {
|
||||||
(require: $stack:ident, $min:expr, $r:expr) => ({
|
(require: $stack:ident, $top:ident, $r:expr) => ({
|
||||||
$stack.require_n_elems($r);
|
$stack.require_n_elems($r);
|
||||||
// Record top
|
$top = $stack.len();
|
||||||
let top = $stack.len();
|
|
||||||
// Check stack size
|
|
||||||
if top < $min { return Err(Error::PopEmptyStack); }
|
|
||||||
});
|
});
|
||||||
(copy: $stack:ident, $min:expr, $c:expr) => ({
|
(copy: $stack:ident, $top:ident, $c:expr) => ({
|
||||||
let top = $stack.len();
|
if $top < $c { return Err(Error::PopEmptyStack); }
|
||||||
if top < $min { return Err(Error::PopEmptyStack); }
|
let elem = $stack[$top - $c].clone();
|
||||||
let elem = $stack[top - $c].clone();
|
|
||||||
$stack.push(elem);
|
$stack.push(elem);
|
||||||
});
|
});
|
||||||
(swap: $stack:ident, $min:expr, ($a:expr, $b:expr)) => ({
|
(swap: $stack:ident, $top:ident, ($a:expr, $b:expr)) => ({
|
||||||
let top = $stack.len();
|
if $top < $a || $top < $b { return Err(Error::PopEmptyStack); }
|
||||||
if top < $min { return Err(Error::PopEmptyStack); }
|
(&mut $stack[..]).swap($top - $a, $top - $b);
|
||||||
(&mut $stack[..]).swap(top - $a, top - $b);
|
|
||||||
});
|
});
|
||||||
(perm: $stack:ident, $min:expr, ($first:expr, $($i:expr),*)) => ({
|
(perm: $stack:ident, $top:ident, ($first:expr, $($i:expr),*)) => ({
|
||||||
let top = $stack.len();
|
if $top < $first { return Err(Error::PopEmptyStack); }
|
||||||
if top < $min { return Err(Error::PopEmptyStack); }
|
|
||||||
let first = $first;
|
let first = $first;
|
||||||
$( (&mut $stack[..]).swap(top - first, top - $i); )*
|
$(
|
||||||
|
if $top < $i { return Err(Error::PopEmptyStack); }
|
||||||
|
(&mut $stack[..]).swap($top - first, $top - $i);
|
||||||
|
)*
|
||||||
});
|
});
|
||||||
(drop: $stack:ident, $min:expr, $d:expr) => ({
|
(drop: $stack:ident, $top:ident, $d:expr) => ({
|
||||||
let top = $stack.len();
|
if $top < $d { return Err(Error::PopEmptyStack); }
|
||||||
if top < $min { return Err(Error::PopEmptyStack); }
|
$stack.remove($top - $d);
|
||||||
$stack.remove(top - $d);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1936,8 +1907,7 @@ impl Script {
|
||||||
let executing = exec_stack.iter().all(|e| *e);
|
let executing = exec_stack.iter().all(|e| *e);
|
||||||
let byte = self.0[index];
|
let byte = self.0[index];
|
||||||
// Write out the trace, except the stack which we don't know yet
|
// Write out the trace, except the stack which we don't know yet
|
||||||
match trace {
|
if let Some(ref mut t) = trace {
|
||||||
Some(ref mut t) => {
|
|
||||||
let opcode = opcodes::All::from(byte);
|
let opcode = opcodes::All::from(byte);
|
||||||
t.push(TraceIteration {
|
t.push(TraceIteration {
|
||||||
index: index,
|
index: index,
|
||||||
|
@ -1949,8 +1919,6 @@ impl Script {
|
||||||
stack: vec!["<failed to execute opcode>".to_owned()]
|
stack: vec!["<failed to execute opcode>".to_owned()]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
op_count += 1;
|
op_count += 1;
|
||||||
index += 1;
|
index += 1;
|
||||||
// The definitions of all these categories are in opcodes.rs
|
// The definitions of all these categories are in opcodes.rs
|
||||||
|
@ -1990,7 +1958,7 @@ impl Script {
|
||||||
index += 4 + n;
|
index += 4 + n;
|
||||||
}
|
}
|
||||||
// If-statements take effect when not executing
|
// If-statements take effect when not executing
|
||||||
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_IF)) => exec_stack.push(false),
|
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_IF)) |
|
||||||
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_NOTIF)) => exec_stack.push(false),
|
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_NOTIF)) => exec_stack.push(false),
|
||||||
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_ELSE)) => {
|
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_ELSE)) => {
|
||||||
match exec_stack.last_mut() {
|
match exec_stack.last_mut() {
|
||||||
|
@ -2047,17 +2015,17 @@ impl Script {
|
||||||
Some(elem) => { stack.push(elem); }
|
Some(elem) => { stack.push(elem); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opcodes::Ordinary::OP_2DROP => stack_opcode!(stack(2): drop 1; drop 2),
|
opcodes::Ordinary::OP_2DROP => stack_opcode!(stack: drop 1; drop 2),
|
||||||
opcodes::Ordinary::OP_2DUP => stack_opcode!(stack(2): copy 2; copy 1),
|
opcodes::Ordinary::OP_2DUP => stack_opcode!(stack: copy 2; copy 1),
|
||||||
opcodes::Ordinary::OP_3DUP => stack_opcode!(stack(3): copy 3; copy 2; copy 1),
|
opcodes::Ordinary::OP_3DUP => stack_opcode!(stack: copy 3; copy 2; copy 1),
|
||||||
opcodes::Ordinary::OP_2OVER => stack_opcode!(stack(4): copy 4; copy 3),
|
opcodes::Ordinary::OP_2OVER => stack_opcode!(stack: copy 4; copy 3),
|
||||||
opcodes::Ordinary::OP_2ROT => stack_opcode!(stack(6): perm (1, 3, 5);
|
opcodes::Ordinary::OP_2ROT => stack_opcode!(stack: perm (1, 3, 5);
|
||||||
perm (2, 4, 6)),
|
perm (2, 4, 6)),
|
||||||
opcodes::Ordinary::OP_2SWAP => stack_opcode!(stack(4): swap (2, 4); swap (1, 3)),
|
opcodes::Ordinary::OP_2SWAP => stack_opcode!(stack: swap (2, 4); swap (1, 3)),
|
||||||
opcodes::Ordinary::OP_DROP => stack_opcode!(stack(1): drop 1),
|
opcodes::Ordinary::OP_DROP => stack_opcode!(stack: drop 1),
|
||||||
opcodes::Ordinary::OP_DUP => stack_opcode!(stack(1): copy 1),
|
opcodes::Ordinary::OP_DUP => stack_opcode!(stack: copy 1),
|
||||||
opcodes::Ordinary::OP_NIP => stack_opcode!(stack(2): drop 2),
|
opcodes::Ordinary::OP_NIP => stack_opcode!(stack: drop 2),
|
||||||
opcodes::Ordinary::OP_OVER => stack_opcode!(stack(2): copy 2),
|
opcodes::Ordinary::OP_OVER => stack_opcode!(stack: copy 2),
|
||||||
opcodes::Ordinary::OP_PICK => {
|
opcodes::Ordinary::OP_PICK => {
|
||||||
let n = match stack.pop() {
|
let n = match stack.pop() {
|
||||||
Some(data) => try!(read_scriptint(&data[..])),
|
Some(data) => try!(read_scriptint(&data[..])),
|
||||||
|
@ -2065,7 +2033,7 @@ impl Script {
|
||||||
};
|
};
|
||||||
if n < 0 { return Err(Error::NegativePick); }
|
if n < 0 { return Err(Error::NegativePick); }
|
||||||
let n = n as usize;
|
let n = n as usize;
|
||||||
stack_opcode!(stack(n + 1): copy (n + 1))
|
stack_opcode!(stack: copy (n + 1))
|
||||||
}
|
}
|
||||||
opcodes::Ordinary::OP_ROLL => {
|
opcodes::Ordinary::OP_ROLL => {
|
||||||
let n = match stack.pop() {
|
let n = match stack.pop() {
|
||||||
|
@ -2074,16 +2042,16 @@ impl Script {
|
||||||
};
|
};
|
||||||
if n < 0 { return Err(Error::NegativeRoll); }
|
if n < 0 { return Err(Error::NegativeRoll); }
|
||||||
let n = n as usize;
|
let n = n as usize;
|
||||||
stack_opcode!(stack(n + 1): copy (n + 1); drop (n + 1))
|
stack_opcode!(stack: copy (n + 1); drop (n + 1))
|
||||||
}
|
}
|
||||||
opcodes::Ordinary::OP_ROT => stack_opcode!(stack(3): perm (1, 2, 3)),
|
opcodes::Ordinary::OP_ROT => stack_opcode!(stack: perm (1, 2, 3)),
|
||||||
opcodes::Ordinary::OP_SWAP => stack_opcode!(stack(2): swap (1, 2)),
|
opcodes::Ordinary::OP_SWAP => stack_opcode!(stack: swap (1, 2)),
|
||||||
opcodes::Ordinary::OP_TUCK => stack_opcode!(stack(2): copy 2; copy 1; drop 2),
|
opcodes::Ordinary::OP_TUCK => stack_opcode!(stack: copy 2; copy 1; drop 2),
|
||||||
opcodes::Ordinary::OP_IFDUP => {
|
opcodes::Ordinary::OP_IFDUP => {
|
||||||
match stack.last().map(|v| read_scriptbool(&v[..])) {
|
match stack.last().map(|v| read_scriptbool(&v[..])) {
|
||||||
None => { return Err(Error::IfEmptyStack); }
|
None => { return Err(Error::IfEmptyStack); }
|
||||||
Some(false) => {}
|
Some(false) => {}
|
||||||
Some(true) => { stack_opcode!(stack(1): copy 1); }
|
Some(true) => { stack_opcode!(stack: copy 1); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opcodes::Ordinary::OP_DEPTH => {
|
opcodes::Ordinary::OP_DEPTH => {
|
||||||
|
@ -2268,8 +2236,7 @@ impl Script {
|
||||||
/// Whether a script can be proven to have no satisfying input
|
/// Whether a script can be proven to have no satisfying input
|
||||||
pub fn is_provably_unspendable(&self) -> bool {
|
pub fn is_provably_unspendable(&self) -> bool {
|
||||||
match self.satisfy() {
|
match self.satisfy() {
|
||||||
Ok(_) => false,
|
Ok(_) | Err(Error::Unanalyzable) => false,
|
||||||
Err(Error::Unanalyzable) => false,
|
|
||||||
Err(_) => true
|
Err(_) => true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2343,7 +2310,7 @@ impl Script {
|
||||||
index += 4 + n;
|
index += 4 + n;
|
||||||
}
|
}
|
||||||
// If-statements take effect when not executing
|
// If-statements take effect when not executing
|
||||||
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_IF)) => exec_stack.push(false),
|
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_IF)) |
|
||||||
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_NOTIF)) => exec_stack.push(false),
|
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_NOTIF)) => exec_stack.push(false),
|
||||||
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_ELSE)) => {
|
(false, opcodes::Class::Ordinary(opcodes::Ordinary::OP_ELSE)) => {
|
||||||
match exec_stack.last_mut() {
|
match exec_stack.last_mut() {
|
||||||
|
@ -2374,9 +2341,8 @@ impl Script {
|
||||||
let mut stack_true = stack.clone();
|
let mut stack_true = stack.clone();
|
||||||
// Try pushing false and see what happens
|
// Try pushing false and see what happens
|
||||||
if stack.peek_mut().set_bool_value(false).is_ok() {
|
if stack.peek_mut().set_bool_value(false).is_ok() {
|
||||||
match recurse(&script[index - 1..], stack, exec_stack.clone(), depth + 1) {
|
if let Ok(res) = recurse(&script[index - 1..], stack, exec_stack.clone(), depth + 1) {
|
||||||
Ok(res) => { return Ok(res); }
|
return Ok(res);
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Failing that, push true
|
// Failing that, push true
|
||||||
|
@ -2399,9 +2365,8 @@ impl Script {
|
||||||
let mut stack_true = stack.clone();
|
let mut stack_true = stack.clone();
|
||||||
// Try pushing false and see what happens
|
// Try pushing false and see what happens
|
||||||
if stack.peek_mut().set_bool_value(false).is_ok() {
|
if stack.peek_mut().set_bool_value(false).is_ok() {
|
||||||
match recurse(&script[index - 1..], stack, exec_stack.clone(), depth + 1) {
|
if let Ok(res) = recurse(&script[index - 1..], stack, exec_stack.clone(), depth + 1) {
|
||||||
Ok(res) => { return Ok(res); }
|
return Ok(res);
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Failing that, push true
|
// Failing that, push true
|
||||||
|
@ -2428,20 +2393,20 @@ impl Script {
|
||||||
opcodes::Ordinary::OP_VERIFY => op_verify_satisfy!(stack),
|
opcodes::Ordinary::OP_VERIFY => op_verify_satisfy!(stack),
|
||||||
opcodes::Ordinary::OP_TOALTSTACK => { stack.top_to_altstack(); }
|
opcodes::Ordinary::OP_TOALTSTACK => { stack.top_to_altstack(); }
|
||||||
opcodes::Ordinary::OP_FROMALTSTACK => { try!(stack.top_from_altstack()); }
|
opcodes::Ordinary::OP_FROMALTSTACK => { try!(stack.top_from_altstack()); }
|
||||||
opcodes::Ordinary::OP_2DROP => stack_opcode!(stack(2): require 2; drop 1; drop 2),
|
opcodes::Ordinary::OP_2DROP => stack_opcode!(stack: require 2; drop 1; drop 2),
|
||||||
opcodes::Ordinary::OP_2DUP => stack_opcode!(stack(2): require 2; copy 2; copy 1),
|
opcodes::Ordinary::OP_2DUP => stack_opcode!(stack: require 2; copy 2; copy 1),
|
||||||
opcodes::Ordinary::OP_3DUP => stack_opcode!(stack(3): require 3; copy 3; copy 2; copy 1),
|
opcodes::Ordinary::OP_3DUP => stack_opcode!(stack: require 3; copy 3; copy 2; copy 1),
|
||||||
opcodes::Ordinary::OP_2OVER => stack_opcode!(stack(4): require 4; copy 4; copy 3),
|
opcodes::Ordinary::OP_2OVER => stack_opcode!(stack: require 4; copy 4; copy 3),
|
||||||
opcodes::Ordinary::OP_2ROT => stack_opcode!(stack(6): require 6;
|
opcodes::Ordinary::OP_2ROT => stack_opcode!(stack: require 6;
|
||||||
perm (1, 3, 5);
|
perm (1, 3, 5);
|
||||||
perm (2, 4, 6)),
|
perm (2, 4, 6)),
|
||||||
opcodes::Ordinary::OP_2SWAP => stack_opcode!(stack(4): require 4;
|
opcodes::Ordinary::OP_2SWAP => stack_opcode!(stack: require 4;
|
||||||
swap (2, 4);
|
swap (2, 4);
|
||||||
swap (1, 3)),
|
swap (1, 3)),
|
||||||
opcodes::Ordinary::OP_DROP => stack_opcode!(stack(1): require 1; drop 1),
|
opcodes::Ordinary::OP_DROP => stack_opcode!(stack: require 1; drop 1),
|
||||||
opcodes::Ordinary::OP_DUP => stack_opcode!(stack(1): require 1; copy 1),
|
opcodes::Ordinary::OP_DUP => stack_opcode!(stack: require 1; copy 1),
|
||||||
opcodes::Ordinary::OP_NIP => stack_opcode!(stack(2): require 2; drop 2),
|
opcodes::Ordinary::OP_NIP => stack_opcode!(stack: require 2; drop 2),
|
||||||
opcodes::Ordinary::OP_OVER => stack_opcode!(stack(2): require 2; copy 2),
|
opcodes::Ordinary::OP_OVER => stack_opcode!(stack: require 2; copy 2),
|
||||||
opcodes::Ordinary::OP_PICK => {
|
opcodes::Ordinary::OP_PICK => {
|
||||||
let top_n = {
|
let top_n = {
|
||||||
let top = stack.peek_mut();
|
let top = stack.peek_mut();
|
||||||
|
@ -2451,7 +2416,7 @@ impl Script {
|
||||||
};
|
};
|
||||||
stack.pop();
|
stack.pop();
|
||||||
match top_n {
|
match top_n {
|
||||||
Some(n) => stack_opcode!(stack(n + 1): require (n + 1); copy (n + 1)),
|
Some(n) => stack_opcode!(stack: require (n + 1); copy (n + 1)),
|
||||||
// The stack will wind up with the 1 and nth inputs being identical
|
// The stack will wind up with the 1 and nth inputs being identical
|
||||||
// with n input-dependent. I can imagine scripts which check this
|
// with n input-dependent. I can imagine scripts which check this
|
||||||
// condition or its negation for various n to get arbitrary finite
|
// condition or its negation for various n to get arbitrary finite
|
||||||
|
@ -2469,7 +2434,7 @@ impl Script {
|
||||||
};
|
};
|
||||||
stack.pop();
|
stack.pop();
|
||||||
match top_n {
|
match top_n {
|
||||||
Some(n) => stack_opcode!(stack(n + 1): require (n + 1); copy (n + 1); drop (n + 1)),
|
Some(n) => stack_opcode!(stack: require (n + 1); copy (n + 1); drop (n + 1)),
|
||||||
// The stack will wind up reordered, so in principle I could just force
|
// The stack will wind up reordered, so in principle I could just force
|
||||||
// the input to be zero (other n values can be converted to zero by just
|
// the input to be zero (other n values can be converted to zero by just
|
||||||
// manually rearranging the input). The problem is if numeric bounds are
|
// manually rearranging the input). The problem is if numeric bounds are
|
||||||
|
@ -2477,9 +2442,9 @@ impl Script {
|
||||||
None => { return Err(Error::Unanalyzable); }
|
None => { return Err(Error::Unanalyzable); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opcodes::Ordinary::OP_ROT => stack_opcode!(stack(3): require 3; perm (1, 2, 3)),
|
opcodes::Ordinary::OP_ROT => stack_opcode!(stack: require 3; perm (1, 2, 3)),
|
||||||
opcodes::Ordinary::OP_SWAP => stack_opcode!(stack(2): require 3; swap (1, 2)),
|
opcodes::Ordinary::OP_SWAP => stack_opcode!(stack: require 3; swap (1, 2)),
|
||||||
opcodes::Ordinary::OP_TUCK => stack_opcode!(stack(2): require 2; copy 2; copy 1; drop 2),
|
opcodes::Ordinary::OP_TUCK => stack_opcode!(stack: require 2; copy 2; copy 1; drop 2),
|
||||||
opcodes::Ordinary::OP_IFDUP => {
|
opcodes::Ordinary::OP_IFDUP => {
|
||||||
let top_bool = {
|
let top_bool = {
|
||||||
let top = stack.peek_mut();
|
let top = stack.peek_mut();
|
||||||
|
@ -2487,14 +2452,13 @@ impl Script {
|
||||||
};
|
};
|
||||||
match top_bool {
|
match top_bool {
|
||||||
Some(false) => { }
|
Some(false) => { }
|
||||||
Some(true) => { stack_opcode!(stack(1): require 1; copy 1); }
|
Some(true) => { stack_opcode!(stack: require 1; copy 1); }
|
||||||
None => {
|
None => {
|
||||||
let mut stack_true = stack.clone();
|
let mut stack_true = stack.clone();
|
||||||
// Try pushing false and see what happens
|
// Try pushing false and see what happens
|
||||||
if stack.peek_mut().set_bool_value(false).is_ok() {
|
if stack.peek_mut().set_bool_value(false).is_ok() {
|
||||||
match recurse(&script[index - 1..], stack, exec_stack.clone(), depth + 1) {
|
if let Ok(res) = recurse(&script[index - 1..], stack, exec_stack.clone(), depth + 1) {
|
||||||
Ok(res) => { return Ok(res); }
|
return Ok(res);
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Failing that, push true
|
// Failing that, push true
|
||||||
|
|
|
@ -195,8 +195,8 @@ macro_rules! impl_array_newtype_encodable {
|
||||||
unsafe {
|
unsafe {
|
||||||
use std::mem;
|
use std::mem;
|
||||||
let mut ret: [$ty; $len] = mem::uninitialized();
|
let mut ret: [$ty; $len] = mem::uninitialized();
|
||||||
for i in 0..$len {
|
for item in ret.mut_iter() {
|
||||||
ret[i] = match try!(v.visit()) {
|
*item = match try!(v.visit()) {
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
None => return Err(::serde::de::Error::end_of_stream_error())
|
None => return Err(::serde::de::Error::end_of_stream_error())
|
||||||
};
|
};
|
||||||
|
|
|
@ -150,7 +150,7 @@ macro_rules! impl_array {
|
||||||
// Set everything to the first decode
|
// Set everything to the first decode
|
||||||
let mut ret = [try!(ConsensusDecodable::consensus_decode(d)); $size];
|
let mut ret = [try!(ConsensusDecodable::consensus_decode(d)); $size];
|
||||||
// Set the rest
|
// Set the rest
|
||||||
for i in 1..$size { ret[i] = try!(ConsensusDecodable::consensus_decode(d)); }
|
for item in ret.iter_mut().take($size).skip(1) { *item = try!(ConsensusDecodable::consensus_decode(d)); }
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub enum Error {
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Error::BadTweak(ref e) => fmt::Display::fmt(&e, f),
|
Error::BadTweak(ref e) |
|
||||||
Error::Secp(ref e) => fmt::Display::fmt(&e, f),
|
Error::Secp(ref e) => fmt::Display::fmt(&e, f),
|
||||||
Error::Script(ref e) => fmt::Display::fmt(&e, f),
|
Error::Script(ref e) => fmt::Display::fmt(&e, f),
|
||||||
Error::UncompressedKey => f.write_str("encountered uncompressed secp public key"),
|
Error::UncompressedKey => f.write_str("encountered uncompressed secp public key"),
|
||||||
|
@ -74,7 +74,7 @@ impl fmt::Display for Error {
|
||||||
impl error::Error for Error {
|
impl error::Error for Error {
|
||||||
fn cause(&self) -> Option<&error::Error> {
|
fn cause(&self) -> Option<&error::Error> {
|
||||||
match *self {
|
match *self {
|
||||||
Error::BadTweak(ref e) => Some(e),
|
Error::BadTweak(ref e) |
|
||||||
Error::Secp(ref e) => Some(e),
|
Error::Secp(ref e) => Some(e),
|
||||||
Error::Script(ref e) => Some(e),
|
Error::Script(ref e) => Some(e),
|
||||||
_ => None
|
_ => None
|
||||||
|
@ -175,7 +175,7 @@ pub fn tweak_secret_key(secp: &Secp256k1, key: &SecretKey, contract: &[u8]) -> R
|
||||||
hmac.raw_result(&mut hmac_raw);
|
hmac.raw_result(&mut hmac_raw);
|
||||||
let hmac_sk = try!(SecretKey::from_slice(&secp, &hmac_raw).map_err(Error::BadTweak));
|
let hmac_sk = try!(SecretKey::from_slice(&secp, &hmac_raw).map_err(Error::BadTweak));
|
||||||
// Execute the tweak
|
// Execute the tweak
|
||||||
let mut key = key.clone();
|
let mut key = *key;
|
||||||
try!(key.add_assign(&secp, &hmac_sk).map_err(Error::Secp));
|
try!(key.add_assign(&secp, &hmac_sk).map_err(Error::Secp));
|
||||||
// Return
|
// Return
|
||||||
Ok(key)
|
Ok(key)
|
||||||
|
|
|
@ -167,7 +167,7 @@ impl Sha256dHash {
|
||||||
|
|
||||||
/// Decodes a big-endian (i.e. reversed vs sha256sum output) hex string as a Sha256dHash
|
/// Decodes a big-endian (i.e. reversed vs sha256sum output) hex string as a Sha256dHash
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_hex<'a>(s: &'a str) -> Result<Sha256dHash, HexError> {
|
pub fn from_hex(s: &str) -> Result<Sha256dHash, HexError> {
|
||||||
if s.len() != 64 {
|
if s.len() != 64 {
|
||||||
return Err(HexError::BadLength(s.len()));
|
return Err(HexError::BadLength(s.len()));
|
||||||
}
|
}
|
||||||
|
@ -204,9 +204,9 @@ impl Sha256dHash {
|
||||||
pub fn le_hex_string(&self) -> String {
|
pub fn le_hex_string(&self) -> String {
|
||||||
let &Sha256dHash(data) = self;
|
let &Sha256dHash(data) = self;
|
||||||
let mut ret = String::with_capacity(64);
|
let mut ret = String::with_capacity(64);
|
||||||
for i in 0..32 {
|
for item in data.iter().take(32) {
|
||||||
ret.push(from_digit((data[i] / 0x10) as u32, 16).unwrap());
|
ret.push(from_digit((*item / 0x10) as u32, 16).unwrap());
|
||||||
ret.push(from_digit((data[i] & 0x0f) as u32, 16).unwrap());
|
ret.push(from_digit((*item & 0x0f) as u32, 16).unwrap());
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,7 +345,7 @@ impl<K, V> PatriciaTree<K, V>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over all elements in the tree
|
/// Returns an iterator over all elements in the tree
|
||||||
pub fn iter<'a>(&'a self) -> Items<'a, K, V> {
|
pub fn iter(&self) -> Items<K, V> {
|
||||||
Items {
|
Items {
|
||||||
node: Some(self),
|
node: Some(self),
|
||||||
parents: vec![],
|
parents: vec![],
|
||||||
|
@ -354,7 +354,7 @@ impl<K, V> PatriciaTree<K, V>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a mutable iterator over all elements in the tree
|
/// Returns a mutable iterator over all elements in the tree
|
||||||
pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, K, V> {
|
pub fn mut_iter(&mut self) -> MutItems<K, V> {
|
||||||
MutItems {
|
MutItems {
|
||||||
node: self as *mut _,
|
node: self as *mut _,
|
||||||
parents: vec![],
|
parents: vec![],
|
||||||
|
|
Loading…
Reference in New Issue