diff --git a/bivrost-abi-parser/build.gradle b/bivrost-abi-parser/build.gradle index 652ff52..fe40be1 100644 --- a/bivrost-abi-parser/build.gradle +++ b/bivrost-abi-parser/build.gradle @@ -11,7 +11,7 @@ dependencies { implementation "com.squareup.moshi:moshi:$versions.moshi" implementation "com.squareup.moshi:moshi-kotlin:$versions.moshi" implementation "com.squareup:kotlinpoet:$versions.kotlinPoet" - implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.57' + implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.61' testImplementation group: 'junit', name: 'junit', version: '4.12' } diff --git a/bivrost-abi-parser/src/main/kotlin/pm/gnosis/AbiParser.kt b/bivrost-abi-parser/src/main/kotlin/pm/gnosis/AbiParser.kt index 5a26077..ebc7dfb 100644 --- a/bivrost-abi-parser/src/main/kotlin/pm/gnosis/AbiParser.kt +++ b/bivrost-abi-parser/src/main/kotlin/pm/gnosis/AbiParser.kt @@ -165,6 +165,7 @@ object AbiParser { .addModifiers(KModifier.DATA) .addSuperinterface(if (typeHolder.isDynamic()) SolidityBase.DynamicType::class else SolidityBase.StaticType::class) .addFunction(generateTupleEncoder(typeHolder)) + .addFunction(generateTuplePackedEncoder()) .addType( GeneratorUtils.generateDecoder( typeHolder.name, @@ -199,6 +200,15 @@ object AbiParser { ) .build() + private fun generateTuplePackedEncoder() = + FunSpec.builder("encodePacked") + .returns(String::class) + .addModifiers(KModifier.OVERRIDE) + .addStatement( + "throw·UnsupportedOperationException(\"Structs are not supported via encodePacked\")" + ) + .build() + private fun generateFunctionEncoder(functionJson: AbiElementJson): FunSpec { val funSpec = FunSpec.builder("encode") functionJson.inputs.forEachIndexed { index, parameter -> diff --git a/bivrost-abi-parser/src/main/kotlin/pm/gnosis/EventParser.kt b/bivrost-abi-parser/src/main/kotlin/pm/gnosis/EventParser.kt index 36f8394..5d73aba 100644 --- a/bivrost-abi-parser/src/main/kotlin/pm/gnosis/EventParser.kt +++ b/bivrost-abi-parser/src/main/kotlin/pm/gnosis/EventParser.kt @@ -87,8 +87,7 @@ internal object EventParser { codeBlock.addStatement("// Decode topics") if (!isAnonymous) { codeBlock.addStatement( - "if·($TOPIC_ARG_NAME.first()·!=·$EVENT_ID_PROPERTY_NAME)·throw·%1T(\"topics[0]·does·not·match·event·id\")", - IllegalArgumentException::class + "if·($TOPIC_ARG_NAME.first().removePrefix(\"0x\")·!=·$EVENT_ID_PROPERTY_NAME)·throw·IllegalArgumentException(\"topics[0]·does·not·match·event·id\")" ) } diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/06_function_input/expected/Abi6.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/06_function_input/expected/Abi6.kt index b60f35f..9fdefb8 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/06_function_input/expected/Abi6.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/06_function_input/expected/Abi6.kt @@ -21,6 +21,8 @@ class Abi6 { return Arguments(arg0) } - data class Arguments(val owner: Solidity.Address) + data class Arguments( + val owner: Solidity.Address + ) } } diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/07_function_input_output/expected/Abi7.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/07_function_input_output/expected/Abi7.kt index b455dda..3ce254d 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/07_function_input_output/expected/Abi7.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/07_function_input_output/expected/Abi7.kt @@ -33,8 +33,12 @@ class Abi7 { return Arguments(arg0) } - data class Return(val data: Solidity.Bytes) + data class Return( + val data: Solidity.Bytes + ) - data class Arguments(val owner: Solidity.Address) + data class Arguments( + val owner: Solidity.Address + ) } } diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/08_unnamed_parameters/expected/Abi8.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/08_unnamed_parameters/expected/Abi8.kt index 007e3cb..d4e67d5 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/08_unnamed_parameters/expected/Abi8.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/08_unnamed_parameters/expected/Abi8.kt @@ -33,8 +33,12 @@ class Abi8 { return Arguments(arg0) } - data class Return(val param0: Solidity.Bytes) + data class Return( + val param0: Solidity.Bytes + ) - data class Arguments(val param0: Solidity.Address) + data class Arguments( + val param0: Solidity.Address + ) } } diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/Abi9.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/Abi9.kt index 7b75038..8b6533d 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/Abi9.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/Abi9.kt @@ -13,9 +13,9 @@ class Abi9 { object Owners { const val METHOD_ID: String = "9f767eb7" - fun encode(c: SolidityBase.Vector, arg2: - SolidityBase.Vector>>>): String - { + fun encode(c: SolidityBase.Vector, + arg2: SolidityBase.Vector>>>): + String { return "0x" + METHOD_ID + pm.gnosis.model.SolidityBase.encodeFunctionArguments(c, arg2) } @@ -42,10 +42,15 @@ class Abi9 { return Arguments(arg0, arg1) } - data class Return(val param0: TupleB, val param1: SolidityBase.Vector) + data class Return( + val param0: TupleB, + val param1: SolidityBase.Vector + ) - data class Arguments(val c: SolidityBase.Vector, val param1: - SolidityBase.Vector>>>) + data class Arguments( + val c: SolidityBase.Vector, + val param1: SolidityBase.Vector>>> + ) } data class TupleA( @@ -57,6 +62,10 @@ class Abi9 { return SolidityBase.encodeFunctionArguments(a, b, param2) } + override fun encodePacked(): String { + throw UnsupportedOperationException("Structs are not supported via encodePacked") + } + class Decoder : SolidityBase.TypeDecoder { override fun isDynamic(): Boolean = true override fun decode(source: SolidityBase.PartitionData): TupleA { @@ -73,11 +82,18 @@ class Abi9 { } } - data class TupleB(val x: Solidity.UInt256, val y: Solidity.UInt256) : SolidityBase.StaticType { + data class TupleB( + val x: Solidity.UInt256, + val y: Solidity.UInt256 + ) : SolidityBase.StaticType { override fun encode(): String { return SolidityBase.encodeFunctionArguments(x, y) } + override fun encodePacked(): String { + throw UnsupportedOperationException("Structs are not supported via encodePacked") + } + class Decoder : SolidityBase.TypeDecoder { override fun isDynamic(): Boolean = false override fun decode(source: SolidityBase.PartitionData): TupleB { diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/arrays/Array5.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/arrays/Array5.kt index b5f9aee..0f98721 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/arrays/Array5.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/arrays/Array5.kt @@ -4,9 +4,12 @@ import kotlin.Boolean import kotlin.collections.List import pm.gnosis.model.SolidityBase -class Array5(items: List) : SolidityBase.Array(items, 5) { - class Decoder(val itemDecoder: SolidityBase.TypeDecoder) : - SolidityBase.TypeDecoder> { +class Array5( + items: List +) : SolidityBase.Array(items, 5) { + class Decoder( + val itemDecoder: SolidityBase.TypeDecoder + ) : SolidityBase.TypeDecoder> { override fun isDynamic(): Boolean = itemDecoder.isDynamic() override fun decode(source: SolidityBase.PartitionData): Array5 { return Array5(SolidityBase.decodeList(source, 5, itemDecoder)) diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/arrays/Array7.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/arrays/Array7.kt index 0cc661f..fe78526 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/arrays/Array7.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/09_complex_arrays/expected/arrays/Array7.kt @@ -4,9 +4,12 @@ import kotlin.Boolean import kotlin.collections.List import pm.gnosis.model.SolidityBase -class Array7(items: List) : SolidityBase.Array(items, 7) { - class Decoder(val itemDecoder: SolidityBase.TypeDecoder) : - SolidityBase.TypeDecoder> { +class Array7( + items: List +) : SolidityBase.Array(items, 7) { + class Decoder( + val itemDecoder: SolidityBase.TypeDecoder + ) : SolidityBase.TypeDecoder> { override fun isDynamic(): Boolean = itemDecoder.isDynamic() override fun decode(source: SolidityBase.PartitionData): Array7 { return Array7(SolidityBase.decodeList(source, 7, itemDecoder)) diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/11_event_static_indexed/expected/Abi11.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/11_event_static_indexed/expected/Abi11.kt index 3d7ec95..69326f0 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/11_event_static_indexed/expected/Abi11.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/11_event_static_indexed/expected/Abi11.kt @@ -1,6 +1,5 @@ package expected -import java.lang.IllegalArgumentException import kotlin.String import kotlin.collections.List import pm.gnosis.model.Solidity @@ -14,13 +13,15 @@ class Abi11 { fun decode(topics: List): Arguments { // Decode topics - if (topics.first() != EVENT_ID) throw IllegalArgumentException("topics[0] does not match event id") + if (topics.first().removePrefix("0x") != EVENT_ID) throw IllegalArgumentException("topics[0] does not match event id") val source1 = SolidityBase.PartitionData.of(topics[1]) val t1 = Solidity.UInt256.DECODER.decode(source1) return Arguments(t1) } - data class Arguments(val transactionid: Solidity.UInt256) + data class Arguments( + val transactionid: Solidity.UInt256 + ) } } } diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/12_event_static_not_indexed/expected/Abi12.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/12_event_static_not_indexed/expected/Abi12.kt index a7dc4ff..cd6aa07 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/12_event_static_not_indexed/expected/Abi12.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/12_event_static_not_indexed/expected/Abi12.kt @@ -1,6 +1,5 @@ package expected -import java.lang.IllegalArgumentException import kotlin.String import kotlin.collections.List import pm.gnosis.model.Solidity @@ -14,7 +13,7 @@ class Abi12 { fun decode(topics: List, data: String): Arguments { // Decode topics - if (topics.first() != EVENT_ID) throw IllegalArgumentException("topics[0] does not match event id") + if (topics.first().removePrefix("0x") != EVENT_ID) throw IllegalArgumentException("topics[0] does not match event id") // Decode data val source = SolidityBase.PartitionData.of(data) @@ -22,7 +21,9 @@ class Abi12 { return Arguments(arg0) } - data class Arguments(val transactionid: Solidity.UInt256) + data class Arguments( + val transactionid: Solidity.UInt256 + ) } } } diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/13_simple_event_dynamic_indexed/expected/Abi13.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/13_simple_event_dynamic_indexed/expected/Abi13.kt index 9281d8e..36d2bfc 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/13_simple_event_dynamic_indexed/expected/Abi13.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/13_simple_event_dynamic_indexed/expected/Abi13.kt @@ -1,6 +1,5 @@ package expected -import java.lang.IllegalArgumentException import kotlin.Boolean import kotlin.String import kotlin.collections.List @@ -15,7 +14,7 @@ class Abi13 { fun decode(topics: List): Arguments { // Decode topics - if (topics.first() != EVENT_ID) throw IllegalArgumentException("topics[0] does not match event id") + if (topics.first().removePrefix("0x") != EVENT_ID) throw IllegalArgumentException("topics[0] does not match event id") val t1 = topics[1] val t2 = topics[2] val t3 = topics[3] @@ -30,11 +29,18 @@ class Abi13 { } } - data class TupleA(val x: Solidity.UInt256, val y: Solidity.UInt256) : SolidityBase.StaticType { + data class TupleA( + val x: Solidity.UInt256, + val y: Solidity.UInt256 + ) : SolidityBase.StaticType { override fun encode(): String { return SolidityBase.encodeFunctionArguments(x, y) } + override fun encodePacked(): String { + throw UnsupportedOperationException("Structs are not supported via encodePacked") + } + class Decoder : SolidityBase.TypeDecoder { override fun isDynamic(): Boolean = false override fun decode(source: SolidityBase.PartitionData): TupleA { diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/14_simple_event_dynamic_not_indexed/expected/Abi14.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/14_simple_event_dynamic_not_indexed/expected/Abi14.kt index e6fa78d..a27aaf1 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/14_simple_event_dynamic_not_indexed/expected/Abi14.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/14_simple_event_dynamic_not_indexed/expected/Abi14.kt @@ -1,6 +1,5 @@ package expected -import java.lang.IllegalArgumentException import java.math.BigInteger import kotlin.Boolean import kotlin.String @@ -17,7 +16,7 @@ class Abi14 { fun decode(topics: List, data: String): Arguments { // Decode topics - if (topics.first() != EVENT_ID) throw IllegalArgumentException("topics[0] does not match event id") + if (topics.first().removePrefix("0x") != EVENT_ID) throw IllegalArgumentException("topics[0] does not match event id") // Decode data val source = SolidityBase.PartitionData.of(data) @@ -37,11 +36,18 @@ class Abi14 { } } - data class TupleA(val x: Solidity.UInt256, val y: Solidity.UInt256) : SolidityBase.StaticType { + data class TupleA( + val x: Solidity.UInt256, + val y: Solidity.UInt256 + ) : SolidityBase.StaticType { override fun encode(): String { return SolidityBase.encodeFunctionArguments(x, y) } + override fun encodePacked(): String { + throw UnsupportedOperationException("Structs are not supported via encodePacked") + } + class Decoder : SolidityBase.TypeDecoder { override fun isDynamic(): Boolean = false override fun decode(source: SolidityBase.PartitionData): TupleA { diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/15_anonymous_event/expected/Abi15.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/15_anonymous_event/expected/Abi15.kt index 7765189..4aa4106 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/15_anonymous_event/expected/Abi15.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/15_anonymous_event/expected/Abi15.kt @@ -18,7 +18,9 @@ class Abi15 { return Arguments(t1) } - data class Arguments(val transactionid: Solidity.UInt256) + data class Arguments( + val transactionid: Solidity.UInt256 + ) } } } diff --git a/bivrost-abi-parser/src/test/resources/automatic_tests/16_malformed_bytes_encoding/expected/Abi16.kt b/bivrost-abi-parser/src/test/resources/automatic_tests/16_malformed_bytes_encoding/expected/Abi16.kt index de405a4..05a3cbb 100644 --- a/bivrost-abi-parser/src/test/resources/automatic_tests/16_malformed_bytes_encoding/expected/Abi16.kt +++ b/bivrost-abi-parser/src/test/resources/automatic_tests/16_malformed_bytes_encoding/expected/Abi16.kt @@ -25,15 +25,23 @@ class Abi16 { return Arguments(arg0) } - data class Arguments(val c: TupleA) + data class Arguments( + val c: TupleA + ) } - data class TupleA(val bytesvar: Solidity.Bytes, val stringvar: Solidity.String) : - SolidityBase.DynamicType { + data class TupleA( + val bytesvar: Solidity.Bytes, + val stringvar: Solidity.String + ) : SolidityBase.DynamicType { override fun encode(): String { return SolidityBase.encodeFunctionArguments(bytesvar, stringvar) } + override fun encodePacked(): String { + throw UnsupportedOperationException("Structs are not supported via encodePacked") + } + class Decoder : SolidityBase.TypeDecoder { override fun isDynamic(): Boolean = true override fun decode(source: SolidityBase.PartitionData): TupleA { diff --git a/bivrost-solidity-types-generator/src/main/kotlin/pm/gnosis/SolidityTypeGenerator.kt b/bivrost-solidity-types-generator/src/main/kotlin/pm/gnosis/SolidityTypeGenerator.kt index 13d559b..801efc8 100644 --- a/bivrost-solidity-types-generator/src/main/kotlin/pm/gnosis/SolidityTypeGenerator.kt +++ b/bivrost-solidity-types-generator/src/main/kotlin/pm/gnosis/SolidityTypeGenerator.kt @@ -202,6 +202,13 @@ private fun generateDynamicBytes(): TypeSpec { .addStatement("return %1T(length, contents)", SolidityBase.DynamicType.Parts::class) .build()) .build()) + .addFunction(FunSpec.builder("encodePacked") + .addModifiers(KModifier.OVERRIDE) + .returns(String::class) + .addCode(CodeBlock.builder() + .addStatement("return items.toHex()") + .build()) + .build()) .addType(GeneratorUtils.generateDecoder(name, CodeBlock.builder() .addStatement("return %1N(%2T.decodeBytes(source))", name, SolidityBase::class) diff --git a/bivrost-solidity-types/src/main/kotlin/pm/gnosis/model/Solidity.kt b/bivrost-solidity-types/src/main/kotlin/pm/gnosis/model/Solidity.kt index 1ec8e6b..2f66ce5 100644 --- a/bivrost-solidity-types/src/main/kotlin/pm/gnosis/model/Solidity.kt +++ b/bivrost-solidity-types/src/main/kotlin/pm/gnosis/model/Solidity.kt @@ -119,687 +119,882 @@ object Solidity { "bytes" to "pm.gnosis.model.Solidity.Bytes", "string" to "pm.gnosis.model.Solidity.String") - data class UInt8(val value: BigInteger) : SolidityBase.UIntBase(value, 8) { + data class UInt8( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 8) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt8(it) }) } } - data class UInt16(val value: BigInteger) : SolidityBase.UIntBase(value, 16) { + data class UInt16( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 16) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt16(it) }) } } - data class UInt24(val value: BigInteger) : SolidityBase.UIntBase(value, 24) { + data class UInt24( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 24) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt24(it) }) } } - data class UInt32(val value: BigInteger) : SolidityBase.UIntBase(value, 32) { + data class UInt32( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 32) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt32(it) }) } } - data class UInt40(val value: BigInteger) : SolidityBase.UIntBase(value, 40) { + data class UInt40( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 40) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt40(it) }) } } - data class UInt48(val value: BigInteger) : SolidityBase.UIntBase(value, 48) { + data class UInt48( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 48) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt48(it) }) } } - data class UInt56(val value: BigInteger) : SolidityBase.UIntBase(value, 56) { + data class UInt56( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 56) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt56(it) }) } } - data class UInt64(val value: BigInteger) : SolidityBase.UIntBase(value, 64) { + data class UInt64( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 64) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt64(it) }) } } - data class UInt72(val value: BigInteger) : SolidityBase.UIntBase(value, 72) { + data class UInt72( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 72) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt72(it) }) } } - data class UInt80(val value: BigInteger) : SolidityBase.UIntBase(value, 80) { + data class UInt80( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 80) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt80(it) }) } } - data class UInt88(val value: BigInteger) : SolidityBase.UIntBase(value, 88) { + data class UInt88( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 88) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt88(it) }) } } - data class UInt96(val value: BigInteger) : SolidityBase.UIntBase(value, 96) { + data class UInt96( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 96) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt96(it) }) } } - data class UInt104(val value: BigInteger) : SolidityBase.UIntBase(value, 104) { + data class UInt104( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 104) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt104(it) }) } } - data class UInt112(val value: BigInteger) : SolidityBase.UIntBase(value, 112) { + data class UInt112( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 112) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt112(it) }) } } - data class UInt120(val value: BigInteger) : SolidityBase.UIntBase(value, 120) { + data class UInt120( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 120) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt120(it) }) } } - data class UInt128(val value: BigInteger) : SolidityBase.UIntBase(value, 128) { + data class UInt128( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 128) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt128(it) }) } } - data class UInt136(val value: BigInteger) : SolidityBase.UIntBase(value, 136) { + data class UInt136( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 136) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt136(it) }) } } - data class UInt144(val value: BigInteger) : SolidityBase.UIntBase(value, 144) { + data class UInt144( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 144) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt144(it) }) } } - data class UInt152(val value: BigInteger) : SolidityBase.UIntBase(value, 152) { + data class UInt152( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 152) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt152(it) }) } } - data class UInt160(val value: BigInteger) : SolidityBase.UIntBase(value, 160) { + data class UInt160( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 160) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt160(it) }) } } - data class UInt168(val value: BigInteger) : SolidityBase.UIntBase(value, 168) { + data class UInt168( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 168) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt168(it) }) } } - data class UInt176(val value: BigInteger) : SolidityBase.UIntBase(value, 176) { + data class UInt176( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 176) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt176(it) }) } } - data class UInt184(val value: BigInteger) : SolidityBase.UIntBase(value, 184) { + data class UInt184( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 184) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt184(it) }) } } - data class UInt192(val value: BigInteger) : SolidityBase.UIntBase(value, 192) { + data class UInt192( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 192) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt192(it) }) } } - data class UInt200(val value: BigInteger) : SolidityBase.UIntBase(value, 200) { + data class UInt200( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 200) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt200(it) }) } } - data class UInt208(val value: BigInteger) : SolidityBase.UIntBase(value, 208) { + data class UInt208( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 208) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt208(it) }) } } - data class UInt216(val value: BigInteger) : SolidityBase.UIntBase(value, 216) { + data class UInt216( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 216) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt216(it) }) } } - data class UInt224(val value: BigInteger) : SolidityBase.UIntBase(value, 224) { + data class UInt224( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 224) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt224(it) }) } } - data class UInt232(val value: BigInteger) : SolidityBase.UIntBase(value, 232) { + data class UInt232( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 232) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt232(it) }) } } - data class UInt240(val value: BigInteger) : SolidityBase.UIntBase(value, 240) { + data class UInt240( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 240) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt240(it) }) } } - data class UInt248(val value: BigInteger) : SolidityBase.UIntBase(value, 248) { + data class UInt248( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 248) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt248(it) }) } } - data class UInt256(val value: BigInteger) : SolidityBase.UIntBase(value, 256) { + data class UInt256( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 256) { companion object { val DECODER: SolidityBase.UIntBase.Decoder = SolidityBase.UIntBase.Decoder({ UInt256(it) }) } } - data class Int8(val value: BigInteger) : SolidityBase.IntBase(value, 8) { + data class Int8( + val value: BigInteger + ) : SolidityBase.IntBase(value, 8) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int8(it) }) } } - data class Int16(val value: BigInteger) : SolidityBase.IntBase(value, 16) { + data class Int16( + val value: BigInteger + ) : SolidityBase.IntBase(value, 16) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int16(it) }) } } - data class Int24(val value: BigInteger) : SolidityBase.IntBase(value, 24) { + data class Int24( + val value: BigInteger + ) : SolidityBase.IntBase(value, 24) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int24(it) }) } } - data class Int32(val value: BigInteger) : SolidityBase.IntBase(value, 32) { + data class Int32( + val value: BigInteger + ) : SolidityBase.IntBase(value, 32) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int32(it) }) } } - data class Int40(val value: BigInteger) : SolidityBase.IntBase(value, 40) { + data class Int40( + val value: BigInteger + ) : SolidityBase.IntBase(value, 40) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int40(it) }) } } - data class Int48(val value: BigInteger) : SolidityBase.IntBase(value, 48) { + data class Int48( + val value: BigInteger + ) : SolidityBase.IntBase(value, 48) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int48(it) }) } } - data class Int56(val value: BigInteger) : SolidityBase.IntBase(value, 56) { + data class Int56( + val value: BigInteger + ) : SolidityBase.IntBase(value, 56) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int56(it) }) } } - data class Int64(val value: BigInteger) : SolidityBase.IntBase(value, 64) { + data class Int64( + val value: BigInteger + ) : SolidityBase.IntBase(value, 64) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int64(it) }) } } - data class Int72(val value: BigInteger) : SolidityBase.IntBase(value, 72) { + data class Int72( + val value: BigInteger + ) : SolidityBase.IntBase(value, 72) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int72(it) }) } } - data class Int80(val value: BigInteger) : SolidityBase.IntBase(value, 80) { + data class Int80( + val value: BigInteger + ) : SolidityBase.IntBase(value, 80) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int80(it) }) } } - data class Int88(val value: BigInteger) : SolidityBase.IntBase(value, 88) { + data class Int88( + val value: BigInteger + ) : SolidityBase.IntBase(value, 88) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int88(it) }) } } - data class Int96(val value: BigInteger) : SolidityBase.IntBase(value, 96) { + data class Int96( + val value: BigInteger + ) : SolidityBase.IntBase(value, 96) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int96(it) }) } } - data class Int104(val value: BigInteger) : SolidityBase.IntBase(value, 104) { + data class Int104( + val value: BigInteger + ) : SolidityBase.IntBase(value, 104) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int104(it) }) } } - data class Int112(val value: BigInteger) : SolidityBase.IntBase(value, 112) { + data class Int112( + val value: BigInteger + ) : SolidityBase.IntBase(value, 112) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int112(it) }) } } - data class Int120(val value: BigInteger) : SolidityBase.IntBase(value, 120) { + data class Int120( + val value: BigInteger + ) : SolidityBase.IntBase(value, 120) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int120(it) }) } } - data class Int128(val value: BigInteger) : SolidityBase.IntBase(value, 128) { + data class Int128( + val value: BigInteger + ) : SolidityBase.IntBase(value, 128) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int128(it) }) } } - data class Int136(val value: BigInteger) : SolidityBase.IntBase(value, 136) { + data class Int136( + val value: BigInteger + ) : SolidityBase.IntBase(value, 136) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int136(it) }) } } - data class Int144(val value: BigInteger) : SolidityBase.IntBase(value, 144) { + data class Int144( + val value: BigInteger + ) : SolidityBase.IntBase(value, 144) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int144(it) }) } } - data class Int152(val value: BigInteger) : SolidityBase.IntBase(value, 152) { + data class Int152( + val value: BigInteger + ) : SolidityBase.IntBase(value, 152) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int152(it) }) } } - data class Int160(val value: BigInteger) : SolidityBase.IntBase(value, 160) { + data class Int160( + val value: BigInteger + ) : SolidityBase.IntBase(value, 160) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int160(it) }) } } - data class Int168(val value: BigInteger) : SolidityBase.IntBase(value, 168) { + data class Int168( + val value: BigInteger + ) : SolidityBase.IntBase(value, 168) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int168(it) }) } } - data class Int176(val value: BigInteger) : SolidityBase.IntBase(value, 176) { + data class Int176( + val value: BigInteger + ) : SolidityBase.IntBase(value, 176) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int176(it) }) } } - data class Int184(val value: BigInteger) : SolidityBase.IntBase(value, 184) { + data class Int184( + val value: BigInteger + ) : SolidityBase.IntBase(value, 184) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int184(it) }) } } - data class Int192(val value: BigInteger) : SolidityBase.IntBase(value, 192) { + data class Int192( + val value: BigInteger + ) : SolidityBase.IntBase(value, 192) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int192(it) }) } } - data class Int200(val value: BigInteger) : SolidityBase.IntBase(value, 200) { + data class Int200( + val value: BigInteger + ) : SolidityBase.IntBase(value, 200) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int200(it) }) } } - data class Int208(val value: BigInteger) : SolidityBase.IntBase(value, 208) { + data class Int208( + val value: BigInteger + ) : SolidityBase.IntBase(value, 208) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int208(it) }) } } - data class Int216(val value: BigInteger) : SolidityBase.IntBase(value, 216) { + data class Int216( + val value: BigInteger + ) : SolidityBase.IntBase(value, 216) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int216(it) }) } } - data class Int224(val value: BigInteger) : SolidityBase.IntBase(value, 224) { + data class Int224( + val value: BigInteger + ) : SolidityBase.IntBase(value, 224) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int224(it) }) } } - data class Int232(val value: BigInteger) : SolidityBase.IntBase(value, 232) { + data class Int232( + val value: BigInteger + ) : SolidityBase.IntBase(value, 232) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int232(it) }) } } - data class Int240(val value: BigInteger) : SolidityBase.IntBase(value, 240) { + data class Int240( + val value: BigInteger + ) : SolidityBase.IntBase(value, 240) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int240(it) }) } } - data class Int248(val value: BigInteger) : SolidityBase.IntBase(value, 248) { + data class Int248( + val value: BigInteger + ) : SolidityBase.IntBase(value, 248) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int248(it) }) } } - data class Int256(val value: BigInteger) : SolidityBase.IntBase(value, 256) { + data class Int256( + val value: BigInteger + ) : SolidityBase.IntBase(value, 256) { companion object { val DECODER: SolidityBase.IntBase.Decoder = SolidityBase.IntBase.Decoder({ Int256(it) }) } } - class Bytes1(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 1) { + class Bytes1( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 1) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes1(it) }, 1) } } - class Bytes2(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 2) { + class Bytes2( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 2) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes2(it) }, 2) } } - class Bytes3(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 3) { + class Bytes3( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 3) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes3(it) }, 3) } } - class Bytes4(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 4) { + class Bytes4( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 4) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes4(it) }, 4) } } - class Bytes5(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 5) { + class Bytes5( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 5) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes5(it) }, 5) } } - class Bytes6(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 6) { + class Bytes6( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 6) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes6(it) }, 6) } } - class Bytes7(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 7) { + class Bytes7( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 7) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes7(it) }, 7) } } - class Bytes8(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 8) { + class Bytes8( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 8) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes8(it) }, 8) } } - class Bytes9(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 9) { + class Bytes9( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 9) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes9(it) }, 9) } } - class Bytes10(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 10) { + class Bytes10( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 10) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes10(it) }, 10) } } - class Bytes11(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 11) { + class Bytes11( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 11) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes11(it) }, 11) } } - class Bytes12(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 12) { + class Bytes12( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 12) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes12(it) }, 12) } } - class Bytes13(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 13) { + class Bytes13( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 13) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes13(it) }, 13) } } - class Bytes14(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 14) { + class Bytes14( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 14) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes14(it) }, 14) } } - class Bytes15(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 15) { + class Bytes15( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 15) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes15(it) }, 15) } } - class Bytes16(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 16) { + class Bytes16( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 16) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes16(it) }, 16) } } - class Bytes17(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 17) { + class Bytes17( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 17) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes17(it) }, 17) } } - class Bytes18(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 18) { + class Bytes18( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 18) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes18(it) }, 18) } } - class Bytes19(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 19) { + class Bytes19( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 19) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes19(it) }, 19) } } - class Bytes20(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 20) { + class Bytes20( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 20) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes20(it) }, 20) } } - class Bytes21(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 21) { + class Bytes21( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 21) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes21(it) }, 21) } } - class Bytes22(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 22) { + class Bytes22( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 22) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes22(it) }, 22) } } - class Bytes23(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 23) { + class Bytes23( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 23) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes23(it) }, 23) } } - class Bytes24(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 24) { + class Bytes24( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 24) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes24(it) }, 24) } } - class Bytes25(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 25) { + class Bytes25( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 25) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes25(it) }, 25) } } - class Bytes26(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 26) { + class Bytes26( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 26) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes26(it) }, 26) } } - class Bytes27(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 27) { + class Bytes27( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 27) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes27(it) }, 27) } } - class Bytes28(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 28) { + class Bytes28( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 28) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes28(it) }, 28) } } - class Bytes29(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 29) { + class Bytes29( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 29) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes29(it) }, 29) } } - class Bytes30(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 30) { + class Bytes30( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 30) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes30(it) }, 30) } } - class Bytes31(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 31) { + class Bytes31( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 31) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes31(it) }, 31) } } - class Bytes32(val bytes: ByteArray) : SolidityBase.StaticBytes(bytes, 32) { + class Bytes32( + val bytes: ByteArray + ) : SolidityBase.StaticBytes(bytes, 32) { companion object { val DECODER: SolidityBase.StaticBytes.Decoder = SolidityBase.StaticBytes.Decoder({ Bytes32(it) }, 32) } } - data class Address(val value: BigInteger) : SolidityBase.UIntBase(value, 160) { + data class Address( + val value: BigInteger + ) : SolidityBase.UIntBase(value, 160) { companion object { val DECODER: SolidityBase.UIntBase.Decoder
= SolidityBase.UIntBase.Decoder
({ Address(it) }) } } - data class Bool(val value: Boolean) : SolidityBase.UIntBase(if (value) BigInteger.ONE else - BigInteger.ZERO, 8) { + data class Bool( + val value: Boolean + ) : SolidityBase.UIntBase(if (value) BigInteger.ONE else BigInteger.ZERO, 8) { class Decoder : SolidityBase.TypeDecoder { override fun isDynamic(): Boolean = false override fun decode(source: SolidityBase.PartitionData): Bool = @@ -811,7 +1006,9 @@ object Solidity { } } - open class Bytes(val items: ByteArray) : SolidityBase.DynamicType { + open class Bytes( + val items: ByteArray + ) : SolidityBase.DynamicType { init { if (BigInteger(items.size.toString(10)) > BigInteger.valueOf(2).pow(256)) throw Exception() @@ -828,6 +1025,8 @@ object Solidity { return SolidityBase.DynamicType.Parts(length, contents) } + override fun encodePacked(): kotlin.String = items.toHex() + class Decoder : SolidityBase.TypeDecoder { override fun isDynamic(): Boolean = true override fun decode(source: SolidityBase.PartitionData): Bytes = @@ -839,7 +1038,9 @@ object Solidity { } } - data class String(val value: kotlin.String) : Bytes(value.toByteArray()) { + data class String( + val value: kotlin.String + ) : Bytes(value.toByteArray()) { class Decoder : SolidityBase.TypeDecoder { override fun isDynamic(): Boolean = true override fun decode(source: SolidityBase.PartitionData): String = diff --git a/bivrost-solidity-types/src/main/kotlin/pm/gnosis/model/SolidityBase.kt b/bivrost-solidity-types/src/main/kotlin/pm/gnosis/model/SolidityBase.kt index a3b1f9b..bf60b19 100644 --- a/bivrost-solidity-types/src/main/kotlin/pm/gnosis/model/SolidityBase.kt +++ b/bivrost-solidity-types/src/main/kotlin/pm/gnosis/model/SolidityBase.kt @@ -7,17 +7,17 @@ import pm.gnosis.utils.toHex import java.math.BigDecimal import java.math.BigInteger import java.nio.charset.Charset -import java.util.* import kotlin.collections.ArrayList object SolidityBase { const val BYTES_PAD = 32 const val PADDED_HEX_LENGTH = BYTES_PAD * 2 - val dynamicTypes: List = listOf("bytes", "string") + val dynamicTypes: List = listOf("bytes", "string") interface Type { fun encode(): String + fun encodePacked(): String } interface StaticType : Type @@ -27,6 +27,12 @@ object SolidityBase { } abstract class Collection(val items: List) : Type { + + override fun encodePacked(): String { + if (items.any { isDynamic(it) }) throw IllegalArgumentException("Cannot encode dynamic items packed!") + return encodeTuple(items) + } + override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false @@ -45,7 +51,7 @@ object SolidityBase { abstract fun isDynamic(): Boolean } - abstract class UIntBase(private val value: BigInteger, bitLength: kotlin.Int) : StaticType { + abstract class UIntBase(private val value: BigInteger, private val bitLength: Int) : StaticType { init { when { bitLength % 8 != 0 -> throw InvalidBitLengthException.NOT_MULTIPLE_OF_EIGHT @@ -59,6 +65,11 @@ object SolidityBase { return string.padStartMultiple(PADDED_HEX_LENGTH, '0') } + override fun encodePacked(): String { + val string = value.toString(16) + return string.padStart(bitLength / 8 * 2, '0') + } + override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false @@ -86,7 +97,7 @@ object SolidityBase { } - abstract class IntBase(private val value: BigInteger, private val bitLength: kotlin.Int) : StaticType { + abstract class IntBase(private val value: BigInteger, private val bitLength: Int) : StaticType { init { if (bitLength % 8 != 0) throw InvalidBitLengthException.NOT_MULTIPLE_OF_EIGHT val min = BigInteger.valueOf(2).pow(bitLength - 1).negate() @@ -95,16 +106,21 @@ object SolidityBase { if (value < min || value > max) throw IllegalArgumentException("Value is not within bit range [$min, $max]") } - override fun encode(): String { + private fun encodeWithPadding(paddingLength: Int): String { return if (value.signum() == -1) { val bits = value.toString(2).removePrefix("-").padStart(bitLength, '0') val x = bits.map { if (it == '0') '1' else '0' }.joinToString("") - BigInteger(x, 2).add(BigInteger.ONE).toString(16).padStartMultiple(PADDED_HEX_LENGTH, 'f') + BigInteger(x, 2).add(BigInteger.ONE).toString(16).padStartMultiple(paddingLength, 'f') } else { - value.toString(16).padStartMultiple(PADDED_HEX_LENGTH, '0') + value.toString(16).padStartMultiple(paddingLength, '0') } + } + override fun encode(): String = encodeWithPadding(PADDED_HEX_LENGTH) + + override fun encodePacked(): String = encodeWithPadding(bitLength / 8 * 2) + override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false @@ -131,7 +147,7 @@ object SolidityBase { } } - abstract class StaticBytes(val byteArray: ByteArray, nBytes: kotlin.Int) : StaticType { + abstract class StaticBytes(val byteArray: ByteArray, nBytes: Int) : StaticType { init { if (byteArray.size > nBytes) throw IllegalArgumentException("Byte array has ${byteArray.size} bytes. It should have no more than $nBytes bytes.") } @@ -140,6 +156,10 @@ object SolidityBase { return byteArray.toHex().padEnd(PADDED_HEX_LENGTH, '0') } + override fun encodePacked(): String { + return byteArray.toHex() + } + override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false diff --git a/bivrost-solidity-types/src/test/kotlin/pm/gnosis/model/SolidityBaseTest.kt b/bivrost-solidity-types/src/test/kotlin/pm/gnosis/model/SolidityBaseTest.kt index 2f1de42..62a4b59 100644 --- a/bivrost-solidity-types/src/test/kotlin/pm/gnosis/model/SolidityBaseTest.kt +++ b/bivrost-solidity-types/src/test/kotlin/pm/gnosis/model/SolidityBaseTest.kt @@ -27,6 +27,41 @@ class SolidityBaseTest { ) } + @Test + fun testUIntPackedEncoding() { + assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", + Solidity.UInt256(BigInteger.ZERO).encodePacked() + ) + + assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001", + Solidity.UInt256(BigInteger.ONE).encodePacked() + ) + + //Max unsigned integer + assertEquals( + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + Solidity.UInt256(BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935")).encodePacked() + ) + + assertEquals( + "00", + Solidity.UInt8(BigInteger.ZERO).encodePacked() + ) + + assertEquals( + "01", + Solidity.UInt8(BigInteger.ONE).encodePacked() + ) + + //Max unsigned integer + assertEquals( + "ff", + Solidity.UInt8(BigInteger("255")).encodePacked() + ) + } + @Test(expected = IllegalArgumentException::class) fun testNegativeUIntThrowsException() { Solidity.UInt256(BigInteger.valueOf(-1L)) @@ -96,6 +131,20 @@ class SolidityBaseTest { ) } + @Test + fun testBoolPackedEncoding() { + assertEquals( + "00", + Solidity.Bool(false).encodePacked() + ) + + assertEquals( + "01", + Solidity.Bool(true).encodePacked() + ) + } + + @Test fun testBoolDecoding() { assertEquals( @@ -150,6 +199,34 @@ class SolidityBaseTest { ) } + @Test + fun testIntPackedEncoding() { + assertEquals( + "00", + Solidity.Int8(BigInteger.ZERO).encodePacked() + ) + + assertEquals( + "01", + Solidity.Int8(BigInteger.ONE).encodePacked() + ) + + assertEquals( + "ff", + Solidity.Int8(BigInteger.valueOf(-1)).encodePacked() + ) + + assertEquals( + "7f", + Solidity.Int8(BigInteger.valueOf(127)).encodePacked() + ) + + assertEquals( + "80", + Solidity.Int8(BigInteger.valueOf(-128)).encodePacked() + ) + } + @Test fun testIntRange() { (8..256 step 8).forEach { @@ -253,6 +330,29 @@ class SolidityBaseTest { ) } + @Test + fun testStaticBytesPackedEncoding() { + assertEquals( + "00", + Solidity.Bytes1(byteArrayOf(0)).encodePacked() + ) + + assertEquals( + "0001", + Solidity.Bytes2(byteArrayOf(0, 1)).encodePacked() + ) + + assertEquals( + "000102", + Solidity.Bytes3(byteArrayOf(0, 1, 2)).encodePacked() + ) + + assertEquals( + "64617665", + Solidity.Bytes4("dave".toByteArray()).encodePacked() + ) + } + @Test fun testStaticBytesDecoding() { assertArrayEquals(byteArrayOf(0), SolidityBase.decodeStaticBytes("0000000000000000000000000000000000000000000000000000000000000000", 1)) @@ -304,7 +404,7 @@ class SolidityBaseTest { } @Test - fun testDynamicArrayEncoding() { + fun testVectorEncoding() { assertEquals( "000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004560000000000000000000000000000000000000000000000000000000000000789", SolidityBase.Vector(listOf(Solidity.UInt32(BigInteger("456", 16)), Solidity.UInt32(BigInteger("789", 16)))).encode() @@ -321,6 +421,24 @@ class SolidityBaseTest { ) } + @Test + fun testVectorPackedEncoding() { + assertEquals( + "00000000000000000000000000000000000000000000000000000000000004560000000000000000000000000000000000000000000000000000000000000789", + SolidityBase.Vector(listOf(Solidity.UInt32(BigInteger("456", 16)), Solidity.UInt32(BigInteger("789", 16)))).encodePacked() + ) + + assertEquals( + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000", + SolidityBase.Vector(listOf(Solidity.Bool(true), Solidity.Bool(false))).encodePacked() + ) + + assertEquals( + "", + SolidityBase.Vector(emptyList()).encodePacked() + ) + } + @Test fun testZeroLengthArray() { val testData = "" @@ -372,6 +490,24 @@ class SolidityBaseTest { ) } + @Test + fun testFixedArrayPackedEncoding() { + assertEquals( + "00000000000000000000000000000000000000000000000000000000000004560000000000000000000000000000000000000000000000000000000000000789", + TestArray(listOf(Solidity.UInt32(BigInteger("456", 16)), Solidity.UInt32(BigInteger("789", 16))), 2).encodePacked() + ) + + assertEquals( + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000", + TestArray(listOf(Solidity.Bool(true), Solidity.Bool(false)), 2).encodePacked() + ) + + assertEquals( + "00000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000", + TestArray(listOf(Solidity.Bytes1(byteArrayOf()), Solidity.Bytes1(byteArrayOf(1))), 2).encodePacked() + ) + } + @Test fun testFixedArrayDecoding() { val testData = @@ -449,6 +585,34 @@ class SolidityBaseTest { ) } + @Test + fun testDynamicBytesPackedEncoding() { + assertEquals( + "48656c6c6f2c20776f726c6421", + Solidity.Bytes("Hello, world!".toByteArray()).encodePacked() + ) + + assertEquals( + "00", + Solidity.Bytes(byteArrayOf(0)).encodePacked() + ) + + assertEquals( + "0001", + Solidity.Bytes(byteArrayOf(0, 1)).encodePacked() + ) + + assertEquals( + "000102", + Solidity.Bytes(byteArrayOf(0, 1, 2)).encodePacked() + ) + + assertEquals( + "64617665", + Solidity.Bytes("dave".toByteArray()).encodePacked() + ) + } + @Test fun testDynamicBytesDecoding() { assertArrayEquals( @@ -521,7 +685,7 @@ class SolidityBaseTest { assertEquals(SolidityBase.Vector.Decoder(Solidity.UInt32.DECODER).decode(source.subData(offsetUint32s)), items[1]) assertEquals(Solidity.Bytes10.DECODER.decode(source), items[2]) val offsetBytes = BigInteger(source.consume(), 16).intValueExact() - Assert.assertArrayEquals(Solidity.Bytes.DECODER.decode(source.subData(offsetBytes)).items, (items[3] as Solidity.Bytes).items) + assertArrayEquals(Solidity.Bytes.DECODER.decode(source.subData(offsetBytes)).items, (items[3] as Solidity.Bytes).items) } @Test @@ -573,6 +737,24 @@ class SolidityBaseTest { } } + @Test(expected = IllegalArgumentException::class) + fun testDynamicVectorPackedEncoding() { + val items = listOf( + Solidity.String("Hi"), Solidity.String("I"), Solidity.String("want"), + Solidity.String("to"), Solidity.String("learn"), Solidity.String("Solidity") + ) + SolidityBase.Vector(items).encodePacked() + } + + @Test(expected = IllegalArgumentException::class) + fun testDynamicArrayPackedEncoding() { + val items = listOf( + Solidity.String("Hi"), Solidity.String("I"), Solidity.String("want"), + Solidity.String("to"), Solidity.String("learn"), Solidity.String("Solidity") + ) + TestArray(items, 6).encodePacked() + } + @Test fun testStringEncoding() { assertEquals( @@ -581,6 +763,14 @@ class SolidityBaseTest { ) } + @Test + fun testStringPackedEncoding() { + assertEquals( + "48656c6c6f2c20776f726c6421", + Solidity.String("Hello, world!").encodePacked() + ) + } + @Test(expected = Exception::class) fun testMalformedArraySizeDecoding() { assertEquals( @@ -598,7 +788,7 @@ class SolidityBaseTest { val source = SolidityBase.PartitionData.of(ENCODED_MALFORMED_BYTES_TUPLE) // This would be the code generated for a tuple (bytes, string) val bytesOffset = BigInteger(source.consume(), 16).intValueExact() - Assert.assertArrayEquals( + assertArrayEquals( Solidity.Bytes(byteArrayOf()).items, Solidity.Bytes.DECODER.decode(source.subData(bytesOffset)).items ) diff --git a/bivrost-utils/build.gradle b/bivrost-utils/build.gradle index e6e99af..2eb7a68 100644 --- a/bivrost-utils/build.gradle +++ b/bivrost-utils/build.gradle @@ -8,7 +8,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib" implementation "com.squareup:kotlinpoet:${versions.kotlinPoet}" - implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.57' + implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.61' testImplementation group: 'junit', name: 'junit', version: '4.12' } diff --git a/build.gradle b/build.gradle index 8c0fae4..47b4a2a 100644 --- a/build.gradle +++ b/build.gradle @@ -4,8 +4,8 @@ buildscript { 'compileSdk' : 28, 'buildTools' : '28.0.3', - 'kotlin' : '1.3.11', - 'kotlinPoet' : '1.0.1', + 'kotlin' : '1.3.21', + 'kotlinPoet' : '1.4.4', 'moshi' : '1.8.0', 'androidPlugin': '3.3.0', ]