From: 志宇 Date: Wed, 20 Nov 2024 22:43:13 +0000 (+1100) Subject: fix(chain): Sqlite - allow persisting anchor without tx X-Git-Tag: v1.0.0-beta.6~10^2~3 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/scripts/struct.Block.html?a=commitdiff_plain;h=8fa899b74619b549e4880c28a0f1d348cb68f755;p=bdk fix(chain): Sqlite - allow persisting anchor without tx Previously, we may error when we insert an anchor where the txid being anchored has no corresponding tx. --- diff --git a/crates/chain/src/rusqlite_impl.rs b/crates/chain/src/rusqlite_impl.rs index 6df4d9f4..873c19a0 100644 --- a/crates/chain/src/rusqlite_impl.rs +++ b/crates/chain/src/rusqlite_impl.rs @@ -376,8 +376,15 @@ where "REPLACE INTO {}(txid, block_height, block_hash, anchor) VALUES(:txid, :block_height, :block_hash, jsonb(:anchor))", Self::ANCHORS_TABLE_NAME, ))?; + let mut statement_txid = db_tx.prepare_cached(&format!( + "INSERT OR IGNORE INTO {}(txid) VALUES(:txid)", + Self::TXS_TABLE_NAME, + ))?; for (anchor, txid) in &self.anchors { let anchor_block = anchor.anchor_block(); + statement_txid.execute(named_params! { + ":txid": Impl(*txid) + })?; statement.execute(named_params! { ":txid": Impl(*txid), ":block_height": anchor_block.height,