Skip to content

Commit

Permalink
add pay methods
Browse files Browse the repository at this point in the history
  • Loading branch information
soaryong-c committed Jan 27, 2023
1 parent fd06291 commit e37ba6b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package io.cosmostation.sui.sample

import android.app.Application
import io.cosmostation.suikotlin.SuiClient
import io.cosmostation.suikotlin.model.Network

class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()
SuiClient.initialize(this)
SuiClient.initialize()
SuiClient.configure(Network.Testnet())
}
}
45 changes: 34 additions & 11 deletions suikotlin/src/main/java/io/cosmostation/suikotlin/SuiClient.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
package io.cosmostation.suikotlin

import android.app.Application
import com.develop.mnemonic.MnemonicUtils
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import io.cosmostation.suikotlin.api.ApiService
import io.cosmostation.suikotlin.api.FaucetService
import io.cosmostation.suikotlin.key.SuiKey
import io.cosmostation.suikotlin.model.*
import io.cosmostation.suikotlin.secure.CipherHelper
import org.bouncycastle.jce.provider.BouncyCastleProvider
import java.math.BigDecimal
import java.math.BigInteger
import java.security.Security
import java.util.*

class SuiClient {
companion object {
val instance = SuiClient()

fun initialize(applicationContext: Application) {
CipherHelper.init(applicationContext)
fun initialize() {
setupBouncyCastle()
}

Expand Down Expand Up @@ -94,16 +91,42 @@ class SuiClient {
FaucetService.create().faucet(FixedAmountRequest(Recipient(address))).body()

suspend fun transferSui(
objectId: String,
receiver: String,
objectId: String, receiver: String, sender: String, gasBudget: Int, amount: BigInteger
): SuiWrappedTxBytes? {
val params = mutableListOf(sender, objectId, gasBudget, receiver, amount)
val result = ApiService.create().postJsonRpcRequest(
JsonRpcRequest("sui_transferSui", params)
).body()?.result
return Gson().fromJson(Gson().toJson(result), SuiWrappedTxBytes::class.java)
}

suspend fun pay(
objectIds: List<String>,
receivers: List<String>,
sender: String,
gasBudget: Int,
amount: BigDecimal? = null
gasObjectId: String? = null,
amounts: List<BigInteger>
): SuiWrappedTxBytes? {
val params = mutableListOf(sender, objectId, gasBudget, receiver)
amount?.let { params.add(it) }
val params: MutableList<Any?> =
mutableListOf(sender, objectIds, receivers, amounts, gasObjectId, gasBudget)
val result = ApiService.create().postJsonRpcRequest(
JsonRpcRequest("sui_transferSui", params)
JsonRpcRequest("sui_pay", params)
).body()?.result
return Gson().fromJson(Gson().toJson(result), SuiWrappedTxBytes::class.java)
}

suspend fun paySui(
objectIds: List<String>,
receivers: List<String>,
sender: String,
gasBudget: Int,
amounts: List<BigInteger>
): SuiWrappedTxBytes? {
val params: MutableList<Any?> =
mutableListOf(sender, objectIds, receivers, amounts, gasBudget)
val result = ApiService.create().postJsonRpcRequest(
JsonRpcRequest("sui_paySui", params)
).body()?.result
return Gson().fromJson(Gson().toJson(result), SuiWrappedTxBytes::class.java)
}
Expand Down

This file was deleted.

0 comments on commit e37ba6b

Please sign in to comment.