-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6474fd3
commit 5c8e29d
Showing
3 changed files
with
69 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,39 @@ | ||
import 'dart:convert'; | ||
import 'package:nostr/nostr.dart'; | ||
|
||
/// When submitting events to relays, clients currently have no way to know if an event was successfully committed to the database. | ||
/// This NIP introduces the concept of command results which are like NOTICE's except provide more information about if an event was accepted or rejected. | ||
/// | ||
/// Event successfully written to the database: | ||
/// | ||
/// ["OK", "b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30", true, ""] | ||
/// | ||
/// Event successfully written to the database because of a reason: | ||
/// | ||
/// ["OK", "b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30", true, "pow: difficulty 25>=24"] | ||
/// | ||
/// Event blocked due to ip filter: | ||
/// | ||
/// ["OK", "b1a649ebe8...", false, "blocked: tor exit nodes not allowed"] | ||
/// | ||
/// … | ||
class Nip20 { | ||
static OKEvent? getOk(String okPayload) { | ||
var ok = Message.deserialize(okPayload); | ||
if(ok.type == 'OK'){ | ||
var object = jsonDecode(ok.message); | ||
return OKEvent(object[0], object[1], object[2]); | ||
} | ||
} | ||
} | ||
late String eventId; | ||
late bool status; | ||
late String message; | ||
|
||
/// Default constructor | ||
Nip20(this.eventId, this.status, this.message); | ||
|
||
class OKEvent { | ||
String eventId; | ||
bool status; | ||
String message; | ||
/// Serialize to nostr close message | ||
/// - ["OK", "event_id", true|false, "message"] | ||
String serialize() => jsonEncode(["OK", eventId, status, message]); | ||
|
||
OKEvent(this.eventId, this.status, this.message); | ||
} | ||
/// Deserialize a nostr close message | ||
/// - ["OK", "event_id", true|false, "message"] | ||
Nip20.deserialize(input) { | ||
assert(input.length == 4); | ||
eventId = input[1]; | ||
status = input[2]; | ||
message = input[3]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters