From 0279d95b1dba0aa2e19960711faba784201b5e39 Mon Sep 17 00:00:00 2001 From: debris Date: Sat, 20 Aug 2016 18:25:41 +0200 Subject: [PATCH] removed compiler warnings --- src/keys/keypair.rs | 42 +++++++++++++++++++++++++++++++++------ src/keys/mod.rs | 3 ++- src/script/interpreter.rs | 12 ++++++++--- src/script/mod.rs | 1 + src/script/script.rs | 10 +++++----- 5 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/keys/keypair.rs b/src/keys/keypair.rs index 767a8e14..92462466 100644 --- a/src/keys/keypair.rs +++ b/src/keys/keypair.rs @@ -1,18 +1,15 @@ //! Bitcoin KeyPair use std::fmt; -use hex::ToHex; use rcrypto::sha2::Sha256; use rcrypto::ripemd160::Ripemd160; use rcrypto::digest::Digest; use secp256k1::key; use network::Network; -use keys::{Public, Error, SECP256K1, Address, Type, AddressHash, Private}; +use keys::{Public, Error, SECP256K1, Address, Type, AddressHash, Private, Message}; pub struct KeyPair { private: Private, - /// Uncompressed public key. 65 bytes - /// TODO: make it optionally compressed public: Public, } @@ -35,7 +32,6 @@ impl KeyPair { let context = &SECP256K1; let s: key::SecretKey = try!(key::SecretKey::from_slice(context, &private.secret)); let pub_key = try!(key::PublicKey::from_secret_key(context, &s)); - // TODO: take into account private field `compressed` let serialized = pub_key.serialize_vec(context, private.compressed); let public = if private.compressed { @@ -93,6 +89,26 @@ impl KeyPair { hash: self.address_hash(), } } + + pub fn is_compressed(&self) -> bool { + self.private.compressed + } + + pub fn sign(&self, _message: &Message) -> Result<(), Error> { + unimplemented!(); + } + + pub fn sign_compact(&self, _message: &Message) -> Result<(), Error> { + unimplemented!(); + } + + pub fn verify(&self, _message: &Message) -> Result { + unimplemented!(); + } + + pub fn recover_compat(&self, _signature: ()) -> Result { + unimplemented!(); + } } #[cfg(test)] @@ -117,12 +133,26 @@ mod tests { kp.address() == address.into() } + fn check_compressed(secret: &'static str, compressed: bool) -> bool { + let kp = KeyPair::from_private(secret.into()).unwrap(); + kp.is_compressed() == compressed + } + #[test] - fn test_generating_address() { + fn test_keypair_address() { assert!(check_addresses(SECRET_0, ADDRESS_0)); assert!(check_addresses(SECRET_1, ADDRESS_1)); assert!(check_addresses(SECRET_2, ADDRESS_2)); assert!(check_addresses(SECRET_3, ADDRESS_3)); assert!(check_addresses(SECRET_4, ADDRESS_4)); } + + #[test] + fn test_keypair_is_compressed() { + assert!(check_compressed(SECRET_0, false)); + assert!(check_compressed(SECRET_1, false)); + assert!(check_compressed(SECRET_2, false)); + assert!(check_compressed(SECRET_3, true)); + assert!(check_compressed(SECRET_4, true)); + } } diff --git a/src/keys/mod.rs b/src/keys/mod.rs index 1b6a4a34..9978a42b 100644 --- a/src/keys/mod.rs +++ b/src/keys/mod.rs @@ -23,9 +23,10 @@ pub use self::error::Error; pub use self::private::Private; pub use self::public::Public; -use hash::{H160, H256, H520}; +use hash::{H160, H256}; pub type AddressHash = H160; pub type Secret = H256; +pub type Message = H256; use secp256k1; lazy_static! { diff --git a/src/script/interpreter.rs b/src/script/interpreter.rs index cedac647..51a3d113 100644 --- a/src/script/interpreter.rs +++ b/src/script/interpreter.rs @@ -3,8 +3,8 @@ use super::{Script, Num, VerificationFlags}; #[derive(Debug, PartialEq, Clone, Copy)] pub enum SignatureVersion { - Base, - Witness_V0, + _Base, + _WitnessV0, } pub trait SignatureChecker { @@ -15,6 +15,12 @@ pub trait SignatureChecker { fn check_sequence(&self, sequence: Num); } -pub fn eval_script(stack: &mut Vec>, script: &Script, flags: &VerificationFlags, checker: &SignatureChecker, version: SignatureVersion) -> Result { +pub fn eval_script( + _stack: &mut Vec>, + _script: &Script, + _flags: &VerificationFlags, + _checker: &SignatureChecker, + _version: SignatureVersion +) -> Result { Ok(false) } diff --git a/src/script/mod.rs b/src/script/mod.rs index d3e490e3..6f45b09d 100644 --- a/src/script/mod.rs +++ b/src/script/mod.rs @@ -7,6 +7,7 @@ mod script; pub use self::error::Error; pub use self::flags::VerificationFlags; +pub use self::interpreter::eval_script; pub use self::opcode::Opcode; pub use self::num::Num; pub use self::script::Script; diff --git a/src/script/script.rs b/src/script/script.rs index 37f530b3..ae2b2ec7 100644 --- a/src/script/script.rs +++ b/src/script/script.rs @@ -3,20 +3,20 @@ use script::Opcode; /// Maximum number of bytes pushable to the stack -const MAX_SCRIPT_ELEMENT_SIZE: u32 = 520; +const _MAX_SCRIPT_ELEMENT_SIZE: u32 = 520; /// Maximum number of non-push operations per script -const MAX_OPS_PER_SCRIPT: u32 = 201; +const _MAX_OPS_PER_SCRIPT: u32 = 201; /// Maximum number of public keys per multisig -const MAX_PUBKEYS_PER_MULTISIG: u32 = 20; +const _MAX_PUBKEYS_PER_MULTISIG: u32 = 20; /// Maximum script length in bytes -const MAX_SCRIPT_SIZE: u32 = 10000; +const _MAX_SCRIPT_SIZE: u32 = 10000; /// Threshold for nLockTime: below this value it is interpreted as block number, /// otherwise as UNIX timestamp. -const LOCKTIME_THRESHOLD: u32 = 500000000; // Tue Nov 5 00:53:20 1985 UTC +const _LOCKTIME_THRESHOLD: u32 = 500000000; // Tue Nov 5 00:53:20 1985 UTC /// Serialized script, used inside transaction inputs and outputs. pub struct Script {