diff --git a/library/src/main/java/ch/decent/sdk/model/FeeSchedule.kt b/library/src/main/java/ch/decent/sdk/model/FeeSchedule.kt index c33e4b1c..54615f65 100644 --- a/library/src/main/java/ch/decent/sdk/model/FeeSchedule.kt +++ b/library/src/main/java/ch/decent/sdk/model/FeeSchedule.kt @@ -3,6 +3,9 @@ package ch.decent.sdk.model import com.google.gson.annotations.SerializedName data class FeeSchedule( - @SerializedName("parameters") val parameters: Map, + /** + * operation types int keys + */ + @SerializedName("parameters") val parameters: Map, @SerializedName("scale") val scale: Long -) \ No newline at end of file +) diff --git a/library/src/main/java/ch/decent/sdk/model/ObjectType.kt b/library/src/main/java/ch/decent/sdk/model/ObjectType.kt index 7cd7fda4..14c18c8c 100644 --- a/library/src/main/java/ch/decent/sdk/model/ObjectType.kt +++ b/library/src/main/java/ch/decent/sdk/model/ObjectType.kt @@ -38,13 +38,14 @@ enum class ObjectType { SUBSCRIPTION_OBJECT, //15 SEEDING_STATISTICS_OBJECT, TRANSACTION_DETAIL_OBJECT, - MESSAGING_OBJECT; + MESSAGING_OBJECT, + UNKNOWN_OBJECT; val space: Byte - get() = if (ordinal < 10) 1 else 2 + get() = if (ordinal < GLOBAL_PROPERTY_OBJECT.ordinal) 1 else 2 val type: Byte - get() = (ordinal - (space - 1) * 10).toByte() + get() = (ordinal - (space - 1) * GLOBAL_PROPERTY_OBJECT.ordinal).toByte() /** * This method is used to return the generic object type in the form space.type.0. @@ -58,6 +59,6 @@ enum class ObjectType { get() = ChainObject(this) companion object { - fun fromSpaceType(space: Int, type: Int) = ObjectType.values()[max(space - 1, 0) * 10 + type] + fun fromSpaceType(space: Int, type: Int) = values().getOrElse(max(space - 1, 0) * GLOBAL_PROPERTY_OBJECT.ordinal + type) { UNKNOWN_OBJECT } } } diff --git a/library/src/main/java/ch/decent/sdk/model/OperationType.kt b/library/src/main/java/ch/decent/sdk/model/OperationType.kt index 189fc67e..0e433d86 100644 --- a/library/src/main/java/ch/decent/sdk/model/OperationType.kt +++ b/library/src/main/java/ch/decent/sdk/model/OperationType.kt @@ -45,10 +45,5 @@ enum class OperationType(val clazz: Class<*>? = null) { READY_TO_PUBLISH2_OPERATION, TRANSFER2_OPERATION(TransferOperation::class.java), UPDATE_USER_ISSUED_ASSET_ADVANCED, - DISALLOW_AUTOMATIC_RENEWAL_OF_SUBSCRIPTION_OPERATION, // VIRTUAL 41 - RETURN_ESCROW_SUBMISSION_OPERATION, // VIRTUAL - RETURN_ESCROW_BUYING_OPERATION, // VIRTUAL - PAY_SEEDER_OPERATION, // VIRTUAL - FINISH_BUYING_OPERATION, // VIRTUAL 45 - RENEWAL_OF_SUBSCRIPTION_OPERATION // VIRTUAL -} \ No newline at end of file + UNKNOWN_OPERATION +} diff --git a/library/src/main/java/ch/decent/sdk/model/Operations.kt b/library/src/main/java/ch/decent/sdk/model/Operations.kt index 0df858c4..8eca1ab7 100644 --- a/library/src/main/java/ch/decent/sdk/model/Operations.kt +++ b/library/src/main/java/ch/decent/sdk/model/Operations.kt @@ -2,7 +2,11 @@ package ch.decent.sdk.model import ch.decent.sdk.crypto.Address import ch.decent.sdk.crypto.Credentials -import ch.decent.sdk.net.serialization.* +import ch.decent.sdk.net.serialization.ByteSerializable +import ch.decent.sdk.net.serialization.Varint +import ch.decent.sdk.net.serialization.VoteId +import ch.decent.sdk.net.serialization.bytes +import ch.decent.sdk.net.serialization.optionalBytes import ch.decent.sdk.utils.hex import ch.decent.sdk.utils.publicElGamal import ch.decent.sdk.utils.unhex @@ -38,6 +42,15 @@ sealed class BaseOperation( override fun hashCode(): Int = Arrays.hashCode(bytes) } +class UnknownOperation(val id: Int) : BaseOperation(OperationType.UNKNOWN_OPERATION) { + override val bytes: ByteArray + get() = byteArrayOf() + + override fun toString(): String { + return "UnknownOperation(id=$id)" + } +} + class EmptyOperation(type: OperationType) : BaseOperation(type) { override val bytes: ByteArray get() = byteArrayOf(0) @@ -351,4 +364,4 @@ class SendMessageOperation constructor( messagePayloadJson: String, payer: ChainObject, requiredAuths: List = listOf(payer) -) : CustomOperation(CustomOperationType.MESSAGING, payer, requiredAuths, messagePayloadJson.toByteArray().hex()) \ No newline at end of file +) : CustomOperation(CustomOperationType.MESSAGING, payer, requiredAuths, messagePayloadJson.toByteArray().hex()) diff --git a/library/src/main/java/ch/decent/sdk/model/TypeAdapters.kt b/library/src/main/java/ch/decent/sdk/model/TypeAdapters.kt index 2a4c0fdd..f84bbcf1 100644 --- a/library/src/main/java/ch/decent/sdk/model/TypeAdapters.kt +++ b/library/src/main/java/ch/decent/sdk/model/TypeAdapters.kt @@ -71,9 +71,11 @@ object OperationTypeFactory : TypeAdapterFactory { override fun read(reader: JsonReader): T? { val el = Streams.parse(reader) - val op = OperationType.values()[el.asJsonArray[0].asInt] + val idx = el.asJsonArray[0].asInt + val op = OperationType.values().getOrElse(idx) { OperationType.UNKNOWN_OPERATION } val obj = el.asJsonArray[1].asJsonObject - return op.clazz?.let { + return if (op == OperationType.UNKNOWN_OPERATION) UnknownOperation(idx) as T? + else op.clazz?.let { val delegate = gson.getDelegateAdapter(this@OperationTypeFactory, TypeToken.get(it)) (delegate.fromJsonTree(obj) as BaseOperation).apply { this.type = op } as T? } ?: EmptyOperation(op) as T? @@ -178,5 +180,5 @@ object OperationTypeAdapter : TypeAdapter() { out.value(value.ordinal) } - override fun read(reader: JsonReader): OperationType = OperationType.values()[reader.nextInt()] -} \ No newline at end of file + override fun read(reader: JsonReader): OperationType = OperationType.values().getOrElse(reader.nextInt()) { OperationType.UNKNOWN_OPERATION } +}