mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-11-15 11:53:54 +01:00
Update transactions via kernel where necessary (#220)
* add test for no change output scenario * rustfmt * add kernel lookup functionality to transaction retrievals * rustfmt * updates and fixes for no-change invoice workflow, test implementations * rustfmt
This commit is contained in:
@@ -130,7 +130,7 @@ where
|
||||
let mut sl = slate.clone();
|
||||
let context = w.get_private_context(keychain_mask, sl.id.as_bytes(), 1)?;
|
||||
tx::complete_tx(&mut *w, keychain_mask, &mut sl, 1, &context)?;
|
||||
tx::update_stored_tx(&mut *w, &mut sl, true)?;
|
||||
tx::update_stored_tx(&mut *w, keychain_mask, &mut sl, true)?;
|
||||
tx::update_message(&mut *w, keychain_mask, &mut sl)?;
|
||||
{
|
||||
let mut batch = w.batch(keychain_mask)?;
|
||||
|
||||
@@ -119,10 +119,13 @@ where
|
||||
validated = update_outputs(w, keychain_mask, false)?;
|
||||
}
|
||||
|
||||
Ok((
|
||||
validated,
|
||||
updater::retrieve_txs(&mut *w, tx_id, tx_slate_id, Some(&parent_key_id), false)?,
|
||||
))
|
||||
let mut txs = updater::retrieve_txs(&mut *w, tx_id, tx_slate_id, Some(&parent_key_id), false)?;
|
||||
|
||||
if refresh_from_node {
|
||||
validated = update_txs_via_kernel(w, keychain_mask, &mut txs)?;
|
||||
}
|
||||
|
||||
Ok((validated, txs))
|
||||
}
|
||||
|
||||
/// Retrieve summary info
|
||||
@@ -274,7 +277,6 @@ where
|
||||
// recieve the transaction back
|
||||
{
|
||||
let mut batch = w.batch(keychain_mask)?;
|
||||
println!("Saving private context: {:?}", slate.id.as_bytes());
|
||||
batch.save_private_context(slate.id.as_bytes(), 1, &context)?;
|
||||
batch.commit()?;
|
||||
}
|
||||
@@ -396,7 +398,7 @@ where
|
||||
let mut sl = slate.clone();
|
||||
let context = w.get_private_context(keychain_mask, sl.id.as_bytes(), 0)?;
|
||||
tx::complete_tx(&mut *w, keychain_mask, &mut sl, 0, &context)?;
|
||||
tx::update_stored_tx(&mut *w, &mut sl, false)?;
|
||||
tx::update_stored_tx(&mut *w, keychain_mask, &mut sl, false)?;
|
||||
tx::update_message(&mut *w, keychain_mask, &mut sl)?;
|
||||
{
|
||||
let mut batch = w.batch(keychain_mask)?;
|
||||
@@ -546,3 +548,44 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Update transactions that need to be validated via kernel lookup
|
||||
fn update_txs_via_kernel<'a, T: ?Sized, C, K>(
|
||||
w: &mut T,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
txs: &mut Vec<TxLogEntry>,
|
||||
) -> Result<bool, Error>
|
||||
where
|
||||
T: WalletBackend<'a, C, K>,
|
||||
C: NodeClient + 'a,
|
||||
K: Keychain + 'a,
|
||||
{
|
||||
let parent_key_id = w.parent_key_id();
|
||||
let height = match w.w2n_client().get_chain_height() {
|
||||
Ok(h) => h,
|
||||
Err(_) => return Ok(false),
|
||||
};
|
||||
for tx in txs.iter_mut() {
|
||||
if tx.confirmed {
|
||||
continue;
|
||||
}
|
||||
if let Some(e) = tx.kernel_excess {
|
||||
let res = w
|
||||
.w2n_client()
|
||||
.get_kernel(&e, tx.kernel_lookup_min_height, Some(height));
|
||||
let kernel = match res {
|
||||
Ok(k) => k,
|
||||
Err(_) => return Ok(false),
|
||||
};
|
||||
if let Some(k) = kernel {
|
||||
debug!("Kernel Retrieved: {:?}", k);
|
||||
let mut batch = w.batch(keychain_mask)?;
|
||||
tx.confirmed = true;
|
||||
tx.update_confirmation_ts();
|
||||
batch.save_tx_log_entry(tx.clone(), &parent_key_id)?;
|
||||
batch.commit()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user