Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup of wallet owner API, rustdoc documentation #2036

Merged
merged 7 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion servers/tests/simulnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ fn replicate_tx_fluff_failure() {
slate = client1_w.send_tx_sync(dest, &slate)?;
api.finalize_tx(&mut slate)?;
api.tx_lock_outputs(&slate, lock_fn)?;
api.post_tx(&slate, false)?;
api.post_tx(&slate.tx, false)?;
Ok(())
}).unwrap();

Expand Down
71 changes: 29 additions & 42 deletions src/bin/cmd/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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",);
Expand Down Expand Up @@ -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.");
Expand All @@ -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")
Expand Down Expand Up @@ -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(())
}
}
}
Expand Down
34 changes: 9 additions & 25 deletions wallet/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,31 +222,31 @@ where
api.retrieve_txs(update_from_node, tx_id, tx_slate_id)
}

fn dump_stored_tx(
fn retrieve_stored_tx(
&self,
req: &Request<Body>,
api: APIOwner<T, C, K>,
) -> Result<Transaction, Error> {
) -> Result<(bool, Option<Transaction>), Error> {
let params = parse_params(req);
if let Some(id_string) = params.get("id") {
match id_string[0].parse() {
Ok(id) => match api.dump_stored_tx(id, false, "") {
Ok(tx) => Ok(tx),
Ok(id) => match api.retrieve_txs(true, Some(id), None) {
Ok((_, txs)) => Ok((txs[0].confirmed, txs[0].get_stored_tx())),
Err(e) => {
error!("dump_stored_tx: failed with error: {}", e);
error!("retrieve_stored_tx: failed with error: {}", e);
Err(e)
}
},
Err(e) => {
error!("dump_stored_tx: could not parse id: {}", e);
error!("retrieve_stored_tx: could not parse id: {}", e);
Err(ErrorKind::TransactionDumpError(
"dump_stored_tx: cannot dump transaction. Could not parse id in request.",
"retrieve_stored_tx: cannot dump transaction. Could not parse id in request.",
).into())
}
}
} else {
Err(ErrorKind::TransactionDumpError(
"dump_stored_tx: Cannot dump transaction. Missing id param in request.",
"retrieve_stored_tx: Cannot retrieve transaction. Missing id param in request.",
).into())
}
}
Expand Down Expand Up @@ -292,7 +292,7 @@ where
"retrieve_summary_info" => json_response(&self.retrieve_summary_info(req, api)?),
"node_height" => json_response(&self.node_height(req, api)?),
"retrieve_txs" => json_response(&self.retrieve_txs(req, api)?),
"dump_stored_tx" => json_response(&self.dump_stored_tx(req, api)?),
"retrieve_stored_tx" => json_response(&self.retrieve_stored_tx(req, api)?),
_ => response(StatusCode::BAD_REQUEST, ""),
})
}
Expand Down Expand Up @@ -439,18 +439,6 @@ where
)
}

fn issue_burn_tx(
&self,
_req: Request<Body>,
mut api: APIOwner<T, C, K>,
) -> Box<Future<Item = (), Error = Error> + Send> {
// TODO: Args
Box::new(match api.issue_burn_tx(60, 10, 1000) {
Ok(_) => ok(()),
Err(e) => err(e),
})
}

fn handle_post_request(&self, req: Request<Body>) -> WalletResponseFuture {
let api = APIOwner::new(self.wallet.clone());
match req
Expand All @@ -477,10 +465,6 @@ where
self.post_tx(req, api)
.and_then(|_| ok(response(StatusCode::OK, ""))),
),
"issue_burn_tx" => Box::new(
self.issue_burn_tx(req, api)
.and_then(|_| ok(response(StatusCode::OK, ""))),
),
_ => Box::new(err(ErrorKind::GenericError(
"Unknown error handling post request".to_owned(),
).into())),
Expand Down
Loading