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

payjoin / rust-payjoin / 16254101487

13 Jul 2025 10:27PM UTC coverage: 85.698% (+0.1%) from 85.566%
16254101487

Pull #873

github

web-flow
Merge 2e0bbfbb3 into 145d1cfc6
Pull Request #873: Migrate payjoin-cli from sled to rusqlite

147 of 166 new or added lines in 3 files covered. (88.55%)

28 existing lines in 3 files now uncovered.

7682 of 8964 relevant lines covered (85.7%)

522.44 hits per line

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

94.0
/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
pub(crate) const DB_PATH: &str = "payjoin.sqlite";
13

14
pub(crate) struct Database {
15
    pool: Pool<SqliteConnectionManager>,
16
}
17

18
impl Database {
19
    pub(crate) fn create(path: impl AsRef<Path>) -> Result<Self> {
10✔
20
        let manager = SqliteConnectionManager::file(path.as_ref());
10✔
21
        let pool = Pool::new(manager)?;
10✔
22

23
        // Initialize database schema
24
        let conn = pool.get()?;
10✔
25
        Self::init_schema(&conn)?;
10✔
26

27
        Ok(Self { pool })
10✔
28
    }
10✔
29

30
    fn init_schema(conn: &Connection) -> Result<()> {
10✔
31
        conn.execute(
10✔
32
            "CREATE TABLE IF NOT EXISTS sessions (
10✔
33
                session_id BLOB PRIMARY KEY,
10✔
34
                session_type TEXT NOT NULL,
10✔
35
                completed_at INTEGER
10✔
36
            )",
10✔
37
            [],
10✔
NEW
38
        )?;
×
39

40
        conn.execute(
10✔
41
            "CREATE TABLE IF NOT EXISTS session_events (
10✔
42
                id INTEGER PRIMARY KEY AUTOINCREMENT,
10✔
43
                session_id BLOB NOT NULL,
10✔
44
                event_data TEXT NOT NULL,
10✔
45
                created_at INTEGER NOT NULL,
10✔
46
                FOREIGN KEY (session_id) REFERENCES sessions(session_id)
10✔
47
            )",
10✔
48
            [],
10✔
NEW
49
        )?;
×
50

51
        conn.execute(
10✔
52
            "CREATE TABLE IF NOT EXISTS inputs_seen (
10✔
53
                input_hash BLOB PRIMARY KEY,
10✔
54
                created_at INTEGER NOT NULL
10✔
55
            )",
10✔
56
            [],
10✔
NEW
57
        )?;
×
58

59
        Ok(())
10✔
60
    }
10✔
61

62
    pub(crate) fn get_connection(&self) -> Result<r2d2::PooledConnection<SqliteConnectionManager>> {
30✔
63
        Ok(self.pool.get()?)
30✔
64
    }
30✔
65

66
    pub(crate) fn insert_input_seen_before(&self, input: OutPoint) -> Result<bool> {
3✔
67
        let conn = self.get_connection()?;
3✔
68
        let key = serialize(&input);
3✔
69
        let timestamp =
3✔
70
            std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs()
3✔
71
                as i64;
3✔
72

73
        let was_seen_before = conn.execute(
3✔
74
            "INSERT OR IGNORE INTO inputs_seen (input_hash, created_at) VALUES (?1, ?2)",
3✔
75
            params![key, timestamp],
3✔
76
        )? == 0;
3✔
77

78
        Ok(was_seen_before)
3✔
79
    }
3✔
80
}
81

82
#[cfg(feature = "v2")]
83
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