Skip to content

Commit

Permalink
update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
soaryong-stamper committed Apr 5, 2023
1 parent 67e8b54 commit 1e577e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
21 changes: 7 additions & 14 deletions suikotlin/src/main/java/io/cosmostation/suikotlin/SuiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class SuiClient {
fun sign(keyPair: EdDSAKeyPair, data: ByteArray) = SuiKey.sign(keyPair, data)

suspend fun getObjectsByOwner(address: String): List<SuiObjectInfo> {
val request = JsonRpcRequest("suix_getOwnedObjects", listOf(address))
val request = JsonRpcRequest("suix_getOwnedObjects", listOf(address, SuiObjectResponseQuery(null, SuiObjectDataOptions(showContent = true))))
val result = ApiService.create().postJsonRpcRequest(request).body()?.result
return Gson().fromJson(Gson().toJson(result), SuiObjectDataResult::class.java).data.map { it.data }
}

suspend fun getMultiObjectDetail(objectIds: List<String>): Any? {
val request = JsonRpcRequest("sui_multiGetObjects", objectIds)
val request = JsonRpcRequest("sui_multiGetObjects", listOf(objectIds, SuiObjectResponseQuery(null, SuiObjectDataOptions(showContent = true))))
return ApiService.create().postJsonRpcRequest(request).body()?.result
}

Expand Down Expand Up @@ -98,17 +98,15 @@ class SuiClient {
suspend fun pay(
objectIds: List<String>, receivers: List<String>, sender: String, gasBudget: Int, gasObjectId: String? = null, amounts: List<BigInteger>
): SuiWrappedTxBytes? {
val params: MutableList<Any?> = mutableListOf(sender, objectIds, receivers, amounts, gasObjectId, gasBudget)
val result = ApiService.create().postJsonRpcRequest(
JsonRpcRequest("unsafe_pay", params)
).body()?.result
val params: MutableList<Any?> = mutableListOf(sender, objectIds, receivers, amounts.map { it.toString() }, gasObjectId, gasBudget)
val result = ApiService.create().postJsonRpcRequest(JsonRpcRequest("unsafe_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 params: MutableList<Any?> = mutableListOf(sender, objectIds, receivers, amounts.map { it.toString() }, gasBudget)
val result = ApiService.create().postJsonRpcRequest(
JsonRpcRequest("unsafe_paySui", params)
).body()?.result
Expand Down Expand Up @@ -138,14 +136,9 @@ class SuiClient {
}

suspend fun executeTransaction(
txBytes: ByteArray, signedBytes: ByteArray, keyPair: EdDSAKeyPair
txBytes: ByteArray, signedBytes: ByteArray, keyPair: EdDSAKeyPair, responseOptions: SuiTransactionBlockResponseOptions? = null
): Any? {
val params = mutableListOf(
Base64.getEncoder().encodeToString(txBytes), listOf(
Base64.getEncoder().encodeToString(byteArrayOf(0x00) + signedBytes + keyPair.publicKey.abyte)
), "WaitForLocalExecution"
)

val params = mutableListOf(Base64.getEncoder().encodeToString(txBytes), listOf(Base64.getEncoder().encodeToString(byteArrayOf(0x00) + signedBytes + keyPair.publicKey.abyte)), responseOptions, "WaitForLocalExecution")
return ApiService.create().postJsonRpcRequest(JsonRpcRequest("sui_executeTransactionBlock", params)).body()?.result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ object SuiKey {
}

fun sign(keyPair: EdDSAKeyPair, data: ByteArray): ByteArray {
val blake2b = Blake2b.Blake2b256()
blake2b.update(data)
val spec: EdDSAParameterSpec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519)
val signature: Signature = EdDSAEngine(MessageDigest.getInstance(spec.hashAlgorithm))
signature.initSign(keyPair.privateKey)
signature.update(data)
signature.update(blake2b.digest())
return signature.sign()
}

Expand Down
23 changes: 11 additions & 12 deletions suikotlin/src/main/java/io/cosmostation/suikotlin/model/SuiModel.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
package io.cosmostation.suikotlin.model

data class SuiObjectInfo(
val objectId: String, val version: Int, val digest: String, val type: String, val owner: SuiObjectOwner, val previousTransaction: String
)
data class SuiObjectInfo(val objectId: String, val version: Int, val digest: String, val type: String, val content: Any, val owner: SuiObjectOwner, val previousTransaction: String)

data class SuiObjectData(
val data: SuiObjectInfo,
)
data class SuiObjectData(val data: SuiObjectInfo)

data class SuiNextCursor(val objectId: String)

data class SuiObjectDataResult(
val data: List<SuiObjectData>, val hasNextPage: Boolean, val nextCursor: SuiNextCursor
)
data class SuiObjectDataResult(val data: List<SuiObjectData>, val hasNextPage: Boolean, val nextCursor: SuiNextCursor)

data class SuiTransactionDataResult(val data: List<SuiTransaction>, val hasNextPage: Boolean, val nextCursor: String)

data class SuiTransactionBlockResponseOptions(val showInput: Boolean = false, val showRawInput: Boolean = false, val showEffects: Boolean = false, val showEvents: Boolean = false, val showObjectChanges: Boolean = false, val showBalanceChanges: Boolean = false)

data class SuiTransaction(val digest: String, val transaction: Any, val effects: Any, val balanceChanges: Any, val timestampMs: Long)

data class SuiObjectOwner(val AddressOwner: String)

data class SuiWrappedTxBytes(
val txBytes: String, val gas: SuiObjectRef, val inputObjects: List<ImmOrOwnedMoveObject>
)
data class SuiWrappedTxBytes(val txBytes: String, val gas: List<SuiObjectRef>, val inputObjects: List<ImmOrOwnedMoveObject>)

data class ImmOrOwnedMoveObject(val ImmOrOwnedMoveObject: SuiObjectRef)

data class SuiObjectRef(val objectId: String, val version: Int, val digest: String)

data class SuiTransactionQueryFilter(val filter: TransactionQuery, val options: SuiTransactionBlockResponseOptions)

data class SuiObjectDataOptions(val showType: Boolean = true, val showContent: Boolean = false, val showDisplay: Boolean = false, val showStorageRebate: Boolean = false, val showPreviousTransaction: Boolean = false, val showOwner: Boolean = false, val showBcs: Boolean = false)

data class SuiObjectDataFilter(val Package: String)

data class SuiObjectResponseQuery(val filter: SuiObjectDataFilter?, val options: SuiObjectDataOptions?)
sealed class TransactionQuery {
class ToAddress(val ToAddress: String) : TransactionQuery()
class FromAddress(val FromAddress: String) : TransactionQuery()
Expand Down

0 comments on commit 1e577e5

Please sign in to comment.