Skip to content

Commit 9d7ce99

Browse files
committed
Implement miner_submitWork RPC API
Also change the type of seal parameter to Vec<Bytes> to make it PoW consensus agnostic.
1 parent 9a6ea46 commit 9d7ce99

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

codechain/rpc_apis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ where
3636
use crpc::v1::*;
3737
handler.extend_with(ChainClient::new(&self.client, &self.miner).to_delegate());
3838
handler.extend_with(DevelClient::new(&self.client).to_delegate());
39-
handler.extend_with(MinerClient::new(&self.miner).to_delegate());
39+
handler.extend_with(MinerClient::new(&self.client, &self.miner).to_delegate());
4040
handler.extend_with(NetClient::new(&self.network_control).to_delegate());
4141
}
4242
}

rpc/src/v1/impls/miner.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@
1616

1717
use std::sync::Arc;
1818

19-
use ccore::{self, MinerService};
19+
use ccore::{self, Client, MinerService};
20+
use ctypes::H256;
2021
use jsonrpc_core::Result;
2122

2223
use super::super::errors;
2324
use super::super::traits::Miner;
2425
use super::super::types::{Bytes, Work};
2526

2627
pub struct MinerClient {
28+
client: Arc<Client>,
2729
miner: Arc<ccore::Miner>,
2830
}
2931

3032
impl MinerClient {
31-
pub fn new(miner: &Arc<ccore::Miner>) -> Self {
33+
pub fn new(client: &Arc<Client>, miner: &Arc<ccore::Miner>) -> Self {
3234
Self {
35+
client: client.clone(),
3336
miner: miner.clone(),
3437
}
3538
}
@@ -44,11 +47,12 @@ impl Miner for MinerClient {
4447
unimplemented!();
4548
}
4649

47-
fn submit_work(&self, _nonce: Bytes, _pow_hash: Bytes) -> Result<bool> {
50+
fn submit_work(&self, pow_hash: H256, seal: Vec<Bytes>) -> Result<bool> {
4851
if !self.miner.can_produce_work_package() {
4952
cwarn!(MINER, "Cannot give work package - engine seals internally.");
5053
return Err(errors::no_work_required())
5154
}
52-
unimplemented!();
55+
let seal = seal.iter().cloned().map(Into::into).collect();
56+
Ok(self.miner.submit_seal(&*self.client, pow_hash, seal).is_ok())
5357
}
5458
}

rpc/src/v1/traits/miner.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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 ctypes::H256;
1718
use jsonrpc_core::Result;
1819

1920
use super::super::types::{Bytes, Work};
@@ -24,6 +25,6 @@ build_rpc_trait! {
2425
fn get_work(&self) -> Result<Work>;
2526

2627
# [rpc(name = "miner_submitWork")]
27-
fn submit_work(&self, Bytes, Bytes) -> Result<bool>;
28+
fn submit_work(&self, H256, Vec<Bytes>) -> Result<bool>;
2829
}
2930
}

0 commit comments

Comments
 (0)