Merge pull request #351 from ethcore/bigint-split
Use shared crate for big integers
This commit is contained in:
commit
ed9b584d7e
|
@ -86,6 +86,17 @@ dependencies = [
|
|||
"verification 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bigint"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-vec"
|
||||
version = "0.4.3"
|
||||
|
@ -699,6 +710,7 @@ dependencies = [
|
|||
name = "primitives"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bigint 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1230,6 +1242,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum arrayvec 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d89f1b0e242270b5b797778af0c8d182a1a2ccac5d8d6fadf414223cc0fab096"
|
||||
"checksum aster 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)" = "258989846dd255a1e0eeef92d425d345477c9999433cecc9f0879f4549d5e5c9"
|
||||
"checksum base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83"
|
||||
"checksum bigint 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4987c855cbe118271721d21f16cacdfedfe7dbeb7ea5970e4ae33db06602e3f2"
|
||||
"checksum bit-vec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5b97c2c8e8bbb4251754f559df8af22fb264853c7d009084a576cdf12565089d"
|
||||
"checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3"
|
||||
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
|
||||
|
|
|
@ -22,7 +22,7 @@ pub trait RepresentH256 {
|
|||
}
|
||||
|
||||
pub use rustc_serialize::hex;
|
||||
pub use primitives::{hash, bytes, uint, compact};
|
||||
pub use primitives::{hash, bytes, bigint, compact};
|
||||
|
||||
pub use block::Block;
|
||||
pub use block_header::BlockHeader;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use byteorder::{WriteBytesExt, LittleEndian};
|
||||
use primitives::bytes::Bytes;
|
||||
use primitives::hash::H256;
|
||||
use primitives::uint::U256;
|
||||
use primitives::bigint::{U256, Uint};
|
||||
use primitives::compact::Compact;
|
||||
use chain::{merkle_root, Transaction, TransactionInput, TransactionOutput};
|
||||
use crypto::dhash256;
|
||||
|
@ -176,7 +176,7 @@ impl CoinbaseTransactionBuilder for P2shCoinbaseTransactionBuilder {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use primitives::uint::U256;
|
||||
use primitives::bigint::{U256, Uint};
|
||||
use block_assembler::BlockTemplate;
|
||||
use super::{find_solution, P2shCoinbaseTransactionBuilder};
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ build = "build.rs"
|
|||
heapsize = "0.3"
|
||||
rustc-serialize = "0.3"
|
||||
byteorder = "0.5"
|
||||
bigint = "1.0"
|
||||
|
||||
[build-dependencies]
|
||||
rustc_version = "0.1"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Compact representation of `U256`
|
||||
|
||||
use uint::U256;
|
||||
use bigint::{U256, Uint};
|
||||
|
||||
/// Compact representation of `U256`
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
|
@ -95,7 +95,7 @@ impl Compact {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use uint::U256;
|
||||
use bigint::{U256, Uint};
|
||||
use super::Compact;
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
extern crate byteorder;
|
||||
#[macro_use] extern crate heapsize;
|
||||
extern crate rustc_serialize;
|
||||
pub extern crate bigint;
|
||||
|
||||
pub mod bytes;
|
||||
pub mod compact;
|
||||
pub mod hash;
|
||||
pub mod uint;
|
||||
|
||||
pub use rustc_serialize::hex;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -524,7 +524,7 @@ pub mod tests {
|
|||
"id": 1
|
||||
}"#)).unwrap();
|
||||
|
||||
assert_eq!(&sample, r#"{"jsonrpc":"2.0","result":{"bits":486604799,"chainwork":"","confirmations":1,"difficulty":1.0,"hash":"000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd","height":2,"mediantime":null,"merkleroot":"9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5","nextblockhash":null,"nonce":1639830024,"previousblockhash":"00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048","size":215,"strippedsize":215,"time":1231469744,"tx":["9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5"],"version":1,"versionHex":"1","weight":215},"id":1}"#);
|
||||
assert_eq!(&sample, r#"{"jsonrpc":"2.0","result":{"bits":486604799,"chainwork":"0","confirmations":1,"difficulty":1.0,"hash":"000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd","height":2,"mediantime":null,"merkleroot":"9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5","nextblockhash":null,"nonce":1639830024,"previousblockhash":"00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048","size":215,"strippedsize":215,"time":1231469744,"tx":["9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5"],"version":1,"versionHex":"1","weight":215},"id":1}"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -76,7 +76,7 @@ mod tests {
|
|||
#[test]
|
||||
fn verbose_block_serialize() {
|
||||
let block = VerboseBlock::default();
|
||||
assert_eq!(serde_json::to_string(&block).unwrap(), r#"{"hash":"0000000000000000000000000000000000000000000000000000000000000000","confirmations":0,"size":0,"strippedsize":0,"weight":0,"height":null,"version":0,"versionHex":"","merkleroot":"0000000000000000000000000000000000000000000000000000000000000000","tx":[],"time":0,"mediantime":null,"nonce":0,"bits":0,"difficulty":0.0,"chainwork":"","previousblockhash":null,"nextblockhash":null}"#);
|
||||
assert_eq!(serde_json::to_string(&block).unwrap(), r#"{"hash":"0000000000000000000000000000000000000000000000000000000000000000","confirmations":0,"size":0,"strippedsize":0,"weight":0,"height":null,"version":0,"versionHex":"","merkleroot":"0000000000000000000000000000000000000000000000000000000000000000","tx":[],"time":0,"mediantime":null,"nonce":0,"bits":0,"difficulty":0.0,"chainwork":"0","previousblockhash":null,"nextblockhash":null}"#);
|
||||
|
||||
let block = VerboseBlock {
|
||||
hash: H256::from(1),
|
||||
|
@ -143,6 +143,6 @@ mod tests {
|
|||
fn get_block_response_verbose_serialize() {
|
||||
let block = VerboseBlock::default();
|
||||
let verbose_response = GetBlockResponse::Verbose(block);
|
||||
assert_eq!(serde_json::to_string(&verbose_response).unwrap(), r#"{"hash":"0000000000000000000000000000000000000000000000000000000000000000","confirmations":0,"size":0,"strippedsize":0,"weight":0,"height":null,"version":0,"versionHex":"","merkleroot":"0000000000000000000000000000000000000000000000000000000000000000","tx":[],"time":0,"mediantime":null,"nonce":0,"bits":0,"difficulty":0.0,"chainwork":"","previousblockhash":null,"nextblockhash":null}"#);
|
||||
assert_eq!(serde_json::to_string(&verbose_response).unwrap(), r#"{"hash":"0000000000000000000000000000000000000000000000000000000000000000","confirmations":0,"size":0,"strippedsize":0,"weight":0,"height":null,"version":0,"versionHex":"","merkleroot":"0000000000000000000000000000000000000000000000000000000000000000","tx":[],"time":0,"mediantime":null,"nonce":0,"bits":0,"difficulty":0.0,"chainwork":"0","previousblockhash":null,"nextblockhash":null}"#);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::str::FromStr;
|
||||
use serde;
|
||||
use primitives::uint::U256 as GlobalU256;
|
||||
use primitives::bigint::{U256 as GlobalU256, Uint};
|
||||
|
||||
macro_rules! impl_uint {
|
||||
($name: ident, $other: ident, $size: expr) => {
|
||||
|
@ -32,7 +32,7 @@ macro_rules! impl_uint {
|
|||
|
||||
impl serde::Serialize for $name {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: serde::Serializer {
|
||||
let as_hex = format!("{:x}", self.0);
|
||||
let as_hex = format!("{}", self.0.to_hex());
|
||||
serializer.serialize_str(&as_hex)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ mod accept_transaction;
|
|||
// backwards compatibility
|
||||
mod chain_verifier;
|
||||
|
||||
pub use primitives::{uint, hash, compact};
|
||||
pub use primitives::{bigint, hash, compact};
|
||||
|
||||
pub use canon::{CanonBlock, CanonHeader, CanonTransaction};
|
||||
pub use accept_block::BlockAcceptor;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::cmp;
|
||||
use primitives::compact::Compact;
|
||||
use primitives::hash::H256;
|
||||
use primitives::uint::U256;
|
||||
use primitives::bigint::U256;
|
||||
use network::Magic;
|
||||
use db::{BlockHeaderProvider, BlockRef};
|
||||
|
||||
|
|
Loading…
Reference in New Issue