Skip to content

Commit b6b1623

Browse files
Merge pull request #14 from blackcoffeexbt/main
Added support for callback functions for any REQ kind. Updated examples. Other performance improvements
2 parents 7b6e5ac + 21432be commit b6b1623

File tree

8 files changed

+156
-84
lines changed

8 files changed

+156
-84
lines changed

Diff for: examples/LilyGoTDisplay/LilyGoTDisplay.ino

+19-19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <NostrEvent.h>
55
#include <NostrRelayManager.h>
66
#include <TFT_eSPI.h>
7+
#include <vector>
78

89
const char* ssid = "<SSID>"; // wifi SSID here
910
const char* password = "<PASSWORD>"; // wifi password here
@@ -94,32 +95,31 @@ void setup() {
9495

9596
long timestamp = getUnixTimestamp();
9697

97-
const char *const relays[] = {
98-
"relay.damus.io",
99-
"nostr.mom",
100-
"relay.nostr.bg"
98+
std::vector<String> relays = {
99+
"relay.damus.io",
100+
"nostr.mom",
101+
"relay.nostr.bg"
101102
};
102-
int relayCount = sizeof(relays) / sizeof(relays[0]);
103103

104-
nostr.setLogging(false);
105-
nostrRelayManager.setRelays(relays, relayCount);
106-
nostrRelayManager.setMinRelaysAndTimeout(2,10000);
104+
nostr.setLogging(false);
105+
nostrRelayManager.setRelays(relays);
106+
nostrRelayManager.setMinRelaysAndTimeout(2,10000);
107107

108-
// Set some event specific callbacks here
109-
nostrRelayManager.setEventCallback("ok", okEvent);
110-
nostrRelayManager.setEventCallback("nip01", nip01Event);
111-
nostrRelayManager.setEventCallback("nip04", nip04Event);
108+
// Set some event specific callbacks here
109+
nostrRelayManager.setEventCallback("ok", okEvent);
110+
nostrRelayManager.setEventCallback("nip01", nip01Event);
111+
nostrRelayManager.setEventCallback("nip04", nip04Event);
112112

113-
nostrRelayManager.connect();
113+
nostrRelayManager.connect();
114114

115-
String subscriptionString = "[\"REQ\", \"" + nostrRelayManager.getNewSubscriptionId() + "\", {\"authors\": [\"d0bfc94bd4324f7df2a7601c4177209828047c4d3904d64009a3c67fb5d5e7ca\"], \"kinds\": [1], \"limit\": 1}]";
116-
nostrRelayManager.enqueueMessage(subscriptionString.c_str());
115+
String subscriptionString = "[\"REQ\", \"" + nostrRelayManager.getNewSubscriptionId() + "\", {\"authors\": [\"d0bfc94bd4324f7df2a7601c4177209828047c4d3904d64009a3c67fb5d5e7ca\"], \"kinds\": [1], \"limit\": 1}]";
116+
nostrRelayManager.enqueueMessage(subscriptionString.c_str());
117117

118-
subscriptionString = "[\"REQ\", \"" + nostrRelayManager.getNewSubscriptionId() + "\", {\"#p\": [\"d0bfc94bd4324f7df2a7601c4177209828047c4d3904d64009a3c67fb5d5e7ca\"], \"kinds\": [4], \"limit\": 1}]";
119-
nostrRelayManager.enqueueMessage(subscriptionString.c_str());
118+
subscriptionString = "[\"REQ\", \"" + nostrRelayManager.getNewSubscriptionId() + "\", {\"#p\": [\"d0bfc94bd4324f7df2a7601c4177209828047c4d3904d64009a3c67fb5d5e7ca\"], \"kinds\": [4], \"limit\": 1}]";
119+
nostrRelayManager.enqueueMessage(subscriptionString.c_str());
120120

121-
subscriptionString = nostr.getEncryptedDm(nsecHex, npubHex, testRecipientPubKeyHex, timestamp, "Running NIP04!");
122-
nostrRelayManager.enqueueMessage(subscriptionString.c_str());
121+
subscriptionString = nostr.getEncryptedDm(nsecHex, npubHex, testRecipientPubKeyHex, timestamp, "Running NIP04!");
122+
nostrRelayManager.enqueueMessage(subscriptionString.c_str());
123123
}
124124

125125
void loop() {

Diff for: examples/Simple/Simple.ino

+26-26
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#include "time.h"
44
#include <NostrEvent.h>
55
#include <NostrRelayManager.h>
6+
#include <vector>
67

7-
const char* ssid = "wubwub"; // wifi SSID here
8-
const char* password = "blob19750405blob"; // wifi password here
8+
const char* ssid = "<SSIDHERE>"; // wifi SSID here
9+
const char* password = "<PASSWORDHERE>"; // wifi password here
910

1011
NostrEvent nostr;
1112
NostrRelayManager nostrRelayManager;
@@ -73,31 +74,30 @@ void setup() {
7374

7475
long timestamp = getUnixTimestamp();
7576

76-
const char *const relays[] = {
77-
"relay.damus.io",
78-
"nostr.mom",
79-
"relay.nostr.bg"
77+
std::vector<String> relays = {
78+
"relay.damus.io",
79+
"nostr.mom",
80+
"relay.nostr.bg"
8081
};
81-
int relayCount = sizeof(relays) / sizeof(relays[0]);
82-
83-
nostr.setLogging(false);
84-
nostrRelayManager.setRelays(relays, relayCount);
85-
nostrRelayManager.setMinRelaysAndTimeout(2,10000);
86-
87-
// Set some event specific callbacks here
88-
nostrRelayManager.setEventCallback("ok", okEvent);
89-
nostrRelayManager.setEventCallback("nip01", nip01Event);
90-
nostrRelayManager.setEventCallback("nip04", nip04Event);
91-
92-
nostrRelayManager.connect();
93-
94-
// Send a basic note
95-
String noteString = nostr.getNote(nsecHex, npubHex, timestamp, "Running NIP01!");
96-
nostrRelayManager.enqueueMessage(noteString.c_str());
97-
98-
// send an encrypted dm to the defined npub
99-
subscriptionString = nostr.getEncryptedDm(nsecHex, npubHex, testRecipientPubKeyHex, timestamp, "Running NIP04!");
100-
nostrRelayManager.enqueueMessage(subscriptionString.c_str());
82+
83+
nostr.setLogging(false);
84+
nostrRelayManager.setRelays(relays);
85+
nostrRelayManager.setMinRelaysAndTimeout(2,10000);
86+
87+
// Set some event specific callbacks here
88+
nostrRelayManager.setEventCallback("ok", okEvent);
89+
nostrRelayManager.setEventCallback("nip01", nip01Event);
90+
nostrRelayManager.setEventCallback("nip04", nip04Event);
91+
92+
nostrRelayManager.connect();
93+
94+
// Send a basic note
95+
String noteString = nostr.getNote(nsecHex, npubHex, timestamp, "Running NIP01!");
96+
nostrRelayManager.enqueueMessage(noteString.c_str());
97+
98+
// send an encrypted dm to the defined npub
99+
String subscriptionString = nostr.getEncryptedDm(nsecHex, npubHex, testRecipientPubKeyHex, timestamp, "Running NIP04!");
100+
nostrRelayManager.enqueueMessage(subscriptionString.c_str());
101101
}
102102

103103
void loop() {

Diff for: examples/SubscribeRequest/SubscribeRequest.ino

+16-16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "time.h"
88
#include <NostrEvent.h>
99
#include <NostrRelayManager.h>
10+
#include <vector>
1011

1112
const char* ssid = "wubwub"; // wifi SSID here
1213
const char* password = "blob19750405blob"; // wifi password here
@@ -77,23 +78,22 @@ void setup() {
7778

7879
long timestamp = getUnixTimestamp();
7980

80-
const char *const relays[] = {
81-
"relay.damus.io",
82-
"nostr.mom",
83-
"relay.nostr.bg"
81+
std::vector<String> relays = {
82+
"relay.damus.io",
83+
"nostr.mom",
84+
"relay.nostr.bg"
8485
};
85-
int relayCount = sizeof(relays) / sizeof(relays[0]);
86-
87-
nostr.setLogging(false);
88-
nostrRelayManager.setRelays(relays, relayCount);
89-
nostrRelayManager.setMinRelaysAndTimeout(2,10000);
90-
91-
// Set some event specific callbacks here
92-
nostrRelayManager.setEventCallback("ok", okEvent);
93-
nostrRelayManager.setEventCallback("nip01", nip01Event);
94-
nostrRelayManager.setEventCallback("nip04", nip04Event);
95-
96-
nostrRelayManager.connect();
86+
87+
nostr.setLogging(false);
88+
nostrRelayManager.setRelays(relays);
89+
nostrRelayManager.setMinRelaysAndTimeout(2,10000);
90+
91+
// Set some event specific callbacks here
92+
nostrRelayManager.setEventCallback("ok", okEvent);
93+
nostrRelayManager.setEventCallback(1, nip01Event);
94+
nostrRelayManager.setEventCallback(4, nip04Event);
95+
96+
nostrRelayManager.connect();
9797

9898
NostrRequestOptions* eventRequestOptions = new NostrRequestOptions();
9999

Diff for: library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"type": "git",
2222
"url": "https://github.com/lnbits/arduino-nostr"
2323
},
24-
"version": "0.1.12",
24+
"version": "0.2.0",
2525
"dependencies": {
2626
"ArduinoJson": "^6.21.1",
2727
"uBitcoin": "^0.2.0",

Diff for: library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Nostr
2-
version=0.1.12
2+
version=0.2.0
33
44
maintainer=BlackCoffee <[email protected]>
55
sentence=Nostr for Arduino.

0 commit comments

Comments
 (0)