From b87cb0346b914c6183ae31039fc3264e0c3751f0 Mon Sep 17 00:00:00 2001 From: Vishal <64505169+vishalxl@users.noreply.github.com> Date: Sun, 28 Aug 2022 02:30:09 +0530 Subject: [PATCH] fixed issue where client tag was being sent with kind 3 event whereas it only has p tags --- .gitignore | 1 + lib/console_ui.dart | 19 ++++++++++++++----- lib/event_ds.dart | 17 +++++++++++------ lib/settings.dart | 9 +++++---- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 189f2fa..5773336 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ doc/api/ *.js.map del*.txt all_nostr_events.txt +bin/nostr_console_win64.exe diff --git a/lib/console_ui.dart b/lib/console_ui.dart index c3c7a9f..f7187a8 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -42,7 +42,7 @@ Future 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 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 sendEvent(Tree node, Event e) async { String strTags = ""; int createdAt = DateTime.now().millisecondsSinceEpoch ~/1000; @@ -71,16 +72,24 @@ Future 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); } diff --git a/lib/event_ds.dart b/lib/event_ds.dart index 96f8367..68433c4 100644 --- a/lib/event_ds.dart +++ b/lib/event_ds.dart @@ -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 ) { diff --git a/lib/settings.dart b/lib/settings.dart index 65b5cb4..346efc8 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -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 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";