@@ -890,7 +890,7 @@ mod test {
890890 miniscript:: descriptor:: Descriptor ,
891891 } ;
892892
893- use bdk_testenv:: persist_test_utils:: persist_txgraph_changeset;
893+ use bdk_testenv:: persist_test_utils:: { persist_indexer_changeset , persist_txgraph_changeset} ;
894894 use std:: sync:: Arc ;
895895 use std:: { collections:: BTreeMap , path:: Path } ;
896896 use tempfile:: NamedTempFile ;
@@ -2182,7 +2182,8 @@ mod test {
21822182 // |db| {
21832183 // let db_tx = db.transaction()?;
21842184 // tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?;
2185- // let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?;
2185+ // let changeset =
2186+ // tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?;
21862187 // db_tx.commit()?;
21872188 // Ok(changeset)
21882189 // },
@@ -2211,4 +2212,51 @@ mod test {
22112212 } ,
22122213 ) ;
22132214 }
2215+
2216+ #[ test]
2217+ fn indexer_is_persisted ( ) {
2218+ // const DB_MAGIC: &[u8] = &[0x21, 0x24, 0x48];
2219+ // persist_indexer_changeset::<bdk_wallet::file_store::Store<keychain_txout::ChangeSet>, _,
2220+ // _, _>( "store.db",
2221+ // |path| Ok(bdk_wallet::file_store::Store::create(DB_MAGIC, path)?),
2222+ // |db| Ok(db.dump().map(Option::unwrap_or_default)?),
2223+ // |db, changeset| Ok(db.append(changeset)?),
2224+ // );
2225+
2226+ // persist_indexer_changeset::<bdk_chain::rusqlite::Connection, _, _, _>(
2227+ // "store.sqlite",
2228+ // |path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
2229+ // |db| {
2230+ // let db_tx = db.transaction()?;
2231+ // keychain_txout::ChangeSet::init_sqlite_tables(&db_tx)?;
2232+ // let changeset =
2233+ // keychain_txout::ChangeSet::from_sqlite(&db_tx)?;
2234+ // db_tx.commit()?;
2235+ // Ok(changeset)
2236+ // },
2237+ // |db, changeset| {
2238+ // let db_tx = db.transaction()?;
2239+ // changeset.persist_to_sqlite(&db_tx)?;
2240+ // Ok(db_tx.commit()?)
2241+ // },
2242+ // );
2243+
2244+ persist_indexer_changeset (
2245+ "wallet.redb" ,
2246+ |path| {
2247+ let db = redb:: Database :: create ( path) ?;
2248+ Ok ( Store :: new ( Arc :: new ( db) , "wallet" . to_string ( ) ) ?)
2249+ } ,
2250+ |db| {
2251+ db. create_tables :: < ConfirmationBlockTime > ( ) ?;
2252+ let mut changeset = keychain_txout:: ChangeSet :: default ( ) ;
2253+ db. read_indexer ( & mut changeset) ?;
2254+ Ok ( changeset)
2255+ } ,
2256+ |db, changeset| {
2257+ db. persist_indexer ( changeset) ?;
2258+ Ok ( ( ) )
2259+ } ,
2260+ ) ;
2261+ }
22142262}
0 commit comments