diff --git a/README.md b/README.md index 874383d..9cd685a 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ allprojects { project build.gradle ```groovy dependencies { - commonMainApi("dev.icerock.moko:web3:0.11.0") + commonMainApi("dev.icerock.moko:web3:0.12.0") } ``` diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8504db2..5eaac71 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,7 +9,7 @@ kbignumVersion = "2.2.0" klockVersion = "2.2.2" ktorClientVersion = "1.6.1" mokoTestVersion = "0.4.0" -mokoWeb3Version = "0.11.0" +mokoWeb3Version = "0.12.0" multidexVersion = "2.0.1" [libraries] diff --git a/web3/src/commonMain/kotlin/dev.icerock.moko.web3/TransactionHash.kt b/web3/src/commonMain/kotlin/dev.icerock.moko.web3/TransactionHash.kt index 5d84286..e015123 100644 --- a/web3/src/commonMain/kotlin/dev.icerock.moko.web3/TransactionHash.kt +++ b/web3/src/commonMain/kotlin/dev.icerock.moko.web3/TransactionHash.kt @@ -6,10 +6,26 @@ package dev.icerock.moko.web3 import dev.icerock.moko.web3.hex.Hex32String import kotlinx.serialization.Serializable +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 -@Serializable +@Serializable(with = TransactionHash.Serializer::class) class TransactionHash(private val value: String) : Hex32String by Hex32String(value) { - override fun toString() = withoutPrefix + override fun toString() = withoutPrefix override fun hashCode(): Int = withoutPrefix.hashCode() override fun equals(other: Any?): Boolean = other is TransactionHash && other.withoutPrefix == withoutPrefix + + @kotlinx.serialization.Serializer(forClass = TransactionHash::class) + object Serializer { + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( + serialName = "dev.icerock.mokoWeb3.TransactionHash", + kind = PrimitiveKind.STRING + ) + + override fun deserialize(decoder: Decoder): TransactionHash = TransactionHash(decoder.decodeString()) + override fun serialize(encoder: Encoder, value: TransactionHash) = encoder.encodeString(value.value) + } } diff --git a/web3/src/commonMain/kotlin/dev.icerock.moko.web3/contract/StaticEncoders.kt b/web3/src/commonMain/kotlin/dev.icerock.moko.web3/contract/StaticEncoders.kt index 10615e5..2dd8200 100644 --- a/web3/src/commonMain/kotlin/dev.icerock.moko.web3/contract/StaticEncoders.kt +++ b/web3/src/commonMain/kotlin/dev.icerock.moko.web3/contract/StaticEncoders.kt @@ -8,6 +8,7 @@ enum class StaticEncoders( val typeAnnotation: String, val encoder: StaticEncoder<*> ) { + UInt8(typeAnnotation = "uint8", encoder = UInt256Param), UInt256(typeAnnotation = "uint256", encoder = UInt256Param), Address(typeAnnotation = "address", encoder = AddressParam); diff --git a/web3/src/commonMain/kotlin/dev.icerock.moko.web3/hex/HexStringValueClass.kt b/web3/src/commonMain/kotlin/dev.icerock.moko.web3/hex/HexStringValueClass.kt index e82f025..39ae8b9 100644 --- a/web3/src/commonMain/kotlin/dev.icerock.moko.web3/hex/HexStringValueClass.kt +++ b/web3/src/commonMain/kotlin/dev.icerock.moko.web3/hex/HexStringValueClass.kt @@ -15,7 +15,7 @@ internal class HexStringValueClass(private val value: String): HexString { override val withoutPrefix: String get() = value.removePrefix(HEX_PREFIX) override val prefixed: String get() = "$HEX_PREFIX$withoutPrefix" - override val bigInt: BigInt get() = value.bi(RADIX) + override val bigInt: BigInt get() = withoutPrefix.bi(RADIX) override fun toString() = withoutPrefix override fun hashCode(): Int = withoutPrefix.hashCode()