Fixing CLI signer

This commit is contained in:
Tomasz Drwięga 2016-12-13 12:17:01 +01:00
parent 05dcf951d1
commit 5affefc763
4 changed files with 60 additions and 25 deletions

View File

@ -18,6 +18,8 @@
use std::fmt; use std::fmt;
use serde::{Serialize, Serializer}; use serde::{Serialize, Serializer};
use util::log::Colour;
use v1::types::{U256, TransactionRequest, RichRawTransaction, H160, H256, H520, Bytes}; use v1::types::{U256, TransactionRequest, RichRawTransaction, H160, H256, H520, Bytes};
use v1::helpers; use v1::helpers;
@ -48,11 +50,10 @@ impl fmt::Display for ConfirmationRequest {
impl fmt::Display for ConfirmationPayload { impl fmt::Display for ConfirmationPayload {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { match *self {
ConfirmationPayload::SendTransaction(ref transaction) ConfirmationPayload::SendTransaction(ref transaction) => write!(f, "{}", transaction),
=> write!(f, "{}", transaction), ConfirmationPayload::SignTransaction(ref transaction) => write!(f, "(Sign only) {}", transaction),
ConfirmationPayload::SignTransaction(_) => write!(f, "TODO: data"), ConfirmationPayload::Signature(ref sign) => write!(f, "{}", sign),
ConfirmationPayload::Decrypt(_) => write!(f, "TODO: decrypt"), ConfirmationPayload::Decrypt(ref decrypt) => write!(f, "{}", decrypt),
ConfirmationPayload::Signature(_) => write!(f, "TODO: signature"),
} }
} }
} }
@ -75,6 +76,17 @@ impl From<(H160, H256)> for SignRequest {
} }
} }
impl fmt::Display for SignRequest {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"sign 0x{:?} with {}",
self.hash,
Colour::White.bold().paint(format!("0x{:?}", self.address)),
)
}
}
/// Decrypt request /// Decrypt request
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct DecryptRequest { pub struct DecryptRequest {
@ -93,6 +105,16 @@ impl From<(H160, Bytes)> for DecryptRequest {
} }
} }
impl fmt::Display for DecryptRequest {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"decrypt data with {}",
Colour::White.bold().paint(format!("0x{:?}", self.address)),
)
}
}
/// Confirmation response for particular payload /// Confirmation response for particular payload
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum ConfirmationResponse { pub enum ConfirmationResponse {

View File

@ -18,6 +18,7 @@
use v1::types::{Bytes, H160, U256}; use v1::types::{Bytes, H160, U256};
use v1::helpers; use v1::helpers;
use util::log::Colour;
use std::fmt; use std::fmt;
@ -62,13 +63,19 @@ impl fmt::Display for TransactionRequest {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let eth = self.value.unwrap_or(U256::from(0)); let eth = self.value.unwrap_or(U256::from(0));
match self.to { match self.to {
Some(ref to) => write!(f, "{} Ether from {:?} to {:?}", Some(ref to) => write!(
format_ether(eth), f,
self.from, "{} ETH from {} to 0x{:?}",
to), Colour::White.bold().paint(format_ether(eth)),
None => write!(f, "{} Ether from {:?}", Colour::White.bold().paint(format!("0x{:?}", self.from)),
format_ether(eth), to
self.from), ),
None => write!(
f,
"{} ETH from {} for contract creation",
Colour::White.bold().paint(format_ether(eth)),
Colour::White.bold().paint(format!("0x{:?}", self.from)),
),
} }
} }
} }

View File

@ -22,13 +22,15 @@ use ws::{
Error as WsError, Error as WsError,
ErrorKind as WsErrorKind, ErrorKind as WsErrorKind,
Message, Message,
Result as WsResult Result as WsResult,
}; };
use serde::Deserialize; use serde::Deserialize;
use serde_json::{self as json, use serde_json::{
Value as JsonValue, self as json,
Error as JsonError}; Value as JsonValue,
Error as JsonError,
};
use futures::{BoxFuture, Canceled, Complete, Future, oneshot, done}; use futures::{BoxFuture, Canceled, Complete, Future, oneshot, done};
@ -170,13 +172,17 @@ impl Pending {
} }
fn get_authcode(path: &PathBuf) -> Result<String, RpcError> { fn get_authcode(path: &PathBuf) -> Result<String, RpcError> {
match File::open(path) { if let Ok(fd) = File::open(path) {
Ok(fd) => match BufReader::new(fd).lines().next() { if let Some(Ok(line)) = BufReader::new(fd).lines().next() {
Some(Ok(code)) => Ok(code), let mut parts = line.split(';');
_ => Err(RpcError::NoAuthCode), let token = parts.next();
},
Err(_) => Err(RpcError::NoAuthCode) if let Some(code) = token {
return Ok(code.into());
}
}
} }
Err(RpcError::NoAuthCode)
} }
/// The handle to the connection /// The handle to the connection

View File

@ -17,7 +17,7 @@ impl SignerRpc {
pub fn requests_to_confirm(&mut self) -> pub fn requests_to_confirm(&mut self) ->
BoxFuture<Result<Vec<ConfirmationRequest>, RpcError>, Canceled> BoxFuture<Result<Vec<ConfirmationRequest>, RpcError>, Canceled>
{ {
self.rpc.request("personal_requestsToConfirm", vec![]) self.rpc.request("signer_requestsToConfirm", vec![])
} }
pub fn confirm_request( pub fn confirm_request(
&mut self, &mut self,
@ -27,7 +27,7 @@ impl SignerRpc {
pwd: &str pwd: &str
) -> BoxFuture<Result<U256, RpcError>, Canceled> ) -> BoxFuture<Result<U256, RpcError>, Canceled>
{ {
self.rpc.request("personal_confirmRequest", vec![ self.rpc.request("signer_confirmRequest", vec![
to_value(&format!("{:#x}", id)), to_value(&format!("{:#x}", id)),
to_value(&TransactionModification { gas_price: new_gas_price, gas: new_gas }), to_value(&TransactionModification { gas_price: new_gas_price, gas: new_gas }),
to_value(&pwd), to_value(&pwd),
@ -36,7 +36,7 @@ impl SignerRpc {
pub fn reject_request(&mut self, id: U256) -> pub fn reject_request(&mut self, id: U256) ->
BoxFuture<Result<bool, RpcError>, Canceled> BoxFuture<Result<bool, RpcError>, Canceled>
{ {
self.rpc.request("personal_rejectRequest", vec![ self.rpc.request("signer_rejectRequest", vec![
JsonValue::String(format!("{:#x}", id)) JsonValue::String(format!("{:#x}", id))
]) ])
} }