Skip to content

Commit

Permalink
support networks
Browse files Browse the repository at this point in the history
  • Loading branch information
soaryong-c committed Jan 18, 2023
1 parent 0b43e60 commit 07a3220
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class SuiClient {
setupBouncyCastle()
}

fun configure(network: Network) {
instance.currentNetwork = network
}

private fun setupBouncyCastle() {
val provider = Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) ?: return

Expand All @@ -34,6 +38,8 @@ class SuiClient {
}
}

var currentNetwork: Network = Network.Devnet()

fun generateMnemonic(): String = MnemonicUtils.generateMnemonic()

fun getAddress(mnemonic: String) = SuiKey.getSuiAddress(mnemonic)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.cosmostation.suikotlin.api

import com.github.cosmostation.suikotlin.BuildConfig
import io.cosmostation.suikotlin.SuiClient
import io.cosmostation.suikotlin.model.JsonRpcRequest
import io.cosmostation.suikotlin.model.JsonRpcResponse
import okhttp3.OkHttpClient
Expand All @@ -14,10 +15,8 @@ import java.util.concurrent.TimeUnit

interface ApiService {
companion object {
private const val SUI_DEV_RPC = "https://fullnode.devnet.sui.io"

fun create(): ApiService {
val builder = Retrofit.Builder().baseUrl(SUI_DEV_RPC)
val builder = Retrofit.Builder().baseUrl(SuiClient.instance.currentNetwork.rpcUrl)
.addConverterFactory(GsonConverterFactory.create())

if (BuildConfig.DEBUG) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.cosmostation.suikotlin.model

sealed class Network(val name: String, val rpcUrl: String) {
class Devnet : Network("Devnet", "https://fullnode.devnet.sui.io")
class Testnet : Network("Testnet", "https://fullnode.testnet.sui.io")
class Localnet : Network("Localhost", "http://127.0.0.1:9000")
}

0 comments on commit 07a3220

Please sign in to comment.