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 serde::{Serialize, Serializer};
use util::log::Colour;
use v1::types::{U256, TransactionRequest, RichRawTransaction, H160, H256, H520, Bytes};
use v1::helpers;
@ -48,11 +50,10 @@ impl fmt::Display for ConfirmationRequest {
impl fmt::Display for ConfirmationPayload {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ConfirmationPayload::SendTransaction(ref transaction)
=> write!(f, "{}", transaction),
ConfirmationPayload::SignTransaction(_) => write!(f, "TODO: data"),
ConfirmationPayload::Decrypt(_) => write!(f, "TODO: decrypt"),
ConfirmationPayload::Signature(_) => write!(f, "TODO: signature"),
ConfirmationPayload::SendTransaction(ref transaction) => write!(f, "{}", transaction),
ConfirmationPayload::SignTransaction(ref transaction) => write!(f, "(Sign only) {}", transaction),
ConfirmationPayload::Signature(ref sign) => write!(f, "{}", sign),
ConfirmationPayload::Decrypt(ref decrypt) => write!(f, "{}", decrypt),
}
}
}
@ -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
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
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
#[derive(Debug, Clone, PartialEq)]
pub enum ConfirmationResponse {

View File

@ -18,6 +18,7 @@
use v1::types::{Bytes, H160, U256};
use v1::helpers;
use util::log::Colour;
use std::fmt;
@ -62,13 +63,19 @@ impl fmt::Display for TransactionRequest {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let eth = self.value.unwrap_or(U256::from(0));
match self.to {
Some(ref to) => write!(f, "{} Ether from {:?} to {:?}",
format_ether(eth),
self.from,
to),
None => write!(f, "{} Ether from {:?}",
format_ether(eth),
self.from),
Some(ref to) => write!(
f,
"{} ETH from {} to 0x{:?}",
Colour::White.bold().paint(format_ether(eth)),
Colour::White.bold().paint(format!("0x{:?}", self.from)),
to
),
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,
ErrorKind as WsErrorKind,
Message,
Result as WsResult
Result as WsResult,
};
use serde::Deserialize;
use serde_json::{self as json,
Value as JsonValue,
Error as JsonError};
use serde_json::{
self as json,
Value as JsonValue,
Error as JsonError,
};
use futures::{BoxFuture, Canceled, Complete, Future, oneshot, done};
@ -170,13 +172,17 @@ impl Pending {
}
fn get_authcode(path: &PathBuf) -> Result<String, RpcError> {
match File::open(path) {
Ok(fd) => match BufReader::new(fd).lines().next() {
Some(Ok(code)) => Ok(code),
_ => Err(RpcError::NoAuthCode),
},
Err(_) => Err(RpcError::NoAuthCode)
if let Ok(fd) = File::open(path) {
if let Some(Ok(line)) = BufReader::new(fd).lines().next() {
let mut parts = line.split(';');
let token = parts.next();
if let Some(code) = token {
return Ok(code.into());
}
}
}
Err(RpcError::NoAuthCode)
}
/// The handle to the connection

View File

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