Repository navigation
implement sqlite database - #376
Conversation
aebf6be to
5f35900
Compare
5f35900 to
79718c1
Compare
a744416 to
a9d3bde
Compare
tcharding
left a comment
There was a problem hiding this comment.
A few minor suggestions/ideas. Don't read too much into my review, I'm not that deep in bdk.
Cheers
| // should this ever really happen? wouldn't an adjusted tx | ||
| // result in a new txid | ||
| self.update_transaction(&transaction.txid(), &serialize(transaction))?; |
There was a problem hiding this comment.
The comment is correct, AFAIU, if the transaction is already in the db we could just noop.
There was a problem hiding this comment.
yeah makes sense, I guess in theory there could be a change to the transaction struct that is outside of the txid calculation. Can't hurt to keep the update here I suppose.
| } | ||
|
|
||
| fn del_raw_tx(&mut self, txid: &Txid) -> Result<Option<Transaction>, Error> { | ||
| match self.select_transaction_by_txid(&txid)? { |
There was a problem hiding this comment.
Double reference, same below. If you lint with clippy +nightly it will catch these for you.
There was a problem hiding this comment.
thanks, yeah I see that clippy finds it. cool.
| // always returns with Option<Transaction> (if exists in db) | ||
| // are there cases where we NEED it to be None even if it exists in db? | ||
| // or is this just a performance improvement? | ||
| match self.select_transaction_details_by_txid(&txid)? { |
There was a problem hiding this comment.
I would assume that Err is for db connection errors, None means not in db, and Some means found in db.
There was a problem hiding this comment.
this comment is actually referring to the fact that my select_transaction_details method ALWAYS includes the raw transaction in the result if it exists in the database. The get_tx method accepts a include_raw flag for whether or not we are supposed to fetch the raw transaction.
So I was just worried about a potential case where the user sets include_raw to false but it's still included. Feels like this should never be an actual problem other than perhaps a performance issue.
| fn get_last_index(&self, keychain: KeychainKind) -> Result<Option<u32>, Error> { | ||
| let keychain = serde_json::to_string(&keychain)?; | ||
| match self.select_last_deriviation_index_by_keychain(keychain)? { | ||
| Some(value) => { | ||
| Ok(Some(value)) | ||
| }, | ||
| None => { | ||
| Ok(None) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Just for your interest, this can also be written as:
fn get_last_index(&self, keychain: KeychainKind) -> Result<Option<u32>, Error> {
let keychain = serde_json::to_string(&keychain)?;
let value = self.select_last_deriviation_index_by_keychain(keychain)?;
Ok(value)
}
``
There was a problem hiding this comment.
ah good point, looks cleaner.
ba14714 to
d12bfb5
Compare
54ae316 to
636de95
Compare
|
A couple places in the CI workflows also need the new
|
|
Also this one needs a rebase to pickup latest |
636de95 to
0fa1328
Compare
0fa1328 to
c06d9f1
Compare
Description
This PR implements all the Database related traits for a database backed by sqlite. It currently uses cached prepared statements which simplify the implementation from trying to use actual prepared Statement objects owned by the SqliteDatabase struct. It should have the same performance as long as the cache is large enough to hold all the statements.
In my own project I use a crate called rusqlite_migration to handle migrations but in an attempt to reduce dependencies I borrowed a simple migration implementation by jb55 that manages a version based on the length of the static migrations array.
Notes to the reviewers
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features:
CHANGELOG.mdBugfixes: