Skip to content

Commit

Permalink
refactor jrpc error handling (#4006)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy authored Jun 1, 2022
1 parent 6a42100 commit d1988e9
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 39 deletions.
6 changes: 4 additions & 2 deletions jormungandr/src/jrpc/eth_block_info/logic.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use super::Error;
use crate::{
blockchain::{Blockchain, Ref},
context::Context,
jrpc::eth_types::{block::Block, block_number::BlockNumber, number::Number},
jrpc::{
eth_types::{block::Block, block_number::BlockNumber, number::Number},
Error,
},
};
use chain_evm::ethereum_types::H256;
use chain_impl_mockchain::block::Block as JorBlock;
Expand Down
8 changes: 0 additions & 8 deletions jormungandr/src/jrpc/eth_block_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ use jsonrpsee_http_server::RpcModule;

mod logic;

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
ContextError(#[from] crate::context::Error),
#[error(transparent)]
Storage(#[from] crate::blockchain::StorageError),
}

pub fn eth_block_info_module(context: ContextLock) -> RpcModule<ContextLock> {
let mut module = RpcModule::new(context);

Expand Down
6 changes: 3 additions & 3 deletions jormungandr/src/jrpc/eth_chain_info/logic.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::Error;
use crate::{
context::Context,
jrpc::eth_types::{
block_number::BlockNumber, fee::FeeHistory, number::Number, sync::SyncStatus,
jrpc::{
eth_types::{block_number::BlockNumber, fee::FeeHistory, number::Number, sync::SyncStatus},
Error,
},
};

Expand Down
3 changes: 0 additions & 3 deletions jormungandr/src/jrpc/eth_chain_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use jsonrpsee_http_server::RpcModule;

mod logic;

#[derive(Debug, thiserror::Error)]
pub enum Error {}

pub fn eth_chain_info_module(context: ContextLock) -> RpcModule<ContextLock> {
let mut module = RpcModule::new(context);

Expand Down
12 changes: 7 additions & 5 deletions jormungandr/src/jrpc/eth_filter/logic.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use super::Error;
use crate::{
context::Context,
jrpc::eth_types::{
filter::{Filter, FilterChanges},
log::Log,
number::Number,
jrpc::{
eth_types::{
filter::{Filter, FilterChanges},
log::Log,
number::Number,
},
Error,
},
};

Expand Down
3 changes: 0 additions & 3 deletions jormungandr/src/jrpc/eth_filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use jsonrpsee_http_server::RpcModule;

mod logic;

#[derive(Debug, thiserror::Error)]
pub enum Error {}

pub fn eth_filter_module(context: ContextLock) -> RpcModule<ContextLock> {
let mut module = RpcModule::new(context);

Expand Down
10 changes: 5 additions & 5 deletions jormungandr/src/jrpc/eth_miner/logic.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use chain_evm::ethereum_types::{H160, H256, H64};

use crate::{
context::Context,
jrpc::eth_types::{number::Number, work::Work},
jrpc::{
eth_types::{number::Number, work::Work},
Error,
},
};

use super::Error;
use chain_evm::ethereum_types::{H160, H256, H64};

pub fn mining(_context: &Context) -> Result<bool, Error> {
// TODO implement
Expand Down
3 changes: 0 additions & 3 deletions jormungandr/src/jrpc/eth_miner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use jsonrpsee_http_server::RpcModule;

mod logic;

#[derive(Debug, thiserror::Error)]
pub enum Error {}

pub fn eth_miner_module(context: ContextLock) -> RpcModule<ContextLock> {
let mut module = RpcModule::new(context);

Expand Down
10 changes: 6 additions & 4 deletions jormungandr/src/jrpc/eth_transaction/logic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use super::Error;
use crate::{
context::Context,
jrpc::eth_types::{
block_number::BlockNumber, bytes::Bytes, number::Number, receipt::Receipt,
transaction::Transaction,
jrpc::{
eth_types::{
block_number::BlockNumber, bytes::Bytes, number::Number, receipt::Receipt,
transaction::Transaction,
},
Error,
},
};
use chain_evm::ethereum_types::{H160, H256, H512};
Expand Down
3 changes: 0 additions & 3 deletions jormungandr/src/jrpc/eth_transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use jsonrpsee_http_server::RpcModule;

mod logic;

#[derive(Debug, thiserror::Error)]
pub enum Error {}

pub fn eth_transaction_module(context: ContextLock) -> RpcModule<ContextLock> {
let mut module = RpcModule::new(context);

Expand Down
9 changes: 9 additions & 0 deletions jormungandr/src/jrpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ mod eth_types;
use crate::context::ContextLock;
use jsonrpsee_http_server::{HttpServerBuilder, RpcModule};
use std::net::SocketAddr;
use thiserror::Error;

pub struct Config {
pub listen: SocketAddr,
}

#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
ContextError(#[from] crate::context::Error),
#[error(transparent)]
Storage(#[from] crate::blockchain::StorageError),
}

pub async fn start_jrpc_server(config: Config, _context: ContextLock) {
let server = HttpServerBuilder::default()
.build(config.listen)
Expand Down

0 comments on commit d1988e9

Please sign in to comment.