mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-11 15:39:37 -05:00
Immediately sync bitcoin tx status upon subscribing
This commit is contained in:
parent
20afb35d5b
commit
2e181dac9c
@ -761,9 +761,10 @@ impl Client {
|
|||||||
self.blockchain.get_tx(txid)
|
self.blockchain.get_tx(txid)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_state(&mut self) -> Result<()> {
|
fn update_state(&mut self, force_sync: bool) -> Result<()> {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
if now < self.last_sync + self.sync_interval {
|
|
||||||
|
if !force_sync && now < self.last_sync + self.sync_interval {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,9 +784,14 @@ impl Client {
|
|||||||
|
|
||||||
if !self.script_history.contains_key(&script) {
|
if !self.script_history.contains_key(&script) {
|
||||||
self.script_history.insert(script.clone(), vec![]);
|
self.script_history.insert(script.clone(), vec![]);
|
||||||
}
|
|
||||||
|
|
||||||
self.update_state()?;
|
// When we first subscribe to a script we want to immediately fetch its status
|
||||||
|
// Otherwise we would have to wait for the next sync interval, which can take a minute
|
||||||
|
// This would result in potentially inaccurate status updates until that next sync interval is hit
|
||||||
|
self.update_state(true)?;
|
||||||
|
} else {
|
||||||
|
self.update_state(false)?;
|
||||||
|
}
|
||||||
|
|
||||||
let history = self.script_history.entry(script).or_default();
|
let history = self.script_history.entry(script).or_default();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user