Skip to content

Commit cf543ff

Browse files
committed
Merge #421: refactor: Delegate rusqlite::Connection persister to transaction persister
b8dfff8 refactor: Delegate Connection persister to transaction persister (shinigami-777) Pull request description: Fixes #279 ### Description The `WalletPersister` implementations for `rusqlite::Connection` and `rusqlite::Transaction` are currently independent. The connection persister just creates a new transaction, does what the transaction persister does, and then commits. This refactor removes that duplication by having the Connection impl delegate directly to the Transaction impl. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `just p` before pushing #### New Features: * [ ] I've added tests for the new feature * [ ] I've added docs for the new feature #### Bugfixes: * [ ] This pull request breaks the existing API * [ ] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR ACKs for top commit: ValuedMammal: ACK b8dfff8 Tree-SHA512: 0bf12f10f6173a77f3e204ae01d05b3b87926dff3ec0cc4e4dd1a3d2eb6b6885900c52cf272ac1953ad6038722515c532b29ba8b3f5e5271fa635f1ac59cf06c
2 parents 5df32ca + b8dfff8 commit cf543ff

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/wallet/persisted.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,16 @@ impl WalletPersister for bdk_chain::rusqlite::Connection {
284284
type Error = bdk_chain::rusqlite::Error;
285285

286286
fn initialize(persister: &mut Self) -> Result<ChangeSet, Self::Error> {
287-
let db_tx = persister.transaction()?;
288-
ChangeSet::init_sqlite_tables(&db_tx)?;
289-
let changeset = ChangeSet::from_sqlite(&db_tx)?;
287+
let mut db_tx = persister.transaction()?;
288+
let changeset =
289+
<bdk_chain::rusqlite::Transaction<'_> as WalletPersister>::initialize(&mut db_tx)?;
290290
db_tx.commit()?;
291291
Ok(changeset)
292292
}
293293

294294
fn persist(persister: &mut Self, changeset: &ChangeSet) -> Result<(), Self::Error> {
295-
let db_tx = persister.transaction()?;
296-
changeset.persist_to_sqlite(&db_tx)?;
295+
let mut db_tx = persister.transaction()?;
296+
<bdk_chain::rusqlite::Transaction<'_> as WalletPersister>::persist(&mut db_tx, changeset)?;
297297
db_tx.commit()
298298
}
299299
}

0 commit comments

Comments
 (0)