Skip to content

Commit f4ed130

Browse files
kakao-jun-esgkim126
authored andcommitted
Add subcommands for RPC
1 parent 9e6cbb8 commit f4ed130

File tree

6 files changed

+97
-39
lines changed

6 files changed

+97
-39
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors = ["CodeChain Team <codechain@kodebox.io>"]
77
[dependencies]
88
byteorder = "1.2"
99
clap = { version = "2", features = ["yaml"] }
10-
codechain-miner = { git = "https://github.com/CodeChain-io/codechain-miner.git", rev = "96e200d" }
10+
codechain-miner = { git = "https://github.com/CodeChain-io/codechain-miner.git", rev = "820e11e" }
1111
cuckoo = { git = "https://github.com/CodeChain-io/rust-cuckoo.git", rev = "280cab9c" }
1212
ethereum-types = "0.3.2"
1313
env_logger = "0.5.10"

README.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ The resulting binary file can be found at `target/release/codechain-cuckoo-miner
1515
## Usage
1616

1717
```
18-
codechain-cuckoo-miner [OPTIONS]
18+
codechain-cuckoo-miner [OPTIONS] [SUBCOMMAND]
1919
```
2020

2121
### Usage Examples
22-
* N=0x10, M=0x8, L=6, listening on port **3333**, submitting on port **8080**, **1** concurrent jobs :
22+
23+
* N=0x10, M=0x8, L=6, **1** concurrent jobs :
24+
25+
Using HTTP (listening on port **3333**, submitting on port **8080**)
26+
```
27+
codechain-cuckoo-miner -n 0x10 -m 0x8 -l 6 -j 1 http -p 3333 -s 8080
28+
```
29+
30+
or
31+
32+
Using Stratum
2333
```
24-
codechain-cuckoo-miner -n 0x10 -m 0x8 -l 6 -p 3333 -s 8080 -j 1
34+
codechain-cuckoo-miner -n 0x10 -m 0x8 -l 6 -j 1 stratum
2535
```
2636

2737
## Configuration
@@ -30,12 +40,24 @@ codechain-cuckoo-miner -n 0x10 -m 0x8 -l 6 -p 3333 -s 8080 -j 1
3040

3141
| Option | Description | Default | Required |
3242
| :----: | ------------------------------ |:-------------:|:--------:|
33-
| `-p` | Port number to receive job | 3333 | No |
34-
| `-s` | Port number to submit solution | 8080 | No |
35-
| `-j` | The number of concurrent jobs | 1 | No |
43+
| `-n` | Number of vertices in graph | None | Yes |
44+
| `-m` | Number of edges in graph | None | Yes |
45+
| `-l` | Length of cycle to detect | None | Yes |
46+
| `-j` | Number of concurrent jobs | 1 | No |
47+
48+
### RPC Subcommands
49+
50+
* HTTP
51+
52+
| Option | Description | Default | Required |
53+
| :----: | ------------------------------ |:-------------:|:--------:|
54+
| `-p` | Port number to receive job | 3333 | No |
55+
| `-s` | Port number to submit solution | 8008 | No |
56+
57+
* Stratum
3658

3759
| Option | Description | Default | Required |
3860
| :----: | ------------------------------ |:-------------:|:--------:|
39-
| `-n` | Number of vertices in graph | None | Yes |
40-
| `-m` | Number of edges in graph | None | Yes |
41-
| `-l` | Length of cycle to detect | None | Yes |
61+
| `-p` | Port number to stratum server | 3333 | No |
62+
| `-i` | Miner name | | No |
63+
| `-w` | Miner password | | No |

src/cli.yml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@ version_short: "v"
44
author: CodeChain Team <codechain@kodebox.io>
55
about: CodeChian Cuckoo Miner
66
args:
7-
- listening port:
8-
short: p
9-
long: port
10-
takes_value: true
11-
default_value: "3333"
12-
- submitting port:
13-
short: s
14-
long: submit
15-
takes_value: true
16-
default_value: "8080"
177
- max vertex:
188
short: n
199
long: max-vertex
@@ -34,3 +24,36 @@ args:
3424
long: jobs
3525
takes_value: true
3626
default_value: "1"
27+
28+
subcommands:
29+
- http:
30+
about: HTTP RPC for Miner
31+
args:
32+
- listening port:
33+
short: p
34+
long: port
35+
takes_value: true
36+
default_value: "3333"
37+
- submitting port:
38+
short: s
39+
long: submit
40+
takes_value: true
41+
default_value: "8080"
42+
- stratum:
43+
about: Stratum RPC for Miner
44+
args:
45+
- server port:
46+
short: p
47+
long: port
48+
takes_value: true
49+
default_value: "8008"
50+
- miner name:
51+
short: i
52+
long: name
53+
takes_value: true
54+
default_value: ""
55+
- miner pwd:
56+
short: w
57+
long: pwd
58+
takes_value: true
59+
default_value: ""

src/config.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,29 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use codechain_miner::{Config, HttpConfig, RpcConfig, Worker};
17+
use codechain_miner::{Config, RpcConfig, Worker};
1818

1919
use super::worker::CuckooWorker;
2020

21-
#[derive(Clone, Copy)]
21+
#[derive(Clone)]
2222
pub struct CuckooConfig {
2323
pub max_vertex: usize,
2424
pub max_edge: usize,
2525
pub cycle_length: usize,
26-
27-
pub listening_port: u16,
28-
pub submitting_port: u16,
29-
26+
pub rpc_config: RpcConfig,
3027
pub concurrent_jobs: u16,
3128
}
3229

3330
impl Config for CuckooConfig {
3431
fn rpc_config(&self) -> RpcConfig {
35-
RpcConfig::Http(HttpConfig {
36-
listen_port: self.listening_port,
37-
submitting_port: self.submitting_port,
38-
})
32+
self.rpc_config.clone()
3933
}
4034

4135
fn jobs(&self) -> usize {
4236
self.concurrent_jobs as usize
4337
}
4438

4539
fn worker(&self) -> Box<Worker> {
46-
Box::new(CuckooWorker::new(*self))
40+
Box::new(CuckooWorker::new(self.clone()))
4741
}
4842
}

src/main.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern crate rustc_hex;
3030
mod config;
3131
mod worker;
3232

33-
use codechain_miner::run;
33+
use codechain_miner::{run, HttpConfig, RpcConfig, StratumConfig};
3434

3535
use self::config::CuckooConfig;
3636

@@ -49,19 +49,38 @@ fn get_options() -> Result<CuckooConfig, String> {
4949
let yaml = load_yaml!("./cli.yml");
5050
let matches = clap::App::from_yaml(yaml).get_matches();
5151

52-
let listening_port = value_t!(matches, "listening port", u16).map_err(|_| "Invalid listening port")?;
53-
let submitting_port = value_t!(matches, "submitting port", u16).map_err(|_| "Invalid submitting port")?;
5452
let max_vertex = hex_value_t!(matches, "max vertex").map_err(|e| format!("Invalid max vertex: {}", e))?;
5553
let max_edge = hex_value_t!(matches, "max edge").map_err(|e| format!("Invalid max edge: {}", e))?;
5654
let cycle_length = value_t!(matches, "cycle length", usize).map_err(|_| "Invalid cycle length")?;
5755
let concurrent_jobs = value_t!(matches, "concurrent jobs", u16).map_err(|_| "Invalid concurrent jobs")?;
5856

57+
let rpc_config: RpcConfig = if let Some(ref matches) = matches.subcommand_matches("http") {
58+
let listening_port = value_t!(matches, "listening port", u16).map_err(|_| "Invalid listening port")?;
59+
let submitting_port = value_t!(matches, "submitting port", u16).map_err(|_| "Invalid submitting port")?;
60+
61+
RpcConfig::Http(HttpConfig {
62+
listen_port: listening_port,
63+
submitting_port,
64+
})
65+
} else if let Some(ref matches) = matches.subcommand_matches("stratum") {
66+
let server_port = value_t!(matches, "server port", u16).map_err(|_| "Invalid server port")?;
67+
let miner_name = value_t!(matches, "miner name", String).map_err(|_| "Invalid miner name")?;
68+
let miner_pwd = value_t!(matches, "miner pwd", String).map_err(|_| "Invalid miner password")?;
69+
70+
RpcConfig::Stratum(StratumConfig {
71+
port: server_port,
72+
id: miner_name,
73+
pwd: miner_pwd,
74+
})
75+
} else {
76+
return Err(format!("Invalid RPC Config"))
77+
};
78+
5979
Ok(CuckooConfig {
6080
max_vertex,
6181
max_edge,
6282
cycle_length,
63-
listening_port,
64-
submitting_port,
83+
rpc_config,
6584
concurrent_jobs,
6685
})
6786
}

0 commit comments

Comments
 (0)