Merge branch 'master' into client-provider
This commit is contained in:
@@ -27,6 +27,7 @@ time = "0.1"
|
||||
rand = "0.3"
|
||||
byteorder = "0.5"
|
||||
transient-hashmap = "0.1"
|
||||
linked-hash-map = "0.3.0"
|
||||
evmjit = { path = "../evmjit", optional = true }
|
||||
clippy = { version = "0.0.96", optional = true}
|
||||
ethash = { path = "../ethash" }
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
@@ -182,8 +182,8 @@
|
||||
"enode://89d5dc2a81e574c19d0465f497c1af96732d1b61a41de89c2a37f35707689ac416529fae1038809852b235c2d30fd325abdc57c122feeefbeaaf802cc7e9580d@45.55.33.62:30303",
|
||||
"enode://605e04a43b1156966b3a3b66b980c87b7f18522f7f712035f84576016be909a2798a438b2b17b1a8c58db314d88539a77419ca4be36148c086900fba487c9d39@188.166.255.12:30303",
|
||||
"enode://016b20125f447a3b203a3cae953b2ede8ffe51290c071e7599294be84317635730c397b8ff74404d6be412d539ee5bb5c3c700618723d3b53958c92bd33eaa82@159.203.210.80:30303",
|
||||
"enode://01f76fa0561eca2b9a7e224378dd854278735f1449793c46ad0c4e79e8775d080c21dcc455be391e90a98153c3b05dcc8935c8440de7b56fe6d67251e33f4e3c@10.6.6.117:30303",
|
||||
"enode://fe11ef89fc5ac9da358fc160857855f25bbf9e332c79b9ca7089330c02b728b2349988c6062f10982041702110745e203d26975a6b34bcc97144f9fe439034e8@10.1.72.117:30303"
|
||||
"enode://01f76fa0561eca2b9a7e224378dd854278735f1449793c46ad0c4e79e8775d080c21dcc455be391e90a98153c3b05dcc8935c8440de7b56fe6d67251e33f4e3c@51.15.42.252:30303",
|
||||
"enode://8d91c8137890d29110b9463882f17ae4e279cd2c90cf56573187ed1c8546fca5f590a9f05e9f108eb1bd91767ed01ede4daad9e001b61727885eaa246ddb39c2@163.172.171.38:30303"
|
||||
],
|
||||
"accounts": {
|
||||
"0000000000000000000000000000000000000001": { "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
|
||||
|
||||
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": "0x52dff57a8a1532e6afb3dc07e2af58bb9eb05b3d",
|
||||
"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" }
|
||||
}
|
||||
}
|
||||
@@ -892,12 +892,9 @@ impl BlockChainClient for Client {
|
||||
let mut mode = self.mode.lock();
|
||||
*mode = new_mode.clone().into();
|
||||
trace!(target: "mode", "Mode now {:?}", &*mode);
|
||||
match *self.on_mode_change.lock() {
|
||||
Some(ref mut f) => {
|
||||
trace!(target: "mode", "Making callback...");
|
||||
f(&*mode)
|
||||
},
|
||||
_ => {}
|
||||
if let Some(ref mut f) = *self.on_mode_change.lock() {
|
||||
trace!(target: "mode", "Making callback...");
|
||||
f(&*mode)
|
||||
}
|
||||
}
|
||||
match new_mode {
|
||||
|
||||
@@ -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")) }
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ extern crate ethcore_bloom_journal as bloom_journal;
|
||||
extern crate byteorder;
|
||||
extern crate transient_hashmap;
|
||||
extern crate ethcore_network as network;
|
||||
extern crate linked_hash_map;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
196
ethcore/src/miner/local_transactions.rs
Normal file
196
ethcore/src/miner/local_transactions.rs
Normal file
@@ -0,0 +1,196 @@
|
||||
// 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/>.
|
||||
|
||||
//! Local Transactions List.
|
||||
|
||||
use linked_hash_map::LinkedHashMap;
|
||||
use transaction::SignedTransaction;
|
||||
use error::TransactionError;
|
||||
use util::{U256, H256};
|
||||
|
||||
/// Status of local transaction.
|
||||
/// Can indicate that the transaction is currently part of the queue (`Pending/Future`)
|
||||
/// or gives a reason why the transaction was removed.
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum Status {
|
||||
/// The transaction is currently in the transaction queue.
|
||||
Pending,
|
||||
/// The transaction is in future part of the queue.
|
||||
Future,
|
||||
/// Transaction is already mined.
|
||||
Mined(SignedTransaction),
|
||||
/// Transaction is dropped because of limit
|
||||
Dropped(SignedTransaction),
|
||||
/// Replaced because of higher gas price of another transaction.
|
||||
Replaced(SignedTransaction, U256, H256),
|
||||
/// Transaction was never accepted to the queue.
|
||||
Rejected(SignedTransaction, TransactionError),
|
||||
/// Transaction is invalid.
|
||||
Invalid(SignedTransaction),
|
||||
}
|
||||
|
||||
impl Status {
|
||||
fn is_current(&self) -> bool {
|
||||
*self == Status::Pending || *self == Status::Future
|
||||
}
|
||||
}
|
||||
|
||||
/// Keeps track of local transactions that are in the queue or were mined/dropped recently.
|
||||
#[derive(Debug)]
|
||||
pub struct LocalTransactionsList {
|
||||
max_old: usize,
|
||||
transactions: LinkedHashMap<H256, Status>,
|
||||
}
|
||||
|
||||
impl Default for LocalTransactionsList {
|
||||
fn default() -> Self {
|
||||
Self::new(10)
|
||||
}
|
||||
}
|
||||
|
||||
impl LocalTransactionsList {
|
||||
pub fn new(max_old: usize) -> Self {
|
||||
LocalTransactionsList {
|
||||
max_old: max_old,
|
||||
transactions: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mark_pending(&mut self, hash: H256) {
|
||||
self.clear_old();
|
||||
self.transactions.insert(hash, Status::Pending);
|
||||
}
|
||||
|
||||
pub fn mark_future(&mut self, hash: H256) {
|
||||
self.transactions.insert(hash, Status::Future);
|
||||
self.clear_old();
|
||||
}
|
||||
|
||||
pub fn mark_rejected(&mut self, tx: SignedTransaction, err: TransactionError) {
|
||||
self.transactions.insert(tx.hash(), Status::Rejected(tx, err));
|
||||
self.clear_old();
|
||||
}
|
||||
|
||||
pub fn mark_replaced(&mut self, tx: SignedTransaction, gas_price: U256, hash: H256) {
|
||||
self.transactions.insert(tx.hash(), Status::Replaced(tx, gas_price, hash));
|
||||
self.clear_old();
|
||||
}
|
||||
|
||||
pub fn mark_invalid(&mut self, tx: SignedTransaction) {
|
||||
self.transactions.insert(tx.hash(), Status::Invalid(tx));
|
||||
self.clear_old();
|
||||
}
|
||||
|
||||
pub fn mark_dropped(&mut self, tx: SignedTransaction) {
|
||||
self.transactions.insert(tx.hash(), Status::Dropped(tx));
|
||||
self.clear_old();
|
||||
}
|
||||
|
||||
pub fn mark_mined(&mut self, tx: SignedTransaction) {
|
||||
self.transactions.insert(tx.hash(), Status::Mined(tx));
|
||||
self.clear_old();
|
||||
}
|
||||
|
||||
pub fn contains(&self, hash: &H256) -> bool {
|
||||
self.transactions.contains_key(hash)
|
||||
}
|
||||
|
||||
pub fn all_transactions(&self) -> &LinkedHashMap<H256, Status> {
|
||||
&self.transactions
|
||||
}
|
||||
|
||||
fn clear_old(&mut self) {
|
||||
let number_of_old = self.transactions
|
||||
.values()
|
||||
.filter(|status| !status.is_current())
|
||||
.count();
|
||||
|
||||
if self.max_old >= number_of_old {
|
||||
return;
|
||||
}
|
||||
|
||||
let to_remove = self.transactions
|
||||
.iter()
|
||||
.filter(|&(_, status)| !status.is_current())
|
||||
.map(|(hash, _)| *hash)
|
||||
.take(number_of_old - self.max_old)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for hash in to_remove {
|
||||
self.transactions.remove(&hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use util::U256;
|
||||
use ethkey::{Random, Generator};
|
||||
use transaction::{Action, Transaction, SignedTransaction};
|
||||
use super::{LocalTransactionsList, Status};
|
||||
|
||||
#[test]
|
||||
fn should_add_transaction_as_pending() {
|
||||
// given
|
||||
let mut list = LocalTransactionsList::default();
|
||||
|
||||
// when
|
||||
list.mark_pending(10.into());
|
||||
list.mark_future(20.into());
|
||||
|
||||
// then
|
||||
assert!(list.contains(&10.into()), "Should contain the transaction.");
|
||||
assert!(list.contains(&20.into()), "Should contain the transaction.");
|
||||
let statuses = list.all_transactions().values().cloned().collect::<Vec<Status>>();
|
||||
assert_eq!(statuses, vec![Status::Pending, Status::Future]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_clear_old_transactions() {
|
||||
// given
|
||||
let mut list = LocalTransactionsList::new(1);
|
||||
let tx1 = new_tx(10.into());
|
||||
let tx1_hash = tx1.hash();
|
||||
let tx2 = new_tx(50.into());
|
||||
let tx2_hash = tx2.hash();
|
||||
|
||||
list.mark_pending(10.into());
|
||||
list.mark_invalid(tx1);
|
||||
list.mark_dropped(tx2);
|
||||
assert!(list.contains(&tx2_hash));
|
||||
assert!(!list.contains(&tx1_hash));
|
||||
assert!(list.contains(&10.into()));
|
||||
|
||||
// when
|
||||
list.mark_future(15.into());
|
||||
|
||||
// then
|
||||
assert!(list.contains(&10.into()));
|
||||
assert!(list.contains(&15.into()));
|
||||
}
|
||||
|
||||
fn new_tx(nonce: U256) -> SignedTransaction {
|
||||
let keypair = Random.generate().unwrap();
|
||||
Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::from(100),
|
||||
data: Default::default(),
|
||||
gas: U256::from(10),
|
||||
gas_price: U256::from(1245),
|
||||
nonce: nonce
|
||||
}.sign(keypair.secret(), None)
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,10 @@ use util::*;
|
||||
use util::using_queue::{UsingQueue, GetAction};
|
||||
use account_provider::AccountProvider;
|
||||
use views::{BlockView, HeaderView};
|
||||
use header::Header;
|
||||
use state::{State, CleanupMode};
|
||||
use client::{MiningBlockChainClient, Executive, Executed, EnvInfo, TransactOptions, BlockID, CallAnalytics};
|
||||
use client::TransactionImportResult;
|
||||
use executive::contract_address;
|
||||
use block::{ClosedBlock, SealedBlock, IsBlock, Block};
|
||||
use error::*;
|
||||
@@ -33,8 +35,8 @@ use engines::Engine;
|
||||
use miner::{MinerService, MinerStatus, TransactionQueue, PrioritizationStrategy, AccountDetails, TransactionOrigin};
|
||||
use miner::banning_queue::{BanningTransactionQueue, Threshold};
|
||||
use miner::work_notify::WorkPoster;
|
||||
use client::TransactionImportResult;
|
||||
use miner::price_info::PriceInfo;
|
||||
use miner::local_transactions::{Status as LocalTransactionStatus};
|
||||
use header::BlockNumber;
|
||||
|
||||
/// Different possible definitions for pending transaction set.
|
||||
@@ -562,7 +564,7 @@ impl Miner {
|
||||
prepare_new
|
||||
}
|
||||
|
||||
fn add_transactions_to_queue(&self, chain: &MiningBlockChainClient, transactions: Vec<SignedTransaction>, origin: TransactionOrigin, transaction_queue: &mut BanningTransactionQueue) ->
|
||||
fn add_transactions_to_queue(&self, chain: &MiningBlockChainClient, transactions: Vec<SignedTransaction>, default_origin: TransactionOrigin, transaction_queue: &mut BanningTransactionQueue) ->
|
||||
Vec<Result<TransactionImportResult, Error>> {
|
||||
|
||||
let fetch_account = |a: &Address| AccountDetails {
|
||||
@@ -570,15 +572,37 @@ impl Miner {
|
||||
balance: chain.latest_balance(a),
|
||||
};
|
||||
|
||||
let accounts = self.accounts.as_ref()
|
||||
.and_then(|provider| provider.accounts().ok())
|
||||
.map(|accounts| accounts.into_iter().collect::<HashSet<_>>());
|
||||
|
||||
let schedule = chain.latest_schedule();
|
||||
let gas_required = |tx: &SignedTransaction| tx.gas_required(&schedule).into();
|
||||
let best_block_header: Header = ::rlp::decode(&chain.best_block_header());
|
||||
transactions.into_iter()
|
||||
.map(|tx| match origin {
|
||||
TransactionOrigin::Local | TransactionOrigin::RetractedBlock => {
|
||||
transaction_queue.add(tx, origin, &fetch_account, &gas_required)
|
||||
},
|
||||
TransactionOrigin::External => {
|
||||
transaction_queue.add_with_banlist(tx, &fetch_account, &gas_required)
|
||||
.filter(|tx| match self.engine.verify_transaction_basic(tx, &best_block_header) {
|
||||
Ok(()) => true,
|
||||
Err(e) => {
|
||||
debug!(target: "miner", "Rejected tx {:?} with invalid signature: {:?}", tx.hash(), e);
|
||||
false
|
||||
}
|
||||
}
|
||||
)
|
||||
.map(|tx| {
|
||||
let origin = accounts.as_ref().and_then(|accounts| {
|
||||
tx.sender().ok().and_then(|sender| match accounts.contains(&sender) {
|
||||
true => Some(TransactionOrigin::Local),
|
||||
false => None,
|
||||
})
|
||||
}).unwrap_or(default_origin);
|
||||
|
||||
match origin {
|
||||
TransactionOrigin::Local | TransactionOrigin::RetractedBlock => {
|
||||
transaction_queue.add(tx, origin, &fetch_account, &gas_required)
|
||||
},
|
||||
TransactionOrigin::External => {
|
||||
transaction_queue.add_with_banlist(tx, &fetch_account, &gas_required)
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
@@ -853,6 +877,14 @@ impl MinerService for Miner {
|
||||
queue.top_transactions()
|
||||
}
|
||||
|
||||
fn local_transactions(&self) -> BTreeMap<H256, LocalTransactionStatus> {
|
||||
let queue = self.transaction_queue.lock();
|
||||
queue.local_transactions()
|
||||
.iter()
|
||||
.map(|(hash, status)| (*hash, status.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn pending_transactions(&self, best_block: BlockNumber) -> Vec<SignedTransaction> {
|
||||
let queue = self.transaction_queue.lock();
|
||||
match self.options.pending_set {
|
||||
|
||||
@@ -41,16 +41,18 @@
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
mod miner;
|
||||
mod external;
|
||||
mod transaction_queue;
|
||||
mod banning_queue;
|
||||
mod work_notify;
|
||||
mod external;
|
||||
mod local_transactions;
|
||||
mod miner;
|
||||
mod price_info;
|
||||
mod transaction_queue;
|
||||
mod work_notify;
|
||||
|
||||
pub use self::transaction_queue::{TransactionQueue, PrioritizationStrategy, AccountDetails, TransactionOrigin};
|
||||
pub use self::miner::{Miner, MinerOptions, Banning, PendingSet, GasPricer, GasPriceCalibratorOptions, GasLimit};
|
||||
pub use self::external::{ExternalMiner, ExternalMinerService};
|
||||
pub use self::miner::{Miner, MinerOptions, Banning, PendingSet, GasPricer, GasPriceCalibratorOptions, GasLimit};
|
||||
pub use self::transaction_queue::{TransactionQueue, PrioritizationStrategy, AccountDetails, TransactionOrigin};
|
||||
pub use self::local_transactions::{Status as LocalTransactionStatus};
|
||||
pub use client::TransactionImportResult;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
@@ -145,6 +147,9 @@ pub trait MinerService : Send + Sync {
|
||||
/// Get a list of all pending transactions.
|
||||
fn pending_transactions(&self, best_block: BlockNumber) -> Vec<SignedTransaction>;
|
||||
|
||||
/// Get a list of local transactions with statuses.
|
||||
fn local_transactions(&self) -> BTreeMap<H256, LocalTransactionStatus>;
|
||||
|
||||
/// Get a list of all pending receipts.
|
||||
fn pending_receipts(&self, best_block: BlockNumber) -> BTreeMap<H256, Receipt>;
|
||||
|
||||
|
||||
@@ -86,11 +86,13 @@ use std::ops::Deref;
|
||||
use std::cmp::Ordering;
|
||||
use std::cmp;
|
||||
use std::collections::{HashSet, HashMap, BTreeSet, BTreeMap};
|
||||
use linked_hash_map::LinkedHashMap;
|
||||
use util::{Address, H256, Uint, U256};
|
||||
use util::table::Table;
|
||||
use transaction::*;
|
||||
use error::{Error, TransactionError};
|
||||
use client::TransactionImportResult;
|
||||
use miner::local_transactions::{LocalTransactionsList, Status as LocalTransactionStatus};
|
||||
|
||||
/// Transaction origin
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -125,6 +127,12 @@ impl Ord for TransactionOrigin {
|
||||
}
|
||||
}
|
||||
|
||||
impl TransactionOrigin {
|
||||
fn is_local(&self) -> bool {
|
||||
*self == TransactionOrigin::Local
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
/// Light structure used to identify transaction and its order
|
||||
struct TransactionOrder {
|
||||
@@ -201,17 +209,16 @@ impl Ord for TransactionOrder {
|
||||
return self.penalties.cmp(&b.penalties);
|
||||
}
|
||||
|
||||
// First check nonce_height
|
||||
if self.nonce_height != b.nonce_height {
|
||||
return self.nonce_height.cmp(&b.nonce_height);
|
||||
}
|
||||
|
||||
// Local transactions should always have priority
|
||||
// NOTE nonce has to be checked first, cause otherwise the order might be wrong.
|
||||
if self.origin != b.origin {
|
||||
return self.origin.cmp(&b.origin);
|
||||
}
|
||||
|
||||
// Check nonce_height
|
||||
if self.nonce_height != b.nonce_height {
|
||||
return self.nonce_height.cmp(&b.nonce_height);
|
||||
}
|
||||
|
||||
match self.strategy {
|
||||
PrioritizationStrategy::GasAndGasPrice => {
|
||||
if self.gas != b.gas {
|
||||
@@ -242,6 +249,7 @@ impl Ord for TransactionOrder {
|
||||
}
|
||||
|
||||
/// Verified transaction (with sender)
|
||||
#[derive(Debug)]
|
||||
struct VerifiedTransaction {
|
||||
/// Transaction
|
||||
transaction: SignedTransaction,
|
||||
@@ -352,7 +360,7 @@ impl TransactionSet {
|
||||
///
|
||||
/// It drops transactions from this set but also removes associated `VerifiedTransaction`.
|
||||
/// Returns addresses and lowest nonces of transactions removed because of limit.
|
||||
fn enforce_limit(&mut self, by_hash: &mut HashMap<H256, VerifiedTransaction>) -> Option<HashMap<Address, U256>> {
|
||||
fn enforce_limit(&mut self, by_hash: &mut HashMap<H256, VerifiedTransaction>, local: &mut LocalTransactionsList) -> Option<HashMap<Address, U256>> {
|
||||
let mut count = 0;
|
||||
let mut gas: U256 = 0.into();
|
||||
let to_drop : Vec<(Address, U256)> = {
|
||||
@@ -379,9 +387,13 @@ impl TransactionSet {
|
||||
.expect("Transaction has just been found in `by_priority`; so it is in `by_address` also.");
|
||||
trace!(target: "txqueue", "Dropped out of limit transaction: {:?}", order.hash);
|
||||
|
||||
by_hash.remove(&order.hash)
|
||||
let order = by_hash.remove(&order.hash)
|
||||
.expect("hash is in `by_priorty`; all hashes in `by_priority` must be in `by_hash`; qed");
|
||||
|
||||
if order.origin.is_local() {
|
||||
local.mark_dropped(order.transaction);
|
||||
}
|
||||
|
||||
let min = removed.get(&sender).map_or(nonce, |val| cmp::min(*val, nonce));
|
||||
removed.insert(sender, min);
|
||||
removed
|
||||
@@ -488,6 +500,8 @@ pub struct TransactionQueue {
|
||||
by_hash: HashMap<H256, VerifiedTransaction>,
|
||||
/// Last nonce of transaction in current (to quickly check next expected transaction)
|
||||
last_nonces: HashMap<Address, U256>,
|
||||
/// List of local transactions and their statuses.
|
||||
local_transactions: LocalTransactionsList,
|
||||
}
|
||||
|
||||
impl Default for TransactionQueue {
|
||||
@@ -529,6 +543,7 @@ impl TransactionQueue {
|
||||
future: future,
|
||||
by_hash: HashMap::new(),
|
||||
last_nonces: HashMap::new(),
|
||||
local_transactions: LocalTransactionsList::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,8 +552,8 @@ impl TransactionQueue {
|
||||
self.current.set_limit(limit);
|
||||
self.future.set_limit(limit);
|
||||
// And ensure the limits
|
||||
self.current.enforce_limit(&mut self.by_hash);
|
||||
self.future.enforce_limit(&mut self.by_hash);
|
||||
self.current.enforce_limit(&mut self.by_hash, &mut self.local_transactions);
|
||||
self.future.enforce_limit(&mut self.by_hash, &mut self.local_transactions);
|
||||
}
|
||||
|
||||
/// Returns current limit of transactions in the queue.
|
||||
@@ -578,7 +593,7 @@ impl TransactionQueue {
|
||||
pub fn set_total_gas_limit(&mut self, gas_limit: U256) {
|
||||
self.future.gas_limit = gas_limit;
|
||||
self.current.gas_limit = gas_limit;
|
||||
self.future.enforce_limit(&mut self.by_hash);
|
||||
self.future.enforce_limit(&mut self.by_hash, &mut self.local_transactions);
|
||||
}
|
||||
|
||||
/// Set the new limit for the amount of gas any individual transaction may have.
|
||||
@@ -609,6 +624,46 @@ impl TransactionQueue {
|
||||
F: Fn(&Address) -> AccountDetails,
|
||||
G: Fn(&SignedTransaction) -> U256,
|
||||
{
|
||||
if origin == TransactionOrigin::Local {
|
||||
let hash = tx.hash();
|
||||
let cloned_tx = tx.clone();
|
||||
|
||||
let result = self.add_internal(tx, origin, fetch_account, gas_estimator);
|
||||
match result {
|
||||
Ok(TransactionImportResult::Current) => {
|
||||
self.local_transactions.mark_pending(hash);
|
||||
},
|
||||
Ok(TransactionImportResult::Future) => {
|
||||
self.local_transactions.mark_future(hash);
|
||||
},
|
||||
Err(Error::Transaction(ref err)) => {
|
||||
// Sometimes transactions are re-imported, so
|
||||
// don't overwrite transactions if they are already on the list
|
||||
if !self.local_transactions.contains(&cloned_tx.hash()) {
|
||||
self.local_transactions.mark_rejected(cloned_tx, err.clone());
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
self.local_transactions.mark_invalid(cloned_tx);
|
||||
},
|
||||
}
|
||||
result
|
||||
} else {
|
||||
self.add_internal(tx, origin, fetch_account, gas_estimator)
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds signed transaction to the queue.
|
||||
fn add_internal<F, G>(
|
||||
&mut self,
|
||||
tx: SignedTransaction,
|
||||
origin: TransactionOrigin,
|
||||
fetch_account: &F,
|
||||
gas_estimator: &G,
|
||||
) -> Result<TransactionImportResult, Error> where
|
||||
F: Fn(&Address) -> AccountDetails,
|
||||
G: Fn(&SignedTransaction) -> U256,
|
||||
{
|
||||
|
||||
if tx.gas_price < self.minimal_gas_price && origin != TransactionOrigin::Local {
|
||||
trace!(target: "txqueue",
|
||||
@@ -647,7 +702,6 @@ impl TransactionQueue {
|
||||
self.gas_limit,
|
||||
self.tx_gas_limit
|
||||
);
|
||||
|
||||
return Err(Error::Transaction(TransactionError::GasLimitExceeded {
|
||||
limit: self.gas_limit,
|
||||
got: tx.gas,
|
||||
@@ -722,6 +776,12 @@ impl TransactionQueue {
|
||||
None => return,
|
||||
Some(t) => t,
|
||||
};
|
||||
|
||||
// Never penalize local transactions
|
||||
if transaction.origin.is_local() {
|
||||
return;
|
||||
}
|
||||
|
||||
let sender = transaction.sender();
|
||||
|
||||
// Penalize all transactions from this sender
|
||||
@@ -766,6 +826,11 @@ impl TransactionQueue {
|
||||
|
||||
trace!(target: "txqueue", "Removing invalid transaction: {:?}", transaction.hash());
|
||||
|
||||
// Mark in locals
|
||||
if self.local_transactions.contains(transaction_hash) {
|
||||
self.local_transactions.mark_invalid(transaction.transaction.clone());
|
||||
}
|
||||
|
||||
// Remove from future
|
||||
let order = self.future.drop(&sender, &nonce);
|
||||
if order.is_some() {
|
||||
@@ -788,6 +853,33 @@ impl TransactionQueue {
|
||||
}
|
||||
}
|
||||
|
||||
/// Marks all transactions from particular sender as local transactions
|
||||
fn mark_transactions_local(&mut self, sender: &Address) {
|
||||
fn mark_local<F: FnMut(H256)>(sender: &Address, set: &mut TransactionSet, mut mark: F) {
|
||||
// Mark all transactions from this sender as local
|
||||
let nonces_from_sender = set.by_address.row(sender)
|
||||
.map(|row_map| {
|
||||
row_map.iter().filter_map(|(nonce, order)| if order.origin.is_local() {
|
||||
None
|
||||
} else {
|
||||
Some(*nonce)
|
||||
}).collect::<Vec<U256>>()
|
||||
})
|
||||
.unwrap_or_else(Vec::new);
|
||||
|
||||
for k in nonces_from_sender {
|
||||
let mut order = set.drop(sender, &k).expect("transaction known to be in self.current/self.future; qed");
|
||||
order.origin = TransactionOrigin::Local;
|
||||
mark(order.hash);
|
||||
set.insert(*sender, k, order);
|
||||
}
|
||||
}
|
||||
|
||||
let local = &mut self.local_transactions;
|
||||
mark_local(sender, &mut self.current, |hash| local.mark_pending(hash));
|
||||
mark_local(sender, &mut self.future, |hash| local.mark_future(hash));
|
||||
}
|
||||
|
||||
/// Update height of all transactions in future transactions set.
|
||||
fn update_future(&mut self, sender: &Address, current_nonce: U256) {
|
||||
// We need to drain all transactions for current sender from future and reinsert them with updated height
|
||||
@@ -821,15 +913,21 @@ impl TransactionQueue {
|
||||
qed");
|
||||
if k >= current_nonce {
|
||||
let order = order.update_height(k, current_nonce);
|
||||
if order.origin.is_local() {
|
||||
self.local_transactions.mark_future(order.hash);
|
||||
}
|
||||
if let Some(old) = self.future.insert(*sender, k, order.clone()) {
|
||||
Self::replace_orders(*sender, k, old, order, &mut self.future, &mut self.by_hash);
|
||||
Self::replace_orders(*sender, k, old, order, &mut self.future, &mut self.by_hash, &mut self.local_transactions);
|
||||
}
|
||||
} else {
|
||||
trace!(target: "txqueue", "Removing old transaction: {:?} (nonce: {} < {})", order.hash, k, current_nonce);
|
||||
self.by_hash.remove(&order.hash).expect("All transactions in `future` are also in `by_hash`");
|
||||
let tx = self.by_hash.remove(&order.hash).expect("All transactions in `future` are also in `by_hash`");
|
||||
if tx.origin.is_local() {
|
||||
self.local_transactions.mark_mined(tx.transaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.future.enforce_limit(&mut self.by_hash);
|
||||
self.future.enforce_limit(&mut self.by_hash, &mut self.local_transactions);
|
||||
}
|
||||
|
||||
/// Returns top transactions from the queue ordered by priority.
|
||||
@@ -841,6 +939,11 @@ impl TransactionQueue {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Returns local transactions (some of them might not be part of the queue anymore).
|
||||
pub fn local_transactions(&self) -> &LinkedHashMap<H256, LocalTransactionStatus> {
|
||||
self.local_transactions.all_transactions()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn future_transactions(&self) -> Vec<SignedTransaction> {
|
||||
self.future.by_priority
|
||||
@@ -897,8 +1000,11 @@ impl TransactionQueue {
|
||||
self.future.by_gas_price.remove(&order.gas_price, &order.hash);
|
||||
// Put to current
|
||||
let order = order.update_height(current_nonce, first_nonce);
|
||||
if order.origin.is_local() {
|
||||
self.local_transactions.mark_pending(order.hash);
|
||||
}
|
||||
if let Some(old) = self.current.insert(address, current_nonce, order.clone()) {
|
||||
Self::replace_orders(address, current_nonce, old, order, &mut self.current, &mut self.by_hash);
|
||||
Self::replace_orders(address, current_nonce, old, order, &mut self.current, &mut self.by_hash, &mut self.local_transactions);
|
||||
}
|
||||
update_last_nonce_to = Some(current_nonce);
|
||||
current_nonce = current_nonce + U256::one();
|
||||
@@ -953,13 +1059,19 @@ impl TransactionQueue {
|
||||
.cloned()
|
||||
.map_or(state_nonce, |n| n + U256::one());
|
||||
|
||||
if tx.origin.is_local() {
|
||||
self.mark_transactions_local(&address);
|
||||
}
|
||||
|
||||
// Future transaction
|
||||
if nonce > next_nonce {
|
||||
// We have a gap - put to future.
|
||||
// Insert transaction (or replace old one with lower gas price)
|
||||
try!(check_too_cheap(Self::replace_transaction(tx, state_nonce, min_gas_price, &mut self.future, &mut self.by_hash)));
|
||||
try!(check_too_cheap(
|
||||
Self::replace_transaction(tx, state_nonce, min_gas_price, &mut self.future, &mut self.by_hash, &mut self.local_transactions)
|
||||
));
|
||||
// Enforce limit in Future
|
||||
let removed = self.future.enforce_limit(&mut self.by_hash);
|
||||
let removed = self.future.enforce_limit(&mut self.by_hash, &mut self.local_transactions);
|
||||
// Return an error if this transaction was not imported because of limit.
|
||||
try!(check_if_removed(&address, &nonce, removed));
|
||||
|
||||
@@ -973,13 +1085,15 @@ impl TransactionQueue {
|
||||
self.move_matching_future_to_current(address, nonce + U256::one(), state_nonce);
|
||||
|
||||
// Replace transaction if any
|
||||
try!(check_too_cheap(Self::replace_transaction(tx, state_nonce, min_gas_price, &mut self.current, &mut self.by_hash)));
|
||||
try!(check_too_cheap(
|
||||
Self::replace_transaction(tx, state_nonce, min_gas_price, &mut self.current, &mut self.by_hash, &mut self.local_transactions)
|
||||
));
|
||||
// Keep track of highest nonce stored in current
|
||||
let new_max = self.last_nonces.get(&address).map_or(nonce, |n| cmp::max(nonce, *n));
|
||||
self.last_nonces.insert(address, new_max);
|
||||
|
||||
// Also enforce the limit
|
||||
let removed = self.current.enforce_limit(&mut self.by_hash);
|
||||
let removed = self.current.enforce_limit(&mut self.by_hash, &mut self.local_transactions);
|
||||
// If some transaction were removed because of limit we need to update last_nonces also.
|
||||
self.update_last_nonces(&removed);
|
||||
// Trigger error if the transaction we are importing was removed.
|
||||
@@ -1010,7 +1124,14 @@ impl TransactionQueue {
|
||||
///
|
||||
/// Returns `true` if transaction actually got to the queue (`false` if there was already a transaction with higher
|
||||
/// gas_price)
|
||||
fn replace_transaction(tx: VerifiedTransaction, base_nonce: U256, min_gas_price: (U256, PrioritizationStrategy), set: &mut TransactionSet, by_hash: &mut HashMap<H256, VerifiedTransaction>) -> bool {
|
||||
fn replace_transaction(
|
||||
tx: VerifiedTransaction,
|
||||
base_nonce: U256,
|
||||
min_gas_price: (U256, PrioritizationStrategy),
|
||||
set: &mut TransactionSet,
|
||||
by_hash: &mut HashMap<H256, VerifiedTransaction>,
|
||||
local: &mut LocalTransactionsList,
|
||||
) -> bool {
|
||||
let order = TransactionOrder::for_transaction(&tx, base_nonce, min_gas_price.0, min_gas_price.1);
|
||||
let hash = tx.hash();
|
||||
let address = tx.sender();
|
||||
@@ -1019,16 +1140,27 @@ impl TransactionQueue {
|
||||
let old_hash = by_hash.insert(hash, tx);
|
||||
assert!(old_hash.is_none(), "Each hash has to be inserted exactly once.");
|
||||
|
||||
trace!(target: "txqueue", "Inserting: {:?}", order);
|
||||
|
||||
if let Some(old) = set.insert(address, nonce, order.clone()) {
|
||||
Self::replace_orders(address, nonce, old, order, set, by_hash)
|
||||
Self::replace_orders(address, nonce, old, order, set, by_hash, local)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fn replace_orders(address: Address, nonce: U256, old: TransactionOrder, order: TransactionOrder, set: &mut TransactionSet, by_hash: &mut HashMap<H256, VerifiedTransaction>) -> bool {
|
||||
fn replace_orders(
|
||||
address: Address,
|
||||
nonce: U256,
|
||||
old: TransactionOrder,
|
||||
order: TransactionOrder,
|
||||
set: &mut TransactionSet,
|
||||
by_hash: &mut HashMap<H256, VerifiedTransaction>,
|
||||
local: &mut LocalTransactionsList,
|
||||
) -> bool {
|
||||
// There was already transaction in queue. Let's check which one should stay
|
||||
let old_hash = old.hash;
|
||||
let new_hash = order.hash;
|
||||
let old_fee = old.gas_price;
|
||||
let new_fee = order.gas_price;
|
||||
if old_fee.cmp(&new_fee) == Ordering::Greater {
|
||||
@@ -1036,12 +1168,18 @@ impl TransactionQueue {
|
||||
// Put back old transaction since it has greater priority (higher gas_price)
|
||||
set.insert(address, nonce, old);
|
||||
// and remove new one
|
||||
by_hash.remove(&order.hash).expect("The hash has been just inserted and no other line is altering `by_hash`.");
|
||||
let order = by_hash.remove(&order.hash).expect("The hash has been just inserted and no other line is altering `by_hash`.");
|
||||
if order.origin.is_local() {
|
||||
local.mark_replaced(order.transaction, old_fee, old_hash);
|
||||
}
|
||||
false
|
||||
} else {
|
||||
trace!(target: "txqueue", "Replaced transaction: {:?} with transaction with higher gas price: {:?}", old.hash, order.hash);
|
||||
// Make sure we remove old transaction entirely
|
||||
by_hash.remove(&old.hash).expect("The hash is coming from `future` so it has to be in `by_hash`.");
|
||||
let old = by_hash.remove(&old.hash).expect("The hash is coming from `future` so it has to be in `by_hash`.");
|
||||
if old.origin.is_local() {
|
||||
local.mark_replaced(old.transaction, new_fee, new_hash);
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -1078,6 +1216,7 @@ mod test {
|
||||
use error::{Error, TransactionError};
|
||||
use super::*;
|
||||
use super::{TransactionSet, TransactionOrder, VerifiedTransaction};
|
||||
use miner::local_transactions::LocalTransactionsList;
|
||||
use client::TransactionImportResult;
|
||||
|
||||
fn unwrap_tx_err(err: Result<TransactionImportResult, Error>) -> TransactionError {
|
||||
@@ -1208,6 +1347,7 @@ mod test {
|
||||
#[test]
|
||||
fn should_create_transaction_set() {
|
||||
// given
|
||||
let mut local = LocalTransactionsList::default();
|
||||
let mut set = TransactionSet {
|
||||
by_priority: BTreeSet::new(),
|
||||
by_address: Table::new(),
|
||||
@@ -1235,7 +1375,7 @@ mod test {
|
||||
assert_eq!(set.by_address.len(), 2);
|
||||
|
||||
// when
|
||||
set.enforce_limit(&mut by_hash);
|
||||
set.enforce_limit(&mut by_hash, &mut local);
|
||||
|
||||
// then
|
||||
assert_eq!(by_hash.len(), 1);
|
||||
@@ -1628,6 +1768,31 @@ mod test {
|
||||
assert_eq!(top.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn when_importing_local_should_mark_others_from_the_same_sender_as_local() {
|
||||
// given
|
||||
let mut txq = TransactionQueue::default();
|
||||
let (tx1, tx2) = new_tx_pair_default(1.into(), 0.into());
|
||||
// the second one has same nonce but higher `gas_price`
|
||||
let (_, tx0) = new_similar_tx_pair();
|
||||
|
||||
txq.add(tx0.clone(), TransactionOrigin::External, &default_account_details, &gas_estimator).unwrap();
|
||||
txq.add(tx1.clone(), TransactionOrigin::External, &default_account_details, &gas_estimator).unwrap();
|
||||
// the one with higher gas price is first
|
||||
assert_eq!(txq.top_transactions()[0], tx0);
|
||||
assert_eq!(txq.top_transactions()[1], tx1);
|
||||
|
||||
// when
|
||||
// insert second as local
|
||||
txq.add(tx2.clone(), TransactionOrigin::Local, &default_account_details, &gas_estimator).unwrap();
|
||||
|
||||
// then
|
||||
// the order should be updated
|
||||
assert_eq!(txq.top_transactions()[0], tx1);
|
||||
assert_eq!(txq.top_transactions()[1], tx2);
|
||||
assert_eq!(txq.top_transactions()[2], tx0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_prioritize_reimported_transactions_within_same_nonce_height() {
|
||||
// given
|
||||
@@ -1695,6 +1860,38 @@ mod test {
|
||||
assert_eq!(top.len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_penalize_local_transactions() {
|
||||
// given
|
||||
let mut txq = TransactionQueue::default();
|
||||
// txa, txb - slightly bigger gas price to have consistent ordering
|
||||
let (txa, txb) = new_tx_pair_default(1.into(), 0.into());
|
||||
let (tx1, tx2) = new_tx_pair_with_gas_price_increment(3.into());
|
||||
|
||||
// insert everything
|
||||
txq.add(txa.clone(), TransactionOrigin::Local, &default_account_details, &gas_estimator).unwrap();
|
||||
txq.add(txb.clone(), TransactionOrigin::Local, &default_account_details, &gas_estimator).unwrap();
|
||||
txq.add(tx1.clone(), TransactionOrigin::Local, &default_account_details, &gas_estimator).unwrap();
|
||||
txq.add(tx2.clone(), TransactionOrigin::Local, &default_account_details, &gas_estimator).unwrap();
|
||||
|
||||
let top = txq.top_transactions();
|
||||
assert_eq!(top[0], tx1);
|
||||
assert_eq!(top[1], txa);
|
||||
assert_eq!(top[2], tx2);
|
||||
assert_eq!(top[3], txb);
|
||||
assert_eq!(top.len(), 4);
|
||||
|
||||
// when
|
||||
txq.penalize(&tx1.hash());
|
||||
|
||||
// then (order is the same)
|
||||
let top = txq.top_transactions();
|
||||
assert_eq!(top[0], tx1);
|
||||
assert_eq!(top[1], txa);
|
||||
assert_eq!(top[2], tx2);
|
||||
assert_eq!(top[3], txb);
|
||||
assert_eq!(top.len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_penalize_transactions_from_sender() {
|
||||
@@ -1940,12 +2137,11 @@ mod test {
|
||||
let mut txq = TransactionQueue::with_limits(PrioritizationStrategy::GasPriceOnly, 100, default_gas_val() * U256::from(2), !U256::zero());
|
||||
let (tx1, tx2) = new_tx_pair_default(U256::from(1), U256::from(1));
|
||||
let (tx3, tx4) = new_tx_pair_default(U256::from(1), U256::from(2));
|
||||
let (tx5, tx6) = new_tx_pair_default(U256::from(1), U256::from(2));
|
||||
let (tx5, _) = new_tx_pair_default(U256::from(1), U256::from(2));
|
||||
txq.add(tx1.clone(), TransactionOrigin::Local, &default_account_details, &gas_estimator).unwrap();
|
||||
txq.add(tx2.clone(), TransactionOrigin::Local, &default_account_details, &gas_estimator).unwrap();
|
||||
txq.add(tx5.clone(), TransactionOrigin::External, &default_account_details, &gas_estimator).unwrap();
|
||||
// Not accepted because of limit
|
||||
txq.add(tx6.clone(), TransactionOrigin::External, &default_account_details, &gas_estimator).unwrap_err();
|
||||
txq.add(tx5.clone(), TransactionOrigin::External, &default_account_details, &gas_estimator).unwrap_err();
|
||||
txq.add(tx3.clone(), TransactionOrigin::Local, &default_account_details, &gas_estimator).unwrap();
|
||||
txq.add(tx4.clone(), TransactionOrigin::Local, &default_account_details, &gas_estimator).unwrap();
|
||||
assert_eq!(txq.status().pending, 4);
|
||||
|
||||
Reference in New Issue
Block a user