-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add new account module * update arguments * update changelog * replace U256 to Number * add eth_accounts method
- Loading branch information
Showing
4 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use super::Error; | ||
use crate::{ | ||
context::Context, | ||
jrpc::eth_types::{block_number::BlockNumber, bytes::Bytes, number::Number}, | ||
}; | ||
use chain_evm::ethereum_types::{H160, H256}; | ||
|
||
pub fn accounts(_context: &Context) -> Result<Vec<H160>, Error> { | ||
// TODO implement | ||
Ok(vec![H160::zero()]) | ||
} | ||
|
||
pub fn get_transaction_count( | ||
_address: H160, | ||
_block_number: BlockNumber, | ||
_context: &Context, | ||
) -> Result<Number, Error> { | ||
// TODO implement | ||
Ok(0.into()) | ||
} | ||
|
||
pub fn get_balance( | ||
_address: H160, | ||
_block_number: BlockNumber, | ||
_context: &Context, | ||
) -> Result<Number, Error> { | ||
// TODO implement | ||
Ok(0.into()) | ||
} | ||
|
||
pub fn get_code( | ||
_address: H160, | ||
_block_number: BlockNumber, | ||
_context: &Context, | ||
) -> Result<Bytes, Error> { | ||
// TODO implement | ||
Ok(Default::default()) | ||
} | ||
|
||
pub fn get_storage_at( | ||
_address: H160, | ||
_key: H256, | ||
_block_number: BlockNumber, | ||
_context: &Context, | ||
) -> Result<H256, Error> { | ||
// TODO implement | ||
Ok(H256::zero()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use jsonrpsee_http_server::RpcModule; | ||
|
||
use crate::context::ContextLock; | ||
|
||
mod logic; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error {} | ||
|
||
pub fn eth_account_module(context: ContextLock) -> RpcModule<ContextLock> { | ||
let mut module = RpcModule::new(context); | ||
|
||
module | ||
.register_async_method("eth_accounts", |_, context| async move { | ||
let context = context.read().await; | ||
logic::accounts(&context).map_err(|err| jsonrpsee_core::Error::Custom(err.to_string())) | ||
}) | ||
.unwrap(); | ||
|
||
module | ||
.register_async_method("eth_getTransactionCount", |params, context| async move { | ||
let context = context.read().await; | ||
let (address, block_number) = params.parse()?; | ||
logic::get_transaction_count(address, block_number, &context) | ||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string())) | ||
}) | ||
.unwrap(); | ||
|
||
module | ||
.register_async_method("eth_getBalance", |params, context| async move { | ||
let context = context.read().await; | ||
let (address, block_number) = params.parse()?; | ||
logic::get_balance(address, block_number, &context) | ||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string())) | ||
}) | ||
.unwrap(); | ||
|
||
module | ||
.register_async_method("eth_getCode", |params, context| async move { | ||
let context = context.read().await; | ||
let (address, block_number) = params.parse()?; | ||
logic::get_code(address, block_number, &context) | ||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string())) | ||
}) | ||
.unwrap(); | ||
|
||
module | ||
.register_async_method("eth_getStorageAt", |params, context| async move { | ||
let context = context.read().await; | ||
let (address, key, block_number) = params.parse()?; | ||
logic::get_storage_at(address, key, block_number, &context) | ||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string())) | ||
}) | ||
.unwrap(); | ||
|
||
module | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters