Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rpc-solana Library #25

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/build
*/build
/.gradle
/.kotlin

# IDE Files
/.idea
Expand Down
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ plugins {
alias(libs.plugins.publish) apply false
}

configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("com.solanamobile:web3-core")).using(project(":core"))
substitute(module("com.solanamobile:web3-solana")).using(project(":solana"))
}
}

//tasks.register("clean", Delete::class) {
// delete(rootProject.buildDir)
//}
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ val artifactIdPrefix: String by project
val moduleArtifactId = "$artifactIdPrefix-core"

kotlin {
jvmToolchain(11)
jvm {
jvmToolchain(11)
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
kotlin.code.style=official
kotlin.js.compiler=ir

#MPP
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.androidSourceSetLayoutVersion=2

# Group name and project version, used when publishing. For official releases, the version should be
# provided to Gradle via '-P version="1.0"'.
group=com.solanamobile
Expand Down
7 changes: 5 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[versions]
kotlinxCoroutines = "1.7.3"
ktor = "2.3.11"
rpcCore = "0.2.7"

# Plugin versions
androidGradlePlugin = "8.0.2"
kotlin = "1.9.21"
kotlin = "2.0.20-Beta2"
kotlinSerialization = "1.6.2"
vanniktechMavenPublish = "0.25.3"

Expand All @@ -18,7 +19,9 @@ 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" }
multimult = { group = "io.github.funkatronics", name = "multimult", version = "0.2.3" }
rpc-core = { group = "com.solanamobile", name = "rpc-core", version = "0.2.5" }
rpc-core = { group = "com.solanamobile", name = "rpc-core", version.ref = "rpcCore" }
rpc-ktordriver = { group = "com.solanamobile", name = "rpc-ktordriver", version.ref = "rpcCore" }
rpc-solana = { group = "com.solanamobile", name = "rpc-solana", version.ref = "rpcCore" }
salkt = { group = "io.github.funkatronics", name = "salkt", version = "0.1.0" }

[plugins]
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 7 additions & 3 deletions solana/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ plugins {

val artifactIdPrefix: String by project
val moduleArtifactId = "$artifactIdPrefix-solana"
val buildDir = layout.buildDirectory.asFile.get()
val generatedDir = "${buildDir}/generated/src/commonTest/kotlin"

kotlin {
jvmToolchain(11)
jvm {
jvmToolchain(11)
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
Expand Down Expand Up @@ -37,14 +39,16 @@ kotlin {
}
}
val commonTest by getting {
kotlin.srcDir(File("${buildDir}/generated/src/commonTest/kotlin"))
kotlin.srcDir(File(generatedDir))
dependencies {
implementation(libs.kotlin.test)
implementation(libs.kotlinx.coroutines.test)
implementation(libs.crypto)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.cio)
implementation(libs.rpc.core)
implementation(libs.rpc.ktordriver)
implementation(libs.rpc.solana)
}
}
}
Expand All @@ -62,7 +66,7 @@ afterEvaluate {
val localRpcUrl = project.properties["testing.rpc.localUrl"]
if (useLocalValidator && localRpcUrl != null) rpcUrl = localRpcUrl

val dir = "${buildDir}/generated/src/commonTest/kotlin/com/solana/config"
val dir = "${generatedDir}/com/solana/config"
mkdir(dir)
File(dir, "TestConfig.kt").writeText(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package com.solana.programs
import com.solana.publickey.SolanaPublicKey
import com.solana.transaction.AccountMeta
import com.solana.transaction.TransactionInstruction
import kotlin.experimental.ExperimentalObjCName
import kotlin.jvm.JvmStatic
import kotlin.native.ObjCName

object MemoProgram : Program {
@OptIn(ExperimentalObjCName::class)
@ObjCName("MemoProgram")
object MemoProgram {
@JvmStatic
val PROGRAM_ID = SolanaPublicKey.from("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import com.solana.publickey.SolanaPublicKey
import com.solana.transaction.AccountMeta
import com.solana.transaction.TransactionInstruction
import kotlinx.serialization.builtins.ByteArraySerializer
import kotlin.experimental.ExperimentalObjCName
import kotlin.jvm.JvmStatic
import kotlin.native.ObjCName

object SystemProgram : Program {
@OptIn(ExperimentalObjCName::class)
@ObjCName("SystemProgram")
object SystemProgram {
@JvmStatic
val PROGRAM_ID = SolanaPublicKey.from("11111111111111111111111111111111")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.solana.programs

import com.solana.config.TestConfig
import com.solana.networking.KtorNetworkDriver
import com.solana.publickey.SolanaPublicKey
import com.solana.rpc.SolanaRpcClient
import com.solana.rpc.TransactionOptions
import com.solana.transaction.Message
import com.solana.transaction.Transaction
import com.solana.util.RpcClient
import diglol.crypto.Ed25519
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
Expand All @@ -18,7 +20,7 @@ class MemoProgramTests {
// given
val keyPair = Ed25519.generateKeyPair()
val pubkey = SolanaPublicKey(keyPair.publicKey)
val rpc = RpcClient(TestConfig.RPC_URL)
val rpc = SolanaRpcClient(TestConfig.RPC_URL, KtorNetworkDriver())
val message = "hello solana!"

// when
Expand All @@ -33,7 +35,7 @@ class MemoProgramTests {
Transaction(listOf(sig), this)
}

val response = rpc.sendTransaction(transaction)
val response = rpc.sendTransaction(transaction, TransactionOptions(skipPreflight = true))

// then
assertNull(airdropResponse.error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.solana.programs

import com.solana.config.TestConfig
import com.solana.networking.KtorNetworkDriver
import com.solana.publickey.SolanaPublicKey
import com.solana.rpc.Commitment
import com.solana.rpc.SolanaRpcClient
import com.solana.rpc.TransactionOptions
import com.solana.transaction.Message
import com.solana.transaction.Transaction
import com.solana.util.RpcClient
import diglol.crypto.Ed25519
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.withContext
import kotlin.test.Test
Expand All @@ -25,7 +26,7 @@ class SystemProgramTests {
val newAccountKeyPair = Ed25519.generateKeyPair()
val payerPubkey = SolanaPublicKey(payerKeyPair.publicKey)
val newAccountPubkey = SolanaPublicKey(newAccountKeyPair.publicKey)
val rpc = RpcClient(TestConfig.RPC_URL)
val rpc = SolanaRpcClient(TestConfig.RPC_URL, KtorNetworkDriver())

// when
val airdropResponse = rpc.requestAirdrop(payerPubkey, 0.1f)
Expand All @@ -49,7 +50,10 @@ class SystemProgramTests {
}

withContext(Dispatchers.Default.limitedParallelism(1)) {
rpc.sendAndConfirmTransaction(transaction)
rpc.sendAndConfirmTransaction(transaction, TransactionOptions(
commitment = Commitment.CONFIRMED,
skipPreflight = true
))
}

val response = rpc.getBalance(newAccountPubkey)
Expand All @@ -69,7 +73,7 @@ class SystemProgramTests {
val receiverKeyPair = Ed25519.generateKeyPair()
val payerPubkey = SolanaPublicKey(payerKeyPair.publicKey)
val receiverPubkey = SolanaPublicKey(receiverKeyPair.publicKey)
val rpc = RpcClient(TestConfig.RPC_URL)
val rpc = SolanaRpcClient(TestConfig.RPC_URL, KtorNetworkDriver())
val balance = 10000000L // lamports

// when
Expand All @@ -85,7 +89,10 @@ class SystemProgramTests {
}

withContext(Dispatchers.Default.limitedParallelism(1)) {
rpc.sendAndConfirmTransaction(transaction)
rpc.sendAndConfirmTransaction(transaction, TransactionOptions(
commitment = Commitment.CONFIRMED,
skipPreflight = true
))
}

val response = rpc.getBalance(receiverPubkey)
Expand Down
Loading
Loading