From ca9777be8306f37ac92956cc1b1ed27527c86906 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 25 Jul 2025 12:42:19 -0400 Subject: [PATCH] Creates a kind type alias --- .../quartz/nip01Core/core/Event.kt | 2 +- .../quartz/nip01Core/core/Kind.kt | 32 +++++++++++++++++++ .../nip01Core/tags/addressables/Address.kt | 3 +- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/core/Kind.kt diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/core/Event.kt b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/core/Event.kt index 806b49996..406969a17 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/core/Event.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/core/Event.kt @@ -34,7 +34,7 @@ open class Event( val id: HexKey, val pubKey: HexKey, val createdAt: Long, - val kind: Int, + val kind: Kind, val tags: TagArray, val content: String, val sig: HexKey, diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/core/Kind.kt b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/core/Kind.kt new file mode 100644 index 000000000..0aea6ba6f --- /dev/null +++ b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/core/Kind.kt @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2025 Vitor Pamplona + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.vitorpamplona.quartz.nip01Core.core + +import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent +import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent + +typealias Kind = Int + +fun Kind.isEphemeral() = this >= 20_000 && this < 30_000 + +fun Kind.isReplaceable() = this == MetadataEvent.KIND || this == ContactListEvent.KIND || (this >= 10_000 && this < 20_000) + +fun Kind.isAddressable() = this >= 30_000 && this < 40_000 diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/tags/addressables/Address.kt b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/tags/addressables/Address.kt index 3ce855153..c2ad93901 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/tags/addressables/Address.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/tags/addressables/Address.kt @@ -22,6 +22,7 @@ package com.vitorpamplona.quartz.nip01Core.tags.addressables import android.util.Log import com.vitorpamplona.quartz.nip01Core.core.HexKey +import com.vitorpamplona.quartz.nip01Core.core.Kind import com.vitorpamplona.quartz.nip19Bech32.Nip19Parser import com.vitorpamplona.quartz.nip19Bech32.entities.NAddress import com.vitorpamplona.quartz.utils.Hex @@ -29,7 +30,7 @@ import com.vitorpamplona.quartz.utils.bytesUsedInMemory import com.vitorpamplona.quartz.utils.pointerSizeInBytes data class Address( - val kind: Int, + val kind: Kind, val pubKeyHex: HexKey, val dTag: String = "", ) : Comparable
{