fixed issue where client tag was being sent with kind 3 event whereas it only has p tags

This commit is contained in:
Vishal 2022-08-28 02:30:09 +05:30
parent 0318202401
commit b87cb0346b
4 changed files with 31 additions and 15 deletions

1
.gitignore vendored
View File

@ -21,3 +21,4 @@ doc/api/
*.js.map
del*.txt
all_nostr_events.txt
bin/nostr_console_win64.exe

View File

@ -42,7 +42,7 @@ Future<void> sendReplyPostLike(Tree node, String replyToId, String replyKind, St
String id = getShaId(userPublicKey, createdAt, replyKind, strTags, content);
String sig = sign(userPrivateKey, id, "12345612345612345612345612345612");
String toSendMessage = '["EVENT", {"id": "$id","pubkey": "$userPublicKey","created_at": $createdAt,"kind": $replyKind,"tags": [$strTags],"content": "$content","sig": "$sig"}]';
String toSendMessage = '["EVENT",{"id":"$id","pubkey":"$userPublicKey","created_at":$createdAt,"kind":$replyKind,"tags":[$strTags],"content":"$content","sig":"$sig"}]';
relays.sendRequest(defaultServerUrl, toSendMessage);
}
@ -55,10 +55,11 @@ Future<void> sendChatMessage(Tree node, String channelId, String messageToSend)
String id = getShaId(userPublicKey, createdAt, replyKind, strTags, messageToSend);
String sig = sign(userPrivateKey, id, "12345612345612345612345612345612");
String toSendMessage = '["EVENT", {"id": "$id","pubkey": "$userPublicKey","created_at": $createdAt,"kind": $replyKind,"tags": [$strTags],"content": "$messageToSend","sig": "$sig"}]';
String toSendMessage = '["EVENT",{"id":"$id","pubkey":"$userPublicKey","created_at":$createdAt,"kind":$replyKind,"tags":[$strTags],"content":"$messageToSend","sig":"$sig"}]';
relays.sendRequest(defaultServerUrl, toSendMessage);
}
// send event e
Future<void> sendEvent(Tree node, Event e) async {
String strTags = "";
int createdAt = DateTime.now().millisecondsSinceEpoch ~/1000;
@ -71,16 +72,24 @@ Future<void> sendEvent(Tree node, Event e) async {
if( relay == "") {
relay = defaultServerUrl;
}
String strContact = '["p","${e.eventData.contactList[i].id}"],';
String comma = ",";
if( i == e.eventData.contactList.length - 1) {
comma = "";
}
String strContact = '["p","${e.eventData.contactList[i].id}","$relay"]$comma';
strTags += strContact;
}
strTags += '["client","nostr_console"]';
// strTags += '["client","nostr_console"]';
}
// TODO send client for kinds other than 3 ( which can only have p tags)
String id = getShaId(userPublicKey, createdAt, e.eventData.kind.toString(), strTags, content);
String sig = sign(userPrivateKey, id, "12345612345612345612345612345612");
String toSendMessage = '["EVENT", {"id":"$id","pubkey":"$userPublicKey","created_at":$createdAt,"kind":${e.eventData.kind.toString()},"tags":[$strTags],"content":"$content","sig":"$sig"}]';
String toSendMessage = '["EVENT",{"id":"$id","pubkey":"$userPublicKey","created_at":$createdAt,"kind":${e.eventData.kind.toString()},"tags":[$strTags],"content":"$content","sig":"$sig"}]';
//print("in send event: calling sendrequiest");
relays.sendRequest(defaultServerUrl, toSendMessage);
}

View File

@ -191,18 +191,23 @@ class EventData {
if(json['kind'] == 3) {
for( int i = 0; i < numTags; i++) {
var tag = jsonTags[i];
var n = tag.length;
if( tag.length < 2) {
if( gDebug > 0) print("In event fromjson: invalid p tag of size 1");
continue;
}
String server = defaultServerUrl;
if( n >=3 ) {
if( tag.length >=3 ) {
server = tag[2].toString();
if( server == 'wss://nostr.rocks' || server == "wss://nostr.bitcoiner.social") {
server = defaultServerUrl;
}
//server = defaultServerUrl;
}
Contact c = Contact(tag[1] as String, server);
contactList.add(c);
if( tag[0] == "p" && tag[1].length == 64) {
Contact c = Contact(tag[1] as String, server);
contactList.add(c);
}
}
} else {
if ( json['kind'] == 1 || json['kind'] == 7 || json['kind'] == 42 ) {

View File

@ -9,6 +9,11 @@ const int numWaitSeconds = 3000;
// global counters of total events read or processed
int numFileEvents = 0, numUserEvents = 0, numFeedEvents = 0, numOtherEvents = 0;
//String defaultServerUrl = 'wss://relay.damus.io';
const String nostrRelayUnther = 'wss://nostr-relay.untethr.me';
const String relayNostrInfo = 'wss://relay.nostr.info';
String defaultServerUrl = relayNostrInfo;
List<String> gListRelayUrls = [defaultServerUrl,
"wss://nostr-verified.wellorder.net",
"wss://nostr-relay.wlvs.space",
@ -65,10 +70,6 @@ String gWarningColor = redColor; // red
const String colorEndMarker = "\x1B[0m";
//String defaultServerUrl = 'wss://relay.damus.io';
const String nostrRelayUnther = 'wss://nostr-relay.untethr.me';
String defaultServerUrl = nostrRelayUnther;
// dummy account pubkey
const String gDummyAccountPubkey = "Non";