-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sdk: add
Client::reset
and switch-account
example
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2022-2023 Yuki Kishimoto | ||
// Copyright (c) 2023-2024 Rust Nostr Developers | ||
// Distributed under the MIT software license | ||
|
||
use std::time::Duration; | ||
|
||
use nostr_sdk::prelude::*; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
tracing_subscriber::fmt::init(); | ||
|
||
// Account 1 | ||
let keys1 = Keys::parse("nsec12kcgs78l06p30jz7z7h3n2x2cy99nw2z6zspjdp7qc206887mwvs95lnkx")?; | ||
let client = Client::new(keys1.clone()); | ||
|
||
client.add_relay("wss://relay.damus.io").await?; | ||
client.connect().await; | ||
|
||
// Subscribe | ||
let filter = Filter::new() | ||
.author(keys1.public_key) | ||
.kind(Kind::TextNote) | ||
.limit(10); | ||
client.subscribe(vec![filter], None).await?; | ||
|
||
// Wait a little | ||
tokio::time::sleep(Duration::from_secs(20)).await; | ||
|
||
println!("Switching account..."); | ||
|
||
// Reset client to change account | ||
client.reset().await?; | ||
|
||
// Account 2 | ||
let keys2 = Keys::parse("nsec1ufnus6pju578ste3v90xd5m2decpuzpql2295m3sknqcjzyys9ls0qlc85")?; | ||
client.set_signer(keys2.clone()).await; | ||
|
||
client.add_relay("wss://nostr.oxtr.dev").await?; | ||
client.connect().await; | ||
|
||
println!("Account switched"); | ||
|
||
// Subscribe | ||
let filter = Filter::new() | ||
.author(keys2.public_key) | ||
.kind(Kind::TextNote) | ||
.limit(5); | ||
client.subscribe(vec![filter], None).await?; | ||
|
||
client | ||
.handle_notifications(|notification| async move { | ||
println!("{notification:?}"); | ||
Ok(false) | ||
}) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters