Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request papers/airgap/beacon-android-sdk!76
  • Loading branch information
jsamol committed Feb 23, 2023
2 parents 47861cf + cb081ba commit 374eb4f
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public sealed class TezosNetwork : Network() {
}
}

@Deprecated("'Ithacanet' is no longer a maintained Tezos test network and will be removed from Beacon in future versions.")
@Serializable
@SerialName(Ithacanet.TYPE)
public data class Ithacanet(
Expand All @@ -178,6 +179,7 @@ public sealed class TezosNetwork : Network() {
}
}

@Deprecated("'Jakartanet' is no longer a maintained Tezos test network and will be removed from Beacon in future versions.")
@Serializable
@SerialName(Jakartanet.TYPE)
public data class Jakartanet(
Expand Down Expand Up @@ -206,6 +208,34 @@ public sealed class TezosNetwork : Network() {
}
}

@Serializable
@SerialName(Limanet.TYPE)
public data class Limanet(
override val name: String? = null,
override val rpcUrl: String? = null,
) : TezosNetwork() {
@Transient
override val type: String = TYPE

public companion object {
internal const val TYPE = "limanet"
}
}

@Serializable
@SerialName(Mumbainet.TYPE)
public data class Mumbainet(
override val name: String? = null,
override val rpcUrl: String? = null,
) : TezosNetwork() {
@Transient
override val type: String = TYPE

public companion object {
internal const val TYPE = "mumbainet"
}
}

