Skip to content

Commit 967e06f

Browse files
authored
update_instance_status_and_pegin_txid add exit check (#51)
1 parent 97cd72c commit 967e06f

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

crates/store/.sqlx/query-e5e7bd1d4b938713758af2317e072ac96656d2309a896945bc6e2438b95c1a2c.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/src/localdb.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,22 +234,30 @@ impl<'a> StorageProcessor<'a> {
234234
status: Option<String>,
235235
pegin_txid: Option<String>,
236236
) -> anyhow::Result<()> {
237-
let mut update_fields = vec![];
238-
if let Some(status) = status {
239-
update_fields.push(format!("status = \'{status}\'"));
240-
}
241-
if let Some(pegin_txid) = pegin_txid {
242-
update_fields.push(format!("pegin_txid = \'{pegin_txid}\'"));
243-
}
244-
if update_fields.is_empty() {
237+
let instance_option = sqlx::query_as!(
238+
Instance,
239+
"SELECT instance_id as \"instance_id:Uuid\", network, bridge_path, from_addr, to_addr, amount, status, goat_txid, \
240+
btc_txid ,pegin_txid, input_uxtos, fee ,created_at, updated_at \
241+
FROM instance where instance_id = ?",
242+
instance_id
243+
).fetch_optional(self.conn())
244+
.await?;
245+
if instance_option.is_none() {
246+
warn!("instance :{instance_id:?} not exit");
245247
return Ok(());
246248
}
247-
let update_str = format!(
248-
"UPDATE instance SET {} WHERE hex(instance_id) COLLATE NOCASE = {}",
249-
update_fields.join(" , "),
250-
hex::encode(instance_id)
251-
);
252-
let _ = sqlx::query(update_str.as_str()).execute(self.conn()).await?;
249+
let instance = instance_option.unwrap();
250+
let status = if let Some(status) = status { status } else { instance.status };
251+
let pegin_txid = if pegin_txid.is_some() { pegin_txid } else { instance.pegin_txid };
252+
253+
let _ = sqlx::query!(
254+
"UPDATE instance SET status =?, pegin_txid =? WHERE instance_id = ?",
255+
status,
256+
pegin_txid,
257+
instance_id
258+
)
259+
.execute(self.conn())
260+
.await?;
253261
Ok(())
254262
}
255263

0 commit comments

Comments
 (0)