#![warn(missing_docs)]
mod miner;
mod filter_options;
pub mod pool_client;
#[cfg(feature = "stratum")]
pub mod stratum;
pub use self::miner::{Miner, MinerOptions, Penalization, PendingSet, AuthoringParams, Author};
pub use self::filter_options::FilterOptions;
pub use vapcore_miner::local_accounts::LocalAccounts;
pub use vapcore_miner::pool::PendingOrdering;
use std::sync::Arc;
use std::collections::{BTreeSet, BTreeMap};
use bytes::Bytes;
use vapcore_miner::pool::{VerifiedTransaction, QueueStatus, local_transactions};
use vapory_types::{H256, U256, Address};
use types::transaction::{self, UnverifiedTransaction, SignedTransaction, PendingTransaction};
use types::{
BlockNumber,
errors::VapcoreError as Error,
block::Block,
header::Header,
receipt::RichReceipt,
};
use call_contract::CallContract;
use tetsy_registrar::RegistrarClient;
use client_traits::{BlockChain, ChainInfo, AccountData, Nonce, ScheduleInfo, ForceUpdateSealing};
use account_state::state::StateInfo;
use crate::{
block::SealedBlock,
client::{BlockProducer, SealedBlockImporter},
};
pub trait TransactionVerifierClient: Send + Sync
+ CallContract + RegistrarClient
+ BlockChain + ScheduleInfo + AccountData
{}
pub trait BlockChainClient: TransactionVerifierClient + BlockProducer + SealedBlockImporter {}
pub trait MinerService : Send + Sync {
type State: StateInfo + 'static;
fn submit_seal(&self, pow_hash: H256, seal: Vec<Bytes>) -> Result<SealedBlock, Error>;
fn is_currently_sealing(&self) -> bool;
fn work_package<C>(&self, chain: &C) -> Option<(H256, BlockNumber, u64, U256)>
where C: BlockChain + CallContract + BlockProducer + SealedBlockImporter + Nonce + Sync;
fn update_sealing<C>(&self, chain: &C, force: ForceUpdateSealing)
where C: BlockChain + CallContract + BlockProducer + SealedBlockImporter + Nonce + Sync;
fn chain_new_blocks<C>(&self, chain: &C, imported: &[H256], invalid: &[H256], enacted: &[H256], retracted: &[H256], is_internal_import: bool)
where C: BlockChainClient;
fn pending_receipts(&self, best_block: BlockNumber) -> Option<Vec<RichReceipt>>;
fn pending_receipt(&self, best_block: BlockNumber, hash: &H256) -> Option<RichReceipt> {
let receipts = self.pending_receipts(best_block)?;
receipts.into_iter().find(|r| &r.transaction_hash == hash)
}
fn pending_state(&self, latest_block_number: BlockNumber) -> Option<Self::State>;
fn pending_block_header(&self, latest_block_number: BlockNumber) -> Option<Header>;
fn pending_block(&self, latest_block_number: BlockNumber) -> Option<Block>;
fn pending_transactions(&self, latest_block_number: BlockNumber) -> Option<Vec<SignedTransaction>>;
fn authoring_params(&self) -> AuthoringParams;
fn set_gas_range_target(&self, gas_range_target: (U256, U256));
fn set_extra_data(&self, extra_data: Bytes);
fn set_author<T: Into<Option<Author>>>(&self, author: T);
fn import_external_transactions<C>(&self, client: &C, transactions: Vec<UnverifiedTransaction>)
-> Vec<Result<(), transaction::Error>>
where C: BlockChainClient;
fn import_own_transaction<C>(&self, chain: &C, transaction: PendingTransaction)
-> Result<(), transaction::Error>
where C: BlockChainClient;
fn import_claimed_local_transaction<C>(&self, chain: &C, transaction: PendingTransaction, trusted: bool)
-> Result<(), transaction::Error>
where C: BlockChainClient;
fn remove_transaction(&self, hash: &H256) -> Option<Arc<VerifiedTransaction>>;
fn transaction(&self, hash: &H256) -> Option<Arc<VerifiedTransaction>>;
fn next_nonce<C>(&self, chain: &C, address: &Address) -> U256
where C: Nonce + Sync;
fn pending_transaction_hashes<C>(&self, chain: &C) -> BTreeSet<H256> where
C: ChainInfo + Sync;
fn ready_transactions<C>(&self, chain: &C, max_len: usize, ordering: PendingOrdering) -> Vec<Arc<VerifiedTransaction>>
where C: ChainInfo + Nonce + Sync;
fn ready_transactions_filtered<C>(&self, chain: &C, max_len: usize, filter: Option<FilterOptions>, ordering: PendingOrdering) -> Vec<Arc<VerifiedTransaction>>
where C: ChainInfo + Nonce + Sync;
fn queued_transactions(&self) -> Vec<Arc<VerifiedTransaction>>;
fn queued_transaction_hashes(&self) -> Vec<H256>;
fn local_transactions(&self) -> BTreeMap<H256, local_transactions::Status>;
fn queue_status(&self) -> QueueStatus;
fn sensible_gas_price(&self) -> U256;
fn sensible_gas_limit(&self) -> U256;
fn set_minimal_gas_price(&self, gas_price: U256) -> Result<bool, &str>;
}