Sending end of the wallet

Most of the logic to build a transaction that sends coin to
another party. Still requires more debugging and clean up.
Main changes and additions are:

* Update to serde 1.0
* API endpoint to retrieve an Output
* Output is now Serialize and Deserialize
* Wallet configuration
* Command line for the send operation
* Wallet data checker to update created outputs into confirmed
* Wallet-specific configuration
This commit is contained in:
Ignotus Peverell
2017-05-28 20:21:29 -07:00
parent da41120293
commit f79fb8ef95
22 changed files with 181 additions and 101 deletions
+11
View File
@@ -17,6 +17,7 @@
//! Primary hash function used in the protocol
//!
use std::cmp::min;
use std::{fmt, ops};
use tiny_keccak::Keccak;
use std::convert::AsRef;
@@ -47,6 +48,16 @@ impl fmt::Display for Hash {
}
impl Hash {
/// Builds a Hash from a byte vector. If the vector is too short, it will be
/// completed by zeroes. If it's too long, it will be truncated.
pub fn from_vec(v: Vec<u8>) -> Hash {
let mut h = [0; 32];
for i in 0..min(v.len(), 32) {
h[i] = v[i];
}
Hash(h)
}
/// Converts the hash to a byte vector
pub fn to_vec(&self) -> Vec<u8> {
self.0.to_vec()
+3 -3
View File
@@ -105,9 +105,9 @@ impl Serialize for Difficulty {
}
}
impl Deserialize for Difficulty {
impl<'de> Deserialize<'de> for Difficulty {
fn deserialize<D>(deserializer: D) -> Result<Difficulty, D::Error>
where D: Deserializer
where D: Deserializer<'de>
{
deserializer.deserialize_i32(DiffVisitor)
}
@@ -115,7 +115,7 @@ impl Deserialize for Difficulty {
struct DiffVisitor;
impl de::Visitor for DiffVisitor {
impl<'de> de::Visitor<'de> for DiffVisitor {
type Value = Difficulty;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+4 -4
View File
@@ -269,6 +269,7 @@ impl Input {
bitflags! {
/// Options for block validation
#[derive(Serialize, Deserialize)]
pub flags OutputFeatures: u8 {
/// No flags
const DEFAULT_OUTPUT = 0b00000000,
@@ -279,10 +280,9 @@ bitflags! {
/// Output for a transaction, defining the new ownership of coins that are being
/// transferred. The commitment is a blinded value for the output while the
/// range
/// proof guarantees the commitment includes a positive value without overflow
/// and the ownership of the private key.
#[derive(Debug, Copy, Clone, PartialEq)]
/// range proof guarantees the commitment includes a positive value without
/// overflow and the ownership of the private key.
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
pub struct Output {
/// Options for an output's structure or use
pub features: OutputFeatures,