removed compiler warnings
This commit is contained in:
parent
c86ec93b60
commit
0279d95b1d
|
@ -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<bool, Error> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
pub fn recover_compat(&self, _signature: ()) -> Result<Public, Error> {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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! {
|
||||
|
|
|
@ -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<Vec<u8>>, script: &Script, flags: &VerificationFlags, checker: &SignatureChecker, version: SignatureVersion) -> Result<bool, ()> {
|
||||
pub fn eval_script(
|
||||
_stack: &mut Vec<Vec<u8>>,
|
||||
_script: &Script,
|
||||
_flags: &VerificationFlags,
|
||||
_checker: &SignatureChecker,
|
||||
_version: SignatureVersion
|
||||
) -> Result<bool, ()> {
|
||||
Ok(false)
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue