-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rpc] Implement
eth_getBalance
(#867)
* [rpc] Implement eth_getBalance
- Loading branch information
Showing
15 changed files
with
175 additions
and
21 deletions.
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
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
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
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,15 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use move_core_types::{ident_str, identifier::IdentStr}; | ||
use moveos_types::state::MoveStructType; | ||
|
||
pub const MODULE_NAME: &IdentStr = ident_str!("gas_coin"); | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct GasCoin; | ||
|
||
impl MoveStructType for GasCoin { | ||
const MODULE_NAME: &'static IdentStr = MODULE_NAME; | ||
const STRUCT_NAME: &'static IdentStr = ident_str!("GasCoin"); | ||
} |
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
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,4 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod request; |
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,41 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::cli_types::{CommandAction, WalletContextOptions}; | ||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use rooch_types::error::RoochResult; | ||
|
||
/// Send a RPC request | ||
#[derive(Debug, Parser)] | ||
pub struct RequestCommand { | ||
/// The RPC method name | ||
/// --method rooch_getAnnotatedStates | ||
#[clap(long)] | ||
pub method: String, | ||
|
||
/// The RPC method params, json value. | ||
/// --params '"/resource/0x3/0x3::timestamp::CurrentTimeMicroseconds"' | ||
/// or | ||
/// --params '["/resource/0x3/0x3::timestamp::CurrentTimeMicroseconds"]' | ||
#[clap(long)] | ||
pub params: Option<serde_json::Value>, | ||
|
||
#[clap(flatten)] | ||
pub(crate) context_options: WalletContextOptions, | ||
} | ||
|
||
#[async_trait] | ||
impl CommandAction<serde_json::Value> for RequestCommand { | ||
async fn execute(self) -> RoochResult<serde_json::Value> { | ||
let client = self.context_options.build().await?.get_client().await?; | ||
let params = match self.params { | ||
Some(serde_json::Value::Array(array)) => array, | ||
Some(value) => { | ||
vec![value] | ||
} | ||
None => vec![], | ||
}; | ||
Ok(client.request(self.method.as_str(), params).await?) | ||
} | ||
} |
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,31 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::cli_types::CommandAction; | ||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use commands::request::RequestCommand; | ||
use rooch_types::error::RoochResult; | ||
|
||
pub mod commands; | ||
|
||
#[derive(Parser)] | ||
pub struct Rpc { | ||
#[clap(subcommand)] | ||
cmd: RpcCommand, | ||
} | ||
|
||
#[async_trait] | ||
impl CommandAction<String> for Rpc { | ||
async fn execute(self) -> RoochResult<String> { | ||
match self.cmd { | ||
RpcCommand::Request(request) => request.execute_serialized().await, | ||
} | ||
} | ||
} | ||
|
||
#[derive(clap::Subcommand)] | ||
#[clap(name = "server")] | ||
pub enum RpcCommand { | ||
Request(RequestCommand), | ||
} |
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
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