pub trait OwnerRpc: Sync + Send {
// Required methods
fn get_status(&self) -> Result<Status, Error>;
fn validate_chain(
&self,
assume_valid_rangeproofs_kernels: bool
) -> Result<(), Error>;
fn compact_chain(&self) -> Result<(), Error>;
fn reset_chain_head(&self, hash: String) -> Result<(), Error>;
fn invalidate_header(&self, hash: String) -> Result<(), Error>;
fn get_peers(
&self,
peer_addr: Option<SocketAddr>
) -> Result<Vec<PeerData>, Error>;
fn get_connected_peers(&self) -> Result<Vec<PeerInfoDisplay>, Error>;
fn ban_peer(&self, peer_addr: SocketAddr) -> Result<(), Error>;
fn unban_peer(&self, peer_addr: SocketAddr) -> Result<(), Error>;
}
Expand description
Public definition used to generate Node jsonrpc api.
- When running
grin
with defaults, the V2 api is available atlocalhost:3413/v2/owner
- The endpoint only supports POST operations, with the json-rpc request as the body
Required Methods§
sourcefn get_status(&self) -> Result<Status, Error>
fn get_status(&self) -> Result<Status, Error>
Networked version of Owner::get_status.
§Json rpc example
{
"jsonrpc": "2.0",
"method": "get_status",
"params": [],
"id": 1
}
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": {
"protocol_version": "2",
"user_agent": "MW/Grin 2.x.x",
"connections": "8",
"tip": {
"height": 371553,
"last_block_pushed": "00001d1623db988d7ed10c5b6319360a52f20c89b4710474145806ba0e8455ec",
"prev_block_to_last": "0000029f51bacee81c49a27b4bc9c6c446e03183867c922890f90bb17108d89f",
"total_difficulty": 1127628411943045
},
"sync_status": "header_sync",
"sync_info": {
"current_height": 371553,
"highest_height": 0
}
}
}
}
sourcefn validate_chain(
&self,
assume_valid_rangeproofs_kernels: bool
) -> Result<(), Error>
fn validate_chain( &self, assume_valid_rangeproofs_kernels: bool ) -> Result<(), Error>
Networked version of Owner::validate_chain.
§Json rpc example
{
"jsonrpc": "2.0",
"method": "validate_chain",
"params": ["false"],
"id": 1
}
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": null
}
}
sourcefn compact_chain(&self) -> Result<(), Error>
fn compact_chain(&self) -> Result<(), Error>
Networked version of Owner::compact_chain.
§Json rpc example
{
"jsonrpc": "2.0",
"method": "compact_chain",
"params": [],
"id": 1
}
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": null
}
}
fn reset_chain_head(&self, hash: String) -> Result<(), Error>
fn invalidate_header(&self, hash: String) -> Result<(), Error>
sourcefn get_peers(
&self,
peer_addr: Option<SocketAddr>
) -> Result<Vec<PeerData>, Error>
fn get_peers( &self, peer_addr: Option<SocketAddr> ) -> Result<Vec<PeerData>, Error>
Networked version of Owner::get_peers.
§Json rpc example
{
"jsonrpc": "2.0",
"method": "get_peers",
"params": ["70.50.33.130:3414"],
"id": 1
}
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": [
{
"addr": "70.50.33.130:3414",
"ban_reason": "None",
"capabilities": {
"bits": 15
},
"flags": "Defunct",
"last_banned": 0,
"last_connected": 1570129317,
"user_agent": "MW/Grin 2.0.0"
}
]
}
}
sourcefn get_connected_peers(&self) -> Result<Vec<PeerInfoDisplay>, Error>
fn get_connected_peers(&self) -> Result<Vec<PeerInfoDisplay>, Error>
Networked version of Owner::get_connected_peers.
§Json rpc example
{
"jsonrpc": "2.0",
"method": "get_connected_peers",
"params": [],
"id": 1
}
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": [
{
"addr": "35.176.195.242:3414",
"capabilities": {
"bits": 15
},
"direction": "Outbound",
"height": 374510,
"total_difficulty": 1133954621205750,
"user_agent": "MW/Grin 2.0.0",
"version": 1
},
{
"addr": "47.97.198.21:3414",
"capabilities": {
"bits": 15
},
"direction": "Outbound",
"height": 374510,
"total_difficulty": 1133954621205750,
"user_agent": "MW/Grin 2.0.0",
"version": 1
},
{
"addr": "148.251.16.13:3414",
"capabilities": {
"bits": 15
},
"direction": "Outbound",
"height": 374510,
"total_difficulty": 1133954621205750,
"user_agent": "MW/Grin 2.0.0",
"version": 1
},
{
"addr": "68.195.18.155:3414",
"capabilities": {
"bits": 15
},
"direction": "Outbound",
"height": 374510,
"total_difficulty": 1133954621205750,
"user_agent": "MW/Grin 2.0.0",
"version": 1
},
{
"addr": "52.53.221.15:3414",
"capabilities": {
"bits": 15
},
"direction": "Outbound",
"height": 0,
"total_difficulty": 1133954621205750,
"user_agent": "MW/Grin 2.0.0",
"version": 1
},
{
"addr": "109.74.202.16:3414",
"capabilities": {
"bits": 15
},
"direction": "Outbound",
"height": 374510,
"total_difficulty": 1133954621205750,
"user_agent": "MW/Grin 2.0.0",
"version": 1
},
{
"addr": "121.43.183.180:3414",
"capabilities": {
"bits": 15
},
"direction": "Outbound",
"height": 374510,
"total_difficulty": 1133954621205750,
"user_agent": "MW/Grin 2.0.0",
"version": 1
},
{
"addr": "35.157.247.209:23414",
"capabilities": {
"bits": 15
},
"direction": "Outbound",
"height": 374510,
"total_difficulty": 1133954621205750,
"user_agent": "MW/Grin 2.0.0",
"version": 1
}
]
}
}
sourcefn ban_peer(&self, peer_addr: SocketAddr) -> Result<(), Error>
fn ban_peer(&self, peer_addr: SocketAddr) -> Result<(), Error>
Networked version of Owner::ban_peer.
§Json rpc example
{
"jsonrpc": "2.0",
"method": "ban_peer",
"params": ["70.50.33.130:3414"],
"id": 1
}
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": null
}
}
sourcefn unban_peer(&self, peer_addr: SocketAddr) -> Result<(), Error>
fn unban_peer(&self, peer_addr: SocketAddr) -> Result<(), Error>
Networked version of Owner::unban_peer.
§Json rpc example
{
"jsonrpc": "2.0",
"method": "unban_peer",
"params": ["70.50.33.130:3414"],
"id": 1
}
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": null
}
}
Trait Implementations§
source§impl Handler for dyn OwnerRpc
impl Handler for dyn OwnerRpc
source§fn handle(&self, method: &str, params: Params) -> Result<Value, Error>
fn handle(&self, method: &str, params: Params) -> Result<Value, Error>
Type-check params and call method if method exists. This method is implemented automatically
by the rpc macro.
source§fn handle_request(&self, raw_request: Value) -> MaybeReply
fn handle_request(&self, raw_request: Value) -> MaybeReply
Parses raw_request as a jsonrpc request, handles request according to the jsonrpc spec.