@@ -2,7 +2,6 @@ package main
22
33import (
44 "context"
5- "fmt"
65
76 "fiatjaf.com/nostr"
87 "fiatjaf.com/nostr/nip19"
@@ -209,10 +208,9 @@ var encode = &cli.Command{
209208 Usage : "generate codes for addressable events" ,
210209 Flags : []cli.Flag {
211210 & cli.StringFlag {
212- Name : "identifier" ,
213- Aliases : []string {"d" },
214- Usage : "the \" d\" tag identifier of this replaceable event -- can also be read from stdin" ,
215- Required : true ,
211+ Name : "identifier" ,
212+ Aliases : []string {"d" },
213+ Usage : "the \" d\" tag identifier of this replaceable event -- can also be read from stdin" ,
216214 },
217215 & PubKeyFlag {
218216 Name : "pubkey" ,
@@ -242,21 +240,27 @@ var encode = &cli.Command{
242240 for d := range getStdinLinesOrBlank () {
243241 pubkey := getPubKey (c , "pubkey" )
244242
245- kind := c .Int ("kind" )
246- if kind < 30000 || kind >= 40000 {
247- return fmt .Errorf ("kind must be between 30000 and 39999, got %d" , kind )
248- }
249-
243+ kind := nostr .Kind (c .Int ("kind" ))
250244 if d == "" {
251245 d = c .String ("identifier" )
252- if d == "" {
253- ctx = lineProcessingError (ctx , "\" d\" tag identifier can't be empty" )
246+ }
247+
248+ if kind .IsAddressable () {
249+ if ! c .IsSet ("identifier" ) {
250+ ctx = lineProcessingError (ctx , "\" d\" tag identifier must be set for addressable events" )
254251 continue
255252 }
253+ } else if kind .IsReplaceable () {
254+ if c .IsSet ("identifier" ) {
255+ ctx = lineProcessingError (ctx , "\" d\" tag identifier must not be set for replaceable events" )
256+ continue
257+ }
258+ } else {
259+ ctx = lineProcessingError (ctx , "can only encode addressable events" )
260+ continue
256261 }
257262
258263 relays := c .StringSlice ("relay" )
259-
260264 if getBoolInt (c , "outbox" ) > 0 {
261265 for _ , r := range sys .FetchOutboxRelays (ctx , pubkey , int (getBoolInt (c , "outbox" ))) {
262266 relays = nostr .AppendUnique (relays , r )
0 commit comments