2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-02-05 13:40:41 +01:00
|
|
|
// 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/>.
|
|
|
|
|
2016-01-27 17:08:59 +01:00
|
|
|
//! Eth rpc implementation.
|
2016-03-26 18:51:27 +01:00
|
|
|
|
2016-06-28 18:46:09 +02:00
|
|
|
use std::thread;
|
|
|
|
use std::time::{Instant, Duration};
|
2017-05-28 14:40:36 +02:00
|
|
|
use std::sync::Arc;
|
2017-01-11 20:02:27 +01:00
|
|
|
|
2017-03-22 14:41:46 +01:00
|
|
|
use rlp::{self, UntrustedRlp};
|
2016-08-23 17:07:00 +02:00
|
|
|
use time::get_time;
|
2017-09-04 16:36:49 +02:00
|
|
|
use bigint::prelude::U256;
|
|
|
|
use bigint::hash::{H64, H160, H256};
|
|
|
|
use util::Address;
|
2017-09-02 20:09:13 +02:00
|
|
|
use parking_lot::Mutex;
|
2017-01-11 20:02:27 +01:00
|
|
|
|
|
|
|
use ethash::SeedHashCompute;
|
2017-01-30 11:10:58 +01:00
|
|
|
use ethcore::account_provider::{AccountProvider, DappId};
|
2016-03-14 14:18:29 +01:00
|
|
|
use ethcore::block::IsBlock;
|
2017-01-11 20:02:27 +01:00
|
|
|
use ethcore::client::{MiningBlockChainClient, BlockId, TransactionId, UncleId};
|
2016-02-29 19:30:13 +01:00
|
|
|
use ethcore::ethereum::Ethash;
|
2016-05-24 21:56:32 +02:00
|
|
|
use ethcore::filter::Filter as EthcoreFilter;
|
2017-01-11 20:02:27 +01:00
|
|
|
use ethcore::header::{Header as BlockHeader, BlockNumber as EthBlockNumber};
|
|
|
|
use ethcore::log_entry::LogEntry;
|
|
|
|
use ethcore::miner::{MinerService, ExternalMinerService};
|
2017-03-14 13:04:32 +01:00
|
|
|
use ethcore::transaction::SignedTransaction;
|
2016-10-31 17:32:53 +01:00
|
|
|
use ethcore::snapshot::SnapshotService;
|
2017-01-11 20:02:27 +01:00
|
|
|
use ethsync::{SyncProvider};
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
use jsonrpc_core::{BoxFuture, Error};
|
|
|
|
use jsonrpc_core::futures::future;
|
2017-01-11 20:02:27 +01:00
|
|
|
use jsonrpc_macros::Trailing;
|
|
|
|
|
2017-03-14 13:04:32 +01:00
|
|
|
use v1::helpers::{errors, limit_logs, fake_sign};
|
2017-11-01 11:23:18 +01:00
|
|
|
use v1::helpers::dispatch::{FullDispatcher, default_gas_price};
|
2017-01-30 21:08:36 +01:00
|
|
|
use v1::helpers::block_import::is_major_importing;
|
2017-03-29 17:07:58 +02:00
|
|
|
use v1::helpers::accounts::unwrap_provider;
|
2016-06-01 19:37:34 +02:00
|
|
|
use v1::traits::Eth;
|
2016-09-23 19:42:33 +02:00
|
|
|
use v1::types::{
|
2016-11-04 17:35:02 +01:00
|
|
|
RichBlock, Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo,
|
2017-01-11 20:02:27 +01:00
|
|
|
Transaction, CallRequest, Index, Filter, Log, Receipt, Work,
|
2016-09-23 19:42:33 +02:00
|
|
|
H64 as RpcH64, H256 as RpcH256, H160 as RpcH160, U256 as RpcU256,
|
|
|
|
};
|
2017-01-11 20:02:27 +01:00
|
|
|
use v1::metadata::Metadata;
|
2016-01-21 01:19:29 +01:00
|
|
|
|
2016-11-04 17:35:02 +01:00
|
|
|
const EXTRA_INFO_PROOF: &'static str = "Object exists in in blockchain (fetched earlier), extra_info is always available if object exists; qed";
|
|
|
|
|
2016-08-03 15:31:00 +02:00
|
|
|
/// Eth RPC options
|
|
|
|
pub struct EthClientOptions {
|
2017-03-10 10:25:13 +01:00
|
|
|
/// Return nonce from transaction queue when pending block not available.
|
|
|
|
pub pending_nonce_from_queue: bool,
|
2016-08-03 15:31:00 +02:00
|
|
|
/// Returns receipt from pending blocks
|
|
|
|
pub allow_pending_receipt_query: bool,
|
|
|
|
/// Send additional block number when asking for work
|
|
|
|
pub send_block_number_in_get_work: bool,
|
|
|
|
}
|
|
|
|
|
2017-03-10 10:25:13 +01:00
|
|
|
impl EthClientOptions {
|
|
|
|
/// Creates new default `EthClientOptions` and allows alterations
|
|
|
|
/// by provided function.
|
|
|
|
pub fn with<F: Fn(&mut Self)>(fun: F) -> Self {
|
|
|
|
let mut options = Self::default();
|
|
|
|
fun(&mut options);
|
|
|
|
options
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-03 15:31:00 +02:00
|
|
|
impl Default for EthClientOptions {
|
|
|
|
fn default() -> Self {
|
|
|
|
EthClientOptions {
|
2017-03-10 10:25:13 +01:00
|
|
|
pending_nonce_from_queue: false,
|
2016-08-03 15:31:00 +02:00
|
|
|
allow_pending_receipt_query: true,
|
|
|
|
send_block_number_in_get_work: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-27 17:08:59 +01:00
|
|
|
/// Eth rpc implementation.
|
2016-10-31 17:32:53 +01:00
|
|
|
pub struct EthClient<C, SN: ?Sized, S: ?Sized, M, EM> where
|
2016-05-31 21:31:42 +02:00
|
|
|
C: MiningBlockChainClient,
|
2016-10-31 17:32:53 +01:00
|
|
|
SN: SnapshotService,
|
2016-05-22 12:42:22 +02:00
|
|
|
S: SyncProvider,
|
|
|
|
M: MinerService,
|
|
|
|
EM: ExternalMinerService {
|
2016-05-23 11:30:11 +02:00
|
|
|
|
2017-05-28 14:40:36 +02:00
|
|
|
client: Arc<C>,
|
|
|
|
snapshot: Arc<SN>,
|
|
|
|
sync: Arc<S>,
|
|
|
|
accounts: Option<Arc<AccountProvider>>,
|
|
|
|
miner: Arc<M>,
|
2016-04-21 17:32:53 +02:00
|
|
|
external_miner: Arc<EM>,
|
2016-03-26 18:51:27 +01:00
|
|
|
seed_compute: Mutex<SeedHashCompute>,
|
2016-08-03 15:31:00 +02:00
|
|
|
options: EthClientOptions,
|
2017-04-19 14:30:00 +02:00
|
|
|
eip86_transition: u64,
|
2016-01-21 01:19:29 +01:00
|
|
|
}
|
|
|
|
|
2016-10-31 17:32:53 +01:00
|
|
|
impl<C, SN: ?Sized, S: ?Sized, M, EM> EthClient<C, SN, S, M, EM> where
|
2016-05-31 21:31:42 +02:00
|
|
|
C: MiningBlockChainClient,
|
2016-10-31 17:32:53 +01:00
|
|
|
SN: SnapshotService,
|
2016-05-22 12:42:22 +02:00
|
|
|
S: SyncProvider,
|
|
|
|
M: MinerService,
|
|
|
|
EM: ExternalMinerService {
|
2016-03-14 14:18:29 +01:00
|
|
|
|
2016-04-21 17:32:53 +02:00
|
|
|
/// Creates new EthClient.
|
2016-10-31 17:32:53 +01:00
|
|
|
pub fn new(
|
|
|
|
client: &Arc<C>,
|
|
|
|
snapshot: &Arc<SN>,
|
|
|
|
sync: &Arc<S>,
|
2017-03-29 17:07:58 +02:00
|
|
|
accounts: &Option<Arc<AccountProvider>>,
|
2016-10-31 17:32:53 +01:00
|
|
|
miner: &Arc<M>,
|
|
|
|
em: &Arc<EM>,
|
|
|
|
options: EthClientOptions
|
|
|
|
) -> Self {
|
2016-01-21 01:19:29 +01:00
|
|
|
EthClient {
|
2017-05-28 14:40:36 +02:00
|
|
|
client: client.clone(),
|
|
|
|
snapshot: snapshot.clone(),
|
|
|
|
sync: sync.clone(),
|
|
|
|
miner: miner.clone(),
|
|
|
|
accounts: accounts.clone(),
|
2016-04-21 17:32:53 +02:00
|
|
|
external_miner: em.clone(),
|
2016-03-26 18:51:27 +01:00
|
|
|
seed_compute: Mutex::new(SeedHashCompute::new()),
|
2016-08-03 15:31:00 +02:00
|
|
|
options: options,
|
2017-04-19 14:30:00 +02:00
|
|
|
eip86_transition: client.eip86_transition(),
|
2016-01-21 01:19:29 +01:00
|
|
|
}
|
|
|
|
}
|
2016-02-10 22:54:12 +01:00
|
|
|
|
2017-03-29 17:07:58 +02:00
|
|
|
/// Attempt to get the `Arc<AccountProvider>`, errors if provider was not
|
2017-05-28 14:40:36 +02:00
|
|
|
/// set.
|
2017-03-29 17:07:58 +02:00
|
|
|
fn account_provider(&self) -> Result<Arc<AccountProvider>, Error> {
|
|
|
|
unwrap_provider(&self.accounts)
|
|
|
|
}
|
|
|
|
|
2016-12-09 23:01:43 +01:00
|
|
|
fn block(&self, id: BlockId, include_txs: bool) -> Result<Option<RichBlock>, Error> {
|
2017-05-28 14:40:36 +02:00
|
|
|
let client = &self.client;
|
2016-02-29 11:58:33 +01:00
|
|
|
match (client.block(id.clone()), client.block_total_difficulty(id)) {
|
2016-12-28 13:44:51 +01:00
|
|
|
(Some(block), Some(total_difficulty)) => {
|
|
|
|
let view = block.header_view();
|
|
|
|
Ok(Some(RichBlock {
|
2017-04-03 11:37:07 +02:00
|
|
|
inner: Block {
|
2017-08-31 11:35:41 +02:00
|
|
|
hash: Some(view.hash().into()),
|
2016-12-28 13:44:51 +01:00
|
|
|
size: Some(block.rlp().as_raw().len().into()),
|
2016-11-04 17:35:02 +01:00
|
|
|
parent_hash: view.parent_hash().into(),
|
|
|
|
uncles_hash: view.uncles_hash().into(),
|
|
|
|
author: view.author().into(),
|
|
|
|
miner: view.author().into(),
|
|
|
|
state_root: view.state_root().into(),
|
|
|
|
transactions_root: view.transactions_root().into(),
|
|
|
|
receipts_root: view.receipts_root().into(),
|
|
|
|
number: Some(view.number().into()),
|
|
|
|
gas_used: view.gas_used().into(),
|
|
|
|
gas_limit: view.gas_limit().into(),
|
|
|
|
logs_bloom: view.log_bloom().into(),
|
|
|
|
timestamp: view.timestamp().into(),
|
|
|
|
difficulty: view.difficulty().into(),
|
2017-02-06 15:28:16 +01:00
|
|
|
total_difficulty: Some(total_difficulty.into()),
|
2017-01-24 21:57:29 +01:00
|
|
|
seal_fields: view.seal().into_iter().map(Into::into).collect(),
|
2016-12-28 13:44:51 +01:00
|
|
|
uncles: block.uncle_hashes().into_iter().map(Into::into).collect(),
|
2016-11-04 17:35:02 +01:00
|
|
|
transactions: match include_txs {
|
2017-04-19 14:30:00 +02:00
|
|
|
true => BlockTransactions::Full(block.view().localized_transactions().into_iter().map(|t| Transaction::from_localized(t, self.eip86_transition)).collect()),
|
2016-12-28 13:44:51 +01:00
|
|
|
false => BlockTransactions::Hashes(block.transaction_hashes().into_iter().map(Into::into).collect()),
|
2016-11-04 17:35:02 +01:00
|
|
|
},
|
|
|
|
extra_data: Bytes::new(view.extra_data()),
|
2016-02-10 22:54:12 +01:00
|
|
|
},
|
2016-11-04 17:35:02 +01:00
|
|
|
extra_info: client.block_extra_info(id.clone()).expect(EXTRA_INFO_PROOF),
|
2016-12-28 13:44:51 +01:00
|
|
|
}))
|
2016-02-10 22:54:12 +01:00
|
|
|
},
|
2016-09-23 19:42:33 +02:00
|
|
|
_ => Ok(None)
|
2016-02-10 22:54:12 +01:00
|
|
|
}
|
|
|
|
}
|
2016-02-29 11:58:33 +01:00
|
|
|
|
2016-12-09 23:01:43 +01:00
|
|
|
fn transaction(&self, id: TransactionId) -> Result<Option<Transaction>, Error> {
|
2017-05-28 14:40:36 +02:00
|
|
|
match self.client.transaction(id) {
|
2017-04-19 14:30:00 +02:00
|
|
|
Some(t) => Ok(Some(Transaction::from_localized(t, self.eip86_transition))),
|
2016-09-23 19:42:33 +02:00
|
|
|
None => Ok(None),
|
2016-02-10 22:54:12 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-14 17:01:10 +01:00
|
|
|
|
2016-12-09 23:01:43 +01:00
|
|
|
fn uncle(&self, id: UncleId) -> Result<Option<RichBlock>, Error> {
|
2017-05-28 14:40:36 +02:00
|
|
|
let client = &self.client;
|
2016-07-01 20:37:17 +02:00
|
|
|
let uncle: BlockHeader = match client.uncle(id) {
|
2016-12-28 13:44:51 +01:00
|
|
|
Some(hdr) => hdr.decode(),
|
2016-09-23 19:42:33 +02:00
|
|
|
None => { return Ok(None); }
|
2016-07-01 20:37:17 +02:00
|
|
|
};
|
2016-12-09 23:01:43 +01:00
|
|
|
let parent_difficulty = match client.block_total_difficulty(BlockId::Hash(uncle.parent_hash().clone())) {
|
2016-07-01 20:37:17 +02:00
|
|
|
Some(difficulty) => difficulty,
|
2016-09-23 19:42:33 +02:00
|
|
|
None => { return Ok(None); }
|
2016-07-01 20:37:17 +02:00
|
|
|
};
|
|
|
|
|
2017-03-02 12:29:18 +01:00
|
|
|
let size = client.block(BlockId::Hash(uncle.hash()))
|
|
|
|
.map(|block| block.into_inner().len())
|
|
|
|
.map(U256::from)
|
|
|
|
.map(Into::into);
|
|
|
|
|
2016-11-04 17:35:02 +01:00
|
|
|
let block = RichBlock {
|
2017-04-03 11:37:07 +02:00
|
|
|
inner: Block {
|
2016-11-04 17:35:02 +01:00
|
|
|
hash: Some(uncle.hash().into()),
|
2017-03-02 12:29:18 +01:00
|
|
|
size: size,
|
2016-11-04 17:35:02 +01:00
|
|
|
parent_hash: uncle.parent_hash().clone().into(),
|
|
|
|
uncles_hash: uncle.uncles_hash().clone().into(),
|
|
|
|
author: uncle.author().clone().into(),
|
|
|
|
miner: uncle.author().clone().into(),
|
|
|
|
state_root: uncle.state_root().clone().into(),
|
|
|
|
transactions_root: uncle.transactions_root().clone().into(),
|
|
|
|
number: Some(uncle.number().into()),
|
|
|
|
gas_used: uncle.gas_used().clone().into(),
|
|
|
|
gas_limit: uncle.gas_limit().clone().into(),
|
|
|
|
logs_bloom: uncle.log_bloom().clone().into(),
|
|
|
|
timestamp: uncle.timestamp().into(),
|
|
|
|
difficulty: uncle.difficulty().clone().into(),
|
2017-02-06 15:28:16 +01:00
|
|
|
total_difficulty: Some((uncle.difficulty().clone() + parent_difficulty).into()),
|
2016-11-04 17:35:02 +01:00
|
|
|
receipts_root: uncle.receipts_root().clone().into(),
|
|
|
|
extra_data: uncle.extra_data().clone().into(),
|
2017-01-24 21:57:29 +01:00
|
|
|
seal_fields: uncle.seal().into_iter().cloned().map(Into::into).collect(),
|
2016-11-04 17:35:02 +01:00
|
|
|
uncles: vec![],
|
|
|
|
transactions: BlockTransactions::Hashes(vec![]),
|
|
|
|
},
|
|
|
|
extra_info: client.uncle_extra_info(id).expect(EXTRA_INFO_PROOF),
|
2016-07-01 20:37:17 +02:00
|
|
|
};
|
2016-09-23 19:42:33 +02:00
|
|
|
Ok(Some(block))
|
2016-03-14 17:01:10 +01:00
|
|
|
}
|
2016-03-22 17:17:50 +01:00
|
|
|
|
2017-01-30 11:10:58 +01:00
|
|
|
fn dapp_accounts(&self, dapp: DappId) -> Result<Vec<H160>, Error> {
|
2017-03-29 17:07:58 +02:00
|
|
|
let store = self.account_provider()?;
|
2017-01-30 11:10:58 +01:00
|
|
|
store
|
|
|
|
.note_dapp_used(dapp.clone())
|
2017-02-20 16:33:12 +01:00
|
|
|
.and_then(|_| store.dapp_addresses(dapp))
|
2017-03-10 10:25:13 +01:00
|
|
|
.map_err(|e| errors::account("Could not fetch accounts.", e))
|
2017-01-30 11:10:58 +01:00
|
|
|
}
|
2016-01-21 01:19:29 +01:00
|
|
|
}
|
2016-03-22 17:17:50 +01:00
|
|
|
|
2016-10-07 12:13:15 +02:00
|
|
|
pub fn pending_logs<M>(miner: &M, best_block: EthBlockNumber, filter: &EthcoreFilter) -> Vec<Log> where M: MinerService {
|
|
|
|
let receipts = miner.pending_receipts(best_block);
|
2016-06-01 19:37:34 +02:00
|
|
|
|
|
|
|
let pending_logs = receipts.into_iter()
|
|
|
|
.flat_map(|(hash, r)| r.logs.into_iter().map(|l| (hash.clone(), l)).collect::<Vec<(H256, LogEntry)>>())
|
|
|
|
.collect::<Vec<(H256, LogEntry)>>();
|
|
|
|
|
|
|
|
let result = pending_logs.into_iter()
|
|
|
|
.filter(|pair| filter.matches(&pair.1))
|
|
|
|
.map(|pair| {
|
|
|
|
let mut log = Log::from(pair.1);
|
2016-07-06 11:23:29 +02:00
|
|
|
log.transaction_hash = Some(pair.0.into());
|
2016-06-01 19:37:34 +02:00
|
|
|
log
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2016-12-23 18:46:17 +01:00
|
|
|
fn check_known<C>(client: &C, number: BlockNumber) -> Result<(), Error> where C: MiningBlockChainClient {
|
|
|
|
use ethcore::block_status::BlockStatus;
|
|
|
|
|
|
|
|
match client.block_status(number.into()) {
|
|
|
|
BlockStatus::InChain => Ok(()),
|
2017-08-04 15:58:14 +02:00
|
|
|
BlockStatus::Pending => Ok(()),
|
2016-12-23 18:46:17 +01:00
|
|
|
_ => Err(errors::unknown_block()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-24 15:13:43 +01:00
|
|
|
const MAX_QUEUE_SIZE_TO_MINE_ON: usize = 4; // because uncles go back 6.
|
2016-03-22 17:17:50 +01:00
|
|
|
|
2016-10-31 17:32:53 +01:00
|
|
|
impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
2016-05-31 21:31:42 +02:00
|
|
|
C: MiningBlockChainClient + 'static,
|
2016-10-31 17:32:53 +01:00
|
|
|
SN: SnapshotService + 'static,
|
2016-05-22 12:42:22 +02:00
|
|
|
S: SyncProvider + 'static,
|
|
|
|
M: MinerService + 'static,
|
2017-01-11 20:02:27 +01:00
|
|
|
EM: ExternalMinerService + 'static,
|
|
|
|
{
|
|
|
|
type Metadata = Metadata;
|
2016-03-11 14:26:23 +01:00
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn protocol_version(&self) -> Result<String, Error> {
|
2017-05-28 14:40:36 +02:00
|
|
|
let version = self.sync.status().protocol_version.to_owned();
|
2016-09-23 19:42:33 +02:00
|
|
|
Ok(format!("{}", version))
|
2016-01-21 01:19:29 +01:00
|
|
|
}
|
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn syncing(&self) -> Result<SyncStatus, Error> {
|
2016-10-31 17:32:53 +01:00
|
|
|
use ethcore::snapshot::RestorationStatus;
|
|
|
|
|
2017-05-28 14:40:36 +02:00
|
|
|
let status = self.sync.status();
|
|
|
|
let client = &self.client;
|
|
|
|
let snapshot_status = self.snapshot.status();
|
2016-10-31 17:32:53 +01:00
|
|
|
|
|
|
|
let (warping, warp_chunks_amount, warp_chunks_processed) = match snapshot_status {
|
|
|
|
RestorationStatus::Ongoing { state_chunks, block_chunks, state_chunks_done, block_chunks_done } =>
|
|
|
|
(true, Some(block_chunks + state_chunks), Some(block_chunks_done + state_chunks_done)),
|
|
|
|
_ => (false, None, None),
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if warping || is_major_importing(Some(status.state), client.queue_info()) {
|
|
|
|
let chain_info = client.chain_info();
|
|
|
|
let current_block = U256::from(chain_info.best_block_number);
|
2016-10-19 18:35:39 +02:00
|
|
|
let highest_block = U256::from(status.highest_block_number.unwrap_or(status.start_block_number));
|
2016-12-19 15:27:17 +01:00
|
|
|
|
2016-10-19 18:35:39 +02:00
|
|
|
let info = SyncInfo {
|
|
|
|
starting_block: status.start_block_number.into(),
|
|
|
|
current_block: current_block.into(),
|
|
|
|
highest_block: highest_block.into(),
|
2016-10-31 17:32:53 +01:00
|
|
|
warp_chunks_amount: warp_chunks_amount.map(|x| U256::from(x as u64)).map(Into::into),
|
|
|
|
warp_chunks_processed: warp_chunks_processed.map(|x| U256::from(x as u64)).map(Into::into),
|
2016-10-19 18:35:39 +02:00
|
|
|
};
|
|
|
|
Ok(SyncStatus::Info(info))
|
|
|
|
} else {
|
|
|
|
Ok(SyncStatus::None)
|
2016-09-23 19:42:33 +02:00
|
|
|
}
|
2016-02-05 13:21:34 +01:00
|
|
|
}
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
fn author(&self, meta: Metadata) -> Result<RpcH160, Error> {
|
2017-02-14 22:45:43 +01:00
|
|
|
let dapp = meta.dapp_id();
|
2017-01-30 11:10:58 +01:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
let mut miner = self.miner.author();
|
|
|
|
if miner == 0.into() {
|
|
|
|
miner = self.dapp_accounts(dapp.into())?.get(0).cloned().unwrap_or_default();
|
|
|
|
}
|
2016-08-08 17:25:15 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
Ok(RpcH160::from(miner))
|
2016-01-21 01:19:29 +01:00
|
|
|
}
|
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn is_mining(&self) -> Result<bool, Error> {
|
2017-07-12 08:52:18 +02:00
|
|
|
Ok(self.miner.is_currently_sealing())
|
2016-01-21 11:25:39 +01:00
|
|
|
}
|
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn hashrate(&self) -> Result<RpcU256, Error> {
|
|
|
|
Ok(RpcU256::from(self.external_miner.hashrate()))
|
2016-01-21 01:19:29 +01:00
|
|
|
}
|
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn gas_price(&self) -> Result<RpcU256, Error> {
|
2017-05-28 14:40:36 +02:00
|
|
|
Ok(RpcU256::from(default_gas_price(&*self.client, &*self.miner)))
|
2016-01-21 01:19:29 +01:00
|
|
|
}
|
2016-01-21 11:25:39 +01:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
fn accounts(&self, meta: Metadata) -> Result<Vec<RpcH160>, Error> {
|
2017-02-14 22:45:43 +01:00
|
|
|
let dapp = meta.dapp_id();
|
2016-08-08 17:25:15 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
let accounts = self.dapp_accounts(dapp.into())?;
|
|
|
|
Ok(accounts.into_iter().map(Into::into).collect())
|
2016-03-12 19:21:08 +01:00
|
|
|
}
|
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn block_number(&self) -> Result<RpcU256, Error> {
|
2017-05-28 14:40:36 +02:00
|
|
|
Ok(RpcU256::from(self.client.chain_info().best_block_number))
|
2016-01-21 11:25:39 +01:00
|
|
|
}
|
2016-01-26 00:42:07 +01:00
|
|
|
|
2017-02-03 16:20:43 +01:00
|
|
|
fn balance(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> {
|
2016-09-23 19:42:33 +02:00
|
|
|
let address = address.into();
|
2017-02-03 17:41:25 +01:00
|
|
|
|
2017-08-04 15:58:14 +02:00
|
|
|
let id = num.unwrap_or_default();
|
|
|
|
|
|
|
|
try_bf!(check_known(&*self.client, id.clone()));
|
|
|
|
let res = match self.client.balance(&address, id.into()) {
|
|
|
|
Some(balance) => Ok(balance.into()),
|
|
|
|
None => Err(errors::state_pruned()),
|
2017-02-03 17:41:25 +01:00
|
|
|
};
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::done(res))
|
2016-03-12 19:51:24 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 17:41:25 +01:00
|
|
|
fn storage_at(&self, address: RpcH160, pos: RpcU256, num: Trailing<BlockNumber>) -> BoxFuture<RpcH256, Error> {
|
2016-09-23 19:42:33 +02:00
|
|
|
let address: Address = RpcH160::into(address);
|
|
|
|
let position: U256 = RpcU256::into(pos);
|
2017-02-03 17:41:25 +01:00
|
|
|
|
2017-08-04 15:58:14 +02:00
|
|
|
let id = num.unwrap_or_default();
|
|
|
|
|
|
|
|
try_bf!(check_known(&*self.client, id.clone()));
|
|
|
|
let res = match self.client.storage_at(&address, &H256::from(position), id.into()) {
|
|
|
|
Some(s) => Ok(s.into()),
|
|
|
|
None => Err(errors::state_pruned()),
|
2017-02-03 17:41:25 +01:00
|
|
|
};
|
2016-03-13 12:09:30 +01:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::done(res))
|
2017-02-03 17:41:25 +01:00
|
|
|
}
|
2016-09-23 19:42:33 +02:00
|
|
|
|
2017-02-03 17:41:25 +01:00
|
|
|
fn transaction_count(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> {
|
2016-09-23 19:42:33 +02:00
|
|
|
let address: Address = RpcH160::into(address);
|
2017-03-10 10:25:13 +01:00
|
|
|
|
2017-06-13 16:29:35 +02:00
|
|
|
let res = match num.unwrap_or_default() {
|
2017-03-10 10:25:13 +01:00
|
|
|
BlockNumber::Pending if self.options.pending_nonce_from_queue => {
|
2017-05-28 14:40:36 +02:00
|
|
|
let nonce = self.miner.last_nonce(&address)
|
2017-03-10 10:25:13 +01:00
|
|
|
.map(|n| n + 1.into())
|
2017-08-04 15:58:14 +02:00
|
|
|
.or_else(|| self.client.nonce(&address, BlockNumber::Pending.into()));
|
2017-03-10 10:25:13 +01:00
|
|
|
match nonce {
|
|
|
|
Some(nonce) => Ok(nonce.into()),
|
2017-07-04 17:01:06 +02:00
|
|
|
None => Err(errors::database("latest nonce missing"))
|
2017-03-10 10:25:13 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-09 20:38:43 +01:00
|
|
|
id => {
|
2017-05-28 14:40:36 +02:00
|
|
|
try_bf!(check_known(&*self.client, id.clone()));
|
|
|
|
match self.client.nonce(&address, id.into()) {
|
2017-02-09 20:38:43 +01:00
|
|
|
Some(nonce) => Ok(nonce.into()),
|
|
|
|
None => Err(errors::state_pruned()),
|
2016-12-23 18:46:17 +01:00
|
|
|
}
|
2016-09-23 19:42:33 +02:00
|
|
|
}
|
2017-02-03 17:41:25 +01:00
|
|
|
};
|
2016-03-13 14:37:33 +01:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::done(res))
|
2016-02-05 13:21:34 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 17:41:25 +01:00
|
|
|
fn block_transaction_count_by_hash(&self, hash: RpcH256) -> BoxFuture<Option<RpcU256>, Error> {
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::ok(self.client.block(BlockId::Hash(hash.into()))
|
|
|
|
.map(|block| block.transactions_count().into())))
|
2016-02-25 16:58:18 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 17:41:25 +01:00
|
|
|
fn block_transaction_count_by_number(&self, num: BlockNumber) -> BoxFuture<Option<RpcU256>, Error> {
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::ok(match num {
|
2017-02-09 20:38:43 +01:00
|
|
|
BlockNumber::Pending => Some(
|
2017-05-28 14:40:36 +02:00
|
|
|
self.miner.status().transactions_in_pending_block.into()
|
2017-02-09 20:38:43 +01:00
|
|
|
),
|
|
|
|
_ =>
|
2017-05-28 14:40:36 +02:00
|
|
|
self.client.block(num.into())
|
2017-02-09 20:38:43 +01:00
|
|
|
.map(|block| block.transactions_count().into())
|
2017-10-05 12:35:01 +02:00
|
|
|
}))
|
2016-03-13 14:37:33 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 17:41:25 +01:00
|
|
|
fn block_uncles_count_by_hash(&self, hash: RpcH256) -> BoxFuture<Option<RpcU256>, Error> {
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::ok(self.client.block(BlockId::Hash(hash.into()))
|
|
|
|
.map(|block| block.uncles_count().into())))
|
2016-01-26 00:42:07 +01:00
|
|
|
}
|
2016-01-26 11:37:24 +01:00
|
|
|
|
2017-02-03 17:41:25 +01:00
|
|
|
fn block_uncles_count_by_number(&self, num: BlockNumber) -> BoxFuture<Option<RpcU256>, Error> {
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::ok(match num {
|
2017-02-09 20:38:43 +01:00
|
|
|
BlockNumber::Pending => Some(0.into()),
|
2017-05-28 14:40:36 +02:00
|
|
|
_ => self.client.block(num.into())
|
2017-02-09 20:38:43 +01:00
|
|
|
.map(|block| block.uncles_count().into()
|
|
|
|
),
|
2017-10-05 12:35:01 +02:00
|
|
|
}))
|
2017-02-03 17:41:25 +01:00
|
|
|
}
|
2016-09-23 19:42:33 +02:00
|
|
|
|
2017-02-03 17:41:25 +01:00
|
|
|
fn code_at(&self, address: RpcH160, num: Trailing<BlockNumber>) -> BoxFuture<Bytes, Error> {
|
2016-09-23 19:42:33 +02:00
|
|
|
let address: Address = RpcH160::into(address);
|
2017-02-03 17:41:25 +01:00
|
|
|
|
2017-08-04 15:58:14 +02:00
|
|
|
let id = num.unwrap_or_default();
|
|
|
|
try_bf!(check_known(&*self.client, id.clone()));
|
|
|
|
|
|
|
|
let res = match self.client.code(&address, id.into()) {
|
|
|
|
Some(code) => Ok(code.map_or_else(Bytes::default, Bytes::new)),
|
|
|
|
None => Err(errors::state_pruned()),
|
2017-02-03 17:41:25 +01:00
|
|
|
};
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::done(res))
|
2016-02-08 10:58:08 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 17:41:25 +01:00
|
|
|
fn block_by_hash(&self, hash: RpcH256, include_txs: bool) -> BoxFuture<Option<RichBlock>, Error> {
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::done(self.block(BlockId::Hash(hash.into()), include_txs)))
|
2016-02-10 22:54:12 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 17:41:25 +01:00
|
|
|
fn block_by_number(&self, num: BlockNumber, include_txs: bool) -> BoxFuture<Option<RichBlock>, Error> {
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::done(self.block(num.into(), include_txs)))
|
2016-01-26 11:37:24 +01:00
|
|
|
}
|
2016-02-09 13:17:44 +01:00
|
|
|
|
2017-10-08 18:19:27 +02:00
|
|
|
fn transaction_by_hash(&self, hash: RpcH256) -> BoxFuture<Option<Transaction>, Error> {
|
2016-09-23 19:42:33 +02:00
|
|
|
let hash: H256 = hash.into();
|
2017-05-28 14:40:36 +02:00
|
|
|
let block_number = self.client.chain_info().best_block_number;
|
2017-10-08 18:19:27 +02:00
|
|
|
let tx = try_bf!(self.transaction(TransactionId::Hash(hash))).or_else(|| {
|
|
|
|
self.miner.transaction(block_number, &hash)
|
|
|
|
.map(|t| Transaction::from_pending(t, block_number, self.eip86_transition))
|
|
|
|
});
|
|
|
|
|
|
|
|
Box::new(future::ok(tx))
|
2016-02-10 11:28:40 +01:00
|
|
|
}
|
|
|
|
|
2017-10-08 18:19:27 +02:00
|
|
|
fn transaction_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> BoxFuture<Option<Transaction>, Error> {
|
|
|
|
Box::new(future::done(
|
|
|
|
self.transaction(TransactionId::Location(BlockId::Hash(hash.into()), index.value()))
|
|
|
|
))
|
2016-02-10 11:28:40 +01:00
|
|
|
}
|
|
|
|
|
2017-10-08 18:19:27 +02:00
|
|
|
fn transaction_by_block_number_and_index(&self, num: BlockNumber, index: Index) -> BoxFuture<Option<Transaction>, Error> {
|
|
|
|
Box::new(future::done(
|
|
|
|
self.transaction(TransactionId::Location(num.into(), index.value()))
|
|
|
|
))
|
2016-02-09 13:17:44 +01:00
|
|
|
}
|
2016-02-15 13:18:26 +01:00
|
|
|
|
2017-10-08 18:19:27 +02:00
|
|
|
fn transaction_receipt(&self, hash: RpcH256) -> BoxFuture<Option<Receipt>, Error> {
|
2017-05-28 14:40:36 +02:00
|
|
|
let best_block = self.client.chain_info().best_block_number;
|
2016-09-23 19:42:33 +02:00
|
|
|
let hash: H256 = hash.into();
|
2017-10-08 18:19:27 +02:00
|
|
|
|
2017-05-28 14:40:36 +02:00
|
|
|
match (self.miner.pending_receipt(best_block, &hash), self.options.allow_pending_receipt_query) {
|
2017-10-08 18:19:27 +02:00
|
|
|
(Some(receipt), true) => Box::new(future::ok(Some(receipt.into()))),
|
2016-09-23 19:42:33 +02:00
|
|
|
_ => {
|
2017-05-28 14:40:36 +02:00
|
|
|
let receipt = self.client.transaction_receipt(TransactionId::Hash(hash));
|
2017-10-08 18:19:27 +02:00
|
|
|
Box::new(future::ok(receipt.map(Into::into)))
|
2016-09-23 19:42:33 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-20 17:29:39 +01:00
|
|
|
}
|
|
|
|
|
2017-10-08 18:19:27 +02:00
|
|
|
fn uncle_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> BoxFuture<Option<RichBlock>, Error> {
|
|
|
|
Box::new(future::done(self.uncle(UncleId {
|
|
|
|
block: BlockId::Hash(hash.into()),
|
|
|
|
position: index.value()
|
|
|
|
})))
|
2016-03-14 17:01:10 +01:00
|
|
|
}
|
|
|
|
|
2017-10-08 18:19:27 +02:00
|
|
|
fn uncle_by_block_number_and_index(&self, num: BlockNumber, index: Index) -> BoxFuture<Option<RichBlock>, Error> {
|
|
|
|
Box::new(future::done(self.uncle(UncleId {
|
|
|
|
block: num.into(),
|
|
|
|
position: index.value()
|
|
|
|
})))
|
2016-03-14 17:01:10 +01:00
|
|
|
}
|
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn compilers(&self) -> Result<Vec<String>, Error> {
|
2017-02-17 12:00:33 +01:00
|
|
|
Err(errors::deprecated("Compilation functionality is deprecated.".to_string()))
|
2016-03-13 15:02:46 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 12:07:54 +02:00
|
|
|
fn logs(&self, filter: Filter) -> BoxFuture<Vec<Log>, Error> {
|
2016-09-23 19:42:33 +02:00
|
|
|
let include_pending = filter.to_block == Some(BlockNumber::Pending);
|
|
|
|
let filter: EthcoreFilter = filter.into();
|
2017-05-28 14:40:36 +02:00
|
|
|
let mut logs = self.client.logs(filter.clone())
|
2016-09-23 19:42:33 +02:00
|
|
|
.into_iter()
|
|
|
|
.map(From::from)
|
|
|
|
.collect::<Vec<Log>>();
|
2016-09-14 12:02:30 +02:00
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
if include_pending {
|
2017-05-28 14:40:36 +02:00
|
|
|
let best_block = self.client.chain_info().best_block_number;
|
|
|
|
let pending = pending_logs(&*self.miner, best_block, &filter);
|
2016-09-23 19:42:33 +02:00
|
|
|
logs.extend(pending);
|
|
|
|
}
|
2016-05-24 21:56:32 +02:00
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
let logs = limit_logs(logs, filter.limit);
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::ok(logs))
|
2016-02-15 13:18:26 +01:00
|
|
|
}
|
2016-02-29 19:30:13 +01:00
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn work(&self, no_new_work_timeout: Trailing<u64>) -> Result<Work, Error> {
|
2017-07-12 08:52:18 +02:00
|
|
|
if !self.miner.can_produce_work_package() {
|
|
|
|
warn!(target: "miner", "Cannot give work package - engine seals internally.");
|
|
|
|
return Err(errors::no_work_required())
|
|
|
|
}
|
|
|
|
|
2017-06-13 16:29:35 +02:00
|
|
|
let no_new_work_timeout = no_new_work_timeout.unwrap_or_default();
|
2016-06-28 18:46:09 +02:00
|
|
|
|
2016-08-08 17:25:15 +02:00
|
|
|
// check if we're still syncing and return empty strings in that case
|
|
|
|
{
|
|
|
|
//TODO: check if initial sync is complete here
|
2017-05-28 14:40:36 +02:00
|
|
|
//let sync = self.sync;
|
|
|
|
if /*sync.status().state != SyncState::Idle ||*/ self.client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON {
|
2016-08-08 17:25:15 +02:00
|
|
|
trace!(target: "miner", "Syncing. Cannot give any work.");
|
|
|
|
return Err(errors::no_work());
|
|
|
|
}
|
2016-03-15 17:13:44 +01:00
|
|
|
|
2016-08-08 17:25:15 +02:00
|
|
|
// Otherwise spin until our submitted block has been included.
|
|
|
|
let timeout = Instant::now() + Duration::from_millis(1000);
|
2017-05-28 14:40:36 +02:00
|
|
|
while Instant::now() < timeout && self.client.queue_info().total_queue_size() > 0 {
|
2016-08-08 17:25:15 +02:00
|
|
|
thread::sleep(Duration::from_millis(1));
|
|
|
|
}
|
2016-02-29 19:30:13 +01:00
|
|
|
}
|
2016-08-08 17:25:15 +02:00
|
|
|
|
2017-05-28 14:40:36 +02:00
|
|
|
if self.miner.author().is_zero() {
|
2016-08-08 17:25:15 +02:00
|
|
|
warn!(target: "miner", "Cannot give work package - no author is configured. Use --author to configure!");
|
|
|
|
return Err(errors::no_author())
|
|
|
|
}
|
2017-05-28 14:40:36 +02:00
|
|
|
self.miner.map_sealing_work(&*self.client, |b| {
|
2016-08-08 17:25:15 +02:00
|
|
|
let pow_hash = b.hash();
|
|
|
|
let target = Ethash::difficulty_to_boundary(b.block().header().difficulty());
|
2017-09-25 19:45:33 +02:00
|
|
|
let seed_hash = self.seed_compute.lock().hash_block_number(b.block().header().number());
|
2016-08-08 17:25:15 +02:00
|
|
|
|
2016-08-23 17:07:00 +02:00
|
|
|
if no_new_work_timeout > 0 && b.block().header().timestamp() + no_new_work_timeout < get_time().sec as u64 {
|
|
|
|
Err(errors::no_new_work())
|
|
|
|
} else if self.options.send_block_number_in_get_work {
|
2016-09-23 19:42:33 +02:00
|
|
|
let block_number = b.block().header().number();
|
|
|
|
Ok(Work {
|
|
|
|
pow_hash: pow_hash.into(),
|
|
|
|
seed_hash: seed_hash.into(),
|
|
|
|
target: target.into(),
|
|
|
|
number: Some(block_number),
|
|
|
|
})
|
2016-08-08 17:25:15 +02:00
|
|
|
} else {
|
2016-09-23 19:42:33 +02:00
|
|
|
Ok(Work {
|
|
|
|
pow_hash: pow_hash.into(),
|
|
|
|
seed_hash: seed_hash.into(),
|
|
|
|
target: target.into(),
|
|
|
|
number: None
|
|
|
|
})
|
2016-08-08 17:25:15 +02:00
|
|
|
}
|
2017-03-10 10:25:13 +01:00
|
|
|
}).unwrap_or(Err(errors::internal("No work found.", "")))
|
2016-02-29 19:30:13 +01:00
|
|
|
}
|
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn submit_work(&self, nonce: RpcH64, pow_hash: RpcH256, mix_hash: RpcH256) -> Result<bool, Error> {
|
2017-07-12 08:52:18 +02:00
|
|
|
if !self.miner.can_produce_work_package() {
|
|
|
|
warn!(target: "miner", "Cannot submit work - engine seals internally.");
|
|
|
|
return Err(errors::no_work_required())
|
|
|
|
}
|
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
let nonce: H64 = nonce.into();
|
|
|
|
let pow_hash: H256 = pow_hash.into();
|
|
|
|
let mix_hash: H256 = mix_hash.into();
|
|
|
|
trace!(target: "miner", "submit_work: Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash);
|
|
|
|
|
2017-06-28 14:16:53 +02:00
|
|
|
let seal = vec![rlp::encode(&mix_hash).into_vec(), rlp::encode(&nonce).into_vec()];
|
2017-05-28 14:40:36 +02:00
|
|
|
Ok(self.miner.submit_seal(&*self.client, pow_hash, seal).is_ok())
|
2016-03-01 00:02:48 +01:00
|
|
|
}
|
2016-02-29 19:30:13 +01:00
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn submit_hashrate(&self, rate: RpcU256, id: RpcH256) -> Result<bool, Error> {
|
|
|
|
self.external_miner.submit_hashrate(rate.into(), id.into());
|
|
|
|
Ok(true)
|
2016-03-01 01:15:00 +01:00
|
|
|
}
|
2016-03-04 18:10:07 +01:00
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn send_raw_transaction(&self, raw: Bytes) -> Result<RpcH256, Error> {
|
2017-01-13 09:51:36 +01:00
|
|
|
UntrustedRlp::new(&raw.into_vec()).as_val()
|
2017-07-04 17:01:06 +02:00
|
|
|
.map_err(errors::rlp)
|
|
|
|
.and_then(|tx| SignedTransaction::new(tx).map_err(errors::transaction))
|
2017-01-13 09:51:36 +01:00
|
|
|
.and_then(|signed_transaction| {
|
2017-11-01 11:23:18 +01:00
|
|
|
FullDispatcher::dispatch_transaction(
|
|
|
|
&*self.client,
|
|
|
|
&*self.miner,
|
|
|
|
signed_transaction.into(),
|
|
|
|
)
|
2017-01-13 09:51:36 +01:00
|
|
|
})
|
|
|
|
.map(Into::into)
|
2016-03-19 21:37:11 +01:00
|
|
|
}
|
2016-03-20 10:29:21 +01:00
|
|
|
|
2016-11-18 11:03:29 +01:00
|
|
|
fn submit_transaction(&self, raw: Bytes) -> Result<RpcH256, Error> {
|
|
|
|
self.send_raw_transaction(raw)
|
|
|
|
}
|
|
|
|
|
2017-08-15 10:23:28 +02:00
|
|
|
fn call(&self, meta: Self::Metadata, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<Bytes, Error> {
|
2016-09-23 19:42:33 +02:00
|
|
|
let request = CallRequest::into(request);
|
2017-10-05 12:35:01 +02:00
|
|
|
let signed = try_bf!(fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp()));
|
2016-09-23 19:42:33 +02:00
|
|
|
|
2017-08-04 15:58:14 +02:00
|
|
|
let num = num.unwrap_or_default();
|
|
|
|
let result = self.client.call(&signed, Default::default(), num.into());
|
2016-09-23 19:42:33 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
Box::new(future::done(result
|
2016-11-04 18:33:10 +01:00
|
|
|
.map(|b| b.output.into())
|
2017-07-04 17:01:06 +02:00
|
|
|
.map_err(errors::call)
|
2017-10-05 12:35:01 +02:00
|
|
|
))
|
2016-03-19 21:37:11 +01:00
|
|
|
}
|
2016-03-20 10:29:21 +01:00
|
|
|
|
2017-08-15 10:23:28 +02:00
|
|
|
fn estimate_gas(&self, meta: Self::Metadata, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> {
|
2016-09-23 19:42:33 +02:00
|
|
|
let request = CallRequest::into(request);
|
2017-10-05 12:35:01 +02:00
|
|
|
let signed = try_bf!(fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp()));
|
|
|
|
Box::new(future::done(self.client.estimate_gas(&signed, num.unwrap_or_default().into())
|
2017-01-10 18:56:41 +01:00
|
|
|
.map(Into::into)
|
2017-07-04 17:01:06 +02:00
|
|
|
.map_err(errors::call)
|
2017-10-05 12:35:01 +02:00
|
|
|
))
|
2016-03-20 10:29:21 +01:00
|
|
|
}
|
2016-05-28 15:25:37 +02:00
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn compile_lll(&self, _: String) -> Result<Bytes, Error> {
|
2017-02-17 12:00:33 +01:00
|
|
|
Err(errors::deprecated("Compilation of LLL via RPC is deprecated".to_string()))
|
2016-05-28 15:25:37 +02:00
|
|
|
}
|
|
|
|
|
2016-09-23 19:42:33 +02:00
|
|
|
fn compile_serpent(&self, _: String) -> Result<Bytes, Error> {
|
2017-02-17 12:00:33 +01:00
|
|
|
Err(errors::deprecated("Compilation of Serpent via RPC is deprecated".to_string()))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compile_solidity(&self, _: String) -> Result<Bytes, Error> {
|
|
|
|
Err(errors::deprecated("Compilation of Solidity via RPC is deprecated".to_string()))
|
2016-05-28 15:25:37 +02:00
|
|
|
}
|
2016-01-21 11:25:39 +01:00
|
|
|
}
|