*** ALL TESTS PASS WITH RUSTC HEAD ***
There is still a lot of work to do modernizing the library, but the code compiles cleanly with all unit tests passing now. Probably not much can be done now until wizards-wallet is in better shape and the library is actually in use.
This commit is contained in:
parent
4b1b1c4a74
commit
adaf50a408
|
@ -2461,8 +2461,8 @@ impl Builder {
|
|||
/// dedicated opcodes to push some small integers.
|
||||
pub fn push_int(&mut self, data: i64) {
|
||||
// We can special-case -1, 1-16
|
||||
if data == -1 || (data >= 1 && data <=16) {
|
||||
self.0.push(data as u8 + opcodes::OP_TRUE as u8);
|
||||
if data == -1 || (data >= 1 && data <= 16) {
|
||||
self.0.push((data + opcodes::OP_TRUE as i64) as u8);
|
||||
}
|
||||
// We can also special-case zero
|
||||
else if data == 0 {
|
||||
|
|
|
@ -79,7 +79,7 @@ pub fn script_find_and_remove(haystack: &mut Vec<u8>, needle: &[u8]) -> usize {
|
|||
n_deleted += 1;
|
||||
// This is ugly but prevents infinite loop in case of overflow
|
||||
let overflow = top < needle.len();
|
||||
top -= needle.len();
|
||||
top = top.wrapping_sub(needle.len());
|
||||
if overflow { break; }
|
||||
} else {
|
||||
i += match opcodes::All::from_u8((*haystack)[i]).classify() {
|
||||
|
@ -91,7 +91,7 @@ pub fn script_find_and_remove(haystack: &mut Vec<u8>, needle: &[u8]) -> usize {
|
|||
};
|
||||
}
|
||||
}
|
||||
haystack.truncate(top + needle.len());
|
||||
haystack.truncate(top.wrapping_add(needle.len()));
|
||||
n_deleted
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use std::default::Default;
|
|||
use std::io::Cursor;
|
||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||
|
||||
use byteorder::{BigEndian, ByteOrder, ReadBytesExt};
|
||||
use byteorder::{BigEndian, ByteOrder, ReadBytesExt, WriteBytesExt};
|
||||
use crypto::digest::Digest;
|
||||
use crypto::hmac::Hmac;
|
||||
use crypto::mac::Mac;
|
||||
|
@ -160,7 +160,7 @@ impl ExtendedPrivKey {
|
|||
pub fn ckd_priv(&self, secp: &Secp256k1, i: ChildNumber) -> Result<ExtendedPrivKey, Error> {
|
||||
let mut result = [0; 64];
|
||||
let mut hmac = Hmac::new(Sha512::new(), &self.chain_code[..]);
|
||||
let mut be_n = [0; 32];
|
||||
let mut be_n = [0; 4];
|
||||
match i {
|
||||
ChildNumber::Normal(n) => {
|
||||
if n >= (1 << 31) { return Err(Error::InvalidChildNumber(i)) }
|
||||
|
@ -241,7 +241,7 @@ impl ExtendedPubKey {
|
|||
ChildNumber::Normal(n) => {
|
||||
let mut hmac = Hmac::new(Sha512::new(), &self.chain_code[..]);
|
||||
hmac.input(&self.public_key[..]);
|
||||
let mut be_n = [0; 32];
|
||||
let mut be_n = [0; 4];
|
||||
BigEndian::write_u32(&mut be_n, n);
|
||||
hmac.input(&be_n);
|
||||
|
||||
|
@ -295,16 +295,14 @@ impl ToBase58 for ExtendedPrivKey {
|
|||
}.iter().cloned());
|
||||
ret.push(self.depth as u8);
|
||||
ret.extend(self.parent_fingerprint[..].iter().cloned());
|
||||
let mut be_n = [0; 32];
|
||||
match self.child_number {
|
||||
ChildNumber::Hardened(n) => {
|
||||
BigEndian::write_u32(&mut be_n, n + (1 << 31));
|
||||
ret.write_u32::<BigEndian>(n + (1 << 31)).unwrap();
|
||||
}
|
||||
ChildNumber::Normal(n) => {
|
||||
BigEndian::write_u32(&mut be_n, n);
|
||||
ret.write_u32::<BigEndian>(n).unwrap();
|
||||
}
|
||||
}
|
||||
ret.extend(be_n.iter().cloned());
|
||||
ret.extend(self.chain_code[..].iter().cloned());
|
||||
ret.push(0);
|
||||
ret.extend(self.secret_key[..].iter().cloned());
|
||||
|
@ -351,7 +349,7 @@ impl ToBase58 for ExtendedPubKey {
|
|||
}.iter().cloned());
|
||||
ret.push(self.depth as u8);
|
||||
ret.extend(self.parent_fingerprint[..].iter().cloned());
|
||||
let mut be_n = [0; 32];
|
||||
let mut be_n = [0; 4];
|
||||
match self.child_number {
|
||||
ChildNumber::Hardened(n) => {
|
||||
BigEndian::write_u32(&mut be_n, n + (1 << 31));
|
||||
|
@ -449,7 +447,7 @@ mod tests {
|
|||
// m
|
||||
test_path(&secp, Bitcoin, &seed, &[],
|
||||
"xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi",
|
||||
"xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8");
|
||||
"xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8");
|
||||
|
||||
// m/0h
|
||||
test_path(&secp, Bitcoin, &seed, &[Hardened(0)],
|
||||
|
|
Loading…
Reference in New Issue