-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crates/nostr/examples/metadata-options
add example
- Loading branch information
1 parent
36dd68a
commit 89075a5
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,70 @@ | ||
// Copyright (c) 2022-2023 Yuki Kishimoto | ||
// Copyright (c) 2023-2024 Rust Nostr Developers | ||
// Distributed under the MIT software license | ||
|
||
#[deny(warnings)] | ||
use clap::Parser; | ||
use nostr::prelude::*; | ||
|
||
#[derive(Parser)] | ||
struct Args { | ||
#[structopt( | ||
name = "secret", | ||
long, | ||
default_value = "6b911fd37cdf5c81d4c0adb1ab7fa822ed253ab0ad9aa18d77257c88b29b718e" | ||
)] | ||
/// Nostr secret key | ||
secret: String, | ||
#[structopt(name = "username", long, default_value = "nostr-rs user")] | ||
/// Nostr username | ||
username: String, | ||
#[structopt(name = "displayname", long, default_value = "nostr-rs user")] | ||
/// Nostr display name | ||
displayname: String, | ||
#[structopt(name = "about", long, default_value = "nostr-rs user")] | ||
/// Nostr about string | ||
about: Option<String>, | ||
#[structopt(name = "picture", long, default_value = "https://robohash.org/nostr-rs")] | ||
/// picture url | ||
picture: Option<String>, | ||
#[structopt(name = "banner", long, default_value = "https://robohash.org/nostr-rs")] | ||
/// banner url | ||
banner: Option<String>, | ||
#[structopt(name = "nip05", long, default_value = "[email protected]")] | ||
/// nip05 | ||
nip05: Option<String>, | ||
#[structopt(name = "lud16", long, default_value = "[email protected]")] | ||
/// lud16 | ||
lud16: Option<String>, | ||
} | ||
|
||
fn run(args: &Args) -> Result<()> { | ||
let metadata = Metadata::new() | ||
.name(args.username.clone()) | ||
.display_name(args.displayname.clone()) | ||
.about(args.about.clone().unwrap()) | ||
.picture(Url::parse(&args.picture.clone().unwrap())?) | ||
.banner(Url::parse(&args.banner.clone().unwrap())?) | ||
.nip05(args.nip05.clone().unwrap()) | ||
.lud16(args.lud16.clone().unwrap()); | ||
|
||
let keys = Keys::parse(&args.secret); | ||
|
||
let event: Event = EventBuilder::metadata(&metadata).sign_with_keys(&keys?).unwrap(); | ||
|
||
// Convert client nessage to JSON | ||
let json = ClientMessage::event(event).as_json(); | ||
println!("{json}"); | ||
|
||
return Ok(()); | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let args = Args::parse(); | ||
match run(&args) { | ||
Ok(()) => {} | ||
Err(e) => println!("error: {}", e), | ||
} | ||
|
||
Ok(()) | ||
} |