mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
Minor cleanup and fixes for wallet send
This commit is contained in:
parent
3d5411b6ad
commit
aeb3dfc0dd
6 changed files with 12 additions and 13 deletions
|
@ -28,7 +28,6 @@ use rest::Error;
|
|||
pub fn get<'a, T>(url: &'a str) -> Result<T, Error>
|
||||
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)
|
||||
|
|
|
@ -74,9 +74,10 @@ impl ApiEndpoint for OutputApi {
|
|||
fn get(&self, id: String) -> ApiResult<Output> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Output, Error> {
|
||||
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<Hash, Error> {
|
||||
|
|
|
@ -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<Output, api::Error> {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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!();
|
||||
|
|
Loading…
Reference in a new issue