Skip to content

Commit

Permalink
Check that personal note is stored in the db (#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-21 authored Dec 18, 2024
1 parent 077e17d commit 6d312c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 2 additions & 3 deletions examples/node/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,10 +1427,9 @@ fn payment_uuid(node: &LightningNode, words: &mut dyn Iterator<Item = &str>) ->

fn set_personal_note(node: &LightningNode, words: &mut dyn Iterator<Item = &str>) -> Result<()> {
let payment_hash = words.next().ok_or(anyhow!("Payment Hash is required"))?;
let note = words.collect::<Vec<_>>().join(" ");

let note = words.collect::<Vec<_>>().join(" ").to_string();
node.activities()
.set_personal_note(payment_hash.to_string(), note.to_string())?;
.set_personal_note(payment_hash.to_string(), note)?;

Ok(())
}
Expand Down
10 changes: 7 additions & 3 deletions src/data_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{EnableStatus, ExchangeRate, OfferKind, PocketOfferError, TzConfig, U
use chrono::{DateTime, Utc};
use crow::FiatTopupSetupInfo;
use crow::{PermanentFailureCode, TemporaryFailureCode};
use perro::MapToError;
use perro::{ensure, invalid_input, MapToError};
use rusqlite::{backup, params, Connection, OptionalExtension, Params, Row};
use std::time::{Duration, SystemTime, UNIX_EPOCH};

Expand Down Expand Up @@ -250,7 +250,8 @@ impl DataStore {
personal_note: Option<&str>,
) -> Result<()> {
self.backup_status = BackupStatus::WaitingForBackup;
self.conn
let number_of_rows = self
.conn
.execute(
"
UPDATE payments \
Expand All @@ -259,7 +260,10 @@ impl DataStore {
params![personal_note, payment_hash],
)
.map_to_permanent_failure("Failed to store personal note in local db")?;

ensure!(
number_of_rows == 1,
invalid_input("Payment not found to set personal note")
);
Ok(())
}

Expand Down

0 comments on commit 6d312c5

Please sign in to comment.