Cleanup of wallet owner API, rustdoc documentation (#2036)

* doc start

* rustfmt

* tightening up wallet owner API

* rustfmt

* remove burn tx functions

* more tx api documentation

* rustfmt
This commit is contained in:
Yeastplume
2018-11-28 15:31:23 +00:00
committed by GitHub
parent 2a77207713
commit fdb0197ef9
13 changed files with 415 additions and 289 deletions
+29 -42
View File
@@ -15,10 +15,14 @@
use clap::ArgMatches;
use rpassword;
use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::thread;
use std::time::Duration;
use serde_json as json;
use api::TLSConfig;
use config::GlobalWalletConfig;
use core::{core, global};
@@ -328,7 +332,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) -> i
} else {
let label = create.unwrap();
let res = controller::owner_single_use(wallet, |api| {
api.new_account_path(label)?;
api.create_account_path(label)?;
thread::sleep(Duration::from_millis(200));
println!("Account: '{}' Created!", label);
Ok(())
@@ -460,7 +464,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) -> i
api.tx_lock_outputs(&slate, lock_fn)?;
}
if adapter.supports_sync() {
let result = api.post_tx(&slate, fluff);
let result = api.post_tx(&slate.tx, fluff);
match result {
Ok(_) => {
info!("Tx sent",);
@@ -513,7 +517,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) -> i
let mut slate = adapter.receive_tx_async(tx_file)?;
let _ = api.finalize_tx(&mut slate).expect("Finalize failed");
let result = api.post_tx(&slate, fluff);
let result = api.post_tx(&slate.tx, fluff);
match result {
Ok(_) => {
info!("Transaction sent successfully, check the wallet again for confirmation.");
@@ -525,24 +529,6 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) -> i
}
}
}
("burn", Some(send_args)) => {
let amount = send_args
.value_of("amount")
.expect("Amount to burn required");
let amount = core::amount_from_hr_string(amount)
.expect("Could not parse amount as number with optional decimal point.");
let minimum_confirmations: u64 = send_args
.value_of("minimum_confirmations")
.unwrap()
.parse()
.expect("Could not parse minimum_confirmations as a whole number.");
let max_outputs = 500;
api.issue_burn_tx(amount, minimum_confirmations, max_outputs)
.unwrap_or_else(|e| {
panic!("Error burning tx: {:?} Config: {:?}", e, wallet_config)
});
Ok(())
}
("info", Some(args)) => {
let minimum_confirmations: u64 = args
.value_of("minimum_confirmations")
@@ -651,32 +637,33 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) -> i
let dump_file = repost_args.value_of("dumpfile");
let fluff = repost_args.is_present("fluff");
let (_, txs) = api.retrieve_txs(true, Some(tx_id), None)?;
let stored_tx = txs[0].get_stored_tx();
if stored_tx.is_none() {
println!(
"Transaction with id {} does not have transaction data. Not reposting.",
tx_id
);
std::process::exit(0);
}
match dump_file {
None => {
let result = api.post_stored_tx(tx_id, fluff);
match result {
Ok(_) => {
info!("Reposted transaction at {}", tx_id);
Ok(())
}
Err(e) => {
error!("Transaction reposting failed: {}", e);
Err(e)
}
if txs[0].confirmed {
println!("Transaction with id {} is confirmed. Not reposting.", tx_id);
std::process::exit(0);
}
api.post_tx(&stored_tx.unwrap(), fluff)?;
info!("Reposted transaction at {}", tx_id);
println!("Reposted transaction at {}", tx_id);
Ok(())
}
Some(f) => {
let result = api.dump_stored_tx(tx_id, true, f);
match result {
Ok(_) => {
warn!("Dumped transaction data for tx {} to {}", tx_id, f);
Ok(())
}
Err(e) => {
error!("Transaction reposting failed: {}", e);
Err(e)
}
}
let mut tx_file = File::create(f)?;
tx_file.write_all(json::to_string(&stored_tx).unwrap().as_bytes())?;
tx_file.sync_all()?;
info!("Dumped transaction data for tx {} to {}", tx_id, f);
println!("Dumped transaction data for tx {} to {}", tx_id, f);
Ok(())
}
}
}