Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk-common: remove rusqlite dependency #1019

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion libs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion libs/sdk-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ querystring = "1"
prost = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true }
rusqlite = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
strum_macros = { workspace = true }
Expand Down
19 changes: 0 additions & 19 deletions libs/sdk-common/src/lnurl/specs/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,11 @@ pub fn validate_invoice(user_amount_msat: u64, bolt11: &str, network: Network) -
pub mod model {
use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, BlockEncryptMut, KeyIvInit};
use anyhow::Result;
use rusqlite::types::{FromSql, FromSqlError, ToSqlOutput};
use rusqlite::ToSql;
use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::prelude::specs::pay::{Aes256CbcDec, Aes256CbcEnc};
use crate::prelude::*;
// use crate::Payment;

/// Represents a LNURL-pay request.
#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -218,22 +215,6 @@ pub mod model {
Url { data: UrlSuccessActionData },
}

impl FromSql for SuccessActionProcessed {
fn column_result(
value: rusqlite::types::ValueRef<'_>,
) -> rusqlite::types::FromSqlResult<Self> {
serde_json::from_str(value.as_str()?).map_err(|_| FromSqlError::InvalidType)
}
}

impl ToSql for SuccessActionProcessed {
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
Ok(ToSqlOutput::from(
serde_json::to_string(&self).map_err(|_| FromSqlError::InvalidType)?,
))
}
}

/// Supported success action types
///
/// Receiving any other (unsupported) success action type will result in a failed parsing,
Expand Down
13 changes: 10 additions & 3 deletions libs/sdk-core/src/persist/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::{HashMap, HashSet};
use std::str::FromStr;

use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef};
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, Type, ValueRef};
use rusqlite::Row;
use rusqlite::{named_params, params, OptionalExtension};
use sdk_common::prelude::*;
Expand Down Expand Up @@ -96,7 +96,7 @@ impl SqliteStorage {

_ = prep_statement.execute((
payment_hash,
payment_external_info.lnurl_pay_success_action,
serde_json::to_string(&payment_external_info.lnurl_pay_success_action)?,
payment_external_info.lnurl_pay_domain,
payment_external_info.lnurl_pay_comment,
payment_external_info.lnurl_metadata,
Expand Down Expand Up @@ -379,7 +379,14 @@ impl SqliteStorage {
};

if let PaymentDetails::Ln { ref mut data } = payment.details {
data.lnurl_success_action = row.get(8)?;
let lnurl_success_action_str: Option<String> = row.get(8)?;
data.lnurl_success_action = match lnurl_success_action_str {
None => None,
Some(s) => serde_json::from_str(&s).map_err(|e| {
rusqlite::Error::FromSqlConversionFailure(8, Type::Text, Box::new(e))
})?,
};

data.lnurl_pay_domain = row.get(17)?;
data.lnurl_pay_comment = row.get(18)?;
data.lnurl_metadata = row.get(9)?;
Expand Down
Loading