Skip to content

Commit

Permalink
Merge pull request #14 from blackcoffeexbt/main
Browse files Browse the repository at this point in the history
Added support for callback functions for any REQ kind. Updated examples. Other performance improvements
  • Loading branch information
blackcoffeexbt authored Aug 3, 2023
2 parents 7b6e5ac + 21432be commit b6b1623
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 84 deletions.
38 changes: 19 additions & 19 deletions examples/LilyGoTDisplay/LilyGoTDisplay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <NostrEvent.h>
#include <NostrRelayManager.h>
#include <TFT_eSPI.h>
#include <vector>

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

long timestamp = getUnixTimestamp();

const char *const relays[] = {
"relay.damus.io",
"nostr.mom",
"relay.nostr.bg"
std::vector<String> relays = {
"relay.damus.io",
"nostr.mom",
"relay.nostr.bg"
};
int relayCount = sizeof(relays) / sizeof(relays[0]);

nostr.setLogging(false);
nostrRelayManager.setRelays(relays, relayCount);
nostrRelayManager.setMinRelaysAndTimeout(2,10000);
nostr.setLogging(false);
nostrRelayManager.setRelays(relays);
nostrRelayManager.setMinRelaysAndTimeout(2,10000);

// Set some event specific callbacks here
nostrRelayManager.setEventCallback("ok", okEvent);
nostrRelayManager.setEventCallback("nip01", nip01Event);
nostrRelayManager.setEventCallback("nip04", nip04Event);
// Set some event specific callbacks here
nostrRelayManager.setEventCallback("ok", okEvent);
nostrRelayManager.setEventCallback("nip01", nip01Event);
nostrRelayManager.setEventCallback("nip04", nip04Event);

nostrRelayManager.connect();
nostrRelayManager.connect();

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

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

subscriptionString = nostr.getEncryptedDm(nsecHex, npubHex, testRecipientPubKeyHex, timestamp, "Running NIP04!");
nostrRelayManager.enqueueMessage(subscriptionString.c_str());
subscriptionString = nostr.getEncryptedDm(nsecHex, npubHex, testRecipientPubKeyHex, timestamp, "Running NIP04!");
nostrRelayManager.enqueueMessage(subscriptionString.c_str());
}

void loop() {
Expand Down
52 changes: 26 additions & 26 deletions examples/Simple/Simple.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#include "time.h"
#include <NostrEvent.h>
#include <NostrRelayManager.h>
#include <vector>

const char* ssid = "wubwub"; // wifi SSID here
const char* password = "blob19750405blob"; // wifi password here
const char* ssid = "<SSIDHERE>"; // wifi SSID here
const char* password = "<PASSWORDHERE>"; // wifi password here

NostrEvent nostr;
NostrRelayManager nostrRelayManager;
Expand Down Expand Up @@ -73,31 +74,30 @@ void setup() {

long timestamp = getUnixTimestamp();

const char *const relays[] = {
"relay.damus.io",
"nostr.mom",
"relay.nostr.bg"
std::vector<String> relays = {
"relay.damus.io",
"nostr.mom",
"relay.nostr.bg"
};
int relayCount = sizeof(relays) / sizeof(relays[0]);

nostr.setLogging(false);
nostrRelayManager.setRelays(relays, relayCount);
nostrRelayManager.setMinRelaysAndTimeout(2,10000);

// Set some event specific callbacks here
nostrRelayManager.setEventCallback("ok", okEvent);
nostrRelayManager.setEventCallback("nip01", nip01Event);
nostrRelayManager.setEventCallback("nip04", nip04Event);

nostrRelayManager.connect();

// Send a basic note
String noteString = nostr.getNote(nsecHex, npubHex, timestamp, "Running NIP01!");
nostrRelayManager.enqueueMessage(noteString.c_str());

// send an encrypted dm to the defined npub
subscriptionString = nostr.getEncryptedDm(nsecHex, npubHex, testRecipientPubKeyHex, timestamp, "Running NIP04!");
nostrRelayManager.enqueueMessage(subscriptionString.c_str());

nostr.setLogging(false);
nostrRelayManager.setRelays(relays);
nostrRelayManager.setMinRelaysAndTimeout(2,10000);

// Set some event specific callbacks here
nostrRelayManager.setEventCallback("ok", okEvent);
nostrRelayManager.setEventCallback("nip01", nip01Event);
nostrRelayManager.setEventCallback("nip04", nip04Event);

nostrRelayManager.connect();

// Send a basic note
String noteString = nostr.getNote(nsecHex, npubHex, timestamp, "Running NIP01!");
nostrRelayManager.enqueueMessage(noteString.c_str());

// send an encrypted dm to the defined npub
String subscriptionString = nostr.getEncryptedDm(nsecHex, npubHex, testRecipientPubKeyHex, timestamp, "Running NIP04!");
nostrRelayManager.enqueueMessage(subscriptionString.c_str());
}

void loop() {
Expand Down
32 changes: 16 additions & 16 deletions examples/SubscribeRequest/SubscribeRequest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "time.h"
#include <NostrEvent.h>
#include <NostrRelayManager.h>
#include <vector>

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

long timestamp = getUnixTimestamp();

const char *const relays[] = {
"relay.damus.io",
"nostr.mom",
"relay.nostr.bg"
std::vector<String> relays = {
"relay.damus.io",
"nostr.mom",
"relay.nostr.bg"
};
int relayCount = sizeof(relays) / sizeof(relays[0]);

nostr.setLogging(false);
nostrRelayManager.setRelays(relays, relayCount);
nostrRelayManager.setMinRelaysAndTimeout(2,10000);

// Set some event specific callbacks here
nostrRelayManager.setEventCallback("ok", okEvent);
nostrRelayManager.setEventCallback("nip01", nip01Event);
nostrRelayManager.setEventCallback("nip04", nip04Event);

nostrRelayManager.connect();

nostr.setLogging(false);
nostrRelayManager.setRelays(relays);
nostrRelayManager.setMinRelaysAndTimeout(2,10000);

// Set some event specific callbacks here
nostrRelayManager.setEventCallback("ok", okEvent);
nostrRelayManager.setEventCallback(1, nip01Event);
nostrRelayManager.setEventCallback(4, nip04Event);

nostrRelayManager.connect();

NostrRequestOptions* eventRequestOptions = new NostrRequestOptions();

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"type": "git",
"url": "https://github.com/lnbits/arduino-nostr"
},
"version": "0.1.12",
"version": "0.2.0",
"dependencies": {
"ArduinoJson": "^6.21.1",
"uBitcoin": "^0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Nostr
version=0.1.12
version=0.2.0
author=bc@omg.lol
maintainer=BlackCoffee <bc@omg.lol>
sentence=Nostr for Arduino.
Expand Down
Loading

0 comments on commit b6b1623

Please sign in to comment.