Skip to content

Commit

Permalink
fix(wallet): don't fail reading Null change_desc column from sqlite
Browse files Browse the repository at this point in the history
If no change descriptor is persisted then `Row::get` fails with
`InvalidColumnType`. This is fixed by changing the FromSql type
to `Option<Impl<Descriptor<DescriptorPublicKey>>>`.
  • Loading branch information
ValuedMammal committed Aug 7, 2024
1 parent a723269 commit d5a023f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions crates/wallet/src/wallet/changeset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,23 @@ impl ChangeSet {
.query_row([], |row| {
Ok((
row.get::<_, Impl<Descriptor<DescriptorPublicKey>>>("descriptor")?,
row.get::<_, Impl<Descriptor<DescriptorPublicKey>>>("change_descriptor")?,
row.get::<_, Impl<Descriptor<DescriptorPublicKey>>>("change_descriptor"),
row.get::<_, Impl<bitcoin::Network>>("network")?,
))
})
.optional()?;
if let Some((Impl(desc), Impl(change_desc), Impl(network))) = row {
if let Some((Impl(desc), res, Impl(network))) = row {
changeset.descriptor = Some(desc);
changeset.change_descriptor = Some(change_desc);
use crate::rusqlite::types::Type;
use crate::rusqlite::Error::*;
changeset.change_descriptor = match res {
Ok(Impl(change_desc)) => Some(change_desc),
Err(e) => match e {
// allow a Null column for change descriptor
InvalidColumnType(_, _, Type::Null) => None,
_ => return Err(e),
},
};
changeset.network = Some(network);
}

Expand Down

0 comments on commit d5a023f

Please sign in to comment.