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;
23use std;
24
25#[derive(Debug, Clone)]
26pub enum Error {
27 NoWork,
28 NoWorkers,
29 InvalidSolution(String),
30 Io(String),
31 Tcp(String),
32 Dispatch(String),
33}
34
35impl From<std::io::Error> for Error {
36 fn from(err: std::io::Error) -> Self { Error::Io(err.to_string()) }
37}
38
39impl From<PushMessageError> for Error {
40 fn from(err: PushMessageError) -> Self {
41 Error::Tcp(format!("Push message error: {:?}", err))
42 }
43}
44
45/// Interface that can provide pow/blockchain-specific responses for the clients
46pub trait JobDispatcher: Send + Sync {
47 // miner job result
48 fn submit(&self, payload: Vec<String>) -> Result<(), Error>;
49}
50
51/// Interface that can handle requests to push job for workers
52pub trait PushWorkHandler: Send + Sync {
53 /// push the same work package for all workers (`payload`: json of
54 /// pow-specific set of work specification)
55 fn push_work_all(&self, payload: String) -> Result<(), Error>;
56}
57
58pub struct ServiceConfiguration {
59 pub io_path: String,
60 pub listen_addr: String,
61 pub port: u16,
62 pub secret: Option<H256>,
63}