Skip to content

Commit

Permalink
🚧 nostr subsription and data fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelStark committed Jul 16, 2024
1 parent 5be23e5 commit dfe378c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
19 changes: 10 additions & 9 deletions crates/cli/src/prover_agent.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use askeladd_core::data_fixture::{self, PROVING_REQ_SUB_ID, SUBSCRIBED_RELAYS};
use askeladd_core::prover_service::ProverService;
use askeladd_core::types::FibonnacciProvingRequest;
use nostr_sdk::prelude::*;

const SUBSCRIBED_RELAYS: &[&str] = &[
"wss://nostr.oxtr.dev",
"wss://relay.damus.io",
"wss://nostr.openchain.fr",
];
const PROVING_REQ_SUB_ID: &str = "askeladd_proving_request";

#[tokio::main]
async fn main() -> Result<()> {
let user_secret_key = SecretKey::from_bech32(data_fixture::USER_BECH32_SK)?;
let user_keys = Keys::new(user_secret_key);
let user_public_key = user_keys.public_key();

let prover_agent_keys =
Keys::new(SecretKey::from_bech32(data_fixture::PROVER_AGENT_SK).unwrap());

let opts = Options::new().wait_for_send(false);
let client = Client::builder().opts(opts).build();
let client = Client::with_opts(&prover_agent_keys, opts);

for relay in SUBSCRIBED_RELAYS {
client.add_relay(Url::parse(relay).unwrap()).await?;
Expand All @@ -21,7 +22,7 @@ async fn main() -> Result<()> {
client.connect().await;

let proving_req_sub_id = SubscriptionId::new(PROVING_REQ_SUB_ID);
let filter = Filter::new().kind(Kind::TextNote);
let filter = Filter::new().kind(Kind::TextNote).author(user_public_key);

client
.subscribe_with_id(proving_req_sub_id.clone(), vec![filter], None)
Expand Down
20 changes: 11 additions & 9 deletions crates/cli/src/user_cli.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use askeladd_core::data_fixture::{self, PROVING_RESP_SUB_ID, SUBSCRIBED_RELAYS};
use askeladd_core::types::{FibonnacciProvingRequest, FibonnacciProvingResponse};
use askeladd_core::verifier_service::VerifierService;
use nostr_sdk::prelude::*;
use uuid::Uuid;

const SUBSCRIBED_RELAYS: &[&str] = &[
"wss://nostr.oxtr.dev",
"wss://relay.damus.io",
"wss://nostr.openchain.fr",
];
const PROVING_RESP_SUB_ID: &str = "askeladd_proving_response";

#[tokio::main]
async fn main() -> Result<()> {
let prover_agent_secret_key = SecretKey::from_bech32(data_fixture::PROVER_AGENT_SK)?;
let prover_agent_keys = Keys::new(prover_agent_secret_key);
let prover_agent_public_key = prover_agent_keys.public_key();
let user_keys = Keys::new(SecretKey::from_bech32(data_fixture::USER_BECH32_SK).unwrap());

let opts = Options::new().wait_for_send(false);
let client = Client::builder().opts(opts).build();
let client = Client::with_opts(&user_keys, opts);

for relay in SUBSCRIBED_RELAYS {
client.add_relay(Url::parse(relay).unwrap()).await?;
Expand Down Expand Up @@ -41,7 +40,10 @@ async fn main() -> Result<()> {

// Subscribe to proving responses
let proving_resp_sub_id = SubscriptionId::new(PROVING_RESP_SUB_ID);
let filter = Filter::new().kind(Kind::TextNote).since(Timestamp::now());
let filter = Filter::new()
.kind(Kind::TextNote)
.author(prover_agent_public_key)
.since(Timestamp::now());

client
.subscribe_with_id(proving_resp_sub_id.clone(), vec![filter], None)
Expand Down
6 changes: 6 additions & 0 deletions crates/core/src/data_fixture.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub const SUBSCRIBED_RELAYS: &[&str] = &["wss://relay.damus.io"];
pub const PROVING_REQ_SUB_ID: &str = "askeladd.proving.request";
pub const PROVING_RESP_SUB_ID: &str = "askeladd.proving.response";

pub const USER_BECH32_SK: &str = "nsec1tsaxyqcxp8atqup4facwp0as52f2c0evj4cxpw6yaqetusu7sg8qqzkr3k";
pub const PROVER_AGENT_SK: &str = "nsec18s6wcqlkglhjmfz3tnjkh0qscf6cqen96ecp5k5k73ktew3l97tstuvy2x";
1 change: 1 addition & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod data_fixture;
pub mod prover_service;
pub mod types;
pub mod verifier_service;
Expand Down

0 comments on commit dfe378c

Please sign in to comment.