diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/P2POrderEvent.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/P2POrderEvent.kt new file mode 100644 index 000000000..ee4be304b --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/P2POrderEvent.kt @@ -0,0 +1,129 @@ +/* + * 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.nip69P2pOrderEvents + +import androidx.compose.runtime.Immutable +import com.vitorpamplona.quartz.nip01Core.core.BaseAddressableEvent +import com.vitorpamplona.quartz.nip01Core.core.HexKey +import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder +import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate +import com.vitorpamplona.quartz.nip01Core.tags.dTag.dTag +import com.vitorpamplona.quartz.nip31Alts.alt +import com.vitorpamplona.quartz.nip40Expiration.expiration +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.FiatAmountTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.OrderStatus +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.OrderType +import com.vitorpamplona.quartz.utils.TimeUtils +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +@Immutable +class P2POrderEvent( + id: HexKey, + pubKey: HexKey, + createdAt: Long, + tags: Array>, + content: String, + sig: HexKey, +) : BaseAddressableEvent(id, pubKey, createdAt, KIND, tags, content, sig) { + fun orderType() = tags.orderType() + + fun currency() = tags.currency() + + fun status() = tags.orderStatus() + + fun amount() = tags.amount() + + fun fiatAmount() = tags.fiatAmount() + + fun paymentMethods() = tags.paymentMethods() + + fun premium() = tags.premium() + + fun expiresAt() = tags.expiresAt() + + fun platform() = tags.platform() + + fun documentType() = tags.documentType() + + fun source() = tags.source() + + fun rating() = tags.rating() + + fun network() = tags.network() + + fun layer() = tags.layer() + + fun makerName() = tags.makerName() + + fun bond() = tags.bond() + + companion object { + const val KIND = 38383 + const val ALT_DESCRIPTION = "P2P Order" + + @OptIn(ExperimentalUuidApi::class) + fun build( + orderType: OrderType, + currency: String, + status: OrderStatus, + amount: Long, + fiatAmount: FiatAmountTag, + paymentMethods: List, + premium: String, + platform: String, + expiresAt: Long, + expiration: Long? = null, + source: String? = null, + ratingJson: String? = null, + network: String? = null, + layer: String? = null, + makerName: String? = null, + geohash: String? = null, + bond: Long? = null, + dTag: String = Uuid.random().toString(), + createdAt: Long = TimeUtils.now(), + initializer: TagArrayBuilder.() -> Unit = {}, + ) = eventTemplate(KIND, "", createdAt) { + dTag(dTag) + orderType(orderType) + currency(currency) + orderStatus(status) + amount(amount) + fiatAmount(fiatAmount) + paymentMethods(paymentMethods) + premium(premium) + expiresAt(expiresAt) + expiration?.let { expiration(it) } + platform(platform) + documentType() + source?.let { source(it) } + ratingJson?.let { rating(it) } + network?.let { network(it) } + layer?.let { layer(it) } + makerName?.let { makerName(it) } + geohash?.let { geohash(it) } + bond?.let { bond(it) } + alt(ALT_DESCRIPTION) + initializer() + } + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/TagArrayBuilderExt.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/TagArrayBuilderExt.kt new file mode 100644 index 000000000..a46ac7dca --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/TagArrayBuilderExt.kt @@ -0,0 +1,76 @@ +/* + * 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.nip69P2pOrderEvents + +import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder +import com.vitorpamplona.quartz.nip01Core.tags.geohash.GeoHashTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.AmountTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.BondTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.CurrencyTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.DocumentTypeTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.ExpiresAtTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.FiatAmountTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.LayerTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.MakerNameTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.NetworkTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.OrderStatus +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.OrderStatusTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.OrderType +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.OrderTypeTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.PaymentMethodTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.PlatformTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.PremiumTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.RatingTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.SourceTag + +fun TagArrayBuilder.orderType(type: OrderType) = addUnique(OrderTypeTag.assemble(type)) + +fun TagArrayBuilder.orderStatus(status: OrderStatus) = addUnique(OrderStatusTag.assemble(status)) + +fun TagArrayBuilder.currency(currency: String) = addUnique(CurrencyTag.assemble(currency)) + +fun TagArrayBuilder.amount(amountSats: Long) = addUnique(AmountTag.assemble(amountSats)) + +fun TagArrayBuilder.fiatAmount(fiatAmount: FiatAmountTag) = addUnique(FiatAmountTag.assemble(fiatAmount)) + +fun TagArrayBuilder.paymentMethods(methods: List) = addUnique(PaymentMethodTag.assemble(methods)) + +fun TagArrayBuilder.premium(premium: String) = addUnique(PremiumTag.assemble(premium)) + +fun TagArrayBuilder.expiresAt(timestamp: Long) = addUnique(ExpiresAtTag.assemble(timestamp)) + +fun TagArrayBuilder.platform(platform: String) = addUnique(PlatformTag.assemble(platform)) + +fun TagArrayBuilder.documentType(type: String = DocumentTypeTag.ORDER) = addUnique(DocumentTypeTag.assemble(type)) + +fun TagArrayBuilder.source(url: String) = addUnique(SourceTag.assemble(url)) + +fun TagArrayBuilder.rating(ratingJson: String) = addUnique(RatingTag.assemble(ratingJson)) + +fun TagArrayBuilder.network(network: String) = addUnique(NetworkTag.assemble(network)) + +fun TagArrayBuilder.layer(layer: String) = addUnique(LayerTag.assemble(layer)) + +fun TagArrayBuilder.makerName(name: String) = addUnique(MakerNameTag.assemble(name)) + +fun TagArrayBuilder.geohash(geohash: String) = addAll(GeoHashTag.assemble(geohash).toList()) + +fun TagArrayBuilder.bond(bond: Long) = addUnique(BondTag.assemble(bond)) diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/TagArrayExt.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/TagArrayExt.kt new file mode 100644 index 000000000..e49f6401c --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/TagArrayExt.kt @@ -0,0 +1,71 @@ +/* + * 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.nip69P2pOrderEvents + +import com.vitorpamplona.quartz.nip01Core.core.TagArray +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.AmountTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.BondTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.CurrencyTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.DocumentTypeTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.ExpiresAtTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.FiatAmountTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.LayerTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.MakerNameTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.NetworkTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.OrderStatusTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.OrderTypeTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.PaymentMethodTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.PlatformTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.PremiumTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.RatingTag +import com.vitorpamplona.quartz.nip69P2pOrderEvents.tags.SourceTag + +fun TagArray.orderType() = firstNotNullOfOrNull(OrderTypeTag::parse) + +fun TagArray.orderStatus() = firstNotNullOfOrNull(OrderStatusTag::parse) + +fun TagArray.currency() = firstNotNullOfOrNull(CurrencyTag::parse) + +fun TagArray.amount() = firstNotNullOfOrNull(AmountTag::parse) + +fun TagArray.fiatAmount() = firstNotNullOfOrNull(FiatAmountTag::parse) + +fun TagArray.paymentMethods() = firstNotNullOfOrNull(PaymentMethodTag::parse) + +fun TagArray.premium() = firstNotNullOfOrNull(PremiumTag::parse) + +fun TagArray.expiresAt() = firstNotNullOfOrNull(ExpiresAtTag::parse) + +fun TagArray.platform() = firstNotNullOfOrNull(PlatformTag::parse) + +fun TagArray.documentType() = firstNotNullOfOrNull(DocumentTypeTag::parse) + +fun TagArray.source() = firstNotNullOfOrNull(SourceTag::parse) + +fun TagArray.rating() = firstNotNullOfOrNull(RatingTag::parse) + +fun TagArray.network() = firstNotNullOfOrNull(NetworkTag::parse) + +fun TagArray.layer() = firstNotNullOfOrNull(LayerTag::parse) + +fun TagArray.makerName() = firstNotNullOfOrNull(MakerNameTag::parse) + +fun TagArray.bond() = firstNotNullOfOrNull(BondTag::parse) diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/AmountTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/AmountTag.kt new file mode 100644 index 000000000..f0f3a7ad7 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/AmountTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class AmountTag { + companion object { + const val TAG_NAME = "amt" + + fun parse(tag: Array): Long? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1].toLongOrNull() + } + + fun assemble(amountSats: Long) = arrayOf(TAG_NAME, amountSats.toString()) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/BondTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/BondTag.kt new file mode 100644 index 000000000..c82af5b00 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/BondTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class BondTag { + companion object { + const val TAG_NAME = "bond" + + fun parse(tag: Array): Long? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1].toLongOrNull() + } + + fun assemble(bond: Long) = arrayOf(TAG_NAME, bond.toString()) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/CurrencyTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/CurrencyTag.kt new file mode 100644 index 000000000..ad0ccd737 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/CurrencyTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class CurrencyTag { + companion object { + const val TAG_NAME = "f" + + fun parse(tag: Array): String? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1] + } + + fun assemble(currency: String) = arrayOf(TAG_NAME, currency) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/DocumentTypeTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/DocumentTypeTag.kt new file mode 100644 index 000000000..1e8b8acef --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/DocumentTypeTag.kt @@ -0,0 +1,40 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class DocumentTypeTag { + companion object { + const val TAG_NAME = "z" + const val ORDER = "order" + + fun parse(tag: Array): String? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1] + } + + fun assemble(type: String = ORDER) = arrayOf(TAG_NAME, type) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/ExpiresAtTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/ExpiresAtTag.kt new file mode 100644 index 000000000..aca507400 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/ExpiresAtTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class ExpiresAtTag { + companion object { + const val TAG_NAME = "expires_at" + + fun parse(tag: Array): Long? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1].toLongOrNull() + } + + fun assemble(timestamp: Long) = arrayOf(TAG_NAME, timestamp.toString()) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/FiatAmountTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/FiatAmountTag.kt new file mode 100644 index 000000000..554134fdf --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/FiatAmountTag.kt @@ -0,0 +1,56 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import androidx.compose.runtime.Stable +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +@Stable +class FiatAmountTag( + val min: String, + val max: String?, +) { + companion object { + const val TAG_NAME = "fa" + + fun parse(tag: Array): FiatAmountTag? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return FiatAmountTag(tag[1], tag.getOrNull(2)) + } + + fun assemble(amount: String) = arrayOf(TAG_NAME, amount) + + fun assemble( + min: String, + max: String, + ) = arrayOf(TAG_NAME, min, max) + + fun assemble(fiatAmount: FiatAmountTag) = + if (fiatAmount.max != null) { + assemble(fiatAmount.min, fiatAmount.max) + } else { + assemble(fiatAmount.min) + } + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/LayerTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/LayerTag.kt new file mode 100644 index 000000000..89d0c4f46 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/LayerTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class LayerTag { + companion object { + const val TAG_NAME = "layer" + + fun parse(tag: Array): String? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1] + } + + fun assemble(layer: String) = arrayOf(TAG_NAME, layer) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/MakerNameTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/MakerNameTag.kt new file mode 100644 index 000000000..fd51696de --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/MakerNameTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class MakerNameTag { + companion object { + const val TAG_NAME = "name" + + fun parse(tag: Array): String? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1] + } + + fun assemble(name: String) = arrayOf(TAG_NAME, name) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/NetworkTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/NetworkTag.kt new file mode 100644 index 000000000..11db053d7 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/NetworkTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class NetworkTag { + companion object { + const val TAG_NAME = "network" + + fun parse(tag: Array): String? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1] + } + + fun assemble(network: String) = arrayOf(TAG_NAME, network) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/OrderStatusTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/OrderStatusTag.kt new file mode 100644 index 000000000..998702e92 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/OrderStatusTag.kt @@ -0,0 +1,57 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +enum class OrderStatus( + val code: String, +) { + PENDING("pending"), + CANCELED("canceled"), + IN_PROGRESS("in-progress"), + SUCCESS("success"), + EXPIRED("expired"), +} + +class OrderStatusTag { + companion object { + const val TAG_NAME = "s" + + fun parse(tag: Array): OrderStatus? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + + return when (tag[1]) { + OrderStatus.PENDING.code -> OrderStatus.PENDING + OrderStatus.CANCELED.code -> OrderStatus.CANCELED + OrderStatus.IN_PROGRESS.code -> OrderStatus.IN_PROGRESS + OrderStatus.SUCCESS.code -> OrderStatus.SUCCESS + OrderStatus.EXPIRED.code -> OrderStatus.EXPIRED + else -> null + } + } + + fun assemble(status: OrderStatus) = arrayOf(TAG_NAME, status.code) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/OrderTypeTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/OrderTypeTag.kt new file mode 100644 index 000000000..305f87546 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/OrderTypeTag.kt @@ -0,0 +1,51 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +enum class OrderType( + val code: String, +) { + BUY("buy"), + SELL("sell"), +} + +class OrderTypeTag { + companion object { + const val TAG_NAME = "k" + + fun parse(tag: Array): OrderType? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + + return when (tag[1]) { + OrderType.BUY.code -> OrderType.BUY + OrderType.SELL.code -> OrderType.SELL + else -> null + } + } + + fun assemble(type: OrderType) = arrayOf(TAG_NAME, type.code) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/PaymentMethodTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/PaymentMethodTag.kt new file mode 100644 index 000000000..f01a08832 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/PaymentMethodTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class PaymentMethodTag { + companion object { + const val TAG_NAME = "pm" + + fun parse(tag: Array): List? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag.drop(1) + } + + fun assemble(methods: List) = arrayOf(TAG_NAME, *methods.toTypedArray()) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/PlatformTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/PlatformTag.kt new file mode 100644 index 000000000..da15e89c9 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/PlatformTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class PlatformTag { + companion object { + const val TAG_NAME = "y" + + fun parse(tag: Array): String? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1] + } + + fun assemble(platform: String) = arrayOf(TAG_NAME, platform) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/PremiumTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/PremiumTag.kt new file mode 100644 index 000000000..2b5d56c2c --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/PremiumTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class PremiumTag { + companion object { + const val TAG_NAME = "premium" + + fun parse(tag: Array): String? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1] + } + + fun assemble(premium: String) = arrayOf(TAG_NAME, premium) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/RatingTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/RatingTag.kt new file mode 100644 index 000000000..7dd5028c0 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/RatingTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class RatingTag { + companion object { + const val TAG_NAME = "rating" + + fun parse(tag: Array): String? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1] + } + + fun assemble(ratingJson: String) = arrayOf(TAG_NAME, ratingJson) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/SourceTag.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/SourceTag.kt new file mode 100644 index 000000000..db9c4c899 --- /dev/null +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip69P2pOrderEvents/tags/SourceTag.kt @@ -0,0 +1,39 @@ +/* + * 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.nip69P2pOrderEvents.tags + +import com.vitorpamplona.quartz.nip01Core.core.has +import com.vitorpamplona.quartz.utils.ensure + +class SourceTag { + companion object { + const val TAG_NAME = "source" + + fun parse(tag: Array): String? { + ensure(tag.has(1)) { return null } + ensure(tag[0] == TAG_NAME) { return null } + ensure(tag[1].isNotEmpty()) { return null } + return tag[1] + } + + fun assemble(url: String) = arrayOf(TAG_NAME, url) + } +} diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/EventFactory.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/EventFactory.kt index ff7fda348..6e4a69480 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/EventFactory.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/EventFactory.kt @@ -153,6 +153,7 @@ import com.vitorpamplona.quartz.nip65RelayList.AdvertisedRelayListEvent import com.vitorpamplona.quartz.nip66RelayMonitor.discovery.RelayDiscoveryEvent import com.vitorpamplona.quartz.nip66RelayMonitor.monitor.RelayMonitorEvent import com.vitorpamplona.quartz.nip68Picture.PictureEvent +import com.vitorpamplona.quartz.nip69P2pOrderEvents.P2POrderEvent import com.vitorpamplona.quartz.nip71Video.VideoHorizontalEvent import com.vitorpamplona.quartz.nip71Video.VideoNormalEvent import com.vitorpamplona.quartz.nip71Video.VideoShortEvent @@ -339,6 +340,7 @@ class EventFactory { OtsEvent.KIND -> OtsEvent(id, pubKey, createdAt, tags, content, sig) PaymentTargetsEvent.KIND -> PaymentTargetsEvent(id, pubKey, createdAt, tags, content, sig) PeopleListEvent.KIND -> PeopleListEvent(id, pubKey, createdAt, tags, content, sig) + P2POrderEvent.KIND -> P2POrderEvent(id, pubKey, createdAt, tags, content, sig) PictureEvent.KIND -> PictureEvent(id, pubKey, createdAt, tags, content, sig) PinListEvent.KIND -> PinListEvent(id, pubKey, createdAt, tags, content, sig) ZapPollEvent.KIND -> ZapPollEvent(id, pubKey, createdAt, tags, content, sig)