Transactions

We found this useful within extrinsic construction in our Substrate client, so if you find this useful too, feel free to use scale codec transactions, currently only for writes:

data class MyCustomType(
    val string: String,
    val int: Int32
)

data class MyAnotherType(
    val timeMs: Int64,
    val randomString: String = UUID.randomUUID().toString()
)

val codec: ScaleCodec
val customType: MyCustomType
val anotherType: MyAnotherType

val result: ByteArray = codec.transaction()
    .append(customType.string, String::class)
    .append(anotherType.timeMs, Int64::class)
    .append(anotherType.randomString, String::class)
    .append(customType.int, Int32::class)
    .commit()

You can combine different data into single transaction to create their SCALE encoding result.

Feel free to create extensions for ScaleCodecTransaction like we did, to avoid code duplicates, and reuse them as many times as you want.

Last updated