spotlessApply
This commit is contained in:
+12
-1
@@ -59,15 +59,19 @@ object CommandKSerializer : KSerializer<Command> {
|
||||
add(FilterKSerializer.serializeToElement(filter))
|
||||
}
|
||||
}
|
||||
|
||||
is EventCmd -> {
|
||||
add(EventKSerializer.serializeToElement(value.event))
|
||||
}
|
||||
|
||||
is CloseCmd -> {
|
||||
add(JsonPrimitive(value.subId))
|
||||
}
|
||||
|
||||
is AuthCmd -> {
|
||||
add(EventKSerializer.serializeToElement(value.event))
|
||||
}
|
||||
|
||||
is CountCmd -> {
|
||||
add(JsonPrimitive(value.queryId))
|
||||
for (filter in value.filters) {
|
||||
@@ -93,6 +97,7 @@ object CommandKSerializer : KSerializer<Command> {
|
||||
}
|
||||
ReqCmd(subId, filters)
|
||||
}
|
||||
|
||||
CountCmd.LABEL -> {
|
||||
val queryId = array[1].jsonPrimitive.content
|
||||
val filters =
|
||||
@@ -101,16 +106,22 @@ object CommandKSerializer : KSerializer<Command> {
|
||||
}
|
||||
CountCmd(queryId, filters)
|
||||
}
|
||||
|
||||
EventCmd.LABEL -> {
|
||||
EventCmd(EventKSerializer.deserializeFromElement(array[1].jsonObject))
|
||||
}
|
||||
|
||||
CloseCmd.LABEL -> {
|
||||
CloseCmd(array[1].jsonPrimitive.content)
|
||||
}
|
||||
|
||||
AuthCmd.LABEL -> {
|
||||
AuthCmd(EventKSerializer.deserializeFromElement(array[1].jsonObject) as RelayAuthEvent)
|
||||
}
|
||||
else -> throw IllegalArgumentException("Message $type is not supported")
|
||||
|
||||
else -> {
|
||||
throw IllegalArgumentException("Message $type is not supported")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -34,8 +34,6 @@ import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.JsonDecoder
|
||||
import kotlinx.serialization.json.JsonEncoder
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.buildJsonArray
|
||||
import kotlinx.serialization.json.buildJsonObject
|
||||
import kotlinx.serialization.json.int
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
@@ -87,7 +85,7 @@ object EventKSerializer : KSerializer<Event> {
|
||||
var createdAt: Long = 0
|
||||
var kind: Kind = 0
|
||||
var tags: TagArray = emptyTagArray
|
||||
var content: String = ""
|
||||
var content = ""
|
||||
var sig: HexKey = ""
|
||||
|
||||
for ((key, value) in jsonObject) {
|
||||
|
||||
+1
-3
@@ -27,18 +27,15 @@ import kotlinx.serialization.descriptors.buildClassSerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.JsonDecoder
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.JsonEncoder
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.buildJsonArray
|
||||
import kotlinx.serialization.json.buildJsonObject
|
||||
import kotlinx.serialization.json.int
|
||||
import kotlinx.serialization.json.intOrNull
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import kotlinx.serialization.json.long
|
||||
import kotlinx.serialization.json.longOrNull
|
||||
import kotlinx.serialization.json.put
|
||||
|
||||
@@ -120,6 +117,7 @@ object FilterKSerializer : KSerializer<Filter> {
|
||||
key.startsWith("#") -> {
|
||||
tags[key.substring(1)] = value.jsonArray.mapNotNull { it.jsonPrimitive.content }
|
||||
}
|
||||
|
||||
key.startsWith("&") -> {
|
||||
tagsAll[key.substring(1)] = value.jsonArray.mapNotNull { it.jsonPrimitive.content }
|
||||
}
|
||||
|
||||
+36
-9
@@ -70,19 +70,46 @@ class KotlinSerializationMapper {
|
||||
|
||||
fun toJson(value: OptimizedSerializable): String =
|
||||
when (value) {
|
||||
is Event -> json.encodeToString(EventKSerializer, value)
|
||||
is Filter -> json.encodeToString(FilterKSerializer, value)
|
||||
is Rumor -> json.encodeToString(RumorKSerializer, value)
|
||||
is Event -> {
|
||||
json.encodeToString(EventKSerializer, value)
|
||||
}
|
||||
|
||||
is Filter -> {
|
||||
json.encodeToString(FilterKSerializer, value)
|
||||
}
|
||||
|
||||
is Rumor -> {
|
||||
json.encodeToString(RumorKSerializer, value)
|
||||
}
|
||||
|
||||
is EventTemplate<*> -> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
json.encodeToString(EventTemplateKSerializer, value as EventTemplate<Event>)
|
||||
}
|
||||
is Message -> json.encodeToString(MessageKSerializer, value)
|
||||
is Command -> json.encodeToString(CommandKSerializer, value)
|
||||
is BunkerRequest -> json.encodeToString(BunkerRequestKSerializer, value)
|
||||
is BunkerResponse -> json.encodeToString(BunkerResponseKSerializer, value)
|
||||
is BunkerMessage -> json.encodeToString(BunkerMessageKSerializer, value)
|
||||
else -> throw IllegalArgumentException("Unsupported type: ${value::class}")
|
||||
|
||||
is Message -> {
|
||||
json.encodeToString(MessageKSerializer, value)
|
||||
}
|
||||
|
||||
is Command -> {
|
||||
json.encodeToString(CommandKSerializer, value)
|
||||
}
|
||||
|
||||
is BunkerRequest -> {
|
||||
json.encodeToString(BunkerRequestKSerializer, value)
|
||||
}
|
||||
|
||||
is BunkerResponse -> {
|
||||
json.encodeToString(BunkerResponseKSerializer, value)
|
||||
}
|
||||
|
||||
is BunkerMessage -> {
|
||||
json.encodeToString(BunkerMessageKSerializer, value)
|
||||
}
|
||||
|
||||
else -> {
|
||||
throw IllegalArgumentException("Unsupported type: ${value::class}")
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : OptimizedSerializable> fromJsonTo(jsonStr: String): T {
|
||||
|
||||
+17
-1
@@ -60,9 +60,11 @@ object MessageKSerializer : KSerializer<Message> {
|
||||
add(JsonPrimitive(value.subId))
|
||||
add(EventKSerializer.serializeToElement(value.event))
|
||||
}
|
||||
|
||||
is NoticeMessage -> {
|
||||
add(JsonPrimitive(value.message))
|
||||
}
|
||||
|
||||
is OkMessage -> {
|
||||
add(JsonPrimitive(value.eventId))
|
||||
// Jackson writes success as a string, not boolean
|
||||
@@ -71,16 +73,20 @@ object MessageKSerializer : KSerializer<Message> {
|
||||
add(JsonPrimitive(value.message))
|
||||
}
|
||||
}
|
||||
|
||||
is AuthMessage -> {
|
||||
add(JsonPrimitive(value.challenge))
|
||||
}
|
||||
|
||||
is NotifyMessage -> {
|
||||
add(JsonPrimitive(value.message))
|
||||
}
|
||||
|
||||
is ClosedMessage -> {
|
||||
add(JsonPrimitive(value.subId))
|
||||
add(JsonPrimitive(value.message))
|
||||
}
|
||||
|
||||
is CountMessage -> {
|
||||
add(CountResultKSerializer.serializeToElement(value.result))
|
||||
}
|
||||
@@ -100,12 +106,15 @@ object MessageKSerializer : KSerializer<Message> {
|
||||
val event = EventKSerializer.deserializeFromElement(array[2].jsonObject)
|
||||
EventMessage(subId, event)
|
||||
}
|
||||
|
||||
EoseMessage.LABEL -> {
|
||||
EoseMessage(array[1].jsonPrimitive.content)
|
||||
}
|
||||
|
||||
NoticeMessage.LABEL -> {
|
||||
NoticeMessage(array[1].jsonPrimitive.content)
|
||||
}
|
||||
|
||||
OkMessage.LABEL -> {
|
||||
OkMessage(
|
||||
eventId = array[1].jsonPrimitive.content,
|
||||
@@ -113,24 +122,31 @@ object MessageKSerializer : KSerializer<Message> {
|
||||
message = if (array.size > 3) array[3].jsonPrimitive.content else "",
|
||||
)
|
||||
}
|
||||
|
||||
AuthMessage.LABEL -> {
|
||||
AuthMessage(array[1].jsonPrimitive.content)
|
||||
}
|
||||
|
||||
NotifyMessage.LABEL -> {
|
||||
NotifyMessage(array[1].jsonPrimitive.content)
|
||||
}
|
||||
|
||||
ClosedMessage.LABEL -> {
|
||||
ClosedMessage(
|
||||
subId = array[1].jsonPrimitive.content,
|
||||
message = if (array.size > 2) array[2].jsonPrimitive.content else "",
|
||||
)
|
||||
}
|
||||
|
||||
CountMessage.LABEL -> {
|
||||
val queryId = array[1].jsonPrimitive.content
|
||||
val result = CountResultKSerializer.deserializeFromElement(array[2].jsonObject)
|
||||
CountMessage(queryId, result)
|
||||
}
|
||||
else -> throw IllegalArgumentException("Message $type is not supported")
|
||||
|
||||
else -> {
|
||||
throw IllegalArgumentException("Message $type is not supported")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+50
-22
@@ -71,27 +71,55 @@ object BunkerMessageKSerializer : KSerializer<BunkerMessage> {
|
||||
id: String,
|
||||
method: String,
|
||||
params: Array<String>,
|
||||
): BunkerRequest {
|
||||
return when (method) {
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestConnect.METHOD_NAME ->
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestConnect.parse(id, params)
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestGetPublicKey.METHOD_NAME ->
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestGetPublicKey.parse(id, params)
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestGetRelays.METHOD_NAME ->
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestGetRelays.parse(id, params)
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip04Decrypt.METHOD_NAME ->
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip04Decrypt.parse(id, params)
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip04Encrypt.METHOD_NAME ->
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip04Encrypt.parse(id, params)
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip44Decrypt.METHOD_NAME ->
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip44Decrypt.parse(id, params)
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip44Encrypt.METHOD_NAME ->
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip44Encrypt.parse(id, params)
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestPing.METHOD_NAME ->
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestPing.parse(id, params)
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestSign.METHOD_NAME ->
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestSign.parse(id, params)
|
||||
else -> BunkerRequest(id, method, params)
|
||||
): BunkerRequest =
|
||||
when (method) {
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestConnect.METHOD_NAME -> {
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestConnect
|
||||
.parse(id, params)
|
||||
}
|
||||
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestGetPublicKey.METHOD_NAME -> {
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestGetPublicKey
|
||||
.parse(id, params)
|
||||
}
|
||||
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestGetRelays.METHOD_NAME -> {
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestGetRelays
|
||||
.parse(id, params)
|
||||
}
|
||||
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip04Decrypt.METHOD_NAME -> {
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip04Decrypt
|
||||
.parse(id, params)
|
||||
}
|
||||
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip04Encrypt.METHOD_NAME -> {
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip04Encrypt
|
||||
.parse(id, params)
|
||||
}
|
||||
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip44Decrypt.METHOD_NAME -> {
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip44Decrypt
|
||||
.parse(id, params)
|
||||
}
|
||||
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip44Encrypt.METHOD_NAME -> {
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip44Encrypt
|
||||
.parse(id, params)
|
||||
}
|
||||
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestPing.METHOD_NAME -> {
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestPing
|
||||
.parse(id, params)
|
||||
}
|
||||
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestSign.METHOD_NAME -> {
|
||||
com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestSign
|
||||
.parse(id, params)
|
||||
}
|
||||
|
||||
else -> {
|
||||
BunkerRequest(id, method, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-2
@@ -81,8 +81,14 @@ object BunkerResponseKSerializer : KSerializer<BunkerResponse> {
|
||||
|
||||
if (result != null) {
|
||||
when (result) {
|
||||
BunkerResponseAck.RESULT -> return BunkerResponseAck.parse(id, result, error)
|
||||
BunkerResponsePong.RESULT -> return BunkerResponsePong.parse(id, result, error)
|
||||
BunkerResponseAck.RESULT -> {
|
||||
return BunkerResponseAck.parse(id, result, error)
|
||||
}
|
||||
|
||||
BunkerResponsePong.RESULT -> {
|
||||
return BunkerResponsePong.parse(id, result, error)
|
||||
}
|
||||
|
||||
else -> {
|
||||
if (result.length == 64 && Hex.isHex(result)) {
|
||||
return BunkerResponsePublicKey.parse(id, result)
|
||||
|
||||
+7
-4
@@ -44,9 +44,7 @@ object Nip47NotificationKSerializer : KSerializer<Notification> {
|
||||
override fun serialize(
|
||||
encoder: Encoder,
|
||||
value: Notification,
|
||||
) {
|
||||
throw UnsupportedOperationException("NIP-47 Notification serialization not supported")
|
||||
}
|
||||
): Unit = throw UnsupportedOperationException("NIP-47 Notification serialization not supported")
|
||||
|
||||
override fun deserialize(decoder: Decoder): Notification {
|
||||
val jsonDecoder = decoder as JsonDecoder
|
||||
@@ -63,6 +61,7 @@ object Nip47NotificationKSerializer : KSerializer<Notification> {
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
NwcNotificationType.PAYMENT_SENT -> {
|
||||
PaymentSentNotification(
|
||||
notification =
|
||||
@@ -71,6 +70,7 @@ object Nip47NotificationKSerializer : KSerializer<Notification> {
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
NwcNotificationType.HOLD_INVOICE_ACCEPTED -> {
|
||||
val notifObj = jsonObject["notification"]?.jsonObject
|
||||
HoldInvoiceAcceptedNotification(
|
||||
@@ -88,7 +88,10 @@ object Nip47NotificationKSerializer : KSerializer<Notification> {
|
||||
},
|
||||
)
|
||||
}
|
||||
else -> throw IllegalArgumentException("Unknown notification type: $notificationType")
|
||||
|
||||
else -> {
|
||||
throw IllegalArgumentException("Unknown notification type: $notificationType")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -68,9 +68,7 @@ object Nip47RequestKSerializer : KSerializer<Request> {
|
||||
override fun serialize(
|
||||
encoder: Encoder,
|
||||
value: Request,
|
||||
) {
|
||||
throw UnsupportedOperationException("NIP-47 Request serialization not supported")
|
||||
}
|
||||
): Unit = throw UnsupportedOperationException("NIP-47 Request serialization not supported")
|
||||
|
||||
override fun deserialize(decoder: Decoder): Request {
|
||||
val jsonDecoder = decoder as JsonDecoder
|
||||
|
||||
+72
-30
@@ -60,9 +60,7 @@ object Nip47ResponseKSerializer : KSerializer<Response> {
|
||||
override fun serialize(
|
||||
encoder: Encoder,
|
||||
value: Response,
|
||||
) {
|
||||
throw UnsupportedOperationException("NIP-47 Response serialization not supported")
|
||||
}
|
||||
): Unit = throw UnsupportedOperationException("NIP-47 Response serialization not supported")
|
||||
|
||||
override fun deserialize(decoder: Decoder): Response {
|
||||
val jsonDecoder = decoder as JsonDecoder
|
||||
@@ -73,7 +71,10 @@ object Nip47ResponseKSerializer : KSerializer<Response> {
|
||||
|
||||
if (hasError) {
|
||||
return when (resultType) {
|
||||
NwcMethod.PAY_INVOICE -> parsePayInvoiceError(jsonObject)
|
||||
NwcMethod.PAY_INVOICE -> {
|
||||
parsePayInvoiceError(jsonObject)
|
||||
}
|
||||
|
||||
else -> {
|
||||
val error = jsonObject["error"]?.jsonObject?.let { parseNwcError(it) }
|
||||
NwcErrorResponse(resultType ?: "", error)
|
||||
@@ -83,19 +84,58 @@ object Nip47ResponseKSerializer : KSerializer<Response> {
|
||||
|
||||
if (hasResult || resultType != null) {
|
||||
return when (resultType) {
|
||||
NwcMethod.PAY_INVOICE -> parsePayInvoiceSuccess(jsonObject)
|
||||
NwcMethod.PAY_KEYSEND -> parsePayKeysendSuccess(jsonObject)
|
||||
NwcMethod.MAKE_INVOICE -> MakeInvoiceSuccessResponse(parseTransaction(jsonObject["result"]?.jsonObject))
|
||||
NwcMethod.LOOKUP_INVOICE -> LookupInvoiceSuccessResponse(parseTransaction(jsonObject["result"]?.jsonObject))
|
||||
NwcMethod.LIST_TRANSACTIONS -> parseListTransactionsSuccess(jsonObject)
|
||||
NwcMethod.GET_BALANCE -> parseGetBalanceSuccess(jsonObject)
|
||||
NwcMethod.GET_INFO -> parseGetInfoSuccess(jsonObject)
|
||||
NwcMethod.GET_BUDGET -> parseGetBudgetSuccess(jsonObject)
|
||||
NwcMethod.SIGN_MESSAGE -> parseSignMessageSuccess(jsonObject)
|
||||
NwcMethod.CREATE_CONNECTION -> parseCreateConnectionSuccess(jsonObject)
|
||||
NwcMethod.MAKE_HOLD_INVOICE -> MakeHoldInvoiceSuccessResponse(parseTransaction(jsonObject["result"]?.jsonObject))
|
||||
NwcMethod.CANCEL_HOLD_INVOICE -> CancelHoldInvoiceSuccessResponse()
|
||||
NwcMethod.SETTLE_HOLD_INVOICE -> SettleHoldInvoiceSuccessResponse()
|
||||
NwcMethod.PAY_INVOICE -> {
|
||||
parsePayInvoiceSuccess(jsonObject)
|
||||
}
|
||||
|
||||
NwcMethod.PAY_KEYSEND -> {
|
||||
parsePayKeysendSuccess(jsonObject)
|
||||
}
|
||||
|
||||
NwcMethod.MAKE_INVOICE -> {
|
||||
MakeInvoiceSuccessResponse(parseTransaction(jsonObject["result"]?.jsonObject))
|
||||
}
|
||||
|
||||
NwcMethod.LOOKUP_INVOICE -> {
|
||||
LookupInvoiceSuccessResponse(parseTransaction(jsonObject["result"]?.jsonObject))
|
||||
}
|
||||
|
||||
NwcMethod.LIST_TRANSACTIONS -> {
|
||||
parseListTransactionsSuccess(jsonObject)
|
||||
}
|
||||
|
||||
NwcMethod.GET_BALANCE -> {
|
||||
parseGetBalanceSuccess(jsonObject)
|
||||
}
|
||||
|
||||
NwcMethod.GET_INFO -> {
|
||||
parseGetInfoSuccess(jsonObject)
|
||||
}
|
||||
|
||||
NwcMethod.GET_BUDGET -> {
|
||||
parseGetBudgetSuccess(jsonObject)
|
||||
}
|
||||
|
||||
NwcMethod.SIGN_MESSAGE -> {
|
||||
parseSignMessageSuccess(jsonObject)
|
||||
}
|
||||
|
||||
NwcMethod.CREATE_CONNECTION -> {
|
||||
parseCreateConnectionSuccess(jsonObject)
|
||||
}
|
||||
|
||||
NwcMethod.MAKE_HOLD_INVOICE -> {
|
||||
MakeHoldInvoiceSuccessResponse(parseTransaction(jsonObject["result"]?.jsonObject))
|
||||
}
|
||||
|
||||
NwcMethod.CANCEL_HOLD_INVOICE -> {
|
||||
CancelHoldInvoiceSuccessResponse()
|
||||
}
|
||||
|
||||
NwcMethod.SETTLE_HOLD_INVOICE -> {
|
||||
SettleHoldInvoiceSuccessResponse()
|
||||
}
|
||||
|
||||
else -> {
|
||||
// backward compatibility: guess by result content
|
||||
val resultObj = jsonObject["result"]?.jsonObject
|
||||
@@ -111,13 +151,14 @@ object Nip47ResponseKSerializer : KSerializer<Response> {
|
||||
}
|
||||
|
||||
private fun parseNwcError(obj: JsonObject): NwcError {
|
||||
val code = obj["code"]?.jsonPrimitive?.content?.let { codeName ->
|
||||
try {
|
||||
NwcErrorCode.valueOf(codeName)
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
val code =
|
||||
obj["code"]?.jsonPrimitive?.content?.let { codeName ->
|
||||
try {
|
||||
NwcErrorCode.valueOf(codeName)
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
return NwcError(code, obj["message"]?.jsonPrimitive?.content)
|
||||
}
|
||||
|
||||
@@ -157,13 +198,14 @@ object Nip47ResponseKSerializer : KSerializer<Response> {
|
||||
return PayInvoiceErrorResponse(
|
||||
error?.let {
|
||||
PayInvoiceErrorResponse.PayInvoiceErrorParams(
|
||||
code = it["code"]?.jsonPrimitive?.content?.let { codeName ->
|
||||
try {
|
||||
NwcErrorCode.valueOf(codeName)
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
},
|
||||
code =
|
||||
it["code"]?.jsonPrimitive?.content?.let { codeName ->
|
||||
try {
|
||||
NwcErrorCode.valueOf(codeName)
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
},
|
||||
message = it["message"]?.jsonPrimitive?.content,
|
||||
)
|
||||
},
|
||||
|
||||
+1
-2
@@ -20,10 +20,9 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip59Giftwrap.rumors.kotlinSerialization
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.kotlinSerialization.TagArrayKSerializer
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArray
|
||||
import com.vitorpamplona.quartz.nip01Core.kotlinSerialization.TagArrayKSerializer
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.rumors.Rumor
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
|
||||
Reference in New Issue
Block a user