Skip to content

Commit

Permalink
Merge branch '293-implement-client-commands' into 'dev'
Browse files Browse the repository at this point in the history
Implement client commands of Massa API endpoints

Closes #293

See merge request massalabs/massa!243
  • Loading branch information
damip committed Oct 5, 2021
2 parents 91e526b + 08c225a commit a859773
Show file tree
Hide file tree
Showing 8 changed files with 356 additions and 87 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions api-private/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ displaydoc = "0.2"
jsonrpc-core = "18.0.0"
jsonrpc-derive = "18.0.0"
jsonrpc-http-server = "18.0.0"
tokio = { version = "1.11", features = ["full"] }
thiserror = "1.0"
# custom modules
crypto = {path = "../crypto"}
api-dto = { path = "../api-dto" }
models = {path = "../models"}
crypto = {path = "../crypto"}
communication = {path = "../communication"}
consensus = {path = "../consensus"}
time = {path = "../time"}
models = {path = "../models"}
rpc-server = {path = "../rpc-server"}
thiserror = "1.0"

tokio = { version = "1.11", features = ["full"] }
time = {path = "../time"}
47 changes: 26 additions & 21 deletions api-private/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ pub struct ApiMassaPrivate {
/// Private Massa-RPC "manager mode" endpoints
#[rpc(server)]
pub trait MassaPrivate {
/// Starts the node and waits for node to start.
/// Signals if the node is already running.
#[rpc(name = "start_node")]
fn start_node(&self) -> Result<(), PrivateApiError>;

/// Gracefully stop the node.
#[rpc(name = "stop_node")]
fn stop_node(&self) -> BoxFuture<Result<(), PrivateApiError>>;
Expand All @@ -48,17 +43,20 @@ pub trait MassaPrivate {

/// Add a vec of new private keys for the node to use to stake.
/// No confirmation to expect.
#[rpc(name = "add_staking_keys")]
fn add_staking_keys(&self, _: Vec<PrivateKey>) -> BoxFuture<Result<(), PrivateApiError>>;
#[rpc(name = "add_staking_private_keys")]
fn add_staking_private_keys(
&self,
_: Vec<PrivateKey>,
) -> BoxFuture<Result<(), PrivateApiError>>;

/// Remove a vec of addresses used to stake.
/// No confirmation to expect.
#[rpc(name = "remove_staking_keys")]
fn remove_staking_keys(&self, _: Vec<Address>) -> BoxFuture<Result<(), PrivateApiError>>;
#[rpc(name = "remove_staking_addresses")]
fn remove_staking_addresses(&self, _: Vec<Address>) -> BoxFuture<Result<(), PrivateApiError>>;

/// Return hashset of staking addresses.
#[rpc(name = "list_staking_keys")]
fn list_staking_keys(&self) -> BoxFuture<Result<AddressHashSet, PrivateApiError>>;
#[rpc(name = "get_staking_addresses")]
fn get_staking_addresses(&self) -> BoxFuture<Result<AddressHashSet, PrivateApiError>>;

/// Bans given node id
/// No confirmation to expect.
Expand All @@ -68,7 +66,7 @@ pub trait MassaPrivate {
/// Unbans given ip addr
/// No confirmation to expect.
#[rpc(name = "unban")]
fn unban(&self, _: IpAddr) -> BoxFuture<Result<(), PrivateApiError>>;
fn unban(&self, _: Vec<IpAddr>) -> BoxFuture<Result<(), PrivateApiError>>;
}

impl ApiMassaPrivate {
Expand Down Expand Up @@ -109,10 +107,6 @@ impl ApiMassaPrivate {
}

impl MassaPrivate for ApiMassaPrivate {
fn start_node(&self) -> Result<(), PrivateApiError> {
todo!()
}

fn stop_node(&self) -> BoxFuture<Result<(), PrivateApiError>> {
let stop = self.stop_node_channel.clone();
let closure = async move || {
Expand All @@ -134,13 +128,19 @@ impl MassaPrivate for ApiMassaPrivate {
Box::pin(closure())
}

fn add_staking_keys(&self, keys: Vec<PrivateKey>) -> BoxFuture<Result<(), PrivateApiError>> {
fn add_staking_private_keys(
&self,
keys: Vec<PrivateKey>,
) -> BoxFuture<Result<(), PrivateApiError>> {
let cmd_sender = self.consensus_command_sender.clone();
let closure = async move || Ok(cmd_sender.register_staking_private_keys(keys).await?);
Box::pin(closure())
}

fn remove_staking_keys(&self, keys: Vec<Address>) -> BoxFuture<Result<(), PrivateApiError>> {
fn remove_staking_addresses(
&self,
keys: Vec<Address>,
) -> BoxFuture<Result<(), PrivateApiError>> {
let cmd_sender = self.consensus_command_sender.clone();
let closure = async move || {
Ok(cmd_sender
Expand All @@ -150,7 +150,7 @@ impl MassaPrivate for ApiMassaPrivate {
Box::pin(closure())
}

fn list_staking_keys(&self) -> BoxFuture<Result<AddressHashSet, PrivateApiError>> {
fn get_staking_addresses(&self) -> BoxFuture<Result<AddressHashSet, PrivateApiError>> {
let cmd_sender = self.consensus_command_sender.clone();
let closure = async move || Ok(cmd_sender.get_staking_addresses().await?);
Box::pin(closure())
Expand All @@ -162,9 +162,14 @@ impl MassaPrivate for ApiMassaPrivate {
Box::pin(closure())
}

fn unban(&self, ip: IpAddr) -> BoxFuture<Result<(), PrivateApiError>> {
fn unban(&self, ips: Vec<IpAddr>) -> BoxFuture<Result<(), PrivateApiError>> {
let network_command_sender = self.network_command_sender.clone();
let closure = async move || Ok(network_command_sender.unban(ip).await?);
let closure = async move || {
for ip in ips {
network_command_sender.unban(ip).await?
}
Ok(())
};
Box::pin(closure())
}
}
5 changes: 5 additions & 0 deletions rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ structopt = { version = "0.3", features = [ "paw" ] }
strum = "0.21"
strum_macros = "0.21"
tokio = { version = "1", features = ["full"] }
# custom modules
api-dto = { path = "../api-dto" }
crypto = { path = "../crypto" }
models = {path = "../models"}
time = {path = "../time"}
Loading

0 comments on commit a859773

Please sign in to comment.