Skip to content

Commit

Permalink
add connect rpc back
Browse files Browse the repository at this point in the history
  • Loading branch information
HarukaMa committed Feb 12, 2022
1 parent 22f1aa3 commit 79731a3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/rpc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,13 @@ fn create_rpc_module<N: Network, E: Environment>(rpc_context: RpcContext<N, E>)
// result_to_response(&req, result)
// }

module.register_async_method("getsharesforprover", |rpc_params, rpc_context| async move {
let prover = rpc_params.parse::<[Address<N>; 1]>()?[0];
module.register_async_method("connect", |_rpc_params, rpc_context| async move {
let addresses = _rpc_params.parse::<Vec<String>>()?;
rpc_context.connect(addresses).map_err(JsonrpseeError::to_call_error).await
})?;

module.register_async_method("getsharesforprover", |_rpc_params, rpc_context| async move {
let prover = _rpc_params.parse::<[Address<N>; 1]>()?[0];
rpc_context
.get_shares_for_prover(prover)
.map_err(JsonrpseeError::to_call_error)
Expand Down
5 changes: 2 additions & 3 deletions src/rpc/rpc_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,14 @@ impl<N: Network, E: Environment> RpcFunctions<N> for RpcContext<N, E> {
Ok(transaction.transaction_id())
}

async fn connect(&self, peers: Vec<serde_json::Value>) -> Result<bool, RpcError> {
async fn connect(&self, peers: Vec<String>) -> Result<bool, RpcError> {
for peer_ip in &peers {
let peer_ip = peer_ip.to_string();
let (router, _handler) = oneshot::channel();
let addr: Result<SocketAddr, std::net::AddrParseError> = peer_ip[1..peer_ip.len() - 1].parse();
let res = match addr {
Ok(addr) => addr,
Err(error) => {
panic!("{}", error.to_string());
return Err(RpcError::Message(error.to_string()));
}
};
if let Err(error) = self
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/rpc_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ pub trait RpcFunctions<N: Network> {
#[doc = include_str!("./documentation/public_endpoints/sendtransaction.md")]
async fn send_transaction(&self, transaction_bytes: String) -> Result<N::TransactionID, RpcError>;

async fn connect(&self, peers: Vec<String>) -> Result<bool, RpcError>;

#[doc = include_str!("./documentation/public_endpoints/getsharesforprover.md")]
async fn get_shares_for_prover(&self, prover: Address<N>) -> Result<u64, RpcError>;

async fn connect(&self, peers: Vec<serde_json::Value>) -> Result<bool, RpcError>;

async fn get_shares(&self) -> u64;

async fn get_provers(&self) -> serde_json::Value;
Expand Down

0 comments on commit 79731a3

Please sign in to comment.