upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/20.md
diff options
context:
space:
mode:
Diffstat (limited to '20.md')
-rw-r--r--20.md88
1 files changed, 2 insertions, 86 deletions
diff --git a/20.md b/20.md
index 7e97dd9..ec6127a 100644
--- a/20.md
+++ b/20.md
@@ -1,93 +1,9 @@
1NIP-20 1NIP-20
2====== 2======
3 3
4
5Command Results 4Command Results
6--------------- 5---------------
7 6
8`draft` `optional` `author:jb55` 7`final` `mandatory` `author:jb55`
9
10When 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.
11
12A command result is a JSON object with the following structure that is returned when an event is successfully saved to the database or rejected:
13
14 ["OK", <event_id>, <true|false>, <message>]
15
16Relays MUST return `true` when the event is a duplicate and has already been saved. The `message` SHOULD start with `duplicate:` in this case.
17
18Relays MUST return `false` when the event was rejected and not saved.
19
20The `message` SHOULD provide additional information as to why the command succeeded or failed.
21
22The `message` SHOULD start with `blocked:` if the pubkey or network address has been blocked, banned, or is not on a whitelist.
23
24The `message` SHOULD start with `invalid:` if the event is invalid or doesn't meet some specific criteria (created_at is too far off, id is wrong, signature is wrong, etc)
25
26The `message` SHOULD start with `pow:` if the event doesn't meet some proof-of-work difficulty. The client MAY consult the relay metadata at this point to retrieve the required posting difficulty.
27
28The `message` SHOULD start with `rate-limited:` if the event was rejected due to rate limiting techniques.
29
30The `message` SHOULD start with `error:` if the event failed to save due to a server issue.
31
32Ephemeral events are not acknowledged with OK responses, unless there is a failure.
33
34If the event or `EVENT` command is malformed and could not be parsed, a NOTICE message SHOULD be used instead of a command result. This NIP only applies to non-malformed EVENT commands.
35
36
37Examples
38--------
39
40Event successfully written to the database:
41
42 ["OK", "b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30", true, ""]
43
44Event successfully written to the database because of a reason:
45
46 ["OK", "b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30", true, "pow: difficulty 25>=24"]
47
48Event blocked due to ip filter
49
50 ["OK", "b1a649ebe8...", false, "blocked: tor exit nodes not allowed"]
51
52Event blocked due to pubkey ban
53
54 ["OK", "b1a649ebe8...", false, "blocked: you are banned from posting here"]
55
56Event blocked, pubkey not registered
57
58 ["OK", "b1a649ebe8...", false, "blocked: please register your pubkey at https://my-expensive-relay.example.com"]
59
60Event rejected, rate limited
61
62 ["OK", "b1a649ebe8...", false, "rate-limited: slow down there chief"]
63
64Event rejected, `created_at` too far off
65
66 ["OK", "b1a649ebe8...", false, "invalid: event creation date is too far off from the current time. Is your system clock in sync?"]
67
68Event rejected, insufficient proof-of-work difficulty
69
70 ["OK", "b1a649ebe8...", false, "pow: difficulty 26 is less than 30"]
71
72Event failed to save,
73
74 ["OK", "b1a649ebe8...", false, "error: could not connect to the database"]
75
76
77
78Client Handling
79---------------
80
81`messages` are meant for humans, with `reason:` prefixes so that clients can be slightly more intelligent with what to do with them. For example, with a `rate-limited:` reason the client may not show anything and simply try again with a longer timeout.
82
83For the `pow:` prefix it may query relay metadata to get the updated difficulty requirement and try again in the background.
84
85For the `invalid:` and `blocked:` prefix the client may wish to show these as styled error popups.
86
87The prefixes include a colon so that the message can be cleanly separated from the prefix by taking everything after `:` and trimming it.
88
89
90Future Extensions
91-----------------
92 8
93This proposal SHOULD be extended to support further commands in the future, such as REQ and AUTH. They are left out of this initial version to keep things simpler. 9Moved to [NIP-01](01.md).