Merge branch 'master' into delete-accounts
This commit is contained in:
15
ethcore/hash-fetch/Cargo.toml
Normal file
15
ethcore/hash-fetch/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
description = "Fetching hash-addressed content."
|
||||
homepage = "https://ethcore.io"
|
||||
license = "GPL-3.0"
|
||||
name = "ethcore-hash-fetch"
|
||||
version = "1.5.0"
|
||||
authors = ["Ethcore <admin@ethcore.io>"]
|
||||
|
||||
[dependencies]
|
||||
log = "0.3"
|
||||
rustc-serialize = "0.3"
|
||||
ethabi = "0.2.2"
|
||||
mime_guess = "1.6.1"
|
||||
fetch = { path = "../../util/fetch" }
|
||||
ethcore-util = { path = "../../util" }
|
||||
21
ethcore/hash-fetch/res/registrar.json
Normal file
21
ethcore/hash-fetch/res/registrar.json
Normal file
@@ -0,0 +1,21 @@
|
||||
[
|
||||
{"constant":false,"inputs":[{"name":"_new","type":"address"}],"name":"setOwner","outputs":[],"type":"function"},
|
||||
{"constant":false,"inputs":[{"name":"_name","type":"string"}],"name":"confirmReverse","outputs":[{"name":"success","type":"bool"}],"type":"function"},
|
||||
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"reserve","outputs":[{"name":"success","type":"bool"}],"type":"function"},
|
||||
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_key","type":"string"},{"name":"_value","type":"bytes32"}],"name":"set","outputs":[{"name":"success","type":"bool"}],"type":"function"},
|
||||
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"drop","outputs":[{"name":"success","type":"bool"}],"type":"function"},
|
||||
{"constant":true,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_key","type":"string"}],"name":"getAddress","outputs":[{"name":"","type":"address"}],"type":"function"},
|
||||
{"constant":false,"inputs":[{"name":"_amount","type":"uint256"}],"name":"setFee","outputs":[],"type":"function"},
|
||||
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_to","type":"address"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"type":"function"},
|
||||
{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"type":"function"},
|
||||
{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"reserved","outputs":[{"name":"reserved","type":"bool"}],"type":"function"},
|
||||
{"constant":false,"inputs":[],"name":"drain","outputs":[],"type":"function"},
|
||||
{"constant":false,"inputs":[{"name":"_name","type":"string"},{"name":"_who","type":"address"}],"name":"proposeReverse","outputs":[{"name":"success","type":"bool"}],"type":"function"},
|
||||
{"constant":true,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_key","type":"string"}],"name":"getUint","outputs":[{"name":"","type":"uint256"}],"type":"function"},
|
||||
{"constant":true,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_key","type":"string"}],"name":"get","outputs":[{"name":"","type":"bytes32"}],"type":"function"},
|
||||
{"constant":true,"inputs":[],"name":"fee","outputs":[{"name":"","type":"uint256"}],"type":"function"},
|
||||
{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"reverse","outputs":[{"name":"","type":"string"}],"type":"function"},
|
||||
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_key","type":"string"},{"name":"_value","type":"uint256"}],"name":"setUint","outputs":[{"name":"success","type":"bool"}],"type":"function"},
|
||||
{"constant":false,"inputs":[],"name":"removeReverse","outputs":[],"type":"function"},
|
||||
{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_key","type":"string"},{"name":"_value","type":"address"}],"name":"setAddress","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"amount","type":"uint256"}],"name":"Drained","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"amount","type":"uint256"}],"name":"FeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"},{"indexed":true,"name":"owner","type":"address"}],"name":"Reserved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"},{"indexed":true,"name":"oldOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"Transferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"},{"indexed":true,"name":"owner","type":"address"}],"name":"Dropped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"},{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"key","type":"string"}],"name":"DataChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"string"},{"indexed":true,"name":"reverse","type":"address"}],"name":"ReverseProposed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"string"},{"indexed":true,"name":"reverse","type":"address"}],"name":"ReverseConfirmed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"string"},{"indexed":true,"name":"reverse","type":"address"}],"name":"ReverseRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"old","type":"address"},{"indexed":true,"name":"current","type":"address"}],"name":"NewOwner","type":"event"}
|
||||
]
|
||||
6
ethcore/hash-fetch/res/urlhint.json
Normal file
6
ethcore/hash-fetch/res/urlhint.json
Normal file
@@ -0,0 +1,6 @@
|
||||
[
|
||||
{"constant":false,"inputs":[{"name":"_content","type":"bytes32"},{"name":"_url","type":"string"}],"name":"hintURL","outputs":[],"type":"function"},
|
||||
{"constant":false,"inputs":[{"name":"_content","type":"bytes32"},{"name":"_accountSlashRepo","type":"string"},{"name":"_commit","type":"bytes20"}],"name":"hint","outputs":[],"type":"function"},
|
||||
{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"entries","outputs":[{"name":"accountSlashRepo","type":"string"},{"name":"commit","type":"bytes20"},{"name":"owner","type":"address"}],"type":"function"},
|
||||
{"constant":false,"inputs":[{"name":"_content","type":"bytes32"}],"name":"unhint","outputs":[],"type":"function"}
|
||||
]
|
||||
114
ethcore/hash-fetch/src/client.rs
Normal file
114
ethcore/hash-fetch/src/client.rs
Normal file
@@ -0,0 +1,114 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Hash-addressed content resolver & fetcher.
|
||||
|
||||
use std::{io, fs};
|
||||
use std::sync::Arc;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use util::{Mutex, H256, sha3};
|
||||
use fetch::{Fetch, FetchError, Client as FetchClient};
|
||||
|
||||
use urlhint::{ContractClient, URLHintContract, URLHint, URLHintResult};
|
||||
|
||||
/// API for fetching by hash.
|
||||
pub trait HashFetch {
|
||||
/// Fetch hash-addressed content.
|
||||
/// Parameters:
|
||||
/// 1. `hash` - content hash
|
||||
/// 2. `on_done` - callback function invoked when the content is ready (or there was error during fetch)
|
||||
///
|
||||
/// This function may fail immediately when fetch cannot be initialized or content cannot be resolved.
|
||||
fn fetch(&self, hash: H256, on_done: Box<Fn(Result<PathBuf, Error>) + Send>) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
/// Hash-fetching error.
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// Hash could not be resolved to a valid content address.
|
||||
NoResolution,
|
||||
/// Downloaded content hash does not match.
|
||||
HashMismatch { expected: H256, got: H256 },
|
||||
/// IO Error while validating hash.
|
||||
IO(io::Error),
|
||||
/// Error during fetch.
|
||||
Fetch(FetchError),
|
||||
}
|
||||
|
||||
impl From<FetchError> for Error {
|
||||
fn from(error: FetchError) -> Self {
|
||||
Error::Fetch(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(error: io::Error) -> Self {
|
||||
Error::IO(error)
|
||||
}
|
||||
}
|
||||
|
||||
/// Default Hash-fetching client using on-chain contract to resolve hashes to URLs.
|
||||
pub struct Client {
|
||||
contract: URLHintContract,
|
||||
fetch: Mutex<FetchClient>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
/// Creates new instance of the `Client` given on-chain contract client.
|
||||
pub fn new(contract: Arc<ContractClient>) -> Self {
|
||||
Client {
|
||||
contract: URLHintContract::new(contract),
|
||||
fetch: Mutex::new(FetchClient::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HashFetch for Client {
|
||||
fn fetch(&self, hash: H256, on_done: Box<Fn(Result<PathBuf, Error>) + Send>) -> Result<(), Error> {
|
||||
debug!(target: "dapps", "Fetching: {:?}", hash);
|
||||
|
||||
let url = try!(
|
||||
self.contract.resolve(hash.to_vec()).map(|content| match content {
|
||||
URLHintResult::Dapp(dapp) => {
|
||||
dapp.url()
|
||||
},
|
||||
URLHintResult::Content(content) => {
|
||||
content.url
|
||||
},
|
||||
}).ok_or_else(|| Error::NoResolution)
|
||||
);
|
||||
|
||||
debug!(target: "dapps", "Resolved {:?} to {:?}. Fetching...", hash, url);
|
||||
|
||||
self.fetch.lock().request_async(&url, Default::default(), Box::new(move |result| {
|
||||
fn validate_hash(hash: H256, result: Result<PathBuf, FetchError>) -> Result<PathBuf, Error> {
|
||||
let path = try!(result);
|
||||
let mut file_reader = io::BufReader::new(try!(fs::File::open(&path)));
|
||||
let content_hash = try!(sha3(&mut file_reader));
|
||||
|
||||
if content_hash != hash {
|
||||
Err(Error::HashMismatch{ got: content_hash, expected: hash })
|
||||
} else {
|
||||
Ok(path)
|
||||
}
|
||||
}
|
||||
|
||||
debug!(target: "dapps", "Content fetched, validating hash ({:?})", hash);
|
||||
on_done(validate_hash(hash, result))
|
||||
})).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
33
ethcore/hash-fetch/src/lib.rs
Normal file
33
ethcore/hash-fetch/src/lib.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Hash-addressed content resolver & fetcher.
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate rustc_serialize;
|
||||
extern crate mime_guess;
|
||||
extern crate ethabi;
|
||||
extern crate ethcore_util as util;
|
||||
extern crate fetch;
|
||||
|
||||
mod client;
|
||||
|
||||
pub mod urlhint;
|
||||
|
||||
pub use client::{HashFetch, Client};
|
||||
409
ethcore/hash-fetch/src/urlhint.rs
Normal file
409
ethcore/hash-fetch/src/urlhint.rs
Normal file
@@ -0,0 +1,409 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! URLHint Contract
|
||||
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use rustc_serialize::hex::ToHex;
|
||||
use mime_guess;
|
||||
|
||||
use ethabi::{Interface, Contract, Token};
|
||||
use util::{Address, Bytes, Hashable};
|
||||
|
||||
const COMMIT_LEN: usize = 20;
|
||||
|
||||
/// RAW Contract interface.
|
||||
/// Should execute transaction using current blockchain state.
|
||||
pub trait ContractClient: Send + Sync {
|
||||
/// Get registrar address
|
||||
fn registrar(&self) -> Result<Address, String>;
|
||||
/// Call Contract
|
||||
fn call(&self, address: Address, data: Bytes) -> Result<Bytes, String>;
|
||||
}
|
||||
|
||||
/// Github-hosted dapp.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct GithubApp {
|
||||
/// Github Account
|
||||
pub account: String,
|
||||
/// Github Repository
|
||||
pub repo: String,
|
||||
/// Commit on Github
|
||||
pub commit: [u8;COMMIT_LEN],
|
||||
/// Dapp owner address
|
||||
pub owner: Address,
|
||||
}
|
||||
|
||||
impl GithubApp {
|
||||
/// Returns URL of this Github-hosted dapp package.
|
||||
pub fn url(&self) -> String {
|
||||
// Since https fetcher doesn't support redirections we use direct link
|
||||
// format!("https://github.com/{}/{}/archive/{}.zip", self.account, self.repo, self.commit.to_hex())
|
||||
format!("https://codeload.github.com/{}/{}/zip/{}", self.account, self.repo, self.commit.to_hex())
|
||||
}
|
||||
|
||||
fn commit(bytes: &[u8]) -> Option<[u8;COMMIT_LEN]> {
|
||||
if bytes.len() < COMMIT_LEN {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut commit = [0; COMMIT_LEN];
|
||||
for i in 0..COMMIT_LEN {
|
||||
commit[i] = bytes[i];
|
||||
}
|
||||
|
||||
Some(commit)
|
||||
}
|
||||
}
|
||||
|
||||
/// Hash-Addressed Content
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Content {
|
||||
/// URL of the content
|
||||
pub url: String,
|
||||
/// MIME type of the content
|
||||
pub mime: String,
|
||||
/// Content owner address
|
||||
pub owner: Address,
|
||||
}
|
||||
|
||||
/// Result of resolving id to URL
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum URLHintResult {
|
||||
/// Dapp
|
||||
Dapp(GithubApp),
|
||||
/// Content
|
||||
Content(Content),
|
||||
}
|
||||
|
||||
/// URLHint Contract interface
|
||||
pub trait URLHint {
|
||||
/// Resolves given id to registrar entry.
|
||||
fn resolve(&self, id: Bytes) -> Option<URLHintResult>;
|
||||
}
|
||||
|
||||
/// `URLHintContract` API
|
||||
pub struct URLHintContract {
|
||||
urlhint: Contract,
|
||||
registrar: Contract,
|
||||
client: Arc<ContractClient>,
|
||||
}
|
||||
|
||||
impl URLHintContract {
|
||||
/// Creates new `URLHintContract`
|
||||
pub fn new(client: Arc<ContractClient>) -> Self {
|
||||
let urlhint = Interface::load(include_bytes!("../res/urlhint.json")).expect("urlhint.json is valid ABI");
|
||||
let registrar = Interface::load(include_bytes!("../res/registrar.json")).expect("registrar.json is valid ABI");
|
||||
|
||||
URLHintContract {
|
||||
urlhint: Contract::new(urlhint),
|
||||
registrar: Contract::new(registrar),
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
fn urlhint_address(&self) -> Option<Address> {
|
||||
let res = || {
|
||||
let get_address = try!(self.registrar.function("getAddress".into()).map_err(as_string));
|
||||
let params = try!(get_address.encode_call(
|
||||
vec![Token::FixedBytes((*"githubhint".sha3()).to_vec()), Token::String("A".into())]
|
||||
).map_err(as_string));
|
||||
let output = try!(self.client.call(try!(self.client.registrar()), params));
|
||||
let result = try!(get_address.decode_output(output).map_err(as_string));
|
||||
|
||||
match result.get(0) {
|
||||
Some(&Token::Address(address)) if address != *Address::default() => Ok(address.into()),
|
||||
Some(&Token::Address(_)) => Err(format!("Contract not found.")),
|
||||
e => Err(format!("Invalid result: {:?}", e)),
|
||||
}
|
||||
};
|
||||
|
||||
match res() {
|
||||
Ok(res) => Some(res),
|
||||
Err(e) => {
|
||||
warn!(target: "dapps", "Error while calling registrar: {:?}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_urlhint_call(&self, id: Bytes) -> Option<Bytes> {
|
||||
let call = self.urlhint
|
||||
.function("entries".into())
|
||||
.and_then(|f| f.encode_call(vec![Token::FixedBytes(id)]));
|
||||
|
||||
match call {
|
||||
Ok(res) => {
|
||||
Some(res)
|
||||
},
|
||||
Err(e) => {
|
||||
warn!(target: "dapps", "Error while encoding urlhint call: {:?}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn decode_urlhint_output(&self, output: Bytes) -> Option<URLHintResult> {
|
||||
trace!(target: "dapps", "Output: {:?}", output.to_hex());
|
||||
let output = self.urlhint
|
||||
.function("entries".into())
|
||||
.and_then(|f| f.decode_output(output));
|
||||
|
||||
if let Ok(vec) = output {
|
||||
if vec.len() != 3 {
|
||||
warn!(target: "dapps", "Invalid contract output: {:?}", vec);
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut it = vec.into_iter();
|
||||
let account_slash_repo = it.next().expect("element 0 of 3-len vector known to exist; qed");
|
||||
let commit = it.next().expect("element 1 of 3-len vector known to exist; qed");
|
||||
let owner = it.next().expect("element 2 of 3-len vector known to exist qed");
|
||||
|
||||
match (account_slash_repo, commit, owner) {
|
||||
(Token::String(account_slash_repo), Token::FixedBytes(commit), Token::Address(owner)) => {
|
||||
let owner = owner.into();
|
||||
if owner == Address::default() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let commit = GithubApp::commit(&commit);
|
||||
if commit == Some(Default::default()) {
|
||||
let mime = guess_mime_type(&account_slash_repo).unwrap_or("application/octet-stream".into());
|
||||
return Some(URLHintResult::Content(Content {
|
||||
url: account_slash_repo,
|
||||
mime: mime,
|
||||
owner: owner,
|
||||
}));
|
||||
}
|
||||
|
||||
let (account, repo) = {
|
||||
let mut it = account_slash_repo.split('/');
|
||||
match (it.next(), it.next()) {
|
||||
(Some(account), Some(repo)) => (account.into(), repo.into()),
|
||||
_ => return None,
|
||||
}
|
||||
};
|
||||
|
||||
commit.map(|commit| URLHintResult::Dapp(GithubApp {
|
||||
account: account,
|
||||
repo: repo,
|
||||
commit: commit,
|
||||
owner: owner,
|
||||
}))
|
||||
},
|
||||
e => {
|
||||
warn!(target: "dapps", "Invalid contract output parameters: {:?}", e);
|
||||
None
|
||||
},
|
||||
}
|
||||
} else {
|
||||
warn!(target: "dapps", "Invalid contract output: {:?}", output);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl URLHint for URLHintContract {
|
||||
fn resolve(&self, id: Bytes) -> Option<URLHintResult> {
|
||||
self.urlhint_address().and_then(|address| {
|
||||
// Prepare contract call
|
||||
self.encode_urlhint_call(id)
|
||||
.and_then(|data| {
|
||||
let call = self.client.call(address, data);
|
||||
if let Err(ref e) = call {
|
||||
warn!(target: "dapps", "Error while calling urlhint: {:?}", e);
|
||||
}
|
||||
call.ok()
|
||||
})
|
||||
.and_then(|output| self.decode_urlhint_output(output))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn guess_mime_type(url: &str) -> Option<String> {
|
||||
const CONTENT_TYPE: &'static str = "content-type=";
|
||||
|
||||
let mut it = url.split('#');
|
||||
// skip url
|
||||
let url = it.next();
|
||||
// get meta headers
|
||||
let metas = it.next();
|
||||
if let Some(metas) = metas {
|
||||
for meta in metas.split('&') {
|
||||
let meta = meta.to_lowercase();
|
||||
if meta.starts_with(CONTENT_TYPE) {
|
||||
return Some(meta[CONTENT_TYPE.len()..].to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
url.and_then(|url| {
|
||||
url.split('.').last()
|
||||
}).and_then(|extension| {
|
||||
mime_guess::get_mime_type_str(extension).map(Into::into)
|
||||
})
|
||||
}
|
||||
|
||||
fn as_string<T: fmt::Debug>(e: T) -> String {
|
||||
format!("{:?}", e)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use std::str::FromStr;
|
||||
use rustc_serialize::hex::FromHex;
|
||||
|
||||
use super::*;
|
||||
use super::guess_mime_type;
|
||||
use util::{Bytes, Address, Mutex, ToPretty};
|
||||
|
||||
struct FakeRegistrar {
|
||||
pub calls: Arc<Mutex<Vec<(String, String)>>>,
|
||||
pub responses: Mutex<Vec<Result<Bytes, String>>>,
|
||||
}
|
||||
|
||||
const REGISTRAR: &'static str = "8e4e9b13d4b45cb0befc93c3061b1408f67316b2";
|
||||
const URLHINT: &'static str = "deadbeefcafe0000000000000000000000000000";
|
||||
|
||||
impl FakeRegistrar {
|
||||
fn new() -> Self {
|
||||
FakeRegistrar {
|
||||
calls: Arc::new(Mutex::new(Vec::new())),
|
||||
responses: Mutex::new(
|
||||
vec![
|
||||
Ok(format!("000000000000000000000000{}", URLHINT).from_hex().unwrap()),
|
||||
Ok(Vec::new())
|
||||
]
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ContractClient for FakeRegistrar {
|
||||
|
||||
fn registrar(&self) -> Result<Address, String> {
|
||||
Ok(REGISTRAR.parse().unwrap())
|
||||
}
|
||||
|
||||
fn call(&self, address: Address, data: Bytes) -> Result<Bytes, String> {
|
||||
self.calls.lock().push((address.to_hex(), data.to_hex()));
|
||||
self.responses.lock().remove(0)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_call_registrar_and_urlhint_contracts() {
|
||||
// given
|
||||
let registrar = FakeRegistrar::new();
|
||||
let calls = registrar.calls.clone();
|
||||
let urlhint = URLHintContract::new(Arc::new(registrar));
|
||||
|
||||
// when
|
||||
let res = urlhint.resolve("test".bytes().collect());
|
||||
let calls = calls.lock();
|
||||
let call0 = calls.get(0).expect("Registrar resolve called");
|
||||
let call1 = calls.get(1).expect("URLHint Resolve called");
|
||||
|
||||
// then
|
||||
assert!(res.is_none());
|
||||
assert_eq!(call0.0, REGISTRAR);
|
||||
assert_eq!(call0.1,
|
||||
"6795dbcd058740ee9a5a3fb9f1cfa10752baec87e09cc45cd7027fd54708271aca300c75000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000014100000000000000000000000000000000000000000000000000000000000000".to_owned()
|
||||
);
|
||||
assert_eq!(call1.0, URLHINT);
|
||||
assert_eq!(call1.1,
|
||||
"267b69227465737400000000000000000000000000000000000000000000000000000000".to_owned()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_decode_urlhint_output() {
|
||||
// given
|
||||
let mut registrar = FakeRegistrar::new();
|
||||
registrar.responses = Mutex::new(vec![
|
||||
Ok(format!("000000000000000000000000{}", URLHINT).from_hex().unwrap()),
|
||||
Ok("0000000000000000000000000000000000000000000000000000000000000060ec4c1fe06c808fe3739858c347109b1f5f1ed4b5000000000000000000000000000000000000000000000000deadcafebeefbeefcafedeaddeedfeedffffffff0000000000000000000000000000000000000000000000000000000000000011657468636f72652f64616f2e636c61696d000000000000000000000000000000".from_hex().unwrap()),
|
||||
]);
|
||||
let urlhint = URLHintContract::new(Arc::new(registrar));
|
||||
|
||||
// when
|
||||
let res = urlhint.resolve("test".bytes().collect());
|
||||
|
||||
// then
|
||||
assert_eq!(res, Some(URLHintResult::Dapp(GithubApp {
|
||||
account: "ethcore".into(),
|
||||
repo: "dao.claim".into(),
|
||||
commit: GithubApp::commit(&"ec4c1fe06c808fe3739858c347109b1f5f1ed4b5".from_hex().unwrap()).unwrap(),
|
||||
owner: Address::from_str("deadcafebeefbeefcafedeaddeedfeedffffffff").unwrap(),
|
||||
})))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_decode_urlhint_content_output() {
|
||||
// given
|
||||
let mut registrar = FakeRegistrar::new();
|
||||
registrar.responses = Mutex::new(vec![
|
||||
Ok(format!("000000000000000000000000{}", URLHINT).from_hex().unwrap()),
|
||||
Ok("00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000deadcafebeefbeefcafedeaddeedfeedffffffff000000000000000000000000000000000000000000000000000000000000003d68747470733a2f2f657468636f72652e696f2f6173736574732f696d616765732f657468636f72652d626c61636b2d686f72697a6f6e74616c2e706e67000000".from_hex().unwrap()),
|
||||
]);
|
||||
let urlhint = URLHintContract::new(Arc::new(registrar));
|
||||
|
||||
// when
|
||||
let res = urlhint.resolve("test".bytes().collect());
|
||||
|
||||
// then
|
||||
assert_eq!(res, Some(URLHintResult::Content(Content {
|
||||
url: "https://ethcore.io/assets/images/ethcore-black-horizontal.png".into(),
|
||||
mime: "image/png".into(),
|
||||
owner: Address::from_str("deadcafebeefbeefcafedeaddeedfeedffffffff").unwrap(),
|
||||
})))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_return_valid_url() {
|
||||
// given
|
||||
let app = GithubApp {
|
||||
account: "test".into(),
|
||||
repo: "xyz".into(),
|
||||
commit: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
|
||||
owner: Address::default(),
|
||||
};
|
||||
|
||||
// when
|
||||
let url = app.url();
|
||||
|
||||
// then
|
||||
assert_eq!(url, "https://codeload.github.com/test/xyz/zip/000102030405060708090a0b0c0d0e0f10111213".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_guess_mime_type_from_url() {
|
||||
let url1 = "https://ethcore.io/parity";
|
||||
let url2 = "https://ethcore.io/parity#content-type=image/png";
|
||||
let url3 = "https://ethcore.io/parity#something&content-type=image/png";
|
||||
let url4 = "https://ethcore.io/parity.png#content-type=image/jpeg";
|
||||
let url5 = "https://ethcore.io/parity.png";
|
||||
|
||||
|
||||
assert_eq!(guess_mime_type(url1), None);
|
||||
assert_eq!(guess_mime_type(url2), Some("image/png".into()));
|
||||
assert_eq!(guess_mime_type(url3), Some("image/png".into()));
|
||||
assert_eq!(guess_mime_type(url4), Some("image/jpeg".into()));
|
||||
assert_eq!(guess_mime_type(url5), Some("image/png".into()));
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@
|
||||
"genesis": {
|
||||
"seal": {
|
||||
"generic": {
|
||||
"fields": 1,
|
||||
"rlp": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"
|
||||
"fields": 2,
|
||||
"rlp": "0x200"
|
||||
}
|
||||
},
|
||||
"difficulty": "0x20000",
|
||||
|
||||
304
ethcore/res/ethereum/ropsten.json
Normal file
304
ethcore/res/ethereum/ropsten.json
Normal file
@@ -0,0 +1,304 @@
|
||||
{
|
||||
"name": "Ropsten",
|
||||
"engine": {
|
||||
"Ethash": {
|
||||
"params": {
|
||||
"gasLimitBoundDivisor": "0x0400",
|
||||
"minimumDifficulty": "0x020000",
|
||||
"difficultyBoundDivisor": "0x0800",
|
||||
"durationLimit": "0x0d",
|
||||
"blockReward": "0x4563918244F40000",
|
||||
"registrar": "0x81a4b044831c4f12ba601adb9274516939e9b8a2",
|
||||
"homesteadTransition": 0,
|
||||
"eip150Transition": 0,
|
||||
"eip155Transition": 10,
|
||||
"eip160Transition": 10,
|
||||
"eip161abcTransition": 10,
|
||||
"eip161dTransition": 10
|
||||
}
|
||||
}
|
||||
},
|
||||
"params": {
|
||||
"accountStartNonce": "0x0",
|
||||
"maximumExtraDataSize": "0x20",
|
||||
"minGasLimit": "0x1388",
|
||||
"networkID" : "0x3"
|
||||
},
|
||||
"genesis": {
|
||||
"seal": {
|
||||
"ethereum": {
|
||||
"nonce": "0x0000000000000042",
|
||||
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
}
|
||||
},
|
||||
"difficulty": "0x100000",
|
||||
"author": "0x0000000000000000000000000000000000000000",
|
||||
"timestamp": "0x00",
|
||||
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"extraData": "0x3535353535353535353535353535353535353535353535353535353535353535",
|
||||
"gasLimit": "0x1000000"
|
||||
},
|
||||
"nodes": [
|
||||
"enode://a22f0977ce02653bf95e38730106356342df48b5222e2c2a1a6f9ef34769bf593bae9ca0a888cf60839edd52efc1b6e393c63a57d76f4c4fe14e641f1f9e637e@128.199.55.137:30303",
|
||||
"enode://012239fccf3ff1d92b036983a430cb6705c6528c96c0354413f8854802138e5135c084ab36e7c54efb621c46728df8c3a6f4c1db9bb48a1330efe3f82f2dd7a6@52.169.94.142:30303"
|
||||
],
|
||||
"accounts": {
|
||||
"0000000000000000000000000000000000000001": { "balance": "1", "nonce": "0", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
|
||||
"0000000000000000000000000000000000000002": { "balance": "1", "nonce": "0", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
|
||||
"0000000000000000000000000000000000000003": { "balance": "1", "nonce": "0", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
|
||||
"0000000000000000000000000000000000000004": { "balance": "1", "nonce": "0", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
|
||||
"0000000000000000000000000000000000000000": { "balance": "1" },
|
||||
"0000000000000000000000000000000000000005": { "balance": "1" },
|
||||
"0000000000000000000000000000000000000006": { "balance": "1" },
|
||||
"0000000000000000000000000000000000000007": { "balance": "1" },
|
||||
"0000000000000000000000000000000000000008": { "balance": "1" },
|
||||
"0000000000000000000000000000000000000009": { "balance": "1" },
|
||||
"000000000000000000000000000000000000000a": { "balance": "0" },
|
||||
"000000000000000000000000000000000000000b": { "balance": "0" },
|
||||
"000000000000000000000000000000000000000c": { "balance": "0" },
|
||||
"000000000000000000000000000000000000000d": { "balance": "0" },
|
||||
"000000000000000000000000000000000000000e": { "balance": "0" },
|
||||
"000000000000000000000000000000000000000f": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000010": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000011": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000012": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000013": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000014": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000015": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000016": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000017": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000018": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000019": { "balance": "0" },
|
||||
"000000000000000000000000000000000000001a": { "balance": "0" },
|
||||
"000000000000000000000000000000000000001b": { "balance": "0" },
|
||||
"000000000000000000000000000000000000001c": { "balance": "0" },
|
||||
"000000000000000000000000000000000000001d": { "balance": "0" },
|
||||
"000000000000000000000000000000000000001e": { "balance": "0" },
|
||||
"000000000000000000000000000000000000001f": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000020": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000021": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000022": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000023": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000024": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000025": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000026": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000027": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000028": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000029": { "balance": "0" },
|
||||
"000000000000000000000000000000000000002a": { "balance": "0" },
|
||||
"000000000000000000000000000000000000002b": { "balance": "0" },
|
||||
"000000000000000000000000000000000000002c": { "balance": "0" },
|
||||
"000000000000000000000000000000000000002d": { "balance": "0" },
|
||||
"000000000000000000000000000000000000002e": { "balance": "0" },
|
||||
"000000000000000000000000000000000000002f": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000030": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000031": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000032": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000033": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000034": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000035": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000036": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000037": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000038": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000039": { "balance": "0" },
|
||||
"000000000000000000000000000000000000003a": { "balance": "0" },
|
||||
"000000000000000000000000000000000000003b": { "balance": "0" },
|
||||
"000000000000000000000000000000000000003c": { "balance": "0" },
|
||||
"000000000000000000000000000000000000003d": { "balance": "0" },
|
||||
"000000000000000000000000000000000000003e": { "balance": "0" },
|
||||
"000000000000000000000000000000000000003f": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000040": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000041": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000042": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000043": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000044": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000045": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000046": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000047": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000048": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000049": { "balance": "0" },
|
||||
"000000000000000000000000000000000000004a": { "balance": "0" },
|
||||
"000000000000000000000000000000000000004b": { "balance": "0" },
|
||||
"000000000000000000000000000000000000004c": { "balance": "0" },
|
||||
"000000000000000000000000000000000000004d": { "balance": "0" },
|
||||
"000000000000000000000000000000000000004e": { "balance": "0" },
|
||||
"000000000000000000000000000000000000004f": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000050": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000051": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000052": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000053": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000054": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000055": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000056": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000057": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000058": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000059": { "balance": "0" },
|
||||
"000000000000000000000000000000000000005a": { "balance": "0" },
|
||||
"000000000000000000000000000000000000005b": { "balance": "0" },
|
||||
"000000000000000000000000000000000000005c": { "balance": "0" },
|
||||
"000000000000000000000000000000000000005d": { "balance": "0" },
|
||||
"000000000000000000000000000000000000005e": { "balance": "0" },
|
||||
"000000000000000000000000000000000000005f": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000060": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000061": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000062": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000063": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000064": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000065": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000066": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000067": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000068": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000069": { "balance": "0" },
|
||||
"000000000000000000000000000000000000006a": { "balance": "0" },
|
||||
"000000000000000000000000000000000000006b": { "balance": "0" },
|
||||
"000000000000000000000000000000000000006c": { "balance": "0" },
|
||||
"000000000000000000000000000000000000006d": { "balance": "0" },
|
||||
"000000000000000000000000000000000000006e": { "balance": "0" },
|
||||
"000000000000000000000000000000000000006f": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000070": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000071": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000072": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000073": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000074": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000075": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000076": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000077": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000078": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000079": { "balance": "0" },
|
||||
"000000000000000000000000000000000000007a": { "balance": "0" },
|
||||
"000000000000000000000000000000000000007b": { "balance": "0" },
|
||||
"000000000000000000000000000000000000007c": { "balance": "0" },
|
||||
"000000000000000000000000000000000000007d": { "balance": "0" },
|
||||
"000000000000000000000000000000000000007e": { "balance": "0" },
|
||||
"000000000000000000000000000000000000007f": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000080": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000081": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000082": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000083": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000084": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000085": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000086": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000087": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000088": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000089": { "balance": "0" },
|
||||
"000000000000000000000000000000000000008a": { "balance": "0" },
|
||||
"000000000000000000000000000000000000008b": { "balance": "0" },
|
||||
"000000000000000000000000000000000000008c": { "balance": "0" },
|
||||
"000000000000000000000000000000000000008d": { "balance": "0" },
|
||||
"000000000000000000000000000000000000008e": { "balance": "0" },
|
||||
"000000000000000000000000000000000000008f": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000090": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000091": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000092": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000093": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000094": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000095": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000096": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000097": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000098": { "balance": "0" },
|
||||
"0000000000000000000000000000000000000099": { "balance": "0" },
|
||||
"000000000000000000000000000000000000009a": { "balance": "0" },
|
||||
"000000000000000000000000000000000000009b": { "balance": "0" },
|
||||
"000000000000000000000000000000000000009c": { "balance": "0" },
|
||||
"000000000000000000000000000000000000009d": { "balance": "0" },
|
||||
"000000000000000000000000000000000000009e": { "balance": "0" },
|
||||
"000000000000000000000000000000000000009f": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000a0": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000a1": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000a2": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000a3": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000a4": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000a5": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000a6": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000a7": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000a8": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000a9": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000aa": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ab": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ac": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ad": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ae": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000af": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000b0": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000b1": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000b2": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000b3": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000b4": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000b5": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000b6": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000b7": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000b8": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000b9": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ba": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000bb": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000bc": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000bd": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000be": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000bf": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000c0": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000c1": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000c2": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000c3": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000c4": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000c5": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000c6": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000c7": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000c8": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000c9": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ca": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000cb": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000cc": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000cd": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ce": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000cf": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000d0": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000d1": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000d2": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000d3": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000d4": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000d5": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000d6": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000d7": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000d8": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000d9": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000da": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000db": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000dc": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000dd": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000de": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000df": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000e0": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000e1": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000e2": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000e3": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000e4": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000e5": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000e6": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000e7": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000e8": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000e9": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ea": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000eb": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ec": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ed": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ee": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ef": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000f0": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000f1": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000f2": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000f3": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000f4": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000f5": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000f6": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000f7": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000f8": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000f9": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000fa": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000fb": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000fc": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000fd": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000fe": { "balance": "0" },
|
||||
"00000000000000000000000000000000000000ff": { "balance": "0" },
|
||||
"874b54a8bd152966d63f706bae1ffeb0411921e5": { "balance": "1000000000000000000000000000000" }
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,9 @@
|
||||
},
|
||||
"genesis": {
|
||||
"seal": {
|
||||
"ethereum": {
|
||||
"nonce": "0x00006d6f7264656e",
|
||||
"mixHash": "0x00000000000000000000000000000000000000647572616c65787365646c6578"
|
||||
"generic": {
|
||||
"fields": 0,
|
||||
"rlp": "0x0"
|
||||
}
|
||||
},
|
||||
"difficulty": "0x20000",
|
||||
|
||||
@@ -254,8 +254,8 @@ impl Engine for AuthorityRound {
|
||||
|
||||
/// Check if the signature belongs to the correct proposer.
|
||||
fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
||||
let header_step = try!(header_step(header));
|
||||
// Give one step slack if step is lagging, double vote is still not possible.
|
||||
let header_step = try!(header_step(header));
|
||||
// Give one step slack if step is lagging, double vote is still not possible.
|
||||
if header_step <= self.step() + 1 {
|
||||
let proposer_signature = try!(header_signature(header));
|
||||
let ok_sig = try!(verify_address(self.step_proposer(header_step), &proposer_signature, &header.bare_hash()));
|
||||
@@ -417,13 +417,13 @@ mod tests {
|
||||
let engine = Spec::new_test_round().engine;
|
||||
|
||||
let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap();
|
||||
let mut step = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
||||
let time = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
||||
// Two authorities.
|
||||
let mut step = time - time % 2;
|
||||
header.set_seal(vec![encode(&step).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
|
||||
let first_ok = engine.verify_block_seal(&header).is_ok();
|
||||
assert!(engine.verify_block_seal(&header).is_err());
|
||||
step = step + 1;
|
||||
header.set_seal(vec![encode(&step).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
|
||||
let second_ok = engine.verify_block_seal(&header).is_ok();
|
||||
|
||||
assert!(first_ok ^ second_ok);
|
||||
assert!(engine.verify_block_seal(&header).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,9 @@ pub fn new_transition_test() -> Spec { load(include_bytes!("../../res/ethereum/t
|
||||
/// Create a new Frontier main net chain spec without genesis accounts.
|
||||
pub fn new_mainnet_like() -> Spec { load(include_bytes!("../../res/ethereum/frontier_like_test.json")) }
|
||||
|
||||
/// Create a new Ropsten chain spec.
|
||||
pub fn new_ropsten() -> Spec { load(include_bytes!("../../res/ethereum/ropsten.json")) }
|
||||
|
||||
/// Create a new Morden chain spec.
|
||||
pub fn new_morden() -> Spec { load(include_bytes!("../../res/ethereum/morden.json")) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user