Style rewrite

This commit is contained in:
Kristoffer Ström 2016-11-02 15:55:03 +01:00 committed by arkpar
parent 1d0ccb1c30
commit 6552319074
3 changed files with 47 additions and 30 deletions

View File

@ -15,7 +15,10 @@ use std::fs::File;
use futures::Future; 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); print!("\n{}\nSign this transaction? (y)es/(N)o/(r)eject: ", request);
let _ = stdout().flush(); 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<String, String> { fn sign_transactions(
signer: &mut SignerRpc, password: String
) -> Result<String, String> {
try!(signer.requests_to_confirm().map(|reqs| { try!(signer.requests_to_confirm().map(|reqs| {
match reqs { match reqs {
Ok(ref reqs) if reqs.is_empty() => { Ok(ref reqs) if reqs.is_empty() => {
@ -82,9 +87,9 @@ fn list_transactions(signer: &mut SignerRpc) -> Result<String, String> {
}).wait()) }).wait())
} }
fn sign_transaction(signer: &mut SignerRpc, fn sign_transaction(
id: U256, signer: &mut SignerRpc, id: U256, password: &str
password: &str) -> Result<String, String> { ) -> Result<String, String> {
try!(signer.confirm_request(id, None, password).map(|res| { try!(signer.confirm_request(id, None, password).map(|res| {
match res { match res {
Ok(u) => Ok(format!("Signed transaction id: {:#x}", u)), Ok(u) => Ok(format!("Signed transaction id: {:#x}", u)),
@ -95,8 +100,9 @@ fn sign_transaction(signer: &mut SignerRpc,
}).wait()) }).wait())
} }
fn reject_transaction(signer: &mut SignerRpc, fn reject_transaction(
id: U256) -> Result<String, String> { signer: &mut SignerRpc, id: U256) -> Result<String, String>
{
try!(signer.reject_request(id).map(|res| { try!(signer.reject_request(id).map(|res| {
match res { match res {
Ok(true) => Ok(format!("Rejected transaction id {:#x}", id)), Ok(true) => Ok(format!("Rejected transaction id {:#x}", id)),
@ -110,27 +116,34 @@ fn reject_transaction(signer: &mut SignerRpc,
// cmds // cmds
pub fn cmd_signer_list(signerport: u16, pub fn cmd_signer_list(
authfile: PathBuf) -> Result<String, String> { signerport: u16, authfile: PathBuf
let mut signer = try!(SignerRpc::new(&format!("ws://127.0.0.1:{}", signerport), &authfile).map_err(|err| { ) -> Result<String, String> {
let addr = &format!("ws://127.0.0.1:{}", signerport);
let mut signer = try!(SignerRpc::new(addr, &authfile));
signer.map_err(|err| {
format!("{:?}", err) format!("{:?}", err)
})); }));
list_transactions(&mut signer) list_transactions(&mut signer)
} }
pub fn cmd_signer_reject(id: Option<usize>, signerport: u16, pub fn cmd_signer_reject(
authfile: PathBuf) -> Result<String, String> { id: Option<usize>, signerport: u16, authfile: PathBuf
) -> Result<String, String> {
let id = try!(id.ok_or(format!("id required for signer reject"))); 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) format!("{:?}", err)
})); }));
reject_transaction(&mut signer, U256::from(id)) reject_transaction(&mut signer, U256::from(id))
} }
pub fn cmd_signer_sign(id: Option<usize>, pub fn cmd_signer_sign(
pwfile: Option<PathBuf>, id: Option<usize>,
signerport: u16, pwfile: Option<PathBuf>,
authfile: PathBuf) -> Result<String, String> { signerport: u16,
authfile: PathBuf
) -> Result<String, String> {
let password; let password;
match pwfile { match pwfile {
Some(pwfile) => { Some(pwfile) => {

View File

@ -46,10 +46,11 @@ struct RpcHandler {
} }
impl RpcHandler { impl RpcHandler {
fn new(out: Sender, fn new(
auth_code: String, out: Sender,
complete: Complete<Result<Rpc, RpcError>>) auth_code: String,
-> Self { complete: Complete<Result<Rpc, RpcError>>
) -> Self {
RpcHandler { RpcHandler {
out: Some(out), out: Some(out),
auth_code: auth_code, auth_code: auth_code,
@ -169,8 +170,9 @@ impl Rpc {
rpc rpc
} }
/// Non-blocking, returns a future /// Non-blocking, returns a future
pub fn connect(url: &str, authpath: &PathBuf) pub fn connect(
-> BoxFuture<Result<Self, RpcError>, Canceled> { url: &str, authpath: &PathBuf
) -> BoxFuture<Result<Self, RpcError>, Canceled> {
let (c, p) = oneshot::<Result<Self, RpcError>>(); let (c, p) = oneshot::<Result<Self, RpcError>>();
match get_authcode(authpath) { match get_authcode(authpath) {
Err(e) => return done(Ok(Err(e))).boxed(), Err(e) => return done(Ok(Err(e))).boxed(),
@ -203,8 +205,9 @@ impl Rpc {
} }
} }
/// Non-blocking, returns a future of the request response /// Non-blocking, returns a future of the request response
pub fn request<T>(&mut self, method: &'static str, params: Vec<JsonValue>) pub fn request<T>(
-> BoxFuture<Result<T, RpcError>, Canceled> &mut self, method: &'static str, params: Vec<JsonValue>
) -> BoxFuture<Result<T, RpcError>, Canceled>
where T: Deserialize + Send + Sized { where T: Deserialize + Send + Sized {
let (c, p) = oneshot::<Result<JsonValue, RpcError>>(); let (c, p) = oneshot::<Result<JsonValue, RpcError>>();

View File

@ -19,11 +19,12 @@ impl SignerRpc {
{ {
self.rpc.request("personal_requestsToConfirm", vec![]) self.rpc.request("personal_requestsToConfirm", vec![])
} }
pub fn confirm_request(&mut self, pub fn confirm_request(
id: U256, &mut self,
new_gas_price: Option<U256>, id: U256,
pwd: &str) -> new_gas_price: Option<U256>,
BoxFuture<Result<U256, RpcError>, Canceled> pwd: &str
) -> BoxFuture<Result<U256, RpcError>, Canceled>
{ {
self.rpc.request("personal_confirmRequest", vec![ self.rpc.request("personal_confirmRequest", vec![
to_value(&format!("{:#x}", id)), to_value(&format!("{:#x}", id)),