Skip to content

Commit

Permalink
kind checking moved to top-level functions on kinds.go
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Nov 3, 2024
1 parent 99c3765 commit 1d06176
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
21 changes: 0 additions & 21 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,3 @@ func (evt *Event) Serialize() []byte {

return dst
}

// IsRegular checks if the given kind is in Regular range.
func (evt *Event) IsRegular() bool {
return evt.Kind < 10000 && evt.Kind != 0 && evt.Kind != 3
}

// IsReplaceable checks if the given kind is in Replaceable range.
func (evt *Event) IsReplaceable() bool {
return evt.Kind == 0 || evt.Kind == 3 ||
(10000 <= evt.Kind && evt.Kind < 20000)
}

// IsEphemeral checks if the given kind is in Ephemeral range.
func (evt *Event) IsEphemeral() bool {
return 20000 <= evt.Kind && evt.Kind < 30000
}

// IsAddressable checks if the given kind is in Addressable range.
func (evt *Event) IsAddressable() bool {
return 30000 <= evt.Kind && evt.Kind < 40000
}
12 changes: 0 additions & 12 deletions event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,3 @@ func BenchmarkIDCheck(b *testing.B) {
}
})
}

func EventKindTest(t *testing.T) {
require.True(t, (&Event{Kind: 1}).IsRegular())
require.True(t, (&Event{Kind: 9}).IsRegular())
require.True(t, (&Event{Kind: 1111}).IsRegular())
require.True(t, (&Event{Kind: 0}).IsReplaceable())
require.True(t, (&Event{Kind: 3}).IsReplaceable())
require.True(t, (&Event{Kind: 10002}).IsReplaceable())
require.True(t, (&Event{Kind: 10050}).IsReplaceable())
require.True(t, (&Event{Kind: 30023}).IsAddressable())
require.True(t, (&Event{Kind: 39000}).IsAddressable())
}
16 changes: 16 additions & 0 deletions kinds.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,19 @@ const (
KindSimpleGroupAdmins int = 39001
KindSimpleGroupMembers int = 39002
)

func IsRegularKind(kind int) bool {
return kind < 10000 && kind != 0 && kind != 3
}

func IsReplaceableKind(kind int) bool {
return kind == 0 || kind == 3 || (10000 <= kind && kind < 20000)
}

func IsEphemeralKind(kind int) bool {
return 20000 <= kind && kind < 30000
}

func IsAddressableKind(kind int) bool {
return 30000 <= kind && kind < 40000
}
19 changes: 19 additions & 0 deletions kinds_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package nostr

import (
"testing"

"github.com/stretchr/testify/require"
)

func KindKindTest(t *testing.T) {
require.True(t, IsRegularKind(1))
require.True(t, IsRegularKind(9))
require.True(t, IsRegularKind(1111))
require.True(t, IsReplaceableKind(0))
require.True(t, IsReplaceableKind(3))
require.True(t, IsReplaceableKind(10002))
require.True(t, IsReplaceableKind(10050))
require.True(t, IsAddressableKind(30023))
require.True(t, IsAddressableKind(39000))
}

0 comments on commit 1d06176

Please sign in to comment.