diff --git a/api/src/client.rs b/api/src/client.rs index ab17e9a6a..0db78716a 100644 --- a/api/src/client.rs +++ b/api/src/client.rs @@ -28,7 +28,6 @@ use rest::Error; pub fn get<'a, T>(url: &'a str) -> Result where for<'de> T: Deserialize<'de> { - println!("get {}", url); let client = hyper::Client::new(); let res = check_error(client.get(url).send())?; serde_json::from_reader(res) diff --git a/api/src/endpoints.rs b/api/src/endpoints.rs index 001f82490..7806242f4 100644 --- a/api/src/endpoints.rs +++ b/api/src/endpoints.rs @@ -74,9 +74,10 @@ impl ApiEndpoint for OutputApi { fn get(&self, id: String) -> ApiResult { debug!("GET output {}", 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)) - .map_err(|e| Error::Internal(e.to_string())) + .map_err(|e| Error::Internal(e.to_string())); + out } } diff --git a/chain/src/store.rs b/chain/src/store.rs index 0b1f92c72..20af053cd 100644 --- a/chain/src/store.rs +++ b/chain/src/store.rs @@ -96,9 +96,7 @@ impl ChainStore for ChainKVStore { // saving the full output under its hash, as well as a commitment to hash index for out in &b.outputs { 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.hash())?; + batch = batch.put_ser(&to_key(OUTPUT_COMMIT_PREFIX, &mut out_bytes)[..], out)?; } batch.write() } @@ -113,8 +111,8 @@ impl ChainStore for ChainKVStore { } fn get_output_by_commit(&self, commit: &Commitment) -> Result { - option_to_not_found(self.db.get_ser(&to_key(OUTPUT_COMMIT_PREFIX, - &mut commit.as_ref().to_vec()))) + option_to_not_found(self.db + .get_ser(&to_key(OUTPUT_COMMIT_PREFIX, &mut commit.as_ref().to_vec()))) } fn has_output_commit(&self, commit: &Commitment) -> Result { diff --git a/wallet/src/checker.rs b/wallet/src/checker.rs index 24e6e998e..1154d3c3f 100644 --- a/wallet/src/checker.rs +++ b/wallet/src/checker.rs @@ -24,14 +24,14 @@ use util; use extkey::ExtendedKey; 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) { - println!("REFRESH"); 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 changed = 0; for out in &mut wallet_data.outputs { - println!("check out {}", out.n_child); if out.status != OutputStatus::Spent { let key = ext_key.derive(&secp, out.n_child).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 let out_res = get_output_by_commitment(config, commitment); if out_res.is_ok() { - println!("ok"); out.status = OutputStatus::Unspent; 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, commit: pedersen::Commitment) -> Result { diff --git a/wallet/src/receiver.rs b/wallet/src/receiver.rs index f0991aa1d..0b3a3cea5 100644 --- a/wallet/src/receiver.rs +++ b/wallet/src/receiver.rs @@ -140,5 +140,5 @@ fn receive_coinbase(ext_key: &ExtendedKey, amount: u64) -> Result<(Output, TxKer info!("Using child {} for a new coinbase output.", 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); } diff --git a/wallet/src/sender.rs b/wallet/src/sender.rs index fec1fd27a..e5e1b3843 100644 --- a/wallet/src/sender.rs +++ b/wallet/src/sender.rs @@ -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 json_tx = partial_tx_to_json(amount, blind_sum, tx); if dest == "stdout" { - println!("{}", dest); + println!("{}", json_tx); } else if &dest[..4] == "http" { // TODO unimplemented!();