• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

payjoin / rust-payjoin / 16473198763

23 Jul 2025 02:15PM UTC coverage: 85.622% (-0.08%) from 85.706%
16473198763

Pull #873

github

web-flow
Merge fc7098e50 into e4badaa21
Pull Request #873: Migrate payjoin-cli from sled to rusqlite

155 of 179 new or added lines in 4 files covered. (86.59%)

1 existing line in 1 file now uncovered.

7801 of 9111 relevant lines covered (85.62%)

514.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.59
/payjoin-cli/src/db/mod.rs
1
use std::path::Path;
2

3
use payjoin::bitcoin::consensus::encode::serialize;
4
use payjoin::bitcoin::OutPoint;
5
use r2d2::Pool;
6
use r2d2_sqlite::SqliteConnectionManager;
7
use rusqlite::{params, Connection};
8

9
pub(crate) mod error;
10
use error::*;
11

12
macro_rules! now {
13
    () => {
14
        std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() as i64
15
    };
16
}
17

18
pub(crate) const DB_PATH: &str = "payjoin.sqlite";
19

20
pub(crate) struct Database {
21
    pool: Pool<SqliteConnectionManager>,
22
}
23

24
impl Database {
25
    pub(crate) fn create(path: impl AsRef<Path>) -> Result<Self> {
10✔
26
        let manager = SqliteConnectionManager::file(path.as_ref());
10✔
27
        let pool = Pool::new(manager)?;
10✔
28

29
        // Initialize database schema
30
        let conn = pool.get()?;
10✔
31
        Self::init_schema(&conn)?;
10✔
32

33
        Ok(Self { pool })
10✔
34
    }
10✔
35

36
    fn init_schema(conn: &Connection) -> Result<()> {
10✔
37
        conn.execute(
10✔
38
            "CREATE TABLE IF NOT EXISTS send_sessions (
10✔
39
                session_id INTEGER PRIMARY KEY AUTOINCREMENT,
10✔
40
                completed_at INTEGER
10✔
41
            )",
10✔
42
            [],
10✔
NEW
43
        )?;
×
44

45
        conn.execute(
10✔
46
            "CREATE TABLE IF NOT EXISTS receive_sessions (
10✔
47
                session_id INTEGER PRIMARY KEY AUTOINCREMENT,
10✔
48
                completed_at INTEGER
10✔
49
            )",
10✔
50
            [],
10✔
NEW
51
        )?;
×
52

53
        conn.execute(
10✔
54
            "CREATE TABLE IF NOT EXISTS session_events (
10✔
55
                id INTEGER PRIMARY KEY AUTOINCREMENT,
10✔
56
                session_id INTEGER NOT NULL,
10✔
57
                session_type TEXT NOT NULL,
10✔
58
                event_data TEXT NOT NULL,
10✔
59
                created_at INTEGER NOT NULL
10✔
60
            )",
10✔
61
            [],
10✔
NEW
62
        )?;
×
63

64
        conn.execute(
10✔
65
            "CREATE TABLE IF NOT EXISTS inputs_seen (
10✔
66
                outpoint BLOB PRIMARY KEY,
10✔
67
                created_at INTEGER NOT NULL
10✔
68
            )",
10✔
69
            [],
10✔
NEW
70
        )?;
×
71

72
        Ok(())
10✔
73
    }
10✔
74

75
    pub(crate) fn get_connection(&self) -> Result<r2d2::PooledConnection<SqliteConnectionManager>> {
31✔
76
        Ok(self.pool.get()?)
31✔
77
    }
31✔
78
    /// Inserts the input and returns true if the input was seen before, false otherwise.
79
    pub(crate) fn insert_input_seen_before(&self, input: OutPoint) -> Result<bool> {
3✔
80
        let conn = self.get_connection()?;
3✔
81
        let key = serialize(&input);
3✔
82
        let timestamp = now!();
3✔
83

84
        let was_seen_before = conn.execute(
3✔
85
            "INSERT OR IGNORE INTO inputs_seen (outpoint, created_at) VALUES (?1, ?2)",
3✔
86
            params![key, timestamp],
3✔
87
        )? == 0;
3✔
88

89
        Ok(was_seen_before)
3✔
90
    }
3✔
91
}
92

93
#[cfg(feature = "v2")]
94
pub(crate) mod v2;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc