script lib
This commit is contained in:
parent
0edcc08ab1
commit
fdc4bfe2d7
|
@ -8,6 +8,7 @@ dependencies = [
|
|||
"keys 0.1.0",
|
||||
"primitives 0.1.0",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"script 0.1.0",
|
||||
"serialization 0.1.0",
|
||||
]
|
||||
|
||||
|
@ -142,6 +143,17 @@ name = "rustc-serialize"
|
|||
version = "0.3.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "script"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bitcrypto 0.1.0",
|
||||
"chain 0.1.0",
|
||||
"keys 0.1.0",
|
||||
"primitives 0.1.0",
|
||||
"serialization 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serialization"
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -11,4 +11,5 @@ bitcrypto = { path = "crypto" }
|
|||
chain = { path = "chain" }
|
||||
keys = { path = "keys" }
|
||||
primitives = { path = "primitives" }
|
||||
script = { path = "script" }
|
||||
serialization = { path = "serialization" }
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "script"
|
||||
version = "0.1.0"
|
||||
authors = ["debris <marek.kotewicz@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
bitcrypto = { path = "../crypto" }
|
||||
chain = { path = "../chain" }
|
||||
keys = { path = "../keys" }
|
||||
primitives = { path = "../primitives" }
|
||||
serialization = { path = "../serialization" }
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use bytes::Bytes;
|
||||
use script::{Opcode, Script, Num};
|
||||
use {Opcode, Script, Num};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Builder {
|
|
@ -1,5 +1,5 @@
|
|||
use std::fmt;
|
||||
use script::Opcode;
|
||||
use Opcode;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Error {
|
|
@ -3,7 +3,7 @@ use bytes::Bytes;
|
|||
use keys::{Signature, Public};
|
||||
use chain::SEQUENCE_LOCKTIME_DISABLE_FLAG;
|
||||
use crypto::{sha1, sha256, dhash160, dhash256, ripemd160};
|
||||
use script::{
|
||||
use {
|
||||
script, Script, Num, VerificationFlags, Opcode, Error,
|
||||
Sighash, SignatureChecker, SignatureVersion, Stack
|
||||
};
|
||||
|
@ -890,10 +890,9 @@ pub fn eval_script(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use hex::FromHex;
|
||||
use bytes::Bytes;
|
||||
use chain::Transaction;
|
||||
use script::{
|
||||
use {
|
||||
Opcode, Script, VerificationFlags, Builder, Error, Num, TransactionInputSigner,
|
||||
NoopSignatureChecker, SignatureVersion, TransactionSignatureChecker, Stack
|
||||
};
|
||||
|
@ -903,7 +902,7 @@ mod tests {
|
|||
fn tests_is_public_key() {
|
||||
assert!(!is_public_key(&[]));
|
||||
assert!(!is_public_key(&[1]));
|
||||
assert!(is_public_key(&"0495dfb90f202c7d016ef42c65bc010cd26bb8237b06253cc4d12175097bef767ed6b1fcb3caf1ed57c98d92e6cb70278721b952e29a335134857acd4c199b9d2f".from_hex().unwrap()));
|
||||
assert!(is_public_key(&Bytes::from("0495dfb90f202c7d016ef42c65bc010cd26bb8237b06253cc4d12175097bef767ed6b1fcb3caf1ed57c98d92e6cb70278721b952e29a335134857acd4c199b9d2f")));
|
||||
assert!(is_public_key(&[2; 33]));
|
||||
assert!(is_public_key(&[3; 33]));
|
||||
assert!(!is_public_key(&[4; 33]));
|
|
@ -1,3 +1,9 @@
|
|||
extern crate bitcrypto as crypto;
|
||||
extern crate chain;
|
||||
extern crate keys;
|
||||
extern crate primitives;
|
||||
extern crate serialization as ser;
|
||||
|
||||
mod builder;
|
||||
mod error;
|
||||
mod flags;
|
||||
|
@ -9,6 +15,8 @@ mod sign;
|
|||
mod stack;
|
||||
mod verify;
|
||||
|
||||
pub use primitives::{bytes, hash};
|
||||
|
||||
pub use self::builder::Builder;
|
||||
pub use self::error::Error;
|
||||
pub use self::flags::VerificationFlags;
|
|
@ -1,7 +1,7 @@
|
|||
//! Script numeric.
|
||||
use std::ops;
|
||||
use bytes::Bytes;
|
||||
use script::Error;
|
||||
use Error;
|
||||
|
||||
/// Numeric opcodes (OP_1ADD, etc) are restricted to operating on 4-byte integers.
|
||||
/// The semantics are subtle, though: operands must be in the range [-2^31 +1...2^31 -1],
|
|
@ -1,9 +1,8 @@
|
|||
//! Serialized script, used inside transaction inputs and outputs.
|
||||
|
||||
use std::{fmt, ops};
|
||||
use hex::ToHex;
|
||||
use bytes::Bytes;
|
||||
use script::{Opcode, Error};
|
||||
use {Opcode, Error};
|
||||
|
||||
/// Maximum number of bytes pushable to the stack
|
||||
pub const MAX_SCRIPT_ELEMENT_SIZE: usize = 520;
|
||||
|
@ -345,7 +344,7 @@ impl fmt::Display for Script {
|
|||
};
|
||||
|
||||
match instruction.data {
|
||||
Some(data) => try!(writeln!(f, "{:?} 0x{}", instruction.opcode, data.to_hex())),
|
||||
Some(data) => try!(writeln!(f, "{:?} 0x{:?}", instruction.opcode, Bytes::from(data.to_vec()))),
|
||||
None => try!(writeln!(f, "{:?}", instruction.opcode)),
|
||||
}
|
||||
|
||||
|
@ -358,7 +357,7 @@ impl fmt::Display for Script {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use script::{Builder, Opcode};
|
||||
use {Builder, Opcode};
|
||||
use super::{Script, ScriptType};
|
||||
|
||||
#[test]
|
|
@ -1,10 +1,10 @@
|
|||
use script::{Script, Builder};
|
||||
use bytes::Bytes;
|
||||
use keys::KeyPair;
|
||||
use crypto::dhash256;
|
||||
use hash::H256;
|
||||
use ser::Stream;
|
||||
use chain::{Transaction, TransactionOutput, OutPoint, TransactionInput};
|
||||
use {Script, Builder};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub enum SignatureVersion {
|
||||
|
@ -223,7 +223,6 @@ impl TransactionInputSigner {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use hex::FromHex;
|
||||
use bytes::Bytes;
|
||||
use hash::H256;
|
||||
use keys::{KeyPair, Private, Address};
|
||||
|
@ -244,7 +243,7 @@ mod tests {
|
|||
let previous_output = "76a914df3bd30160e6c6145baaf2c88a8844c13a00d1d588ac".into();
|
||||
let current_output: Bytes = "76a914c8e90996c7c6080ee06284600c684ed904d14c5c88ac".into();
|
||||
let value = 91234;
|
||||
let expected_signature_hash = "5fda68729a6312e17e641e9a49fac2a4a6a680126610af573caab270d232f850".from_hex().unwrap();
|
||||
let expected_signature_hash = "5fda68729a6312e17e641e9a49fac2a4a6a680126610af573caab270d232f850".into();
|
||||
|
||||
// this is irrelevant
|
||||
let kp = KeyPair::from_private(private).unwrap();
|
||||
|
@ -272,7 +271,7 @@ mod tests {
|
|||
};
|
||||
|
||||
let hash = input_signer.signature_hash(0, &previous_output, SighashBase::All.into());
|
||||
assert_eq!(hash.to_vec(), expected_signature_hash);
|
||||
assert_eq!(hash, expected_signature_hash);
|
||||
}
|
||||
|
||||
fn run_test_sighash(
|
|
@ -1,5 +1,5 @@
|
|||
use std::ops;
|
||||
use script::Error;
|
||||
use Error;
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Clone)]
|
||||
pub struct Stack<T> {
|
||||
|
@ -151,7 +151,7 @@ impl<T> Stack<T> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use script::Error;
|
||||
use Error;
|
||||
use super::Stack;
|
||||
|
||||
#[test]
|
|
@ -1,9 +1,9 @@
|
|||
use keys::{Public, Signature};
|
||||
use script::{script, SignatureVersion, Script, TransactionInputSigner, Num};
|
||||
use chain::{
|
||||
SEQUENCE_FINAL, SEQUENCE_LOCKTIME_DISABLE_FLAG,
|
||||
SEQUENCE_LOCKTIME_MASK, SEQUENCE_LOCKTIME_TYPE_FLAG
|
||||
};
|
||||
use {script, SignatureVersion, Script, TransactionInputSigner, Num};
|
||||
|
||||
pub trait SignatureChecker {
|
||||
fn check_signature(
|
|
@ -17,10 +17,10 @@ extern crate bitcrypto as crypto;
|
|||
extern crate chain;
|
||||
extern crate keys;
|
||||
extern crate primitives;
|
||||
extern crate script;
|
||||
extern crate serialization as ser;
|
||||
|
||||
pub mod net;
|
||||
pub mod script;
|
||||
|
||||
pub use rustc_serialize::hex;
|
||||
pub use primitives::{hash, bytes};
|
||||
|
|
Loading…
Reference in New Issue