Skip to content

Commit 7d8ffae

Browse files
ValuedMammalevanlinjin
authored andcommitted
refactor(tx_graph): make tx_graph::ChangeSet nested again
The serialization format of the nested structure is exactly the same as the as the old `indexed_tx_graph::ChangeSet`. The old `tx_graph::ChangeSet` is replaced with `tx_graph::TxChangeSet`.
1 parent 2dcc017 commit 7d8ffae

8 files changed

Lines changed: 185 additions & 103 deletions

File tree

crates/bitcoind_rpc/tests/test_emitter.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
189189
assert!(emitter.next_block()?.is_none());
190190

191191
let mempool_txs = emitter.mempool()?;
192-
let tx_graph_changeset = tx_graph.batch_insert_unconfirmed(mempool_txs);
192+
let tx_graph_changeset = tx_graph.batch_insert_unconfirmed(mempool_txs).tx_data;
193193
assert_eq!(
194194
tx_graph_changeset
195195
.txs
@@ -221,7 +221,9 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
221221
let emission = emitter.next_block()?.expect("must get mined block");
222222
let height = emission.block_height();
223223
let _ = chain.apply_update(emission.checkpoint)?;
224-
let tx_graph_changeset = tx_graph.apply_block_relevant(&emission.block, height);
224+
let tx_graph_changeset = tx_graph
225+
.apply_block_relevant(&emission.block, height)
226+
.tx_data;
225227
assert!(tx_graph_changeset.txs.is_empty());
226228
assert!(tx_graph_changeset.txouts.is_empty());
227229
assert_eq!(tx_graph_changeset.anchors, exp_anchors);

crates/chain/src/rusqlite_impl.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ fn to_sql_error<E: std::error::Error + Send + Sync + 'static>(err: E) -> rusqlit
199199
rusqlite::Error::ToSqlConversionFailure(Box::new(err))
200200
}
201201

202-
impl tx_graph::ChangeSet<ConfirmationBlockTime> {
203-
/// Schema name for [`tx_graph::ChangeSet`].
202+
impl tx_graph::TxChangeSet<ConfirmationBlockTime> {
203+
/// Schema name for [`tx_graph::TxChangeSet`].
204204
pub const SCHEMA_NAME: &'static str = "bdk_txgraph";
205205
/// Name of table that stores full transactions and `last_seen` timestamps.
206206
pub const TXS_TABLE_NAME: &'static str = "bdk_txs";
@@ -209,7 +209,7 @@ impl tx_graph::ChangeSet<ConfirmationBlockTime> {
209209
/// Name of table that stores [`Anchor`]s.
210210
pub const ANCHORS_TABLE_NAME: &'static str = "bdk_anchors";
211211

212-
/// Get v0 of sqlite [tx_graph::ChangeSet] schema
212+
/// Get v0 of sqlite [`tx_graph::TxChangeSet`] schema
213213
pub fn schema_v0() -> String {
214214
// full transactions
215215
let create_txs_table = format!(
@@ -247,7 +247,7 @@ impl tx_graph::ChangeSet<ConfirmationBlockTime> {
247247
format!("{create_txs_table}; {create_txouts_table}; {create_anchors_table}")
248248
}
249249

250-
/// Get v1 of sqlite [tx_graph::ChangeSet] schema
250+
/// Get v1 of sqlite [`tx_graph::TxChangeSet`] schema
251251
pub fn schema_v1() -> String {
252252
let add_confirmation_time_column = format!(
253253
"ALTER TABLE {} ADD COLUMN confirmation_time INTEGER DEFAULT -1 NOT NULL",
@@ -567,7 +567,7 @@ mod test {
567567

568568
#[test]
569569
fn can_persist_anchors_and_txs_independently() -> anyhow::Result<()> {
570-
type ChangeSet = tx_graph::ChangeSet<ConfirmationBlockTime>;
570+
type ChangeSet = tx_graph::TxChangeSet<ConfirmationBlockTime>;
571571
let mut conn = rusqlite::Connection::open_in_memory()?;
572572

573573
// init tables
@@ -629,7 +629,7 @@ mod test {
629629

630630
#[test]
631631
fn v0_to_v1_schema_migration_is_backward_compatible() -> anyhow::Result<()> {
632-
type ChangeSet = tx_graph::ChangeSet<ConfirmationBlockTime>;
632+
type ChangeSet = tx_graph::TxChangeSet<ConfirmationBlockTime>;
633633
let mut conn = rusqlite::Connection::open_in_memory()?;
634634

635635
// Create initial database with v0 sqlite schema

0 commit comments

Comments
 (0)