-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new configuration RPC endpoints (#17)
feat: Add new configuration RPC endpoints (config_getShowCalls, config_setShowCalls, and config_setResolveHashes). Add example http REST file for quickly testing the node locally. Add recommended plugins for VSCode. Add SUPPORTED_APIS.md. Update version to 1.0.3
- Loading branch information
1 parent
f5db37f
commit 0c9d64c
Showing
10 changed files
with
261 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"recommendations": [ | ||
"rust-lang.rust-analyzer", | ||
"humao.rest-client", | ||
], | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,82 @@ | ||
# 🔧 Supported APIs for In-Memory Node 🔧 | ||
|
||
> ⚠️ **WORK IN PROGRESS**: This list is non-comprehensive and being updated | ||
# Key | ||
|
||
The `status` options are: | ||
|
||
+ `SUPPORTED` - Basic support is complete | ||
+ `PARTIALLY` - Partial support and a description including more specific details | ||
+ `NOT IMPLEMENTED` - Currently not supported/implemented | ||
|
||
# `CONFIG NAMESPACE` | ||
|
||
## `config_getShowCalls` | ||
|
||
[source](src/configuration_api.rs) | ||
|
||
Gets the current value of `show_calls` that's originally set with `--show-calls` option | ||
|
||
### Arguments | ||
|
||
+ _NONE_ | ||
|
||
### Status | ||
|
||
`SUPPORTED` | ||
|
||
### Example | ||
|
||
```bash | ||
curl --request POST \ | ||
--url http://localhost:8011/ \ | ||
--header 'content-type: application/json' \ | ||
--data '{"jsonrpc": "2.0","id": "1","method": "config_getShowCalls","params": []}' | ||
``` | ||
|
||
## `config_setShowCalls` | ||
|
||
[source](src/configuration_api.rs) | ||
|
||
Updates `show_calls` to print more detailed call traces | ||
|
||
### Arguments | ||
|
||
+ `value: String ('None', 'User', 'System', 'All')` | ||
|
||
### Status | ||
|
||
`SUPPORTED` | ||
|
||
### Example | ||
|
||
```bash | ||
curl --request POST \ | ||
--url http://localhost:8011/ \ | ||
--header 'content-type: application/json' \ | ||
--data '{"jsonrpc": "2.0","id": "1","method": "config_setShowCalls","params": ["all"]}' | ||
``` | ||
|
||
## `config_setResolveHashes` | ||
|
||
[source](src/configuration_api.rs) | ||
|
||
Updates `resolve-hashes` to call OpenChain for human-readable ABI names in call traces | ||
|
||
### Arguments | ||
|
||
+ `value: boolean` | ||
|
||
### Status | ||
|
||
`SUPPORTED` | ||
|
||
### Example | ||
|
||
```bash | ||
curl --request POST \ | ||
--url http://localhost:8011/ \ | ||
--header 'content-type: application/json' \ | ||
--data '{"jsonrpc": "2.0","id": "1","method": "config_setResolveHashes","params": [true]}' | ||
``` |
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,78 @@ | ||
// Built-in uses | ||
use std::sync::{Arc, RwLock}; | ||
|
||
// External uses | ||
use jsonrpc_core::Result; | ||
use jsonrpc_derive::rpc; | ||
|
||
// Workspace uses | ||
|
||
// Local uses | ||
use crate::{node::InMemoryNodeInner, ShowCalls}; | ||
|
||
pub struct ConfigurationApiNamespace { | ||
node: Arc<RwLock<InMemoryNodeInner>>, | ||
} | ||
|
||
impl ConfigurationApiNamespace { | ||
pub fn new(node: Arc<RwLock<InMemoryNodeInner>>) -> Self { | ||
Self { node } | ||
} | ||
} | ||
|
||
#[rpc] | ||
pub trait ConfigurationApiNamespaceT { | ||
/// Get the InMemoryNodeInner's show_calls property as a string | ||
/// | ||
/// # Returns | ||
/// The current `show_calls` value for the InMemoryNodeInner. | ||
#[rpc(name = "config_getShowCalls", returns = "String")] | ||
fn config_get_show_calls(&self) -> Result<String>; | ||
|
||
/// Set show_calls for the InMemoryNodeInner | ||
/// | ||
/// # Parameters | ||
/// - `value`: A ShowCalls enum to update show_calls to | ||
/// | ||
/// # Returns | ||
/// The updated/current `show_calls` value for the InMemoryNodeInner. | ||
#[rpc(name = "config_setShowCalls", returns = "String")] | ||
fn config_set_show_calls(&self, value: String) -> Result<String>; | ||
|
||
/// Set resolve_hashes for the InMemoryNodeInner | ||
/// | ||
/// # Parameters | ||
/// - `value`: A bool to update resolve_hashes to | ||
/// | ||
/// # Returns | ||
/// The updated `resolve_hashes` value for the InMemoryNodeInner. | ||
#[rpc(name = "config_setResolveHashes", returns = "bool")] | ||
fn config_set_resolve_hashes(&self, value: bool) -> Result<bool>; | ||
} | ||
|
||
impl ConfigurationApiNamespaceT for ConfigurationApiNamespace { | ||
fn config_get_show_calls(&self) -> Result<String> { | ||
let reader = self.node.read().unwrap(); | ||
Ok(reader.show_calls.to_string()) | ||
} | ||
|
||
fn config_set_show_calls(&self, value: String) -> Result<String> { | ||
let show_calls = match value.parse::<ShowCalls>() { | ||
Ok(value) => value, | ||
Err(_) => { | ||
let reader = self.node.read().unwrap(); | ||
return Ok(reader.show_calls.to_string()); | ||
} | ||
}; | ||
|
||
let mut inner = self.node.write().unwrap(); | ||
inner.show_calls = show_calls; | ||
Ok(inner.show_calls.to_string()) | ||
} | ||
|
||
fn config_set_resolve_hashes(&self, value: bool) -> Result<bool> { | ||
let mut inner = self.node.write().unwrap(); | ||
inner.resolve_hashes = value; | ||
Ok(inner.resolve_hashes) | ||
} | ||
} |
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,56 @@ | ||
POST http://localhost:8011 | ||
content-type: application/json | ||
|
||
{ | ||
"jsonrpc": "2.0", | ||
"id": "1", | ||
"method": "eth_blockNumber", | ||
"params": [] | ||
} | ||
|
||
### | ||
POST http://localhost:8011 | ||
content-type: application/json | ||
|
||
{ | ||
"jsonrpc": "2.0", | ||
"id": "1", | ||
"method": "net_version", | ||
"params": [] | ||
} | ||
|
||
### | ||
POST http://localhost:8011 | ||
content-type: application/json | ||
|
||
{ | ||
"jsonrpc": "2.0", | ||
"id": "1", | ||
"method": "config_getShowCalls", | ||
"params": [] | ||
} | ||
|
||
### | ||
POST http://localhost:8011 | ||
content-type: application/json | ||
|
||
{ | ||
"jsonrpc": "2.0", | ||
"id": "1", | ||
"method": "config_setShowCalls", | ||
"params": ["All"] | ||
} | ||
|
||
### | ||
POST http://localhost:8011 | ||
content-type: application/json | ||
|
||
{ | ||
"jsonrpc": "2.0", | ||
"id": "1", | ||
"method": "config_setResolveHashes", | ||
"params": [true] | ||
} | ||
|
||
### | ||
|