Fixes to grin wallet repost, cancel tx (#2029)

* fixes to wallet cancel, repost, ensure stored transaction is updated with final signatures

* rustfmt

* add tests for reposting

* fixes to tests

* repost
This commit is contained in:
Yeastplume
2018-11-27 13:36:49 +00:00
committed by GitHub
parent 79d540cf86
commit b95caecc27
9 changed files with 314 additions and 23 deletions
+5 -13
View File
@@ -222,9 +222,11 @@ where
/// propagation.
pub fn finalize_tx(&mut self, slate: &mut Slate) -> Result<(), Error> {
let mut w = self.wallet.lock();
let parent_key_id = w.parent_key_id();
w.open_with_credentials()?;
let context = w.get_private_context(slate.id.as_bytes())?;
tx::complete_tx(&mut *w, slate, &context)?;
tx::update_tx_hex(&mut *w, &parent_key_id, slate)?;
{
let mut batch = w.batch()?;
batch.delete_private_context(slate.id.as_bytes())?;
@@ -367,23 +369,13 @@ where
);
return Err(ErrorKind::TransactionBuildingNotCompleted(tx_id))?;
}
let res = client.post_tx(
client.post_tx(
&TxWrapper {
tx_hex: tx_hex.unwrap(),
},
fluff,
);
if let Err(e) = res {
error!("api: repost_tx: failed with error: {}", e);
Err(e)
} else {
debug!(
"api: repost_tx: successfully posted tx at: {}, fluff? {}",
tx_id, fluff
);
Ok(())
}
)?;
Ok(())
}
/// Attempt to restore contents of wallet
+13 -1
View File
@@ -195,7 +195,19 @@ pub enum ErrorKind {
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Display::fmt(&self.inner, f)
let cause = match self.cause() {
Some(c) => format!("{}", c),
None => String::from("Unknown"),
};
let backtrace = match self.backtrace() {
Some(b) => format!("{}", b),
None => String::from("Unknown"),
};
let output = format!(
"{} \n Cause: {} \n Backtrace: {}",
self.inner, cause, backtrace
);
Display::fmt(&output, f)
}
}
+26 -1
View File
@@ -15,11 +15,12 @@
//! Transaction building functions
use std::sync::Arc;
use util::RwLock;
use util::{self, RwLock};
use uuid::Uuid;
use core::core::verifier_cache::LruVerifierCache;
use core::core::Transaction;
use core::ser;
use keychain::{Identifier, Keychain};
use libtx::slate::Slate;
use libtx::{build, tx_fee};
@@ -206,6 +207,30 @@ where
Ok((tx.confirmed, tx.tx_hex))
}
/// Update the stored hex transaction (this update needs to happen when the TX is finalised)
pub fn update_tx_hex<T: ?Sized, C, K>(
wallet: &mut T,
parent_key_id: &Identifier,
slate: &Slate,
) -> Result<(), Error>
where
T: WalletBackend<C, K>,
C: NodeClient,
K: Keychain,
{
let tx_hex = util::to_hex(ser::ser_vec(&slate.tx).unwrap());
let tx_vec = updater::retrieve_txs(wallet, None, Some(slate.id), parent_key_id)?;
if tx_vec.len() != 1 {
return Err(ErrorKind::TransactionDoesntExist(slate.id.to_string()))?;
}
let mut tx = tx_vec[0].clone();
tx.tx_hex = Some(tx_hex);
let batch = wallet.batch()?;
batch.save_tx_log_entry(tx, &parent_key_id)?;
batch.commit()?;
Ok(())
}
/// Issue a burn tx
pub fn issue_burn_tx<T: ?Sized, C, K>(
wallet: &mut T,
+3 -1
View File
@@ -91,7 +91,9 @@ where
{
// just read the wallet here, no need for a write lock
let mut txs = if let Some(id) = tx_id {
let tx = wallet.tx_log_iter().find(|t| t.id == id);
let tx = wallet
.tx_log_iter()
.find(|t| t.id == id && t.parent_key_id == *parent_key_id);
if let Some(t) = tx {
vec![t]
} else {