2016-03-13 17:01:50 +01:00
|
|
|
// 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/>.
|
|
|
|
|
2016-03-18 19:16:46 +01:00
|
|
|
//! Test implementation of miner service.
|
|
|
|
|
2016-03-16 10:48:31 +01:00
|
|
|
use util::{Address, H256, Bytes};
|
2016-03-13 17:01:50 +01:00
|
|
|
use util::standard::*;
|
|
|
|
use ethcore::error::Error;
|
|
|
|
use ethcore::client::BlockChainClient;
|
|
|
|
use ethcore::block::ClosedBlock;
|
|
|
|
use ethcore::transaction::SignedTransaction;
|
2016-03-16 10:40:33 +01:00
|
|
|
use ethminer::{MinerService, MinerStatus, AccountDetails};
|
2016-03-13 17:01:50 +01:00
|
|
|
|
2016-03-18 19:16:46 +01:00
|
|
|
/// Test miner service.
|
2016-03-16 10:37:08 +01:00
|
|
|
pub struct TestMinerService {
|
2016-03-18 19:16:46 +01:00
|
|
|
/// Imported transactions.
|
2016-03-16 10:37:08 +01:00
|
|
|
pub imported_transactions: RwLock<Vec<H256>>,
|
2016-03-18 19:16:46 +01:00
|
|
|
/// Latest closed block.
|
2016-03-16 10:37:08 +01:00
|
|
|
pub latest_closed_block: Mutex<Option<ClosedBlock>>,
|
2016-03-27 16:16:15 +02:00
|
|
|
/// Pre-existed pending transactions
|
|
|
|
pub pending_transactions: Mutex<HashMap<H256, SignedTransaction>>,
|
2016-03-16 10:37:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TestMinerService {
|
|
|
|
fn default() -> TestMinerService {
|
|
|
|
TestMinerService {
|
|
|
|
imported_transactions: RwLock::new(Vec::new()),
|
|
|
|
latest_closed_block: Mutex::new(None),
|
2016-03-27 16:16:15 +02:00
|
|
|
pending_transactions: Mutex::new(HashMap::new()),
|
2016-03-16 10:37:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-13 17:01:50 +01:00
|
|
|
|
|
|
|
impl MinerService for TestMinerService {
|
|
|
|
|
|
|
|
/// Returns miner's status.
|
2016-03-17 11:19:12 +01:00
|
|
|
fn status(&self) -> MinerStatus {
|
|
|
|
MinerStatus {
|
2016-03-17 11:19:12 +01:00
|
|
|
transactions_in_pending_queue: 0,
|
|
|
|
transactions_in_future_queue: 0,
|
|
|
|
transactions_in_pending_block: 1
|
2016-03-17 11:19:12 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-13 17:01:50 +01:00
|
|
|
|
|
|
|
/// Imports transactions to transaction queue.
|
2016-03-17 17:19:46 +01:00
|
|
|
fn import_transactions<T>(&self, _transactions: Vec<SignedTransaction>, _fetch_account: T) -> Vec<Result<(), Error>>
|
2016-03-16 10:40:33 +01:00
|
|
|
where T: Fn(&Address) -> AccountDetails { unimplemented!(); }
|
2016-03-13 17:01:50 +01:00
|
|
|
|
|
|
|
/// Returns hashes of transactions currently in pending
|
2016-03-19 12:23:48 +01:00
|
|
|
fn pending_transactions_hashes(&self) -> Vec<H256> { vec![] }
|
2016-03-13 17:01:50 +01:00
|
|
|
|
|
|
|
/// Removes all transactions from the queue and restart mining operation.
|
|
|
|
fn clear_and_reset(&self, _chain: &BlockChainClient) { unimplemented!(); }
|
|
|
|
|
|
|
|
/// Called when blocks are imported to chain, updates transactions queue.
|
|
|
|
fn chain_new_blocks(&self, _chain: &BlockChainClient, _imported: &[H256], _invalid: &[H256], _enacted: &[H256], _retracted: &[H256]) { unimplemented!(); }
|
|
|
|
|
|
|
|
/// New chain head event. Restart mining operation.
|
2016-03-17 12:47:31 +01:00
|
|
|
fn update_sealing(&self, _chain: &BlockChainClient) { unimplemented!(); }
|
2016-03-13 17:01:50 +01:00
|
|
|
|
2016-03-24 23:03:22 +01:00
|
|
|
fn map_sealing_work<F, T>(&self, _chain: &BlockChainClient, _f: F) -> Option<T> where F: FnOnce(&ClosedBlock) -> T { unimplemented!(); }
|
2016-03-13 17:01:50 +01:00
|
|
|
|
2016-03-27 16:16:15 +02:00
|
|
|
fn transaction(&self, hash: &H256) -> Option<SignedTransaction> {
|
|
|
|
self.pending_transactions.lock().unwrap().get(hash).and_then(|tx_ref| Some(tx_ref.clone()))
|
2016-03-27 15:12:21 +02:00
|
|
|
}
|
|
|
|
|
2016-03-13 17:01:50 +01:00
|
|
|
/// Submit `seal` as a valid solution for the header of `pow_hash`.
|
|
|
|
/// Will check the seal, but not actually insert the block into the chain.
|
|
|
|
fn submit_seal(&self, _chain: &BlockChainClient, _pow_hash: H256, _seal: Vec<Bytes>) -> Result<(), Error> { unimplemented!(); }
|
2016-03-16 10:37:08 +01:00
|
|
|
}
|