@Serializable
@SerialName(Custom.TYPE)
public data class Custom(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
import kotlinx.serialization.descriptors.element
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.encoding.decodeStructure
import kotlinx.serialization.encoding.encodeStructure
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.*

/**
Expand Down Expand Up @@ -93,6 +90,7 @@ public data class MichelinePrimitiveString(public val string: String) : Michelin
public data class MichelinePrimitiveBytes(public val bytes: String) : MichelineMichelsonV1Expression() {
public companion object {}

@OptIn(ExperimentalSerializationApi::class)
internal object Serializer : KSerializer<MichelinePrimitiveBytes> {
object Field {
const val BYTES = "bytes"
Expand All @@ -104,9 +102,18 @@ public data class MichelinePrimitiveBytes(public val bytes: String) : MichelineM

override fun deserialize(decoder: Decoder): MichelinePrimitiveBytes =
decoder.decodeStructure(descriptor) {
val primitive = HexString(decodeStringElement(descriptor, 0))
var primitive: HexString? = null
while (true) {
when (decodeElementIndex(descriptor)) {
0 -> primitive = HexString(decodeStringElement(descriptor, 0))
CompositeDecoder.DECODE_DONE -> break
else -> continue
}
}

primitive ?: failWithMissingField(descriptor.getElementName(0))

return MichelinePrimitiveBytes(primitive.asString(withPrefix = false))
MichelinePrimitiveBytes(primitive.asString(withPrefix = false))
}

override fun serialize(encoder: Encoder, value: MichelinePrimitiveBytes) {
Expand Down
11 changes: 6 additions & 5 deletions buildSrc/src/main/java/GradleConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ object Android {
const val minSdk = 21
const val targetSdk = 33

const val versionCode = 31
const val versionName = "3.2.3"
const val versionCode = 33
const val versionName = "3.2.4"
}

object Version {
const val kotlin = "1.7.20"

const val kotlinSerialization = "1.3.1"
const val kotlinSerialization = "1.4.1"

const val androidxCore = "1.6.0"
const val androidxAppCompat = "1.3.1"
Expand All @@ -25,7 +25,7 @@ object Version {

const val coroutines = "1.5.1"

const val ktor = "1.6.2"
const val ktor = "2.2.3"

const val lazySodium = "5.0.2"
const val jna = "5.9.0"
Expand All @@ -52,7 +52,8 @@ object Dependencies {

const val ktorOkHttp = "io.ktor:ktor-client-okhttp:${Version.ktor}"
const val ktorJson = "io.ktor:ktor-client-json:${Version.ktor}"
const val ktorSerializationJvm = "io.ktor:ktor-client-serialization-jvm:${Version.ktor}"
const val ktorContentNegotiation = "io.ktor:ktor-client-content-negotiation:${Version.ktor}"
const val ktorSerializationJson = "io.ktor:ktor-serialization-kotlinx-json:${Version.ktor}"
const val ktorLoggingJvm = "io.ktor:ktor-client-logging-jvm:${Version.ktor}"

const val androidxCore = "androidx.core:core-ktx:${Version.androidxCore}"
Expand Down
3 changes: 2 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ dependencies {
// Ktor
implementation(Dependencies.ktorOkHttp)
implementation(Dependencies.ktorJson)
implementation(Dependencies.ktorSerializationJvm)
implementation(Dependencies.ktorContentNegotiation)
implementation(Dependencies.ktorSerializationJson)
implementation(Dependencies.ktorLoggingJvm)

// Lazy Sodium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
import kotlinx.serialization.descriptors.element
import kotlinx.serialization.encoding.decodeStructure
import kotlinx.serialization.encoding.encodeStructure
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.JsonDecoder
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonEncoder
Expand Down Expand Up @@ -106,7 +105,7 @@ public data class ErrorV1BeaconResponse(
public fun serializer(beaconScope: BeaconScope? = null): KSerializer<ErrorV1BeaconResponse> = Serializer(beaconScope)
}

internal class Serializer(blockchainRegistry: BlockchainRegistry, compat: Compat<VersionedCompat>) : KJsonSerializer<ErrorV1BeaconResponse> {
internal class Serializer(blockchainRegistry: BlockchainRegistry, compat: Compat<VersionedCompat>) : KSerializer<ErrorV1BeaconResponse> {
constructor(beaconScope: BeaconScope? = null) : this(blockchainRegistry(beaconScope), compat(beaconScope))

private val beaconErrorSerializer: KSerializer<BeaconError> = BeaconError.serializer(blockchainRegistry, compat.versioned.blockchain.identifier)
Expand All @@ -119,20 +118,33 @@ public data class ErrorV1BeaconResponse(
element("errorType", beaconErrorSerializer.descriptor)
}

override fun deserialize(
jsonDecoder: JsonDecoder,
jsonElement: JsonElement,
): ErrorV1BeaconResponse = jsonDecoder.decodeStructure(descriptor) {
val version = decodeStringElement(descriptor, 1)
val id = decodeStringElement(descriptor, 2)
val beaconId = decodeStringElement(descriptor, 3)
val errorType = decodeSerializableElement(descriptor, 4, beaconErrorSerializer)
override fun deserialize(decoder: Decoder): ErrorV1BeaconResponse = decoder.decodeStructure(descriptor) {
var version: String? = null
var id: String? = null
var beaconId: String? = null
var errorType: BeaconError? = null

while (true) {
when (decodeElementIndex(descriptor)) {
1 -> version = decodeStringElement(descriptor, 1)
2 -> id = decodeStringElement(descriptor, 2)
3 -> beaconId = decodeStringElement(descriptor, 3)
4 -> errorType = decodeSerializableElement(descriptor, 4, beaconErrorSerializer)
CompositeDecoder.DECODE_DONE -> break
else -> continue
}
}

version ?: failWithMissingField(descriptor.getElementName(1))
id ?: failWithMissingField(descriptor.getElementName(2))
beaconId ?: failWithMissingField(descriptor.getElementName(3))
errorType ?: failWithMissingField(descriptor.getElementName(4))

return ErrorV1BeaconResponse(version, id, beaconId, errorType)
ErrorV1BeaconResponse(version, id, beaconId, errorType)
}

override fun serialize(jsonEncoder: JsonEncoder, value: ErrorV1BeaconResponse) {
jsonEncoder.encodeStructure(descriptor) {
override fun serialize(encoder: Encoder, value: ErrorV1BeaconResponse) {
encoder.encodeStructure(descriptor) {
with(value) {
encodeStringElement(descriptor, 0, type)
encodeStringElement(descriptor, 1, version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import it.airgap.beaconsdk.core.data.Connection
import it.airgap.beaconsdk.core.internal.blockchain.BlockchainRegistry
import it.airgap.beaconsdk.core.internal.compat.Compat
import it.airgap.beaconsdk.core.internal.compat.VersionedCompat
import it.airgap.beaconsdk.core.internal.data.HexString
import it.airgap.beaconsdk.core.internal.message.VersionedBeaconMessage
import it.airgap.beaconsdk.core.internal.utils.KJsonSerializer
import it.airgap.beaconsdk.core.internal.utils.blockchainRegistry
import it.airgap.beaconsdk.core.internal.utils.compat
import it.airgap.beaconsdk.core.internal.utils.getString
import it.airgap.beaconsdk.core.internal.utils.*
import it.airgap.beaconsdk.core.message.AcknowledgeBeaconResponse
import it.airgap.beaconsdk.core.message.BeaconMessage
import it.airgap.beaconsdk.core.message.DisconnectBeaconMessage
Expand All @@ -20,8 +18,7 @@ import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
import kotlinx.serialization.descriptors.element
import kotlinx.serialization.encoding.decodeStructure
import kotlinx.serialization.encoding.encodeStructure
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.JsonDecoder
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonEncoder
Expand Down Expand Up @@ -130,7 +127,7 @@ public data class ErrorV2BeaconResponse(
Serializer(beaconScope)
}

internal class Serializer(blockchainRegistry: BlockchainRegistry, compat: Compat<VersionedCompat>) : KJsonSerializer<ErrorV2BeaconResponse> {
internal class Serializer(blockchainRegistry: BlockchainRegistry, compat: Compat<VersionedCompat>) : KSerializer<ErrorV2BeaconResponse> {
constructor(beaconScope: BeaconScope? = null) : this(blockchainRegistry(beaconScope), compat(beaconScope))

private val beaconErrorSerializer: KSerializer<BeaconError> = BeaconError.serializer(blockchainRegistry, compat.versioned.blockchain.identifier)
Expand All @@ -143,20 +140,33 @@ public data class ErrorV2BeaconResponse(
element("errorType", beaconErrorSerializer.descriptor)
}

override fun deserialize(
jsonDecoder: JsonDecoder,
jsonElement: JsonElement,
): ErrorV2BeaconResponse = jsonDecoder.decodeStructure(descriptor) {
val version = decodeStringElement(descriptor, 1)
val id = decodeStringElement(descriptor, 2)
val senderId = decodeStringElement(descriptor, 3)
val errorType = decodeSerializableElement(descriptor, 4, beaconErrorSerializer)
override fun deserialize(decoder: Decoder): ErrorV2BeaconResponse = decoder.decodeStructure(descriptor) {
var version: String? = null
var id: String? = null
var senderId: String? = null
var errorType: BeaconError? = null

while (true) {
when (decodeElementIndex(descriptor)) {
1 -> version = decodeStringElement(descriptor, 1)
2 -> id = decodeStringElement(descriptor, 2)
3 -> senderId = decodeStringElement(descriptor, 3)
4 -> errorType = decodeSerializableElement(descriptor, 4, beaconErrorSerializer)
CompositeDecoder.DECODE_DONE -> break
else -> continue
}
}

version ?: failWithMissingField(descriptor.getElementName(1))
id ?: failWithMissingField(descriptor.getElementName(2))
senderId ?: failWithMissingField(descriptor.getElementName(3))
errorType ?: failWithMissingField(descriptor.getElementName(4))

return ErrorV2BeaconResponse(version, id, senderId, errorType)
ErrorV2BeaconResponse(version, id, senderId, errorType)
}

override fun serialize(jsonEncoder: JsonEncoder, value: ErrorV2BeaconResponse) {
jsonEncoder.encodeStructure(descriptor) {
override fun serialize(encoder: Encoder, value: ErrorV2BeaconResponse) {
encoder.encodeStructure(descriptor) {
with(value) {
encodeStringElement(descriptor, 0, type)
encodeStringElement(descriptor, 1, version)
Expand Down
Loading

0 comments on commit 374eb4f

Please sign in to comment.