Skip to content

Commit

Permalink
Merge pull request #62 from avianlabs/cleanup-serializable-stuff
Browse files Browse the repository at this point in the history
Cleanup serializable stuff
  • Loading branch information
wiyarmir authored Mar 25, 2024
2 parents ff654e9 + 01feaf8 commit 60e1612
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 31 deletions.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ org.gradle.jvmargs=-Xmx3g
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.enableHierarchicalCommonization=true
kotlin.mpp.androidSourceSetLayoutVersion=2
kotlin.native.ignoreDisabledTargets=true
2 changes: 2 additions & 0 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ coroutinesJdk8 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8", ver
kermit = { module = "co.touchlab:kermit", version.ref = "kermit" }
kotlin-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin" }
ktorClientContentNegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktorClientCio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktorClientCore = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktorClientDarwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
ktorClientLogging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
ktorClientOkHttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktorClientWinHttp = { module = "io.ktor:ktor-client-winhttp", version.ref = "ktor" }
ktorSerializationKotlinxJson = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktorUtils = { module = "io.ktor:ktor-utils", version.ref = "ktor" }
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
Expand Down
13 changes: 13 additions & 0 deletions solana-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ kotlin {
}

mingwX64()
linuxX64()

sourceSets {
val jvmMain by getting {
Expand Down Expand Up @@ -80,6 +81,18 @@ kotlin {

val nativeMain by getting {
}

val linuxMain by getting {
dependencies {
implementation(libs.ktorClientCio)
}
}

val mingwMain by getting {
dependencies {
implementation(libs.ktorClientWinHttp)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package net.avianlabs.solana.domain.program

import kotlinx.serialization.Serializable
import net.avianlabs.solana.tweetnacl.ed25519.PublicKey

@Serializable
public data class ProgramDerivedAddress(val address: PublicKey, val nonce: UByte)
public data class ProgramDerivedAddress(
val address: PublicKey,
val nonce: UByte,
)
4 changes: 1 addition & 3 deletions tweetnacl-multiplatform/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import co.touchlab.cklib.gradle.CompileToBitcode.Language
import co.touchlab.skie.configuration.ClassInterop
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.cklib)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.mavenPublish)
alias(libs.plugins.dokka)
signing
Expand Down Expand Up @@ -40,6 +38,7 @@ kotlin {
}

mingwX64()
linuxX64()

sourceSets {
val jvmMain by getting {
Expand All @@ -52,7 +51,6 @@ kotlin {

val commonMain by getting {
dependencies {
implementation(libs.serializationCore)
}
}
val commonTest by getting {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
package net.avianlabs.solana.tweetnacl.ed25519

import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import net.avianlabs.solana.tweetnacl.TweetNaCl
import net.avianlabs.solana.tweetnacl.TweetNaCl.Signature.Companion.PUBLIC_KEY_BYTES
import net.avianlabs.solana.tweetnacl.vendor.decodeBase58
import net.avianlabs.solana.tweetnacl.vendor.encodeToBase58String

@Serializable(with = PublicKeySerializer::class)
public data class PublicKey(public val bytes: ByteArray) {

init {
Expand Down Expand Up @@ -43,19 +34,3 @@ public data class PublicKey(public val bytes: ByteArray) {
public fun fromBase58(base58: String): PublicKey = PublicKey(base58.decodeBase58())
}
}

private class PublicKeySerializer : KSerializer<PublicKey> {

private val delegateSerializer = String.serializer()

override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("PublicKey", PrimitiveKind.STRING)

override fun serialize(encoder: Encoder, value: PublicKey) = with(encoder) {
encodeSerializableValue(delegateSerializer, value.toBase58())
}

override fun deserialize(decoder: Decoder): PublicKey = PublicKey.fromBase58(
decoder.decodeSerializableValue(delegateSerializer),
)
}

0 comments on commit 60e1612

Please sign in to comment.