From 65523190742f25cbb488e72edb66c5945c10b26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Str=C3=B6m?= Date: Wed, 2 Nov 2016 15:55:03 +0100 Subject: [PATCH] Style rewrite --- rpc_cli/src/lib.rs | 47 +++++++++++++++++++++------------ rpc_client/src/client.rs | 19 +++++++------ rpc_client/src/signer_client.rs | 11 ++++---- 3 files changed, 47 insertions(+), 30 deletions(-) diff --git a/rpc_cli/src/lib.rs b/rpc_cli/src/lib.rs index 7461e8abd..b30c134ef 100644 --- a/rpc_cli/src/lib.rs +++ b/rpc_cli/src/lib.rs @@ -15,7 +15,10 @@ use std::fs::File; use futures::Future; -fn sign_interactive(signer: &mut SignerRpc, password: &str, request: ConfirmationRequest) +fn sign_interactive( + signer: &mut SignerRpc, + password: &str, + request: ConfirmationRequest) { print!("\n{}\nSign this transaction? (y)es/(N)o/(r)eject: ", request); let _ = stdout().flush(); @@ -39,7 +42,9 @@ fn sign_interactive(signer: &mut SignerRpc, password: &str, request: Confirmatio } } -fn sign_transactions(signer: &mut SignerRpc, password: String) -> Result { +fn sign_transactions( + signer: &mut SignerRpc, password: String +) -> Result { try!(signer.requests_to_confirm().map(|reqs| { match reqs { Ok(ref reqs) if reqs.is_empty() => { @@ -82,9 +87,9 @@ fn list_transactions(signer: &mut SignerRpc) -> Result { }).wait()) } -fn sign_transaction(signer: &mut SignerRpc, - id: U256, - password: &str) -> Result { +fn sign_transaction( + signer: &mut SignerRpc, id: U256, password: &str +) -> Result { try!(signer.confirm_request(id, None, password).map(|res| { match res { Ok(u) => Ok(format!("Signed transaction id: {:#x}", u)), @@ -95,8 +100,9 @@ fn sign_transaction(signer: &mut SignerRpc, }).wait()) } -fn reject_transaction(signer: &mut SignerRpc, - id: U256) -> Result { +fn reject_transaction( + signer: &mut SignerRpc, id: U256) -> Result +{ try!(signer.reject_request(id).map(|res| { match res { Ok(true) => Ok(format!("Rejected transaction id {:#x}", id)), @@ -110,27 +116,34 @@ fn reject_transaction(signer: &mut SignerRpc, // cmds -pub fn cmd_signer_list(signerport: u16, - authfile: PathBuf) -> Result { - let mut signer = try!(SignerRpc::new(&format!("ws://127.0.0.1:{}", signerport), &authfile).map_err(|err| { +pub fn cmd_signer_list( + signerport: u16, authfile: PathBuf +) -> Result { + let addr = &format!("ws://127.0.0.1:{}", signerport); + let mut signer = try!(SignerRpc::new(addr, &authfile)); + signer.map_err(|err| { format!("{:?}", err) })); list_transactions(&mut signer) } -pub fn cmd_signer_reject(id: Option, signerport: u16, - authfile: PathBuf) -> Result { +pub fn cmd_signer_reject( + id: Option, signerport: u16, authfile: PathBuf +) -> Result { let id = try!(id.ok_or(format!("id required for signer reject"))); - let mut signer = try!(SignerRpc::new(&format!("ws://127.0.0.1:{}", signerport), &authfile).map_err(|err| { + let addr = &format!("ws://127.0.0.1:{}", signerport); + let mut signer = try!(SignerRpc::new(addr, &authfile).map_err(|err| { format!("{:?}", err) })); reject_transaction(&mut signer, U256::from(id)) } -pub fn cmd_signer_sign(id: Option, - pwfile: Option, - signerport: u16, - authfile: PathBuf) -> Result { +pub fn cmd_signer_sign( + id: Option, + pwfile: Option, + signerport: u16, + authfile: PathBuf +) -> Result { let password; match pwfile { Some(pwfile) => { diff --git a/rpc_client/src/client.rs b/rpc_client/src/client.rs index 72036c8c8..dddea729f 100644 --- a/rpc_client/src/client.rs +++ b/rpc_client/src/client.rs @@ -46,10 +46,11 @@ struct RpcHandler { } impl RpcHandler { - fn new(out: Sender, - auth_code: String, - complete: Complete>) - -> Self { + fn new( + out: Sender, + auth_code: String, + complete: Complete> + ) -> Self { RpcHandler { out: Some(out), auth_code: auth_code, @@ -169,8 +170,9 @@ impl Rpc { rpc } /// Non-blocking, returns a future - pub fn connect(url: &str, authpath: &PathBuf) - -> BoxFuture, Canceled> { + pub fn connect( + url: &str, authpath: &PathBuf + ) -> BoxFuture, Canceled> { let (c, p) = oneshot::>(); match get_authcode(authpath) { Err(e) => return done(Ok(Err(e))).boxed(), @@ -203,8 +205,9 @@ impl Rpc { } } /// Non-blocking, returns a future of the request response - pub fn request(&mut self, method: &'static str, params: Vec) - -> BoxFuture, Canceled> + pub fn request( + &mut self, method: &'static str, params: Vec + ) -> BoxFuture, Canceled> where T: Deserialize + Send + Sized { let (c, p) = oneshot::>(); diff --git a/rpc_client/src/signer_client.rs b/rpc_client/src/signer_client.rs index 3a135d32b..587fa42b7 100644 --- a/rpc_client/src/signer_client.rs +++ b/rpc_client/src/signer_client.rs @@ -19,11 +19,12 @@ impl SignerRpc { { self.rpc.request("personal_requestsToConfirm", vec![]) } - pub fn confirm_request(&mut self, - id: U256, - new_gas_price: Option, - pwd: &str) -> - BoxFuture, Canceled> + pub fn confirm_request( + &mut self, + id: U256, + new_gas_price: Option, + pwd: &str + ) -> BoxFuture, Canceled> { self.rpc.request("personal_confirmRequest", vec![ to_value(&format!("{:#x}", id)),