@@ -890,6 +890,7 @@ mod test {
890890 miniscript:: descriptor:: Descriptor ,
891891 } ;
892892
893+ use bdk_testenv:: persist_test_utils:: persist_txgraph_changeset;
893894 use std:: sync:: Arc ;
894895 use std:: { collections:: BTreeMap , path:: Path } ;
895896 use tempfile:: NamedTempFile ;
@@ -2164,4 +2165,50 @@ mod test {
21642165 Ok ( Store :: new ( Arc :: new ( db) , "wallet" . to_string ( ) ) ?)
21652166 } ) ;
21662167 }
2168+
2169+ #[ test]
2170+ fn txgraph_is_persisted ( ) {
2171+ // const DB_MAGIC: &[u8] = &[0x21, 0x24, 0x48];
2172+ // persist_txgraph_changeset::<bdk_wallet::file_store::Store<tx_graph::ChangeSet<ConfirmationBlockTime>>, _, _, _>(
2173+ // "store.db",
2174+ // |path| Ok(bdk_wallet::file_store::Store::create(DB_MAGIC, path)?),
2175+ // |db| Ok(db.dump().map(Option::unwrap_or_default)?),
2176+ // |db, changeset| Ok(db.append(changeset)?),
2177+ // );
2178+
2179+ // persist_txgraph_changeset::<bdk_chain::rusqlite::Connection, _, _, _>(
2180+ // "store.sqlite",
2181+ // |path| Ok(bdk_chain::rusqlite::Connection::open(path)?),
2182+ // |db| {
2183+ // let db_tx = db.transaction()?;
2184+ // tx_graph::ChangeSet::<ConfirmationBlockTime>::init_sqlite_tables(&db_tx)?;
2185+ // let changeset = tx_graph::ChangeSet::<ConfirmationBlockTime>::from_sqlite(&db_tx)?;
2186+ // db_tx.commit()?;
2187+ // Ok(changeset)
2188+ // },
2189+ // |db, changeset| {
2190+ // let db_tx = db.transaction()?;
2191+ // changeset.persist_to_sqlite(&db_tx)?;
2192+ // Ok(db_tx.commit()?)
2193+ // },
2194+ // );
2195+
2196+ persist_txgraph_changeset (
2197+ "wallet.redb" ,
2198+ |path| {
2199+ let db = redb:: Database :: create ( path) ?;
2200+ Ok ( Store :: new ( Arc :: new ( db) , "wallet" . to_string ( ) ) ?)
2201+ } ,
2202+ |db| {
2203+ db. create_tables :: < ConfirmationBlockTime > ( ) ?;
2204+ let mut changeset = tx_graph:: ChangeSet :: < ConfirmationBlockTime > :: default ( ) ;
2205+ db. read_tx_graph ( & mut changeset) ?;
2206+ Ok ( changeset)
2207+ } ,
2208+ |db, changeset| {
2209+ db. persist_tx_graph ( changeset) ?;
2210+ Ok ( ( ) )
2211+ } ,
2212+ ) ;
2213+ }
21672214}
0 commit comments