Get library building on stable
This commit is contained in:
parent
2320f099c1
commit
99a4845719
|
@ -1,4 +1,8 @@
|
||||||
language: rust
|
language: rust
|
||||||
|
rust:
|
||||||
|
- stable
|
||||||
|
- beta
|
||||||
|
- nightly
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- git clone https://github.com/bitcoin/secp256k1.git
|
- git clone https://github.com/bitcoin/secp256k1.git
|
||||||
|
|
|
@ -167,24 +167,16 @@ impl Clone for Validator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validators
|
// Validators
|
||||||
fn check_op_size(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
mod check {
|
||||||
|
use super::AbstractStackElem;
|
||||||
|
|
||||||
|
pub fn op_size(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
let other = unsafe { elem.lookup(others[0]) };
|
let other = unsafe { elem.lookup(others[0]) };
|
||||||
elem.num_hi() >= other.len_lo() as i64 &&
|
elem.num_hi() >= other.len_lo() as i64 &&
|
||||||
elem.num_lo() <= other.len_hi() as i64
|
elem.num_lo() <= other.len_hi() as i64
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_op_size(elem: &mut AbstractStackElem, others: &[usize])
|
pub fn op_equal(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
-> Result<(), Error> {
|
|
||||||
let (lo, hi) = {
|
|
||||||
let one = unsafe { elem.lookup(others[0]) };
|
|
||||||
(one.len_lo() as i64, one.len_hi() as i64)
|
|
||||||
};
|
|
||||||
try!(elem.set_numeric());
|
|
||||||
try!(elem.set_num_lo(lo));
|
|
||||||
elem.set_num_hi(hi)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_op_equal(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
|
||||||
let one = unsafe { elem.lookup(others[0]) };
|
let one = unsafe { elem.lookup(others[0]) };
|
||||||
let two = unsafe { elem.lookup(others[1]) };
|
let two = unsafe { elem.lookup(others[1]) };
|
||||||
match elem.bool_value() {
|
match elem.bool_value() {
|
||||||
|
@ -209,7 +201,164 @@ fn check_op_equal(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_boolean(elem: &mut AbstractStackElem) -> Result<(), Error> {
|
pub fn op_not(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
|
let one = unsafe { elem.lookup(others[0]) };
|
||||||
|
if !one.may_be_numeric() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
match elem.bool_value() {
|
||||||
|
None => true,
|
||||||
|
Some(false) => one.num_hi() != 0 || one.num_lo() != 0,
|
||||||
|
Some(true) => one.num_hi() >= 0 && one.num_lo() <= 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_0notequal(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
|
let one = unsafe { elem.lookup(others[0]) };
|
||||||
|
if !one.may_be_numeric() { return false; }
|
||||||
|
match elem.bool_value() {
|
||||||
|
None => true,
|
||||||
|
Some(false) => one.num_hi() >= 0 && one.num_lo() <= 0,
|
||||||
|
Some(true) => one.num_hi() != 0 || one.num_lo() != 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_numequal(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
|
let one = unsafe { elem.lookup(others[0]) };
|
||||||
|
let two = unsafe { elem.lookup(others[1]) };
|
||||||
|
if !one.may_be_numeric() { return false; }
|
||||||
|
if !two.may_be_numeric() { return false; }
|
||||||
|
match elem.bool_value() {
|
||||||
|
None => true,
|
||||||
|
Some(false) => {
|
||||||
|
(one.num_value().is_none() || two.num_value().is_none() ||
|
||||||
|
one.num_value().unwrap() != two.num_value().unwrap()) &&
|
||||||
|
(one.bool_value().is_none() || two.bool_value().is_none() ||
|
||||||
|
one.bool_value().unwrap() != two.bool_value().unwrap())
|
||||||
|
}
|
||||||
|
Some(true) => {
|
||||||
|
one.num_lo() <= two.num_hi() &&
|
||||||
|
one.num_hi() >= two.num_lo() &&
|
||||||
|
(one.num_value().is_none() || two.num_value().is_none() ||
|
||||||
|
one.num_value().unwrap() == two.num_value().unwrap()) &&
|
||||||
|
(one.bool_value().is_none() || two.bool_value().is_none() ||
|
||||||
|
one.bool_value().unwrap() == two.bool_value().unwrap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_numnotequal(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
|
let one = unsafe { elem.lookup(others[0]) };
|
||||||
|
let two = unsafe { elem.lookup(others[1]) };
|
||||||
|
if !one.may_be_numeric() { return false; }
|
||||||
|
if !two.may_be_numeric() { return false; }
|
||||||
|
match elem.bool_value() {
|
||||||
|
None => true,
|
||||||
|
Some(false) => one.may_be_lt(two) || one.may_be_gt(two),
|
||||||
|
Some(true) => one.may_be_lteq(two) && one.may_be_gteq(two)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_numlt(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
|
let one = unsafe { elem.lookup(others[0]) };
|
||||||
|
let two = unsafe { elem.lookup(others[1]) };
|
||||||
|
if !one.may_be_numeric() { return false; }
|
||||||
|
if !two.may_be_numeric() { return false; }
|
||||||
|
match elem.bool_value() {
|
||||||
|
None => true,
|
||||||
|
Some(true) => one.may_be_lt(two),
|
||||||
|
Some(false) => one.may_be_gteq(two),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_numgt(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
|
let one = unsafe { elem.lookup(others[0]) };
|
||||||
|
let two = unsafe { elem.lookup(others[1]) };
|
||||||
|
if !one.may_be_numeric() { return false; }
|
||||||
|
if !two.may_be_numeric() { return false; }
|
||||||
|
match elem.bool_value() {
|
||||||
|
None => true,
|
||||||
|
Some(true) => one.may_be_gt(two),
|
||||||
|
Some(false) => one.may_be_lteq(two)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_numlteq(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
|
let one = unsafe { elem.lookup(others[0]) };
|
||||||
|
let two = unsafe { elem.lookup(others[1]) };
|
||||||
|
if !one.may_be_numeric() { return false; }
|
||||||
|
if !two.may_be_numeric() { return false; }
|
||||||
|
match elem.bool_value() {
|
||||||
|
None => true,
|
||||||
|
Some(false) => one.may_be_gt(two),
|
||||||
|
Some(true) => one.may_be_lteq(two)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_numgteq(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
|
let one = unsafe { elem.lookup(others[0]) };
|
||||||
|
let two = unsafe { elem.lookup(others[1]) };
|
||||||
|
if !one.may_be_numeric() { return false; }
|
||||||
|
if !two.may_be_numeric() { return false; }
|
||||||
|
match elem.bool_value() {
|
||||||
|
None => true,
|
||||||
|
Some(true) => one.may_be_gteq(two),
|
||||||
|
Some(false) => one.may_be_lt(two)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_ripemd160(elem: &AbstractStackElem, _: &[usize]) -> bool {
|
||||||
|
elem.may_be_hash160()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_sha1(elem: &AbstractStackElem, _: &[usize]) -> bool {
|
||||||
|
elem.may_be_hash160()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_hash160(elem: &AbstractStackElem, _: &[usize]) -> bool {
|
||||||
|
elem.may_be_hash160()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_sha256(elem: &AbstractStackElem, _: &[usize]) -> bool {
|
||||||
|
elem.may_be_hash256()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_hash256(elem: &AbstractStackElem, _: &[usize]) -> bool {
|
||||||
|
elem.may_be_hash256()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn op_checksig(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
||||||
|
let one = unsafe { elem.lookup(others[0]) };
|
||||||
|
let two = unsafe { elem.lookup(others[1]) };
|
||||||
|
match elem.bool_value() {
|
||||||
|
None => true,
|
||||||
|
Some(false) => true,
|
||||||
|
Some(true) => one.may_be_signature() && two.may_be_pubkey()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mod update {
|
||||||
|
use super::{AbstractStackElem, Error};
|
||||||
|
use crypto::digest::Digest;
|
||||||
|
use crypto::ripemd160::Ripemd160;
|
||||||
|
use crypto::sha1::Sha1;
|
||||||
|
use crypto::sha2::Sha256;
|
||||||
|
|
||||||
|
pub fn op_size(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
|
-> Result<(), Error> {
|
||||||
|
let (lo, hi) = {
|
||||||
|
let one = unsafe { elem.lookup(others[0]) };
|
||||||
|
(one.len_lo() as i64, one.len_hi() as i64)
|
||||||
|
};
|
||||||
|
try!(elem.set_numeric());
|
||||||
|
try!(elem.set_num_lo(lo));
|
||||||
|
elem.set_num_hi(hi)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn boolean(elem: &mut AbstractStackElem) -> Result<(), Error> {
|
||||||
// Test boolean values
|
// Test boolean values
|
||||||
elem.bool_val = Some(true);
|
elem.bool_val = Some(true);
|
||||||
let true_works = elem.validate();
|
let true_works = elem.validate();
|
||||||
|
@ -225,10 +374,10 @@ fn update_boolean(elem: &mut AbstractStackElem) -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_op_equal(elem: &mut AbstractStackElem, others: &[usize])
|
pub fn op_equal(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
match elem.bool_value() {
|
match elem.bool_value() {
|
||||||
None => update_boolean(elem),
|
None => boolean(elem),
|
||||||
Some(false) => {
|
Some(false) => {
|
||||||
let one = unsafe { elem.lookup_mut(others[0]) };
|
let one = unsafe { elem.lookup_mut(others[0]) };
|
||||||
let two = unsafe { elem.lookup_mut(others[1]) };
|
let two = unsafe { elem.lookup_mut(others[1]) };
|
||||||
|
@ -270,23 +419,10 @@ fn update_op_equal(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_not(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
pub fn op_not(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
let one = unsafe { elem.lookup(others[0]) };
|
|
||||||
if !one.may_be_numeric() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
match elem.bool_value() {
|
|
||||||
None => true,
|
|
||||||
Some(false) => one.num_hi() != 0 || one.num_lo() != 0,
|
|
||||||
Some(true) => one.num_hi() >= 0 && one.num_lo() <= 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_not(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
match elem.bool_value() {
|
match elem.bool_value() {
|
||||||
None => update_boolean(elem),
|
None => boolean(elem),
|
||||||
Some(false) => {
|
Some(false) => {
|
||||||
let one = unsafe { elem.lookup_mut(others[0]) };
|
let one = unsafe { elem.lookup_mut(others[0]) };
|
||||||
try!(one.set_numeric());
|
try!(one.set_numeric());
|
||||||
|
@ -308,20 +444,10 @@ fn update_op_not(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_0notequal(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
pub fn op_0notequal(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
let one = unsafe { elem.lookup(others[0]) };
|
|
||||||
if !one.may_be_numeric() { return false; }
|
|
||||||
match elem.bool_value() {
|
|
||||||
None => true,
|
|
||||||
Some(false) => one.num_hi() >= 0 && one.num_lo() <= 0,
|
|
||||||
Some(true) => one.num_hi() != 0 || one.num_lo() != 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_0notequal(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
match elem.bool_value() {
|
match elem.bool_value() {
|
||||||
None => update_boolean(elem),
|
None => boolean(elem),
|
||||||
Some(false) => {
|
Some(false) => {
|
||||||
let one = unsafe { elem.lookup_mut(others[0]) };
|
let one = unsafe { elem.lookup_mut(others[0]) };
|
||||||
try!(one.set_numeric());
|
try!(one.set_numeric());
|
||||||
|
@ -343,34 +469,10 @@ fn update_op_0notequal(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_numequal(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
pub fn op_numequal(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
let one = unsafe { elem.lookup(others[0]) };
|
|
||||||
let two = unsafe { elem.lookup(others[1]) };
|
|
||||||
if !one.may_be_numeric() { return false; }
|
|
||||||
if !two.may_be_numeric() { return false; }
|
|
||||||
match elem.bool_value() {
|
|
||||||
None => true,
|
|
||||||
Some(false) => {
|
|
||||||
(one.num_value().is_none() || two.num_value().is_none() ||
|
|
||||||
one.num_value().unwrap() != two.num_value().unwrap()) &&
|
|
||||||
(one.bool_value().is_none() || two.bool_value().is_none() ||
|
|
||||||
one.bool_value().unwrap() != two.bool_value().unwrap())
|
|
||||||
}
|
|
||||||
Some(true) => {
|
|
||||||
one.num_lo() <= two.num_hi() &&
|
|
||||||
one.num_hi() >= two.num_lo() &&
|
|
||||||
(one.num_value().is_none() || two.num_value().is_none() ||
|
|
||||||
one.num_value().unwrap() == two.num_value().unwrap()) &&
|
|
||||||
(one.bool_value().is_none() || two.bool_value().is_none() ||
|
|
||||||
one.bool_value().unwrap() == two.bool_value().unwrap())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_numequal(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
match elem.bool_value() {
|
match elem.bool_value() {
|
||||||
None => update_boolean(elem),
|
None => boolean(elem),
|
||||||
Some(false) => {
|
Some(false) => {
|
||||||
// todo: find a way to force the numbers to be nonequal
|
// todo: find a way to force the numbers to be nonequal
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -388,22 +490,10 @@ fn update_op_numequal(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_numnotequal(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
pub fn op_numnotequal(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
let one = unsafe { elem.lookup(others[0]) };
|
|
||||||
let two = unsafe { elem.lookup(others[1]) };
|
|
||||||
if !one.may_be_numeric() { return false; }
|
|
||||||
if !two.may_be_numeric() { return false; }
|
|
||||||
match elem.bool_value() {
|
|
||||||
None => true,
|
|
||||||
Some(false) => one.may_be_lt(two) || one.may_be_gt(two),
|
|
||||||
Some(true) => one.may_be_lteq(two) && one.may_be_gteq(two)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_numnotequal(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
match elem.bool_value() {
|
match elem.bool_value() {
|
||||||
None => update_boolean(elem),
|
None => boolean(elem),
|
||||||
Some(false) => {
|
Some(false) => {
|
||||||
let one = unsafe { elem.lookup_mut(others[0]) };
|
let one = unsafe { elem.lookup_mut(others[0]) };
|
||||||
let two = unsafe { elem.lookup_mut(others[1]) };
|
let two = unsafe { elem.lookup_mut(others[1]) };
|
||||||
|
@ -421,22 +511,10 @@ fn update_op_numnotequal(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_numlt(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
pub fn op_numlt(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
let one = unsafe { elem.lookup(others[0]) };
|
|
||||||
let two = unsafe { elem.lookup(others[1]) };
|
|
||||||
if !one.may_be_numeric() { return false; }
|
|
||||||
if !two.may_be_numeric() { return false; }
|
|
||||||
match elem.bool_value() {
|
|
||||||
None => true,
|
|
||||||
Some(true) => one.may_be_lt(two),
|
|
||||||
Some(false) => one.may_be_gteq(two),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_numlt(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
match elem.bool_value() {
|
match elem.bool_value() {
|
||||||
None => update_boolean(elem),
|
None => boolean(elem),
|
||||||
Some(true) => {
|
Some(true) => {
|
||||||
let one = unsafe { elem.lookup_mut(others[0]) };
|
let one = unsafe { elem.lookup_mut(others[0]) };
|
||||||
let two = unsafe { elem.lookup_mut(others[1]) };
|
let two = unsafe { elem.lookup_mut(others[1]) };
|
||||||
|
@ -458,22 +536,10 @@ fn update_op_numlt(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_numgt(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
pub fn op_numgt(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
let one = unsafe { elem.lookup(others[0]) };
|
|
||||||
let two = unsafe { elem.lookup(others[1]) };
|
|
||||||
if !one.may_be_numeric() { return false; }
|
|
||||||
if !two.may_be_numeric() { return false; }
|
|
||||||
match elem.bool_value() {
|
|
||||||
None => true,
|
|
||||||
Some(true) => one.may_be_gt(two),
|
|
||||||
Some(false) => one.may_be_lteq(two)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_numgt(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
match elem.bool_value() {
|
match elem.bool_value() {
|
||||||
None => try!(update_boolean(elem)),
|
None => try!(boolean(elem)),
|
||||||
Some(true) => {
|
Some(true) => {
|
||||||
let one = unsafe { elem.lookup_mut(others[0]) };
|
let one = unsafe { elem.lookup_mut(others[0]) };
|
||||||
let two = unsafe { elem.lookup_mut(others[1]) };
|
let two = unsafe { elem.lookup_mut(others[1]) };
|
||||||
|
@ -496,22 +562,10 @@ fn update_op_numgt(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_numlteq(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
pub fn op_numlteq(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
let one = unsafe { elem.lookup(others[0]) };
|
|
||||||
let two = unsafe { elem.lookup(others[1]) };
|
|
||||||
if !one.may_be_numeric() { return false; }
|
|
||||||
if !two.may_be_numeric() { return false; }
|
|
||||||
match elem.bool_value() {
|
|
||||||
None => true,
|
|
||||||
Some(false) => one.may_be_gt(two),
|
|
||||||
Some(true) => one.may_be_lteq(two)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_numlteq(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
match elem.bool_value() {
|
match elem.bool_value() {
|
||||||
None => try!(update_boolean(elem)),
|
None => try!(boolean(elem)),
|
||||||
Some(true) => {
|
Some(true) => {
|
||||||
let one = unsafe { elem.lookup_mut(others[0]) };
|
let one = unsafe { elem.lookup_mut(others[0]) };
|
||||||
let two = unsafe { elem.lookup_mut(others[1]) };
|
let two = unsafe { elem.lookup_mut(others[1]) };
|
||||||
|
@ -534,22 +588,10 @@ fn update_op_numlteq(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_numgteq(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
pub fn op_numgteq(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
let one = unsafe { elem.lookup(others[0]) };
|
|
||||||
let two = unsafe { elem.lookup(others[1]) };
|
|
||||||
if !one.may_be_numeric() { return false; }
|
|
||||||
if !two.may_be_numeric() { return false; }
|
|
||||||
match elem.bool_value() {
|
|
||||||
None => true,
|
|
||||||
Some(true) => one.may_be_gteq(two),
|
|
||||||
Some(false) => one.may_be_lt(two)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_numgteq(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
match elem.bool_value() {
|
match elem.bool_value() {
|
||||||
None => try!(update_boolean(elem)),
|
None => try!(boolean(elem)),
|
||||||
Some(true) => {
|
Some(true) => {
|
||||||
let one = unsafe { elem.lookup_mut(others[0]) };
|
let one = unsafe { elem.lookup_mut(others[0]) };
|
||||||
let two = unsafe { elem.lookup_mut(others[1]) };
|
let two = unsafe { elem.lookup_mut(others[1]) };
|
||||||
|
@ -572,11 +614,7 @@ fn update_op_numgteq(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_ripemd160(elem: &AbstractStackElem, _: &[usize]) -> bool {
|
pub fn op_ripemd160(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
elem.may_be_hash160()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_ripemd160(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
try!(elem.set_len_lo(20));
|
try!(elem.set_len_lo(20));
|
||||||
try!(elem.set_len_hi(20));
|
try!(elem.set_len_hi(20));
|
||||||
|
@ -598,11 +636,7 @@ fn update_op_ripemd160(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_sha1(elem: &AbstractStackElem, _: &[usize]) -> bool {
|
pub fn op_sha1(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
elem.may_be_hash160()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_sha1(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
try!(elem.set_len_lo(20));
|
try!(elem.set_len_lo(20));
|
||||||
try!(elem.set_len_hi(20));
|
try!(elem.set_len_hi(20));
|
||||||
|
@ -624,11 +658,7 @@ fn update_op_sha1(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_hash160(elem: &AbstractStackElem, _: &[usize]) -> bool {
|
pub fn op_hash160(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
elem.may_be_hash160()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_hash160(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
try!(elem.set_len_lo(20));
|
try!(elem.set_len_lo(20));
|
||||||
try!(elem.set_len_hi(20));
|
try!(elem.set_len_hi(20));
|
||||||
|
@ -654,11 +684,7 @@ fn update_op_hash160(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_sha256(elem: &AbstractStackElem, _: &[usize]) -> bool {
|
pub fn op_sha256(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
elem.may_be_hash256()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_sha256(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
try!(elem.set_len_lo(32));
|
try!(elem.set_len_lo(32));
|
||||||
try!(elem.set_len_hi(32));
|
try!(elem.set_len_hi(32));
|
||||||
|
@ -680,11 +706,7 @@ fn update_op_sha256(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_hash256(elem: &AbstractStackElem, _: &[usize]) -> bool {
|
pub fn op_hash256(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
elem.may_be_hash256()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_hash256(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
try!(elem.set_len_lo(32));
|
try!(elem.set_len_lo(32));
|
||||||
try!(elem.set_len_hi(32));
|
try!(elem.set_len_hi(32));
|
||||||
|
@ -709,20 +731,10 @@ fn update_op_hash256(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_op_checksig(elem: &AbstractStackElem, others: &[usize]) -> bool {
|
pub fn op_checksig(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
let one = unsafe { elem.lookup(others[0]) };
|
|
||||||
let two = unsafe { elem.lookup(others[1]) };
|
|
||||||
match elem.bool_value() {
|
|
||||||
None => true,
|
|
||||||
Some(false) => true,
|
|
||||||
Some(true) => one.may_be_signature() && two.may_be_pubkey()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_op_checksig(elem: &mut AbstractStackElem, others: &[usize])
|
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
match elem.bool_value() {
|
match elem.bool_value() {
|
||||||
None => update_boolean(elem),
|
None => boolean(elem),
|
||||||
Some(false) => Ok(()), // nothing we can do to enforce an invalid sig
|
Some(false) => Ok(()), // nothing we can do to enforce an invalid sig
|
||||||
Some(true) => {
|
Some(true) => {
|
||||||
let sig = unsafe { elem.lookup_mut(others[0]) };
|
let sig = unsafe { elem.lookup_mut(others[0]) };
|
||||||
|
@ -736,6 +748,7 @@ fn update_op_checksig(elem: &mut AbstractStackElem, others: &[usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An abstract element on the stack, used to describe a satisfying
|
/// An abstract element on the stack, used to describe a satisfying
|
||||||
/// script input
|
/// script input
|
||||||
|
@ -1646,8 +1659,8 @@ macro_rules! unary_opcode_satisfy {
|
||||||
let one = $stack.pop();
|
let one = $stack.pop();
|
||||||
let cond = $stack.push_alloc(AbstractStackElem::new_unknown());
|
let cond = $stack.push_alloc(AbstractStackElem::new_unknown());
|
||||||
try!(cond.add_validator(Validator { args: vec![one],
|
try!(cond.add_validator(Validator { args: vec![one],
|
||||||
check: concat_idents!(check_, $op),
|
check: check::$op,
|
||||||
update: concat_idents!(update_, $op) }));
|
update: update::$op }));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1657,8 +1670,8 @@ macro_rules! boolean_opcode_satisfy {
|
||||||
let cond = $stack.push_alloc(AbstractStackElem::new_unknown());
|
let cond = $stack.push_alloc(AbstractStackElem::new_unknown());
|
||||||
try!(cond.set_boolean());
|
try!(cond.set_boolean());
|
||||||
try!(cond.add_validator(Validator { args: vec![one],
|
try!(cond.add_validator(Validator { args: vec![one],
|
||||||
check: concat_idents!(check_, $op),
|
check: check::$op,
|
||||||
update: concat_idents!(update_, $op) }));
|
update: update::$op }));
|
||||||
});
|
});
|
||||||
($stack:ident, binary $op:ident) => ({
|
($stack:ident, binary $op:ident) => ({
|
||||||
let one = $stack.pop();
|
let one = $stack.pop();
|
||||||
|
@ -1666,8 +1679,8 @@ macro_rules! boolean_opcode_satisfy {
|
||||||
let cond = $stack.push_alloc(AbstractStackElem::new_unknown());
|
let cond = $stack.push_alloc(AbstractStackElem::new_unknown());
|
||||||
try!(cond.set_boolean());
|
try!(cond.set_boolean());
|
||||||
try!(cond.add_validator(Validator { args: vec![two, one],
|
try!(cond.add_validator(Validator { args: vec![two, one],
|
||||||
check: concat_idents!(check_, $op),
|
check: check::$op,
|
||||||
update: concat_idents!(update_, $op) }));
|
update: update::$op }));
|
||||||
});
|
});
|
||||||
($stack:ident, ternary $op:ident) => ({
|
($stack:ident, ternary $op:ident) => ({
|
||||||
let one = $stack.pop();
|
let one = $stack.pop();
|
||||||
|
@ -1676,8 +1689,8 @@ macro_rules! boolean_opcode_satisfy {
|
||||||
let mut cond = $stack.push_alloc(AbstractStackElem::new_unknown());
|
let mut cond = $stack.push_alloc(AbstractStackElem::new_unknown());
|
||||||
try!(cond.set_boolean());
|
try!(cond.set_boolean());
|
||||||
try!(cond.add_validator(Validator { args: vec![three, two, one],
|
try!(cond.add_validator(Validator { args: vec![three, two, one],
|
||||||
check: concat_idents!(check_, $op),
|
check: check::$op,
|
||||||
update: concat_idents!(update_, $op) }));
|
update: update::$op }));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2341,8 +2354,8 @@ impl Script {
|
||||||
let new_elem = stack.push_alloc(AbstractStackElem::new_unknown());
|
let new_elem = stack.push_alloc(AbstractStackElem::new_unknown());
|
||||||
try!(new_elem.set_numeric());
|
try!(new_elem.set_numeric());
|
||||||
try!(new_elem.add_validator(Validator { args: vec![top],
|
try!(new_elem.add_validator(Validator { args: vec![top],
|
||||||
check: check_op_size,
|
check: check::op_size,
|
||||||
update: update_op_size }));
|
update: update::op_size }));
|
||||||
}
|
}
|
||||||
opcodes::Ordinary::OP_EQUAL => boolean_opcode_satisfy!(stack, binary op_equal),
|
opcodes::Ordinary::OP_EQUAL => boolean_opcode_satisfy!(stack, binary op_equal),
|
||||||
opcodes::Ordinary::OP_EQUALVERIFY => {
|
opcodes::Ordinary::OP_EQUALVERIFY => {
|
||||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -28,13 +28,7 @@
|
||||||
#![crate_type = "rlib"]
|
#![crate_type = "rlib"]
|
||||||
|
|
||||||
// Experimental features we need
|
// Experimental features we need
|
||||||
#![feature(box_patterns)]
|
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
|
||||||
#![feature(concat_idents)]
|
|
||||||
#![feature(custom_derive, plugin)]
|
|
||||||
#![feature(hashmap_hasher)]
|
|
||||||
#![feature(ip_addr)]
|
|
||||||
#![feature(slice_patterns)]
|
|
||||||
#![cfg_attr(test, feature(test))]
|
|
||||||
|
|
||||||
// Coding conventions
|
// Coding conventions
|
||||||
#![deny(non_upper_case_globals)]
|
#![deny(non_upper_case_globals)]
|
||||||
|
@ -52,7 +46,7 @@ extern crate rand;
|
||||||
extern crate rustc_serialize as serialize;
|
extern crate rustc_serialize as serialize;
|
||||||
extern crate secp256k1;
|
extern crate secp256k1;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
#[cfg(test)] extern crate test;
|
#[cfg(all(test, feature = "unstable"))] extern crate test;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -30,9 +30,7 @@
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::default::Default;
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::collections::hash_state::HashState;
|
|
||||||
use std::u32;
|
use std::u32;
|
||||||
|
|
||||||
use util::hash::Sha256dHash;
|
use util::hash::Sha256dHash;
|
||||||
|
@ -315,9 +313,8 @@ impl<D: SimpleDecoder, T: ConsensusDecodable<D>> ConsensusDecodable<D> for Box<T
|
||||||
}
|
}
|
||||||
|
|
||||||
// HashMap
|
// HashMap
|
||||||
impl<S, K, V, H> ConsensusEncodable<S> for HashMap<K, V, H>
|
impl<S, K, V> ConsensusEncodable<S> for HashMap<K, V>
|
||||||
where S: SimpleEncoder,
|
where S: SimpleEncoder,
|
||||||
H: HashState + Default,
|
|
||||||
K: ConsensusEncodable<S> + Eq + Hash,
|
K: ConsensusEncodable<S> + Eq + Hash,
|
||||||
V: ConsensusEncodable<S>
|
V: ConsensusEncodable<S>
|
||||||
{
|
{
|
||||||
|
@ -332,17 +329,16 @@ impl<S, K, V, H> ConsensusEncodable<S> for HashMap<K, V, H>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D, K, V, H> ConsensusDecodable<D> for HashMap<K, V, H>
|
impl<D, K, V> ConsensusDecodable<D> for HashMap<K, V>
|
||||||
where D: SimpleDecoder,
|
where D: SimpleDecoder,
|
||||||
H: HashState + Default,
|
|
||||||
K: ConsensusDecodable<D> + Eq + Hash,
|
K: ConsensusDecodable<D> + Eq + Hash,
|
||||||
V: ConsensusDecodable<D>
|
V: ConsensusDecodable<D>
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn consensus_decode(d: &mut D) -> Result<HashMap<K, V, H>, D::Error> {
|
fn consensus_decode(d: &mut D) -> Result<HashMap<K, V>, D::Error> {
|
||||||
let VarInt(len): VarInt = try!(ConsensusDecodable::consensus_decode(d));
|
let VarInt(len): VarInt = try!(ConsensusDecodable::consensus_decode(d));
|
||||||
|
|
||||||
let mut ret = HashMap::with_capacity_and_hash_state(len as usize, Default::default());
|
let mut ret = HashMap::with_capacity(len as usize);
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
ret.insert(try!(ConsensusDecodable::consensus_decode(d)),
|
ret.insert(try!(ConsensusDecodable::consensus_decode(d)),
|
||||||
try!(ConsensusDecodable::consensus_decode(d)));
|
try!(ConsensusDecodable::consensus_decode(d)));
|
||||||
|
|
|
@ -33,10 +33,10 @@ use network::serialize::{RawEncoder, RawDecoder};
|
||||||
use util::{self, propagate_err};
|
use util::{self, propagate_err};
|
||||||
|
|
||||||
/// Format an IP address in the 16-byte bitcoin protocol serialization
|
/// Format an IP address in the 16-byte bitcoin protocol serialization
|
||||||
fn ipaddr_to_bitcoin_addr(ipaddr: &net::IpAddr) -> [u16; 8] {
|
fn ipaddr_to_bitcoin_addr(addr: &net::SocketAddr) -> [u16; 8] {
|
||||||
match *ipaddr {
|
match *addr {
|
||||||
net::IpAddr::V4(ref addr) => addr.to_ipv6_mapped().segments(),
|
net::SocketAddr::V4(ref addr) => addr.ip().to_ipv6_mapped().segments(),
|
||||||
net::IpAddr::V6(ref addr) => addr.segments()
|
net::SocketAddr::V6(ref addr) => addr.ip().segments()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ impl Socket {
|
||||||
Ok(addr) => {
|
Ok(addr) => {
|
||||||
Ok(Address {
|
Ok(Address {
|
||||||
services: self.services,
|
services: self.services,
|
||||||
address: ipaddr_to_bitcoin_addr(&addr.ip()),
|
address: ipaddr_to_bitcoin_addr(&addr),
|
||||||
port: addr.port()
|
port: addr.port()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -133,7 +133,7 @@ impl Socket {
|
||||||
Ok(addr) => {
|
Ok(addr) => {
|
||||||
Ok(Address {
|
Ok(Address {
|
||||||
services: self.services,
|
services: self.services,
|
||||||
address: ipaddr_to_bitcoin_addr(&addr.ip()),
|
address: ipaddr_to_bitcoin_addr(&addr),
|
||||||
port: addr.port()
|
port: addr.port()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -249,8 +249,9 @@ impl<K, V> PatriciaTree<K, V>
|
||||||
}
|
}
|
||||||
match (tree.child_l.take(), tree.child_r.take()) {
|
match (tree.child_l.take(), tree.child_r.take()) {
|
||||||
(Some(_), Some(_)) => unreachable!(),
|
(Some(_), Some(_)) => unreachable!(),
|
||||||
(Some(box PatriciaTree { data, child_l, child_r, skip_prefix, skip_len }), None) |
|
(Some(child), None) | (None, Some(child)) => {
|
||||||
(None, Some(box PatriciaTree { data, child_l, child_r, skip_prefix, skip_len })) => {
|
let child = *child; /* workaround for rustc #28536 */
|
||||||
|
let PatriciaTree { data, child_l, child_r, skip_len, skip_prefix } = child;
|
||||||
tree.data = data;
|
tree.data = data;
|
||||||
tree.child_l = child_l;
|
tree.child_l = child_l;
|
||||||
tree.child_r = child_r;
|
tree.child_r = child_r;
|
||||||
|
@ -307,8 +308,9 @@ impl<K, V> PatriciaTree<K, V>
|
||||||
return (false, ret);
|
return (false, ret);
|
||||||
}
|
}
|
||||||
// One child? Consolidate
|
// One child? Consolidate
|
||||||
(bit, Some(box PatriciaTree { data, child_l, child_r, skip_prefix, skip_len }), None) |
|
(bit, Some(child), None) | (bit, None, Some(child)) => {
|
||||||
(bit, None, Some(box PatriciaTree { data, child_l, child_r, skip_prefix, skip_len })) => {
|
let child = *child; /* workaround for rustc #28536 */
|
||||||
|
let PatriciaTree { data, child_l, child_r, skip_len, skip_prefix } = child;
|
||||||
tree.data = data;
|
tree.data = data;
|
||||||
tree.child_l = child_l;
|
tree.child_l = child_l;
|
||||||
tree.child_r = child_r;
|
tree.child_r = child_r;
|
||||||
|
|
Loading…
Reference in New Issue