cfx_stratum/traits.rs
1// Copyright 2019-2020 Conflux Foundation. All rights reserved.
2// Conflux is free software and distributed under GNU General Public License.
3// See http://www.gnu.org/licenses/
4
5// Copyright 2015-2019 Parity Technologies (UK) Ltd.
6// This file is part of Parity Ethereum.
7
8// Parity Ethereum is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// Parity Ethereum is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License
19// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
20
21use cfx_types::H256;
22use jsonrpc_tcp_server::PushMessageError;
23
24#[derive(Debug, Clone)]
25pub enum Error {
26 NoWork,
27 NoWorkers,
28 InvalidSolution(String),
29 Io(String),
30 Tcp(String),
31 Dispatch(String),
32}
33
34impl From<std::io::Error> for Error {
35 fn from(err: std::io::Error) -> Self { Error::Io(err.to_string()) }
36}
37
38impl From<PushMessageError> for Error {
39 fn from(err: PushMessageError) -> Self {
40 Error::Tcp(format!("Push message error: {:?}", err))
41 }
42}
43
44/// Interface that can provide pow/blockchain-specific responses for the clients
45pub trait JobDispatcher: Send + Sync {
46 // miner job result
47 fn submit(&self, payload: Vec<String>) -> Result<(), Error>;
48}
49
50/// Interface that can handle requests to push job for workers
51pub trait PushWorkHandler: Send + Sync {
52 /// push the same work package for all workers (`payload`: json of
53 /// pow-specific set of work specification)
54 fn push_work_all(&self, payload: String) -> Result<(), Error>;
55}
56
57pub struct ServiceConfiguration {
58 pub io_path: String,
59 pub listen_addr: String,
60 pub port: u16,
61 pub secret: Option<H256>,
62}