Skip to content

Commit 0c69701

Browse files
committed
Fix typo and refactoring reviewed function
1 parent 0627bcb commit 0c69701

File tree

3 files changed

+9
-39
lines changed

3 files changed

+9
-39
lines changed

codechain/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,15 @@ pub fn client_start(cfg: &config::Config, spec: &Spec, miner: Arc<Miner>) -> Res
144144

145145
pub fn stratum_start(cfg: &StratumConfig, miner: Arc<Miner>, client: Arc<Client>) -> Result<(), String> {
146146
info!("STRATUM Listening on {}", cfg.port);
147-
match Stratum::register(cfg, miner, client) {
147+
match Stratum::start(cfg, miner.clone(), client) {
148148
// FIXME: Add specified condition like AddrInUse
149149
Err(StratumError::Service(_)) =>
150150
Err(format!("STRATUM address {} is already in use, make sure that another instance of a CodeChain node is not running or change the address using the --stratum-port option.", cfg.port)),
151151
Err(e) => Err(format!("STRATUM start error: {:?}", e)),
152-
Ok(_) => Ok(())
152+
Ok(stratum) => {
153+
miner.add_work_listener(Box::new(stratum));
154+
Ok(())
155+
}
153156
}
154157
}
155158

core/src/miner/stratum.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
use std::net::{AddrParseError, SocketAddr};
2020
use std::sync::Arc;
2121

22-
use cstratum::PushWorkHandler;
23-
use cstratum::{Error as StratumServiceError, JobDispatcher, Stratum as StratumService};
22+
use cstratum::{Error as StratumServiceError, JobDispatcher, PushWorkHandler, Stratum as StratumService};
2423
use primitives::{Bytes, H256, U256};
2524

2625
use super::super::client::Client;
@@ -38,16 +37,6 @@ pub struct Config {
3837
pub secret: Option<H256>,
3938
}
4039

41-
impl Default for Config {
42-
fn default() -> Self {
43-
Config {
44-
listen_addr: "0.0.0.0:0".parse().unwrap(),
45-
port: 3333,
46-
secret: None,
47-
}
48-
}
49-
}
50-
5140
/// Job dispatcher for stratum service
5241
pub struct StratumJobDispatcher {
5342
client: Arc<Client>,
@@ -60,21 +49,6 @@ impl JobDispatcher for StratumJobDispatcher {
6049
self.job()
6150
}
6251

63-
fn job(&self) -> Option<String> {
64-
if !self.miner.can_produce_work_package() {
65-
cwarn!(STRATUM, "Cannot give work package - engine seals internally.");
66-
return None
67-
}
68-
69-
if self.miner.author().is_zero() {
70-
cwarn!(STRATUM, "Cannot give work package - no author is configured. Use --author to configure!");
71-
return None
72-
}
73-
74-
// TODO: should provide initial values for mining
75-
None
76-
}
77-
7852
fn submit(&self, payload: (H256, Vec<Bytes>)) -> Result<(), StratumServiceError> {
7953
let (pow_hash, seal) = payload;
8054

@@ -163,11 +137,4 @@ impl Stratum {
163137
service: stratum_svc,
164138
})
165139
}
166-
167-
/// Start STRATUM job dispatcher and register it in the miner
168-
pub fn register(cfg: &Config, miner: Arc<Miner>, client: Arc<Client>) -> Result<(), Error> {
169-
let stratum = Stratum::start(cfg, miner.clone(), client.clone())?;
170-
miner.add_work_listener(Box::new(stratum) as Box<NotifyWork>);
171-
Ok(())
172-
}
173140
}

stratum/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ mod tests {
428428
fn can_authorize() {
429429
let addr = SocketAddr::from_str("127.0.0.1:19970").unwrap();
430430
let stratum =
431-
Stratum::start(&addr, Arc::new(DummyManager::build().of_initial(r#"["dummy autorize payload"]"#)), None)
431+
Stratum::start(&addr, Arc::new(DummyManager::build().of_initial(r#"["dummy authorize payload"]"#)), None)
432432
.expect("There should be no error starting stratum");
433433

434434
let request = r#"{"jsonrpc": "2.0", "method": "mining.authorize", "params": ["miner1", ""], "id": 1}"#;
@@ -442,7 +442,7 @@ mod tests {
442442
fn can_push_work() {
443443
let addr = SocketAddr::from_str("127.0.0.1:19995").unwrap();
444444
let stratum =
445-
Stratum::start(&addr, Arc::new(DummyManager::build().of_initial(r#"["dummy autorize payload"]"#)), None)
445+
Stratum::start(&addr, Arc::new(DummyManager::build().of_initial(r#"["dummy authorize payload"]"#)), None)
446446
.expect("There should be no error starting stratum");
447447

448448
let mut auth_request = r#"{"jsonrpc": "2.0", "method": "mining.authorize", "params": ["miner1", ""], "id": 1}"#.as_bytes()
@@ -491,7 +491,7 @@ mod tests {
491491
fn can_respond_to_submition() {
492492
let addr = SocketAddr::from_str("127.0.0.1:19990").unwrap();
493493
let _stratum =
494-
Stratum::start(&addr, Arc::new(DummyManager::build().of_initial(r#"["dummy autorize payload"]"#)), None)
494+
Stratum::start(&addr, Arc::new(DummyManager::build().of_initial(r#"["dummy authorize payload"]"#)), None)
495495
.expect("There should be no error starting stratum");
496496

497497
let mut auth_request = r#"{"jsonrpc": "2.0", "method": "mining.authorize", "params": ["miner1", ""], "id": 1}"#.as_bytes()

0 commit comments

Comments
 (0)