slatepack: return concrete error on sync workflow instead of none, optimize sending requirement detection

This commit is contained in:
ardocrat
2026-06-23 00:37:00 +03:00
parent 4587eb918d
commit f92a2d6b43
6 changed files with 215 additions and 190 deletions
+1 -37
View File
@@ -14,11 +14,11 @@
//! Generic implementation of owner API functions
use grin_keychain::Identifier;
use strum::IntoEnumIterator;
use super::owner::tx_lock_outputs;
use crate::api_impl::owner::{check_ttl, post_tx};
use crate::api_impl::types::update_tx_slate_state;
use crate::backend::WalletBackend;
use crate::grin_core::core::FeeFields;
use crate::grin_keychain::Keychain;
@@ -236,39 +236,3 @@ where
}
Ok(sl)
}
/// Update transaction slate state.
fn update_tx_slate_state<C, K>(
wallet: &mut WalletBackend<C, K>,
keychain_mask: Option<&SecretKey>,
parent_key_id: &Identifier,
slate: &Slate,
) -> Result<(), Error>
where
C: NodeClient,
K: Keychain,
{
let mut bad_records = 0;
let tx = wallet
.tx_log_iter()?
.filter(|tx| {
if tx.is_err() {
bad_records += 1;
}
tx.is_ok()
})
.map(|tx| tx.unwrap())
.find(|tx| tx.tx_slate_id == Some(slate.id));
if let Some(mut tx) = tx {
let mut batch = wallet.batch(keychain_mask)?;
tx.tx_slate_state = Some(slate.state.clone());
batch.save_tx_log_entry(tx.clone(), parent_key_id)?;
batch.commit()?;
} else {
return Err(Error::Backend(format!(
"Tx log entry with slate id {} not found, there are {} bad tx log records",
slate.id, bad_records
)));
}
Ok(())
}
+39 -1
View File
@@ -21,10 +21,12 @@ use crate::grin_util::secp::pedersen;
use crate::slate_versions::ser as dalek_ser;
use crate::slate_versions::SlateVersion;
use crate::types::OutputData;
use crate::SlatepackAddress;
use crate::{Error, NodeClient, Slate, SlatepackAddress, WalletBackend};
use chrono::prelude::*;
use ed25519_dalek::Signature as DalekSignature;
use grin_keychain::Keychain;
use grin_util::secp::SecretKey;
pub use crate::mwixnet::{Hop, MixnetReqCreationParams, SwapReq};
@@ -344,3 +346,39 @@ pub struct BuiltOutput {
/// Output
pub output: Output,
}
/// Update transaction slate state.
pub fn update_tx_slate_state<C, K>(
wallet: &mut WalletBackend<C, K>,
keychain_mask: Option<&SecretKey>,
parent_key_id: &Identifier,
slate: &Slate,
) -> Result<(), Error>
where
C: NodeClient,
K: Keychain,
{
let mut bad_records = 0;
let tx = wallet
.tx_log_iter()?
.filter(|tx| {
if tx.is_err() {
bad_records += 1;
}
tx.is_ok()
})
.map(|tx| tx.unwrap())
.find(|tx| tx.tx_slate_id == Some(slate.id));
if let Some(mut tx) = tx {
let mut batch = wallet.batch(keychain_mask)?;
tx.tx_slate_state = Some(slate.state.clone());
batch.save_tx_log_entry(tx.clone(), parent_key_id)?;
batch.commit()?;
} else {
return Err(Error::Backend(format!(
"Tx log entry with slate id {} not found, there are {} bad tx log records",
slate.id, bad_records
)));
}
Ok(())
}