Skip to content

Commit 0dafd16

Browse files
committed
nostr: fix Kind::is_regular method
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent e938076 commit 0dafd16

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
* nostr: fix `TagStanderd::to_vec` ([nanikamado])
121121
* nostr: fix broken intra doc links ([Yuki Kishimoto])
122122
* nostr: fix `JsonUtil::try_as_pretty_json` method ([Yuki Kishimoto])
123+
* nostr: fix `Kind::is_regular` method ([Yuki Kishimoto])
123124

124125
### Removed
125126

bindings/nostr-ffi/src/event/kind.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ impl Kind {
6767

6868
/// Check if it's regular
6969
///
70+
/// Regular means that event is expected to be stored by relays.
71+
///
7072
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
7173
#[inline]
7274
pub fn is_regular(&self) -> bool {

bindings/nostr-js/src/event/kind.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ impl JsKind {
6060

6161
/// Check if it's regular
6262
///
63+
/// Regular means that event is expected to be stored by relays.
64+
///
6365
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
6466
#[wasm_bindgen(js_name = isRegular)]
6567
pub fn is_regular(&self) -> bool {

crates/nostr/src/event/kind.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ pub const PARAMETERIZED_REPLACEABLE_RANGE: Range<u16> = 30_000..40_000;
2929

3030
macro_rules! kind_variants {
3131
($($name:ident => $value:expr, $doc:expr),* $(,)?) => {
32-
/// Event [`Kind`]
32+
/// Event kind
33+
///
34+
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
3335
#[derive(Debug, Clone, Copy)]
3436
pub enum Kind {
3537
$(
@@ -227,10 +229,19 @@ impl Kind {
227229
NIP90_JOB_RESULT_RANGE.contains(&self.as_u16())
228230
}
229231

230-
/// Check if [`Kind`] is `Regular`
231-
#[inline]
232+
/// Check if it's regular
233+
///
234+
/// Regular means that event is expected to be stored by relays.
232235
pub fn is_regular(&self) -> bool {
233-
REGULAR_RANGE.contains(&self.as_u16())
236+
let kind: u16 = self.as_u16();
237+
238+
// Exclude ALL param replaceable and ephemeral
239+
// Exclude PARTIALLY the replaceable
240+
if kind > 10_000 {
241+
return false;
242+
}
243+
244+
REGULAR_RANGE.contains(&kind) || !self.is_replaceable()
234245
}
235246

236247
/// Check if [`Kind`] is `Replaceable`

0 commit comments

Comments
 (0)