diff --git a/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/Intent.kt b/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/Intent.kt index 41494f9e..138e9b6b 100644 --- a/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/Intent.kt +++ b/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/Intent.kt @@ -28,7 +28,7 @@ enum class AppId { @Serializable data class Intent(val scope: IntentScope, val version: IntentVersion, val appId: AppId) -@Serializable data class IntentMessage(val intent: Intent, val message: T) +@Serializable data class IntentMessage(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 diff --git a/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/ProgrammableTransaction.kt b/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/ProgrammableTransaction.kt index a5ed76b2..7550ddf2 100644 --- a/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/ProgrammableTransaction.kt +++ b/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/ProgrammableTransaction.kt @@ -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, val commands: List) : TransactionKind() class ProgrammableTransactionBuilder { - private val inputs: MutableMap = LinkedHashMap() + private val inputs: MutableMap = 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) @@ -26,12 +27,12 @@ class ProgrammableTransactionBuilder { return input(arg, CallArg.Pure(bytes)) } - inline fun input(value: T): Argument.Input { + inline fun input(value: T): Argument { val bcs = Bcs {} return input(bcs.encodeToByteArray(value), false) } - inline fun forceSeparateInput(value: T): Argument.Input { + inline fun forceSeparateInput(value: T): Argument { val bcs = Bcs {} return input(bcs.encodeToByteArray(value), true) } @@ -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 diff --git a/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/Transaction.kt b/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/Transaction.kt index 8a4f87da..ec1e882f 100644 --- a/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/Transaction.kt +++ b/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/Transaction.kt @@ -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 @@ -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 @@ -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 @@ -414,6 +418,7 @@ open class Command { * @param address to send the objects to. */ @Serializable + @SerialName("") data class TransferObjects(val objects: List, val address: Argument) : Command() /** @@ -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) : Command() + + @Serializable + @SerialName("") + data class SplitCoins(val coin: Argument, val into: List) : Command() /** * Merges n-coins into the first coin @@ -666,10 +674,19 @@ sealed class Argument { @Serializable data object GasCoin : Argument() - @Serializable data class Input(val inputObjectOrPrimitiveValue: Int) : Argument() + @Serializable data class Input (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) + +@Serializable +data class SenderSignedTransaction( + val intentMessage: IntentMessage, + val txSignatures: List, +) diff --git a/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/serializer/CallArgObjectSerializer.kt b/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/serializer/CallArgObjectSerializer.kt new file mode 100644 index 00000000..d24526c2 --- /dev/null +++ b/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/serializer/CallArgObjectSerializer.kt @@ -0,0 +1,17 @@ +package xyz.mcxross.ksui.model.serializer + +import kotlinx.serialization.KSerializer +import xyz.mcxross.ksui.model.CallArg + +object CallArgObjectSerializer : KSerializer { + 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") + } +} diff --git a/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/serializer/CallArgPureSerializer.kt b/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/serializer/CallArgPureSerializer.kt new file mode 100644 index 00000000..255e68c5 --- /dev/null +++ b/lib/src/commonMain/kotlin/xyz/mcxross/ksui/model/serializer/CallArgPureSerializer.kt @@ -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 { + override val descriptor: SerialDescriptor = + kotlinx.serialization.descriptors.buildClassSerialDescriptor("CallArg.Pure") { + element("data", kotlinx.serialization.serializer().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") + } +} diff --git a/lib/src/tvosMain/kotlin/xyz/mcxross/ksui/client/Platform.tvos.kt b/lib/src/tvosMain/kotlin/xyz/mcxross/ksui/client/Platform.tvos.kt new file mode 100644 index 00000000..f9490534 --- /dev/null +++ b/lib/src/tvosMain/kotlin/xyz/mcxross/ksui/client/Platform.tvos.kt @@ -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 runBlocking( + context: CoroutineContext, + block: suspend CoroutineScope.() -> T +): T { + TODO("Not yet implemented") +} diff --git a/lib/src/watchosMain/kotlin/xyz/mcxross/ksui/client/Platform.watchos.kt b/lib/src/watchosMain/kotlin/xyz/mcxross/ksui/client/Platform.watchos.kt new file mode 100644 index 00000000..f9490534 --- /dev/null +++ b/lib/src/watchosMain/kotlin/xyz/mcxross/ksui/client/Platform.watchos.kt @@ -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 runBlocking( + context: CoroutineContext, + block: suspend CoroutineScope.() -> T +): T { + TODO("Not yet implemented") +}