From 122c27e210b8cdc29755095e13963834dec98260 Mon Sep 17 00:00:00 2001 From: funkatronics Date: Fri, 7 Jun 2024 16:10:33 -0600 Subject: [PATCH 1/4] fix sendtx --- .../kotlin/com/solana/rpc/SolanaRpcClient.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt b/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt index b2f0e37..7b3f652 100644 --- a/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt +++ b/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt @@ -69,14 +69,14 @@ class SolanaRpcClient( suspend fun sendTransaction( transaction: Transaction, - skipPreflight: Boolean = false, + options: TransactionOptions = defaultTransactionOptions, requestId: String? = null - ) = makeRequest(SendTransactionRequest(transaction, skipPreflight, requestId), String.serializer()) + ) = makeRequest(SendTransactionRequest(transaction, options, requestId), String.serializer()) suspend fun sendAndConfirmTransaction( transaction: Transaction, options: TransactionOptions = defaultTransactionOptions - ) = sendTransaction(transaction).apply { + ) = sendTransaction(transaction, options).apply { result?.let { confirmTransaction(it, options) } } @@ -181,14 +181,16 @@ class SolanaRpcClient( class SendTransactionRequest( transaction: Transaction, - skipPreflight: Boolean = false, + options: TransactionOptions, requestId: String? = null ) : SolanaRpcRequest( method = "sendTransaction", params = buildJsonArray { add(Base58.encodeToString(transaction.serialize())) addJsonObject { - put("skipPreflight", skipPreflight) + put("encoding", options.encoding.getEncoding()) + put("skipPreflight", options.skipPreflight) + put("preflightCommitment", options.preflightCommitment.value) } }, requestId From e08bbde6903e0211376d47dcb4a885a30beff842 Mon Sep 17 00:00:00 2001 From: funkatronics Date: Fri, 7 Jun 2024 16:18:35 -0600 Subject: [PATCH 2/4] fix tests and tx encoding --- .../commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt | 7 ++++++- .../src/commonTest/kotlin/com/solana/rpc/RpcClientTests.kt | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt b/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt index 7b3f652..804a03f 100644 --- a/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt +++ b/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt @@ -1,6 +1,7 @@ package com.solana.rpc import com.funkatronics.encoders.Base58 +import com.funkatronics.encoders.Base64 import com.solana.networking.HttpNetworkDriver import com.solana.networking.Rpc20Driver import com.solana.publickey.SolanaPublicKey @@ -186,7 +187,11 @@ class SolanaRpcClient( ) : SolanaRpcRequest( method = "sendTransaction", params = buildJsonArray { - add(Base58.encodeToString(transaction.serialize())) + add( + if(options.encoding == Encoding.base58) + Base58.encodeToString(transaction.serialize()) + else Base64.encodeToString(transaction.serialize()) + ) addJsonObject { put("encoding", options.encoding.getEncoding()) put("skipPreflight", options.skipPreflight) diff --git a/solanaclient/src/commonTest/kotlin/com/solana/rpc/RpcClientTests.kt b/solanaclient/src/commonTest/kotlin/com/solana/rpc/RpcClientTests.kt index 530ca9a..b8d6e57 100644 --- a/solanaclient/src/commonTest/kotlin/com/solana/rpc/RpcClientTests.kt +++ b/solanaclient/src/commonTest/kotlin/com/solana/rpc/RpcClientTests.kt @@ -106,7 +106,12 @@ class RpcClientTests { Transaction(listOf(sig), this) } - val response = rpc.sendTransaction(transaction, skipPreflight = true) + val response = rpc.sendTransaction(transaction, + TransactionOptions( + commitment = Commitment.CONFIRMED, + skipPreflight = true + ) + ) // then assertNull(airdropResponse.error) From 1f05bc6735384ec79ad2eb05ea340e3eba1ecaf7 Mon Sep 17 00:00:00 2001 From: funkatronics Date: Fri, 7 Jun 2024 16:25:43 -0600 Subject: [PATCH 3/4] more fix --- .../kotlin/com/solana/rpc/SolanaRpcClient.kt | 12 +++--- .../com/solana/rpc/TransactionOptions.kt | 3 +- .../kotlin/com/solana/rpc/RpcClientTests.kt | 39 ++++++++++++++++++- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt b/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt index 804a03f..7ec1bdf 100644 --- a/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt +++ b/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt @@ -187,15 +187,15 @@ class SolanaRpcClient( ) : SolanaRpcRequest( method = "sendTransaction", params = buildJsonArray { - add( - if(options.encoding == Encoding.base58) - Base58.encodeToString(transaction.serialize()) - else Base64.encodeToString(transaction.serialize()) - ) + add(when (options.encoding) { + Encoding.base58 -> Base58.encodeToString(transaction.serialize()) + Encoding.base64 -> Base64.getEncoder(true) + .encodeToString(transaction.serialize()) + }) addJsonObject { put("encoding", options.encoding.getEncoding()) put("skipPreflight", options.skipPreflight) - put("preflightCommitment", options.preflightCommitment.value) + put("preflightCommitment", options.preflightCommitment.toString()) } }, requestId diff --git a/solanaclient/src/commonMain/kotlin/com/solana/rpc/TransactionOptions.kt b/solanaclient/src/commonMain/kotlin/com/solana/rpc/TransactionOptions.kt index a7a20e3..5185e9d 100644 --- a/solanaclient/src/commonMain/kotlin/com/solana/rpc/TransactionOptions.kt +++ b/solanaclient/src/commonMain/kotlin/com/solana/rpc/TransactionOptions.kt @@ -6,8 +6,7 @@ import kotlin.time.Duration.Companion.seconds enum class Encoding(private val enc: String) { base64("base64"), - base58("base58"), - jsonParsed("jsonParsed"); + base58("base58"); fun getEncoding(): String { return enc } diff --git a/solanaclient/src/commonTest/kotlin/com/solana/rpc/RpcClientTests.kt b/solanaclient/src/commonTest/kotlin/com/solana/rpc/RpcClientTests.kt index b8d6e57..9c78882 100644 --- a/solanaclient/src/commonTest/kotlin/com/solana/rpc/RpcClientTests.kt +++ b/solanaclient/src/commonTest/kotlin/com/solana/rpc/RpcClientTests.kt @@ -87,7 +87,7 @@ class RpcClientTests { } @Test - fun `sendTransaction returns transaction signature`() = runTest { + fun `sendTransaction with base58 encoding returns transaction signature`() = runTest { // given val keyPair = Ed25519.generateKeyPair() val pubkey = SolanaPublicKey(keyPair.publicKey) @@ -109,6 +109,43 @@ class RpcClientTests { val response = rpc.sendTransaction(transaction, TransactionOptions( commitment = Commitment.CONFIRMED, + encoding = Encoding.base58, + skipPreflight = true + ) + ) + + // then + assertNull(airdropResponse.error) + assertNotNull(airdropResponse.result) + assertNull(response.error) + assertNotNull(response.result) + assertTrue { response.result!!.isNotEmpty() } + } + + @Test + fun `sendTransaction with base64 encoding returns transaction signature`() = runTest { + // given + val keyPair = Ed25519.generateKeyPair() + val pubkey = SolanaPublicKey(keyPair.publicKey) + val rpc = SolanaRpcClient(TestConfig.RPC_URL, KtorNetworkDriver()) + val message = "hello solana!" + + // when + val airdropResponse = rpc.requestAirdrop(pubkey, 0.1f) + val blockhashResponse = rpc.getLatestBlockhash() + + val transaction = Message.Builder() + .setRecentBlockhash(blockhashResponse.result!!.blockhash) + .addInstruction(buildMemoTransaction(pubkey, message)) + .build().run { + val sig = Ed25519.sign(keyPair, serialize()) + Transaction(listOf(sig), this) + } + + val response = rpc.sendTransaction(transaction, + TransactionOptions( + commitment = Commitment.CONFIRMED, + encoding = Encoding.base64, skipPreflight = true ) ) From 8415ae31ca636a60f09e1716f1ed1fa12288e171 Mon Sep 17 00:00:00 2001 From: funkatronics Date: Mon, 10 Jun 2024 16:37:13 -0600 Subject: [PATCH 4/4] update to fixed multimult version --- gradle/libs.versions.toml | 2 +- .../src/commonMain/kotlin/com/solana/networking/Rpc20Driver.kt | 3 --- .../src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt | 3 +-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 05b2f16..350e859 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,7 +16,7 @@ kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-cor ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" } ktor-client-cio = { group = "io.ktor", name = "ktor-client-cio", version.ref = "ktor" } ktor-client-mock = { group = "io.ktor", name = "ktor-client-mock", version.ref = "ktor" } -multimult = { group = "io.github.funkatronics", name = "multimult", version = "0.2.1" } +multimult = { group = "io.github.funkatronics", name = "multimult", version = "0.2.2" } web3-solana = { group = "com.solanamobile", name = "web3-solana", version = "0.3.0-beta3" } [plugins] diff --git a/rpccore/src/commonMain/kotlin/com/solana/networking/Rpc20Driver.kt b/rpccore/src/commonMain/kotlin/com/solana/networking/Rpc20Driver.kt index 68e580d..c42a2d5 100644 --- a/rpccore/src/commonMain/kotlin/com/solana/networking/Rpc20Driver.kt +++ b/rpccore/src/commonMain/kotlin/com/solana/networking/Rpc20Driver.kt @@ -3,9 +3,6 @@ package com.solana.networking import com.solana.rpccore.* import kotlinx.serialization.KSerializer import kotlinx.serialization.json.Json -import kotlinx.serialization.modules.SerializersModule -import kotlinx.serialization.modules.polymorphic -import kotlinx.serialization.modules.subclass class Rpc20Driver(private val url: String, private val httpDriver: HttpNetworkDriver, diff --git a/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt b/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt index 7ec1bdf..eec7beb 100644 --- a/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt +++ b/solanaclient/src/commonMain/kotlin/com/solana/rpc/SolanaRpcClient.kt @@ -189,8 +189,7 @@ class SolanaRpcClient( params = buildJsonArray { add(when (options.encoding) { Encoding.base58 -> Base58.encodeToString(transaction.serialize()) - Encoding.base64 -> Base64.getEncoder(true) - .encodeToString(transaction.serialize()) + Encoding.base64 -> Base64.encodeToString(transaction.serialize()) }) addJsonObject { put("encoding", options.encoding.getEncoding())