forked from starcoinorg/starcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [rpc] dry run api require sender's public_key resolve starcoinorg#2480 * [rpc] Add contract.dry_run_raw api and * [cmd] Add dev call-api method for call any json rpc api.
- Loading branch information
1 parent
59e7b81
commit 8dbde12
Showing
10 changed files
with
139 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) The Starcoin Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::cli_state::CliState; | ||
use crate::StarcoinOpt; | ||
use anyhow::Result; | ||
use scmd::{CommandAction, ExecContext}; | ||
use serde_json::Value; | ||
use starcoin_rpc_client::Params; | ||
use structopt::StructOpt; | ||
|
||
/// Call rpc api command | ||
/// Some examples: | ||
/// ``` shell | ||
/// dev call-api node.info | ||
/// dev call-api chain.get_block_by_number [0] | ||
/// ``` | ||
#[derive(Debug, StructOpt)] | ||
#[structopt(name = "call-api")] | ||
pub struct CallApiOpt { | ||
#[structopt(name = "rpc-api-name")] | ||
/// api name to call, example: node.info | ||
rpc_api_name: String, | ||
|
||
#[structopt(name = "api-params")] | ||
/// api params, should be a json array string | ||
params: Option<String>, | ||
} | ||
|
||
pub struct CallApiCommand; | ||
|
||
impl CommandAction for CallApiCommand { | ||
type State = CliState; | ||
type GlobalOpt = StarcoinOpt; | ||
type Opt = CallApiOpt; | ||
type ReturnItem = Value; | ||
|
||
fn run( | ||
&self, | ||
ctx: &ExecContext<Self::State, Self::GlobalOpt, Self::Opt>, | ||
) -> Result<Self::ReturnItem> { | ||
let opt = ctx.opt(); | ||
|
||
let params = match opt.params.as_ref() { | ||
Some(param) => serde_json::from_str(param.as_str())?, | ||
None => Params::None, | ||
}; | ||
|
||
let result = ctx | ||
.state() | ||
.client() | ||
.call_raw_api(opt.rpc_api_name.as_str(), params)?; | ||
Ok(result) | ||
} | ||
} |
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
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