@@ -43,20 +43,26 @@ async fn main() -> Result<()> {
43
43
let bech32_pubkey: String = my_keys.public_key().to_bech32()?;
44
44
println!("Bech32 PubKey: {}", bech32_pubkey);
45
45
46
- // Create new client
47
- let client = Client::new(&my_keys);
48
-
49
- let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050)));
46
+ // Configure client to use proxy for `.onion` relays
47
+ let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050));
48
+ let connection: Connection = Connection::new()
49
+ .proxy(addr) // Use `.embedded_tor()` instead to enable the embedded tor client (require `tor` feature)
50
+ .target(ConnectionTarget::Onion);
51
+ let opts = Options::new().connection(connection);
52
+
53
+ // Create new client with custom options.
54
+ // Use `Client::new(signer)` to construct the client with a custom signer and default options
55
+ // or `Client::default()` to create one without signer and with default options.
56
+ let client = Client::with_opts(&my_keys, opts);
50
57
51
58
// Add relays
52
59
client.add_relay("wss://relay.damus.io").await?;
60
+ client.add_relay("ws://jgqaglhautb4k6e6i2g34jakxiemqp6z4wynlirltuukgkft2xuglmqd.onion").await?;
61
+
62
+ // Add relay with custom options
53
63
client.add_relay_with_opts(
54
64
"wss://relay.nostr.info",
55
- RelayOptions::new().proxy(proxy).write(false)
56
- ).await?;
57
- client.add_relay_with_opts(
58
- "ws://jgqaglhautb4k6e6i2g34jakxiemqp6z4wynlirltuukgkft2xuglmqd.onion",
59
- RelayOptions::new().proxy(proxy),
65
+ RelayOptions::new().write(false)
60
66
).await?;
61
67
62
68
// Connect to relays
0 commit comments