* Use try!/map_err instead of match
* Use jsonrpc_core for serializing/deserializing rpc messages * Factor out unwraps * Remove mem::replace * Add nicer formating of ConfirmationRequests
This commit is contained in:
@@ -41,16 +41,16 @@ impl From<helpers::ConfirmationRequest> for ConfirmationRequest {
|
||||
|
||||
impl fmt::Display for ConfirmationRequest {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "id: {:?}, {}", self.id, self.payload)
|
||||
write!(f, "#{}: {}", self.id, self.payload)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ConfirmationPayload {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&ConfirmationPayload::Transaction(ref transaction)
|
||||
match *self {
|
||||
ConfirmationPayload::Transaction(ref transaction)
|
||||
=> write!(f, "{}", transaction),
|
||||
&ConfirmationPayload::Sign(_) => write!(f, "TODO: data"),
|
||||
ConfirmationPayload::Sign(_) => write!(f, "TODO: data"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,10 +44,16 @@ pub struct TransactionRequest {
|
||||
|
||||
impl fmt::Display for TransactionRequest {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:?} from {:?} to {:?}",
|
||||
self.value.unwrap_or(U256::from(0)),
|
||||
self.from,
|
||||
self.to)
|
||||
let eth = self.value.unwrap_or(U256::from(0));
|
||||
match self.to {
|
||||
Some(ref to) => write!(f, "{} Ether from {:?} to {:?}",
|
||||
eth.format_ether(),
|
||||
self.from,
|
||||
to),
|
||||
None => write!(f, "{} Ether from {:?}",
|
||||
eth.format_ether(),
|
||||
self.from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,25 @@ macro_rules! impl_uint {
|
||||
}
|
||||
}
|
||||
|
||||
impl $name {
|
||||
/// Human readable formatting
|
||||
pub fn format_ether(&self) -> String {
|
||||
let divisor = $other::from(10u64.pow(18));
|
||||
let ether = self.0 / divisor;
|
||||
let rest = self.0 - ether * divisor;
|
||||
let string = format!("{}.{}", ether, rest);
|
||||
string.trim_right_matches('0')
|
||||
.trim_right_matches('.')
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for $name {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::LowerHex for $name {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:#x}", self.0)
|
||||
|
||||
Reference in New Issue
Block a user