Skip to content
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
6 changes: 3 additions & 3 deletions src/database/contacts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dash_sdk::platform::Identifier;
use rusqlite::params;
use rusqlite::{Connection, params};

#[derive(Debug, Clone)]
pub struct ContactPrivateInfo {
Expand All @@ -11,7 +11,7 @@ pub struct ContactPrivateInfo {
}

impl crate::database::Database {
pub fn init_contacts_tables(&self) -> rusqlite::Result<()> {
pub fn init_contacts_tables(&self, conn: &Connection) -> rusqlite::Result<()> {
let sql = "
CREATE TABLE IF NOT EXISTS contact_private_info (
owner_identity_id BLOB NOT NULL,
Expand All @@ -24,7 +24,7 @@ impl crate::database::Database {
PRIMARY KEY (owner_identity_id, contact_identity_id)
);
";
self.execute(sql, [])?;
conn.execute(sql, [])?;
Ok(())
}

Expand Down
99 changes: 0 additions & 99 deletions src/database/dashpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,105 +161,6 @@ impl crate::database::Database {
Ok(())
}

/// Initialize all DashPay-related database tables
pub fn init_dashpay_tables(&self) -> rusqlite::Result<()> {
// Profiles table
self.execute(
"CREATE TABLE IF NOT EXISTS dashpay_profiles (
identity_id BLOB PRIMARY KEY,
display_name TEXT,
bio TEXT,
avatar_url TEXT,
avatar_hash BLOB,
avatar_fingerprint BLOB,
public_message TEXT,
created_at INTEGER DEFAULT (unixepoch()),
updated_at INTEGER DEFAULT (unixepoch())
)",
[],
)?;

// Contacts table (extends the existing contact_private_info)
self.execute(
"CREATE TABLE IF NOT EXISTS dashpay_contacts (
owner_identity_id BLOB NOT NULL,
contact_identity_id BLOB NOT NULL,
username TEXT,
display_name TEXT,
avatar_url TEXT,
public_message TEXT,
contact_status TEXT DEFAULT 'pending',
created_at INTEGER DEFAULT (unixepoch()),
updated_at INTEGER DEFAULT (unixepoch()),
last_seen INTEGER,
PRIMARY KEY (owner_identity_id, contact_identity_id)
)",
[],
)?;

// Contact requests table
self.execute(
"CREATE TABLE IF NOT EXISTS dashpay_contact_requests (
id INTEGER PRIMARY KEY AUTOINCREMENT,
from_identity_id BLOB NOT NULL,
to_identity_id BLOB NOT NULL,
to_username TEXT,
account_label TEXT,
request_type TEXT NOT NULL CHECK (request_type IN ('sent', 'received')),
status TEXT DEFAULT 'pending' CHECK (status IN ('pending', 'accepted', 'rejected', 'expired')),
created_at INTEGER DEFAULT (unixepoch()),
responded_at INTEGER,
expires_at INTEGER
)",
[],
)?;

// Create index for faster queries
self.execute(
"CREATE INDEX IF NOT EXISTS idx_contact_requests_from
ON dashpay_contact_requests(from_identity_id)",
[],
)?;

self.execute(
"CREATE INDEX IF NOT EXISTS idx_contact_requests_to
ON dashpay_contact_requests(to_identity_id)",
[],
)?;

// Payments/transactions table
self.execute(
"CREATE TABLE IF NOT EXISTS dashpay_payments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
tx_id TEXT UNIQUE NOT NULL,
from_identity_id BLOB NOT NULL,
to_identity_id BLOB NOT NULL,
amount INTEGER NOT NULL,
memo TEXT,
payment_type TEXT NOT NULL CHECK (payment_type IN ('sent', 'received')),
status TEXT DEFAULT 'pending' CHECK (status IN ('pending', 'confirmed', 'failed')),
created_at INTEGER DEFAULT (unixepoch()),
confirmed_at INTEGER
)",
[],
)?;

// Create index for faster queries
self.execute(
"CREATE INDEX IF NOT EXISTS idx_payments_from
ON dashpay_payments(from_identity_id)",
[],
)?;

self.execute(
"CREATE INDEX IF NOT EXISTS idx_payments_to
ON dashpay_payments(to_identity_id)",
[],
)?;

Ok(())
}

// Profile operations

pub fn save_dashpay_profile(
Expand Down
6 changes: 3 additions & 3 deletions src/database/initialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ impl Database {
self.initialize_token_order_table(&conn)?;
self.initialize_identity_token_balances_table(&conn)?;

// Initialize contacts table
self.init_contacts_tables()?;
self.init_dashpay_tables()?;
// Initialize contacts and DashPay tables while holding the same connection lock
self.init_contacts_tables(&conn)?;
self.init_dashpay_tables_in_tx(&conn)?;

Ok(())
}
Expand Down
Loading