Minor cleanup and fixes for wallet send

This commit is contained in:
Ignotus Peverell 2017-06-06 13:18:16 -07:00
parent 3d5411b6ad
commit aeb3dfc0dd
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211
6 changed files with 12 additions and 13 deletions

View file

@ -28,7 +28,6 @@ use rest::Error;
pub fn get<'a, T>(url: &'a str) -> Result<T, Error> pub fn get<'a, T>(url: &'a str) -> Result<T, Error>
where for<'de> T: Deserialize<'de> where for<'de> T: Deserialize<'de>
{ {
println!("get {}", url);
let client = hyper::Client::new(); let client = hyper::Client::new();
let res = check_error(client.get(url).send())?; let res = check_error(client.get(url).send())?;
serde_json::from_reader(res) serde_json::from_reader(res)

View file

@ -74,9 +74,10 @@ impl ApiEndpoint for OutputApi {
fn get(&self, id: String) -> ApiResult<Output> { fn get(&self, id: String) -> ApiResult<Output> {
debug!("GET output {}", id); debug!("GET output {}", id);
let c = util::from_hex(id.clone()).map_err(|e| Error::Argument(format!("Not a valid commitment: {}", id)))?; let c = util::from_hex(id.clone()).map_err(|e| Error::Argument(format!("Not a valid commitment: {}", id)))?;
self.chain_store let out = self.chain_store
.get_output_by_commit(&Commitment::from_vec(c)) .get_output_by_commit(&Commitment::from_vec(c))
.map_err(|e| Error::Internal(e.to_string())) .map_err(|e| Error::Internal(e.to_string()));
out
} }
} }

View file

@ -96,9 +96,7 @@ impl ChainStore for ChainKVStore {
// saving the full output under its hash, as well as a commitment to hash index // saving the full output under its hash, as well as a commitment to hash index
for out in &b.outputs { for out in &b.outputs {
let mut out_bytes = out.commit.as_ref().to_vec(); let mut out_bytes = out.commit.as_ref().to_vec();
println!("OUTSAVE: {:?}", out_bytes); batch = batch.put_ser(&to_key(OUTPUT_COMMIT_PREFIX, &mut out_bytes)[..], out)?;
batch = batch.put_ser(&to_key(OUTPUT_COMMIT_PREFIX, &mut out_bytes)[..],
&out.hash())?;
} }
batch.write() batch.write()
} }
@ -113,8 +111,8 @@ impl ChainStore for ChainKVStore {
} }
fn get_output_by_commit(&self, commit: &Commitment) -> Result<Output, Error> { fn get_output_by_commit(&self, commit: &Commitment) -> Result<Output, Error> {
option_to_not_found(self.db.get_ser(&to_key(OUTPUT_COMMIT_PREFIX, option_to_not_found(self.db
&mut commit.as_ref().to_vec()))) .get_ser(&to_key(OUTPUT_COMMIT_PREFIX, &mut commit.as_ref().to_vec())))
} }
fn has_output_commit(&self, commit: &Commitment) -> Result<Hash, Error> { fn has_output_commit(&self, commit: &Commitment) -> Result<Hash, Error> {

View file

@ -24,14 +24,14 @@ use util;
use extkey::ExtendedKey; use extkey::ExtendedKey;
use types::{WalletConfig, OutputStatus, WalletData}; use types::{WalletConfig, OutputStatus, WalletData};
/// Goes through the list of outputs that haven't been spent yet and check
/// with a node whether their status has changed.
pub fn refresh_outputs(config: &WalletConfig, ext_key: &ExtendedKey) { pub fn refresh_outputs(config: &WalletConfig, ext_key: &ExtendedKey) {
println!("REFRESH");
let secp = secp::Secp256k1::with_caps(secp::ContextFlag::Commit); let secp = secp::Secp256k1::with_caps(secp::ContextFlag::Commit);
let mut wallet_data = WalletData::read_or_create().expect("Could not open wallet data."); let mut wallet_data = WalletData::read_or_create().expect("Could not open wallet data.");
let mut changed = 0; let mut changed = 0;
for out in &mut wallet_data.outputs { for out in &mut wallet_data.outputs {
println!("check out {}", out.n_child);
if out.status != OutputStatus::Spent { if out.status != OutputStatus::Spent {
let key = ext_key.derive(&secp, out.n_child).unwrap(); let key = ext_key.derive(&secp, out.n_child).unwrap();
let commitment = secp.commit(out.value, key.key).unwrap(); let commitment = secp.commit(out.value, key.key).unwrap();
@ -39,7 +39,6 @@ pub fn refresh_outputs(config: &WalletConfig, ext_key: &ExtendedKey) {
// TODO check the pool for unconfirmed // TODO check the pool for unconfirmed
let out_res = get_output_by_commitment(config, commitment); let out_res = get_output_by_commitment(config, commitment);
if out_res.is_ok() { if out_res.is_ok() {
println!("ok");
out.status = OutputStatus::Unspent; out.status = OutputStatus::Unspent;
changed += 1; changed += 1;
} }
@ -50,6 +49,8 @@ pub fn refresh_outputs(config: &WalletConfig, ext_key: &ExtendedKey) {
} }
} }
// queries a reachable node for a given output, checking whether it's been
// confirmed
fn get_output_by_commitment(config: &WalletConfig, fn get_output_by_commitment(config: &WalletConfig,
commit: pedersen::Commitment) commit: pedersen::Commitment)
-> Result<Output, api::Error> { -> Result<Output, api::Error> {

View file

@ -140,5 +140,5 @@ fn receive_coinbase(ext_key: &ExtendedKey, amount: u64) -> Result<(Output, TxKer
info!("Using child {} for a new coinbase output.", info!("Using child {} for a new coinbase output.",
coinbase_key.n_child); coinbase_key.n_child);
Block::reward_output(ext_key.key, &secp).map_err(&From::from) Block::reward_output(coinbase_key.key, &secp).map_err(&From::from);
} }

View file

@ -27,7 +27,7 @@ pub fn issue_send_tx(ext_key: &ExtendedKey, amount: u64, dest: String) -> Result
let (tx, blind_sum) = build_send_tx(ext_key, amount)?; let (tx, blind_sum) = build_send_tx(ext_key, amount)?;
let json_tx = partial_tx_to_json(amount, blind_sum, tx); let json_tx = partial_tx_to_json(amount, blind_sum, tx);
if dest == "stdout" { if dest == "stdout" {
println!("{}", dest); println!("{}", json_tx);
} else if &dest[..4] == "http" { } else if &dest[..4] == "http" {
// TODO // TODO
unimplemented!(); unimplemented!();