Modify get_stored_tx functions + tests (#454)

This commit is contained in:
Yeastplume
2020-06-25 10:06:04 +01:00
committed by GitHub
parent 99c2505bf5
commit f8ea76732b
9 changed files with 135 additions and 60 deletions
+26 -13
View File
@@ -1269,15 +1269,17 @@ where
K: keychain::Keychain + 'static,
{
controller::owner_single_use(None, keychain_mask, Some(owner_api), |api, m| {
let stored_tx_slate = match api.get_stored_tx(m, Some(args.id), None)? {
None => {
error!(
"Transaction with id {} does not have transaction data. Not reposting.",
args.id
);
return Ok(());
}
Some(s) => s,
};
let (_, txs) = api.retrieve_txs(m, true, Some(args.id), None)?;
let stored_tx = api.get_stored_tx(m, txs[0].tx_slate_id.unwrap())?;
if stored_tx.is_none() {
error!(
"Transaction with id {} does not have transaction data. Not reposting.",
args.id
);
return Ok(());
}
match args.dump_file {
None => {
if txs[0].confirmed {
@@ -1287,15 +1289,26 @@ where
);
return Ok(());
}
let mut slate = Slate::blank(2, false);
slate.tx = Some(stored_tx.unwrap());
api.post_tx(m, &slate, args.fluff)?;
info!("Reposted transaction at {}", args.id);
if libwallet::sig_is_blank(
&stored_tx_slate.tx.as_ref().unwrap().kernels()[0].excess_sig,
) {
error!("Transaction at {} has not been finalized.", args.id);
return Ok(());
}
match api.post_tx(m, &stored_tx_slate, args.fluff) {
Ok(_) => info!("Reposted transaction at {}", args.id),
Err(e) => error!("Could not repost transaction at {}. Reason: {}", args.id, e),
}
return Ok(());
}
Some(f) => {
let mut tx_file = File::create(f.clone())?;
tx_file.write_all(json::to_string(&stored_tx).unwrap().as_bytes())?;
tx_file.write_all(
json::to_string(&stored_tx_slate.tx.unwrap())
.unwrap()
.as_bytes(),
)?;
tx_file.sync_all()?;
info!("Dumped transaction data for tx {} to {}", args.id, f);
return Ok(());
+3 -4
View File
@@ -156,7 +156,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
let (_, txs) = api.retrieve_txs(m, true, None, Some(slate.id))?;
println!("TXS[0]: {:?}", txs[0]);
let stored_tx = api.get_stored_tx(m, txs[0].tx_slate_id.unwrap())?;
let stored_tx = api.get_stored_tx(m, None, Some(&txs[0].tx_slate_id.unwrap()))?;
println!("Stored tx: {:?}", stored_tx);
api.post_tx(m, &slate, false)?;
bh += 1;
@@ -225,9 +225,8 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
// Now repost from cached
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
let (_, txs) = api.retrieve_txs(m, true, None, Some(slate.id))?;
let stored_tx = api.get_stored_tx(m, txs[0].tx_slate_id.unwrap())?;
slate.tx = stored_tx;
api.post_tx(m, &slate, false)?;
let stored_tx_slate = api.get_stored_tx(m, Some(txs[0].id), None)?.unwrap();
api.post_tx(m, &stored_tx_slate, false)?;
bh += 1;
Ok(())
})?;
+4 -3
View File
@@ -317,9 +317,10 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
.iter()
.find(|t| t.tx_slate_id == Some(slate.id))
.unwrap();
let stored_tx = sender_api.get_stored_tx(m, tx.tx_slate_id.unwrap())?;
slate.tx = stored_tx;
sender_api.post_tx(m, &slate, false)?;
let stored_tx_slate = sender_api
.get_stored_tx(m, None, Some(&tx.tx_slate_id.unwrap()))?
.unwrap();
sender_api.post_tx(m, &stored_tx_slate, false)?;
let (_, wallet1_info) = sender_api.retrieve_summary_info(m, true, 1)?;
// should be mined now
assert_eq!(