diff --git a/bivrost-abi-parser/build.gradle b/bivrost-abi-parser/build.gradle index 40c42a1..652ff52 100644 --- a/bivrost-abi-parser/build.gradle +++ b/bivrost-abi-parser/build.gradle @@ -2,10 +2,7 @@ apply plugin: 'java' apply plugin: 'kotlin' apply plugin: 'maven' -sourceCompatibility = 1.8 - dependencies { - implementation project(':bivrost-utils') implementation project(':bivrost-solidity-types') @@ -19,13 +16,6 @@ dependencies { testImplementation group: 'junit', name: 'junit', version: '4.12' } -compileKotlin { - kotlinOptions.jvmTarget = "1.8" -} -compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" -} - uploadArchives { repositories { mavenDeployer { @@ -34,7 +24,7 @@ uploadArchives { } } -task sourcesJar(type: Jar, dependsOn:classes) { +task sourcesJar(type: Jar, dependsOn: classes) { from sourceSets.main.allSource classifier = 'sources' } 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 805ba13..5a26077 100644 --- a/bivrost-abi-parser/src/main/kotlin/pm/gnosis/AbiParser.kt +++ b/bivrost-abi-parser/src/main/kotlin/pm/gnosis/AbiParser.kt @@ -5,6 +5,7 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import pm.gnosis.model.* +import pm.gnosis.utils.BigIntegerUtils import pm.gnosis.utils.generateSolidityMethodId import java.io.File import java.math.BigInteger @@ -268,8 +269,10 @@ object AbiParser { val source = if (isSolidityDynamicType(className)) { val dynamicValOffsetName = "$dynamicValName$DECODER_VAR_ARG_OFFSET_SUFFIX" function.addStatement( - "val·$dynamicValOffsetName·=·%T(%L.consume(),·16).intValueExact()", - BigInteger::class.asClassName(), DECODER_VAR_PARTITIONS_NAME + "val·$dynamicValOffsetName·=·%T.exact(%T(%L.consume(),·16))", + BigIntegerUtils::class.asClassName(), + BigInteger::class.asClassName(), + DECODER_VAR_PARTITIONS_NAME ) "%L.subData(%L)" to mutableListOf(DECODER_VAR_PARTITIONS_NAME, dynamicValOffsetName) } else { 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 b6a77f6..b455dda 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 @@ -4,6 +4,7 @@ import java.math.BigInteger import kotlin.String import pm.gnosis.model.Solidity import pm.gnosis.model.SolidityBase +import pm.gnosis.utils.BigIntegerUtils class Abi7 { object Function { @@ -17,7 +18,7 @@ class Abi7 { val source = SolidityBase.PartitionData.of(data) // Add decoders - val arg0Offset = BigInteger(source.consume(), 16).intValueExact() + val arg0Offset = BigIntegerUtils.exact(BigInteger(source.consume(), 16)) val arg0 = Solidity.Bytes.DECODER.decode(source.subData(arg0Offset)) return Return(arg0) 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 d64661c..007e3cb 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 @@ -4,6 +4,7 @@ import java.math.BigInteger import kotlin.String import pm.gnosis.model.Solidity import pm.gnosis.model.SolidityBase +import pm.gnosis.utils.BigIntegerUtils class Abi8 { object Function { @@ -17,7 +18,7 @@ class Abi8 { val source = SolidityBase.PartitionData.of(data) // Add decoders - val arg0Offset = BigInteger(source.consume(), 16).intValueExact() + val arg0Offset = BigIntegerUtils.exact(BigInteger(source.consume(), 16)) val arg0 = Solidity.Bytes.DECODER.decode(source.subData(arg0Offset)) return Return(arg0) 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 49ff8e5..7b75038 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 @@ -7,6 +7,7 @@ import kotlin.Boolean import kotlin.String import pm.gnosis.model.Solidity import pm.gnosis.model.SolidityBase +import pm.gnosis.utils.BigIntegerUtils class Abi9 { object Owners { @@ -23,7 +24,7 @@ class Abi9 { // Add decoders val arg0 = TupleB.DECODER.decode(source) - val arg1Offset = BigInteger(source.consume(), 16).intValueExact() + val arg1Offset = BigIntegerUtils.exact(BigInteger(source.consume(), 16)) val arg1 = SolidityBase.Vector.Decoder(TupleB.DECODER).decode(source.subData(arg1Offset)) return Return(arg0, arg1) @@ -33,9 +34,9 @@ class Abi9 { val source = SolidityBase.PartitionData.of(data) // Add decoders - val arg0Offset = BigInteger(source.consume(), 16).intValueExact() + val arg0Offset = BigIntegerUtils.exact(BigInteger(source.consume(), 16)) val arg0 = SolidityBase.Vector.Decoder(TupleA.DECODER).decode(source.subData(arg0Offset)) - val arg1Offset = BigInteger(source.consume(), 16).intValueExact() + val arg1Offset = BigIntegerUtils.exact(BigInteger(source.consume(), 16)) val arg1 = SolidityBase.Vector.Decoder(SolidityBase.Vector.Decoder(Array7.Decoder(Array5.Decoder(Solidity.UInt256.DECODER)))).decode(source.subData(arg1Offset)) return Arguments(arg0, arg1) @@ -61,7 +62,7 @@ class Abi9 { override fun decode(source: SolidityBase.PartitionData): TupleA { val arg0 = Solidity.UInt256.DECODER.decode(source) val arg1 = Solidity.UInt256.DECODER.decode(source) - val arg2Offset = BigInteger(source.consume(), 16).intValueExact() + val arg2Offset = BigIntegerUtils.exact(BigInteger(source.consume(), 16)) val arg2 = SolidityBase.Vector.Decoder(SolidityBase.Vector.Decoder(Array7.Decoder(Array5.Decoder(Solidity.UInt256.DECODER)))).decode(source.subData(arg2Offset)) return TupleA(arg0, arg1, arg2) } 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 1dff572..e6fa78d 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 @@ -7,6 +7,7 @@ import kotlin.String import kotlin.collections.List import pm.gnosis.model.Solidity import pm.gnosis.model.SolidityBase +import pm.gnosis.utils.BigIntegerUtils class Abi14 { object Events { @@ -20,9 +21,9 @@ class Abi14 { // Decode data val source = SolidityBase.PartitionData.of(data) - val arg0Offset = BigInteger(source.consume(), 16).intValueExact() + val arg0Offset = BigIntegerUtils.exact(BigInteger(source.consume(), 16)) val arg0 = Solidity.Bytes.DECODER.decode(source.subData(arg0Offset)) - val arg1Offset = BigInteger(source.consume(), 16).intValueExact() + val arg1Offset = BigIntegerUtils.exact(BigInteger(source.consume(), 16)) val arg1 = Solidity.String.DECODER.decode(source.subData(arg1Offset)) val arg2 = TupleA.DECODER.decode(source) return Arguments(arg0, arg1, arg2) 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 9cd5d16..de405a4 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 @@ -5,6 +5,7 @@ import kotlin.Boolean import kotlin.String import pm.gnosis.model.Solidity import pm.gnosis.model.SolidityBase +import pm.gnosis.utils.BigIntegerUtils class Abi16 { object Malformed { @@ -18,7 +19,7 @@ class Abi16 { val source = SolidityBase.PartitionData.of(data) // Add decoders - val arg0Offset = BigInteger(source.consume(), 16).intValueExact() + val arg0Offset = BigIntegerUtils.exact(BigInteger(source.consume(), 16)) val arg0 = TupleA.DECODER.decode(source.subData(arg0Offset)) return Arguments(arg0) @@ -36,9 +37,9 @@ class Abi16 { class Decoder : SolidityBase.TypeDecoder { override fun isDynamic(): Boolean = true override fun decode(source: SolidityBase.PartitionData): TupleA { - val arg0Offset = BigInteger(source.consume(), 16).intValueExact() + val arg0Offset = BigIntegerUtils.exact(BigInteger(source.consume(), 16)) val arg0 = Solidity.Bytes.DECODER.decode(source.subData(arg0Offset)) - val arg1Offset = BigInteger(source.consume(), 16).intValueExact() + val arg1Offset = BigIntegerUtils.exact(BigInteger(source.consume(), 16)) val arg1 = Solidity.String.DECODER.decode(source.subData(arg1Offset)) return TupleA(arg0, arg1) } diff --git a/bivrost-gradle-plugin/build.gradle b/bivrost-gradle-plugin/build.gradle index 39a614f..fb7a019 100644 --- a/bivrost-gradle-plugin/build.gradle +++ b/bivrost-gradle-plugin/build.gradle @@ -2,9 +2,6 @@ apply plugin: 'java-library' apply plugin: 'kotlin' apply plugin: 'maven' -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 - dependencies { compileOnly gradleApi() diff --git a/bivrost-solidity-types-generator/build.gradle b/bivrost-solidity-types-generator/build.gradle index 97b89a3..08428d4 100644 --- a/bivrost-solidity-types-generator/build.gradle +++ b/bivrost-solidity-types-generator/build.gradle @@ -2,8 +2,6 @@ apply plugin: 'java' apply plugin: 'kotlin' apply plugin: 'maven' -sourceCompatibility = 1.8 - task runSolidityTypeGenerator(type: JavaExec) { def targetProject = project.parent.childProjects.get("bivrost-solidity-types") ?: project def srcDirs = targetProject.sourceSets.main.kotlin.getSrcDirs() @@ -28,14 +26,6 @@ dependencies { testImplementation group: 'junit', name: 'junit', version: '4.12' } -compileKotlin { - kotlinOptions.jvmTarget = "1.8" -} - -compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" -} - task sourcesJar(type: Jar, dependsOn:classes) { from sourceSets.main.allSource classifier = 'sources' diff --git a/bivrost-solidity-types/build.gradle b/bivrost-solidity-types/build.gradle index ff7d7ca..869a77f 100644 --- a/bivrost-solidity-types/build.gradle +++ b/bivrost-solidity-types/build.gradle @@ -2,21 +2,12 @@ apply plugin: 'java' apply plugin: 'kotlin' apply plugin: 'maven' -sourceCompatibility = 1.8 - dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib" testImplementation group: 'junit', name: 'junit', version: '4.12' } -compileKotlin { - kotlinOptions.jvmTarget = "1.8" -} -compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" -} - uploadArchives { repositories { mavenDeployer { diff --git a/bivrost-solidity-types/src/main/kotlin/pm/gnosis/utils/DataTypeExtensions.kt b/bivrost-solidity-types/src/main/kotlin/pm/gnosis/utils/DataTypeExtensions.kt index 499d101..df94e2c 100644 --- a/bivrost-solidity-types/src/main/kotlin/pm/gnosis/utils/DataTypeExtensions.kt +++ b/bivrost-solidity-types/src/main/kotlin/pm/gnosis/utils/DataTypeExtensions.kt @@ -1,12 +1,13 @@ package pm.gnosis.utils +import java.math.BigInteger import kotlin.experimental.and fun String.padStartMultiple(multiple: Int, padChar: Char = ' ') = - this.padStart(if (this.length % multiple != 0) this.length + multiple - this.length % multiple else 0, padChar) + this.padStart(if (this.length % multiple != 0) this.length + multiple - this.length % multiple else 0, padChar) fun String.padEndMultiple(multiple: Int, padChar: Char = ' ') = - this.padEnd(if (this.length % multiple != 0) this.length + multiple - this.length % multiple else 0, padChar) + this.padEnd(if (this.length % multiple != 0) this.length + multiple - this.length % multiple else 0, padChar) private val hexArray = "0123456789abcdef".toCharArray() @@ -32,3 +33,10 @@ fun String.hexToByteArray(): ByteArray { } return data } + +// Compatibility method for pre Java8 +object BigIntegerUtils { + fun exact(bigInteger: BigInteger): Int = + if (bigInteger.bitLength() <= 31) bigInteger.toInt() + else throw ArithmeticException("BigInteger out of int range") +} diff --git a/bivrost-utils/build.gradle b/bivrost-utils/build.gradle index aeda2f7..e6e99af 100644 --- a/bivrost-utils/build.gradle +++ b/bivrost-utils/build.gradle @@ -2,10 +2,7 @@ apply plugin: 'java' apply plugin: 'kotlin' apply plugin: 'maven' -sourceCompatibility = 1.8 - dependencies { - implementation project(':bivrost-solidity-types') implementation "org.jetbrains.kotlin:kotlin-stdlib" @@ -16,13 +13,6 @@ dependencies { testImplementation group: 'junit', name: 'junit', version: '4.12' } -compileKotlin { - kotlinOptions.jvmTarget = "1.8" -} -compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" -} - uploadArchives { repositories { mavenDeployer {