Skip to content

Commit

Permalink
feat: add invoice field to send
Browse files Browse the repository at this point in the history
  • Loading branch information
yse committed Apr 12, 2024
1 parent bd022ae commit 493d1e8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
9 changes: 7 additions & 2 deletions lib/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub(crate) enum OngoingSwap {
id: String,
amount_sat: u64,
funding_address: String,
invoice: String,
},
Receive {
id: String,
Expand Down Expand Up @@ -172,12 +173,16 @@ pub struct Payment {
impl From<OngoingSwap> for Payment {
fn from(swap: OngoingSwap) -> Self {
match swap {
OngoingSwap::Send { amount_sat, .. } => Payment {
OngoingSwap::Send {
amount_sat,
invoice,
..
} => Payment {
id: None,
timestamp: None,
payment_type: PaymentType::PendingSend,
amount_sat,
invoice: None,
invoice: Some(invoice),
},
OngoingSwap::Receive {
onchain_amount_sat,
Expand Down
1 change: 1 addition & 0 deletions lib/src/persist/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) fn current_migrations() -> Vec<&'static str> {
id TEXT NOT NULL PRIMARY KEY,
amount_sat INTEGER NOT NULL,
funding_address TEXT NOT NULL,
invoice TEXT NOT NULL,
created_at TEXT DEFAULT CURRENT_TIMESTAMP
) STRICT;",
]
Expand Down
10 changes: 7 additions & 3 deletions lib/src/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,21 @@ impl Persister {
id,
funding_address,
amount_sat,
invoice,
} => {
let mut stmt = con.prepare(
"
INSERT INTO ongoing_send_swaps (
id,
amount_sat,
funding_address
funding_address,
invoice
)
VALUES (?, ?, ?)
VALUES (?, ?, ?, ?)
",
)?;

_ = stmt.execute((&id, &amount_sat, &funding_address))?
_ = stmt.execute((&id, &amount_sat, &funding_address, invoice))?
}
OngoingSwap::Receive {
id,
Expand Down Expand Up @@ -127,6 +129,7 @@ impl Persister {
id,
amount_sat,
funding_address,
invoice,
created_at
FROM ongoing_send_swaps
ORDER BY created_at
Expand All @@ -139,6 +142,7 @@ impl Persister {
id: row.get(0)?,
amount_sat: row.get(1)?,
funding_address: row.get(2)?,
invoice: row.get(3)?,
})
})?
.map(|i| i.unwrap())
Expand Down
1 change: 1 addition & 0 deletions lib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ impl Wallet {
id: id.clone(),
amount_sat,
funding_address: funding_address.clone(),
invoice: invoice.to_string(),
}])
.map_err(|_| PaymentError::PersistError)?;

Expand Down

0 comments on commit 493d1e8

Please sign in to comment.