Skip to content

Commit

Permalink
Add nostr-sdk-db crate
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Oct 12, 2023
1 parent 36e39f4 commit e63a092
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ members = [
"bindings/nostr-sdk-ffi",
"bindings/nostr-sdk-js",
"bindings/uniffi-bindgen",
"crates/nostr",
"crates/nostr-sdk",
"crates/nostr-sdk-net",
"crates/*",
]
default-members = ["crates/*"]
resolver = "2"
Expand Down
16 changes: 16 additions & 0 deletions crates/nostr-sdk-db/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "nostr-sdk-db"
version = "0.1.0"
edition = "2021"
description = "Nostr SDK Database"
authors = ["Yuki Kishimoto <[email protected]>"]
homepage.workspace = true
repository.workspace = true
license.workspace = true
readme = "README.md"
rust-version.workspace = true
keywords = ["nostr", "sdk", "db"]

[dependencies]
async-trait = "0.1"
nostr = { version = "0.24", path = "../nostr", default-features = false, features = ["std"] }
41 changes: 41 additions & 0 deletions crates/nostr-sdk-db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2022-2023 Yuki Kishimoto
// Distributed under the MIT software license

//! Nostr SDK Database
#![warn(missing_docs)]
#![warn(rustdoc::bare_urls)]

use async_trait::async_trait;
use nostr::{Event, EventId, Filter, Url};

/// Nostr SDK Database
#[async_trait]
pub trait NostrDatabase {
/// Error
type Err;

/// Save [`Event`] into store
async fn save_event(&self, event: &Event) -> Result<(), Self::Err>;

/// Save [`EventId`] seen by relay
///
/// Useful for NIP65 (gossip)
async fn save_event_id_seen_by_relay(
&self,
event_id: EventId,
relay_url: Url,
) -> Result<(), Self::Err>;

/// Get list of relays that have seen the [`EventId`]
async fn event_recently_seen_on_relays(&self, event_id: EventId)
-> Result<Vec<Url>, Self::Err>;

/// Query store with filters
async fn query(&self, filters: Vec<Filter>) -> Result<Vec<Event>, Self::Err>;

/// Get event IDs by filters
///
/// Uuseful for negentropy reconciliation
async fn event_ids_by_filters(&self, filters: Vec<Filter>) -> Result<Vec<EventId>, Self::Err>;
}

0 comments on commit e63a092

Please sign in to comment.