Skip to content

Commit

Permalink
update ptb..
Browse files Browse the repository at this point in the history
  • Loading branch information
astinz committed Apr 27, 2024
1 parent fe14eeb commit 7903999
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/Intent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum class AppId {
@Serializable
data class Intent(val scope: IntentScope, val version: IntentVersion, val appId: AppId)

@Serializable data class IntentMessage<T>(val intent: Intent, val message: T)
@Serializable data class IntentMessage<T>(val intent: Intent, val value: T)

// An intent abstraction. This is so as it is scoped, but can well be a top level function
// TODO: This is a placeholder for now, look back at this later
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ package xyz.mcxross.ksui.model

import kotlinx.serialization.Serializable
import xyz.mcxross.bcs.Bcs
import xyz.mcxross.ksui.util.bcs

@Serializable
data class ProgrammableTransaction(val inputs: List<CallArg>, val commands: List<Command>) :
TransactionKind()

class ProgrammableTransactionBuilder {
private val inputs: MutableMap<BuilderArg, CallArg> = LinkedHashMap()
private val inputs: MutableMap<BuilderArg, CallArg> = mutableMapOf()
private val command = Command()

private fun input(arg: BuilderArg, value: CallArg): Argument.Input {
private fun input(arg: BuilderArg, value: CallArg): Argument {
inputs[arg] = value
return Argument.Input(inputs.size - 1)
return Argument.Input((inputs.size - 1).toULong())
}

fun input(bytes: ByteArray, forceSeparate: Boolean): Argument.Input {
fun input(bytes: ByteArray, forceSeparate: Boolean): Argument {
val arg =
if (forceSeparate) {
BuilderArg.ForcedNonUniquePure(inputs.size)
Expand All @@ -26,12 +27,12 @@ class ProgrammableTransactionBuilder {
return input(arg, CallArg.Pure(bytes))
}

inline fun <reified T> input(value: T): Argument.Input {
inline fun <reified T> input(value: T): Argument {
val bcs = Bcs {}
return input(bcs.encodeToByteArray(value), false)
}

inline fun <reified T> forceSeparateInput(value: T): Argument.Input {
inline fun <reified T> forceSeparateInput(value: T): Argument {
val bcs = Bcs {}
return input(bcs.encodeToByteArray(value), true)
}
Expand All @@ -45,9 +46,12 @@ class ProgrammableTransactionBuilder {
}
}

@Serializable
sealed class BuilderArg {
data class Object(val objectId: ObjectId) : BuilderArg()

@Serializable data class Object(val objectId: ObjectId) : BuilderArg()

@Serializable
data class Pure(val data: ByteArray) : BuilderArg() {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
23 changes: 20 additions & 3 deletions lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/Transaction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.mcxross.bcs.Bcs
import xyz.mcxross.ksui.exception.UnknownTransactionFilterException
import xyz.mcxross.ksui.model.serializer.CallArgObjectSerializer
import xyz.mcxross.ksui.model.serializer.CallArgPureSerializer
import xyz.mcxross.ksui.model.serializer.DisassembledFieldSerializer
import xyz.mcxross.ksui.model.serializer.ObjectChangeSerializer
import xyz.mcxross.ksui.model.serializer.TransactionFilterSerializer
Expand Down Expand Up @@ -85,6 +87,7 @@ sealed class TransactionKind {
sealed class CallArg {

@Serializable
@SerialName("")
data class Pure(val data: ByteArray) : CallArg() {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand All @@ -100,7 +103,8 @@ sealed class CallArg {
}
}

@Serializable data class Object(val arg: ObjectArg) : CallArg()
@Serializable(with = CallArgObjectSerializer::class)
data class Object(val arg: ObjectArg) : CallArg()
}

@Serializable
Expand Down Expand Up @@ -414,6 +418,7 @@ open class Command {
* @param address to send the objects to.
*/
@Serializable
@SerialName("")
data class TransferObjects(val objects: List<Argument>, val address: Argument) : Command()

/**
Expand All @@ -422,7 +427,10 @@ open class Command {
* @param coin to split.
* @param into the amounts to split the coin into.
*/
@Serializable data class SplitCoins(val coin: Argument, val into: List<Argument>) : Command()

@Serializable
@SerialName("")
data class SplitCoins(val coin: Argument, val into: List<Argument>) : Command()

/**
* Merges n-coins into the first coin
Expand Down Expand Up @@ -666,10 +674,19 @@ sealed class Argument {

@Serializable data object GasCoin : Argument()

@Serializable data class Input(val inputObjectOrPrimitiveValue: Int) : Argument()
@Serializable data class Input <T> (val inputObjectOrPrimitiveValue: T) : Argument()

@Serializable data class Result(val commandResult: Int) : Argument()

@Serializable
data class NestedResult(val commandIndex: Int, val returnValueIndex: Int) : Argument()
}

@Serializable
data class SenderSignedData(val senderSignedTransactions: List<SenderSignedTransaction>)

@Serializable
data class SenderSignedTransaction(
val intentMessage: IntentMessage<TransactionData>,
val txSignatures: List<String>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package xyz.mcxross.ksui.model.serializer

import kotlinx.serialization.KSerializer
import xyz.mcxross.ksui.model.CallArg

object CallArgObjectSerializer : KSerializer<CallArg.Object> {
override val descriptor: kotlinx.serialization.descriptors.SerialDescriptor =
kotlinx.serialization.descriptors.buildClassSerialDescriptor("CallArg.Object") {}

override fun serialize(encoder: kotlinx.serialization.encoding.Encoder, value: CallArg.Object) {
encoder.encodeByte(1)
}

override fun deserialize(decoder: kotlinx.serialization.encoding.Decoder): CallArg.Object {
throw NotImplementedError("CallArg.Object is not implemented")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package xyz.mcxross.ksui.model.serializer

import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.encoding.encodeCollection
import xyz.mcxross.ksui.model.CallArg

object CallArgPureSerializer : kotlinx.serialization.KSerializer<CallArg.Pure> {
override val descriptor: SerialDescriptor =
kotlinx.serialization.descriptors.buildClassSerialDescriptor("CallArg.Pure") {
element("data", kotlinx.serialization.serializer<Byte>().descriptor)
}

override fun serialize(encoder: Encoder, value: CallArg.Pure) {
encoder.encodeByte(0)
encoder.encodeCollection(descriptor, value.data.size) {
for (element in value.data) {
encoder.encodeByte(element)
}
}
}

override fun deserialize(decoder: Decoder): CallArg.Pure {
throw NotImplementedError("CallArg.Pure is not implemented")
}
}
15 changes: 15 additions & 0 deletions lib/src/tvosMain/kotlin/xyz/mcxross/ksui/client/Platform.tvos.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package xyz.mcxross.ksui.client

import io.ktor.client.engine.*
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext

actual val defaultEngine: HttpClientEngine
get() = TODO("Not yet implemented")

actual suspend fun <T> runBlocking(
context: CoroutineContext,
block: suspend CoroutineScope.() -> T
): T {
TODO("Not yet implemented")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package xyz.mcxross.ksui.client

import io.ktor.client.engine.*
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext

actual val defaultEngine: HttpClientEngine
get() = TODO("Not yet implemented")

actual suspend fun <T> runBlocking(
context: CoroutineContext,
block: suspend CoroutineScope.() -> T
): T {
TODO("Not yet implemented")
}

0 comments on commit 7903999

Please sign in to comment.