Skip to content

Commit

Permalink
Update dependencies (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmrsabino authored and rmeissner committed Jan 22, 2019
1 parent 5de310b commit 5508023
Show file tree
Hide file tree
Showing 29 changed files with 676 additions and 455 deletions.
8 changes: 4 additions & 4 deletions bivrost-abi-parser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ dependencies {
implementation project(':bivrost-utils')
implementation project(':bivrost-solidity-types')

implementation deps.kotlin.stdLibJre8
implementation "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin"

implementation "com.squareup.moshi:moshi:${versions.moshi}"
implementation "com.squareup.moshi:moshi-kotlin:${versions.moshi}"
implementation "com.squareup:kotlinpoet:${versions.kotlinPoet}"
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'

testImplementation group: 'junit', name: 'junit', version: '4.12'
Expand Down
243 changes: 138 additions & 105 deletions bivrost-abi-parser/src/main/kotlin/pm/gnosis/AbiParser.kt

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions bivrost-abi-parser/src/main/kotlin/pm/gnosis/EventParser.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pm.gnosis

import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import pm.gnosis.AbiParser.context
import pm.gnosis.model.AbiElementJson
import pm.gnosis.model.ParameterJson
Expand All @@ -22,8 +23,8 @@ internal object EventParser {
}

context.root.abi.filter { it.type == ABI_SPEC_EVENT_TYPE }
.map { generateEventObject(it) }
.forEach { eventsObject.addType(it) }
.map { generateEventObject(it) }
.forEach { eventsObject.addType(it) }

return eventsObject.build()
}
Expand All @@ -50,7 +51,7 @@ internal object EventParser {
val topicElements = abiElementJson.inputs.filter { it.indexed }
val dataElements = abiElementJson.inputs.filter { !it.indexed }

funSpec.addParameter(TOPIC_ARG_NAME, ParameterizedTypeName.get(List::class, String::class))
funSpec.addParameter(TOPIC_ARG_NAME, List::class.asClassName().parameterizedBy(String::class.asClassName()))
funSpec.addCode(generateTopicsDecoderCodeBlock(topicElements, abiElementJson.anonymous))

if (dataElements.isNotEmpty()) {
Expand Down Expand Up @@ -85,18 +86,21 @@ internal object EventParser {
val codeBlock = CodeBlock.builder()
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)
codeBlock.addStatement(
"if·($TOPIC_ARG_NAME.first()·!=·$EVENT_ID_PROPERTY_NAME)·throw·%1T(\"topics[0]·does·not·match·event·id\")",
IllegalArgumentException::class
)
}

indexedParameters.forEachIndexed { index, topic ->
val typeHolder = mapType(topic, context)
if (typeHolder.isHashTopic(topic)) {
codeBlock.addStatement("val t${index + 1} = $TOPIC_ARG_NAME[${index + 1}]")
codeBlock.addStatement("val·t${index + 1}·=·$TOPIC_ARG_NAME[${index + 1}]")
} else {
val sourceName = "source${index + 1}"
codeBlock
.addStatement("val $sourceName = %1T.of($TOPIC_ARG_NAME[${index + 1}])", SolidityBase.PartitionData::class)
.addStatement("val t${index + 1} = %1T.DECODER.decode(%2L)", typeHolder.toTypeName(), sourceName)
.addStatement("val·$sourceName·=·%1T.of($TOPIC_ARG_NAME[${index + 1}])", SolidityBase.PartitionData::class)
.addStatement("val·t${index + 1}·=·%1T.DECODER.decode(%2L)", typeHolder.toTypeName(), sourceName)
}
}

Expand All @@ -108,7 +112,10 @@ internal object EventParser {

codeBlock.apply {
addStatement("// Decode data")
addStatement("val ${AbiParser.DECODER_VAR_PARTITIONS_NAME} = %1T.of(${AbiParser.DECODER_FUN_ARG_NAME})", SolidityBase.PartitionData::class)
addStatement(
"val·${AbiParser.DECODER_VAR_PARTITIONS_NAME}·=·%1T.of(${AbiParser.DECODER_FUN_ARG_NAME})",
SolidityBase.PartitionData::class
)
add(AbiParser.generateParameterDecoderCode(nonIndexedParameters))
}

Expand Down Expand Up @@ -138,5 +145,5 @@ internal object EventParser {

// Indexed arrays, strings and bytes and tuples only have the keccak hash
private fun TypeHolder.isHashTopic(parameterJson: ParameterJson) =
parameterJson.indexed && (this is TupleTypeHolder || this is CollectionTypeHolder || isDynamic())
parameterJson.indexed && (this is TupleTypeHolder || this is CollectionTypeHolder || isDynamic())
}
16 changes: 9 additions & 7 deletions bivrost-abi-parser/src/main/kotlin/pm/gnosis/TypeHolders.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pm.gnosis

import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.ParameterizedTypeName
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.TypeName
import com.squareup.kotlinpoet.asClassName
import org.bouncycastle.crypto.digests.KeccakDigest
Expand Down Expand Up @@ -47,16 +47,17 @@ internal abstract class CollectionTypeHolder(val listType: ClassName, val itemTy
override fun hash() = generateHash(listOf(listType.toString(), itemType.hash()))
}

internal class ArrayTypeHolder(arraysMap: AbiParser.ArraysMap, itemType: TypeHolder, val capacity: Int) : CollectionTypeHolder(arraysMap.get(capacity), itemType) {
internal class ArrayTypeHolder(arraysMap: AbiParser.ArraysMap, itemType: TypeHolder, val capacity: Int) :
CollectionTypeHolder(arraysMap.get(capacity), itemType) {

override fun toTypeName() = ParameterizedTypeName.get(listType, itemType.toTypeName())
override fun toTypeName() = listType.parameterizedBy(itemType.toTypeName())

override fun isDynamic() = capacity > 0 && itemType.isDynamic()
}

internal class VectorTypeHolder(itemType: TypeHolder) : CollectionTypeHolder(SolidityBase.Vector::class.asClassName(), itemType) {

override fun toTypeName() = ParameterizedTypeName.get(listType, itemType.toTypeName())
override fun toTypeName() = listType.parameterizedBy(itemType.toTypeName())

override fun isDynamic() = true
}
Expand All @@ -73,7 +74,7 @@ internal class TupleTypeHolder(index: Int, val entries: List<Pair<String, TypeHo
}

internal fun checkType(type: String): String {
return Solidity.aliases.getOrElse(type, { type })
return Solidity.aliases.getOrElse(type) { type }
}

internal fun mapType(parameter: ParameterJson, context: AbiParser.GeneratorContext): TypeHolder {
Expand All @@ -82,7 +83,8 @@ internal fun mapType(parameter: ParameterJson, context: AbiParser.GeneratorConte
throw IllegalArgumentException("Invalid parameter definition: ${parameter.type}!")
}
val arrayType = matcher.group(1)
val baseType = SimpleTypeHolder.forType(arrayType) ?: generateTuple(arrayType, parameter, context) ?: throw IllegalArgumentException("Unknown parameter ${parameter.type}!")
val baseType = SimpleTypeHolder.forType(arrayType) ?: generateTuple(arrayType, parameter, context)
?: throw IllegalArgumentException("Unknown parameter ${parameter.type}!")
val arrayDef = matcher.group(2)
if (arrayType.length < parameter.type.length && arrayDef.isNullOrBlank()) {
throw IllegalArgumentException("Invalid parameter definition: ${parameter.type}!")
Expand All @@ -98,7 +100,7 @@ private fun generateTuple(type: String, parameters: ParameterJson, context: AbiP
Pair(if (param.name.isEmpty()) "param$index" else param.name.toLowerCase(), mapType(param, context))
}
val tupleTypeHolder = TupleTypeHolder(context.tuples.size, entries)
return context.tuples.getOrPut(tupleTypeHolder.hash(), { tupleTypeHolder })
return context.tuples.getOrPut(tupleTypeHolder.hash()) { tupleTypeHolder }
}

private fun parseArrayDefinition(arrayDef: String, innerType: TypeHolder, context: AbiParser.GeneratorContext): TypeHolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Abi1 {
object Function {
const val METHOD_ID: String = "9d96e2df"

fun encode(): String = "0x" + METHOD_ID
fun encode(): String {
return "0x" + METHOD_ID
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Abi2 {
object Function {
const val METHOD_ID: String = "9d96e2df"

fun encode(): String = "0x" + METHOD_ID
fun encode(): String {
return "0x" + METHOD_ID
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Abi3 {
object Function {
const val METHOD_ID: String = "9d96e2df"

fun encode(): String = "0x" + METHOD_ID
fun encode(): String {
return "0x" + METHOD_ID
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Abi5 {
object Function {
const val METHOD_ID: String = "9d96e2df"

fun encode(): String = "0x" + METHOD_ID
fun encode(): String {
return "0x" + METHOD_ID
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class Abi6 {
object Function {
const val METHOD_ID: String = "06da0736"

fun encode(owner: Solidity.Address): String = "0x" + METHOD_ID + pm.gnosis.model.SolidityBase.encodeFunctionArguments(owner)
fun encode(owner: Solidity.Address): String {
return "0x" + METHOD_ID + pm.gnosis.model.SolidityBase.encodeFunctionArguments(owner)
}

fun decodeArguments(data: String): Arguments {
val source = SolidityBase.PartitionData.of(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class Abi7 {
object Function {
const val METHOD_ID: String = "06da0736"

fun encode(owner: Solidity.Address): String = "0x" + METHOD_ID + pm.gnosis.model.SolidityBase.encodeFunctionArguments(owner)
fun encode(owner: Solidity.Address): String {
return "0x" + METHOD_ID + pm.gnosis.model.SolidityBase.encodeFunctionArguments(owner)
}

fun decode(data: String): Return {
val source = SolidityBase.PartitionData.of(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class Abi8 {
object Function {
const val METHOD_ID: String = "06da0736"

fun encode(arg1: Solidity.Address): String = "0x" + METHOD_ID + pm.gnosis.model.SolidityBase.encodeFunctionArguments(arg1)
fun encode(arg1: Solidity.Address): String {
return "0x" + METHOD_ID + pm.gnosis.model.SolidityBase.encodeFunctionArguments(arg1)
}

fun decode(data: String): Return {
val source = SolidityBase.PartitionData.of(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class Abi9 {
object Owners {
const val METHOD_ID: String = "9f767eb7"

fun encode(c: SolidityBase.Vector<TupleA>, arg2: SolidityBase.Vector<SolidityBase.Vector<Array7<Array5<Solidity.UInt256>>>>): String = "0x" + METHOD_ID + pm.gnosis.model.SolidityBase.encodeFunctionArguments(c, arg2)
fun encode(c: SolidityBase.Vector<TupleA>, arg2:
SolidityBase.Vector<SolidityBase.Vector<Array7<Array5<Solidity.UInt256>>>>): String
{
return "0x" + METHOD_ID + pm.gnosis.model.SolidityBase.encodeFunctionArguments(c, arg2)
}

fun decode(data: String): Return {
val source = SolidityBase.PartitionData.of(data)
Expand All @@ -39,15 +43,18 @@ class Abi9 {

data class Return(val param0: TupleB, val param1: SolidityBase.Vector<TupleB>)

data class Arguments(val c: SolidityBase.Vector<TupleA>, val param1: SolidityBase.Vector<SolidityBase.Vector<Array7<Array5<Solidity.UInt256>>>>)
data class Arguments(val c: SolidityBase.Vector<TupleA>, val param1:
SolidityBase.Vector<SolidityBase.Vector<Array7<Array5<Solidity.UInt256>>>>)
}

data class TupleA(
val a: Solidity.UInt256,
val b: Solidity.UInt256,
val param2: SolidityBase.Vector<SolidityBase.Vector<Array7<Array5<Solidity.UInt256>>>>
val a: Solidity.UInt256,
val b: Solidity.UInt256,
val param2: SolidityBase.Vector<SolidityBase.Vector<Array7<Array5<Solidity.UInt256>>>>
) : SolidityBase.DynamicType {
override fun encode(): String = SolidityBase.encodeFunctionArguments(a, b, param2)
override fun encode(): String {
return SolidityBase.encodeFunctionArguments(a, b, param2)
}

class Decoder : SolidityBase.TypeDecoder<TupleA> {
override fun isDynamic(): Boolean = true
Expand All @@ -59,13 +66,16 @@ class Abi9 {
return TupleA(arg0, arg1, arg2)
}
}

companion object {
val DECODER: Decoder = Decoder()
}
}

data class TupleB(val x: Solidity.UInt256, val y: Solidity.UInt256) : SolidityBase.StaticType {
override fun encode(): String = SolidityBase.encodeFunctionArguments(x, y)
override fun encode(): String {
return SolidityBase.encodeFunctionArguments(x, y)
}

class Decoder : SolidityBase.TypeDecoder<TupleB> {
override fun isDynamic(): Boolean = false
Expand All @@ -75,6 +85,7 @@ class Abi9 {
return TupleB(arg0, arg1)
}
}

companion object {
val DECODER: Decoder = Decoder()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import kotlin.collections.List
import pm.gnosis.model.SolidityBase

class Array5<T : SolidityBase.Type>(items: List<T>) : SolidityBase.Array<T>(items, 5) {
class Decoder<T : SolidityBase.Type>(val itemDecoder: SolidityBase.TypeDecoder<T>) : SolidityBase.TypeDecoder<Array5<T>> {
class Decoder<T : SolidityBase.Type>(val itemDecoder: SolidityBase.TypeDecoder<T>) :
SolidityBase.TypeDecoder<Array5<T>> {
override fun isDynamic(): Boolean = itemDecoder.isDynamic()
override fun decode(source: SolidityBase.PartitionData): Array5<T> = Array5(SolidityBase.decodeList(source, 5, itemDecoder))
override fun decode(source: SolidityBase.PartitionData): Array5<T> {
return Array5(SolidityBase.decodeList(source, 5, itemDecoder))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import kotlin.collections.List
import pm.gnosis.model.SolidityBase

class Array7<T : SolidityBase.Type>(items: List<T>) : SolidityBase.Array<T>(items, 7) {
class Decoder<T : SolidityBase.Type>(val itemDecoder: SolidityBase.TypeDecoder<T>) : SolidityBase.TypeDecoder<Array7<T>> {
class Decoder<T : SolidityBase.Type>(val itemDecoder: SolidityBase.TypeDecoder<T>) :
SolidityBase.TypeDecoder<Array7<T>> {
override fun isDynamic(): Boolean = itemDecoder.isDynamic()
override fun decode(source: SolidityBase.PartitionData): Array7<T> = Array7(SolidityBase.decodeList(source, 7, itemDecoder))
override fun decode(source: SolidityBase.PartitionData): Array7<T> {
return Array7(SolidityBase.decodeList(source, 7, itemDecoder))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import kotlin.String
class Abi10 {
object Events {
object Executed {
const val EVENT_ID: String = "31a38c898682b31869cf766157e0c918f2026132f81da53d2220a90addbdd887"
const val EVENT_ID: String =
"31a38c898682b31869cf766157e0c918f2026132f81da53d2220a90addbdd887"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import pm.gnosis.model.SolidityBase
class Abi11 {
object Events {
object Submission {
const val EVENT_ID: String = "c0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e51"
const val EVENT_ID: String =
"c0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e51"

fun decode(topics: List<String>): Arguments {
// Decode topics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import pm.gnosis.model.SolidityBase
class Abi12 {
object Events {
object Submission {
const val EVENT_ID: String = "c0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e51"
const val EVENT_ID: String =
"c0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e51"

fun decode(topics: List<String>, data: String): Arguments {
// Decode topics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import pm.gnosis.model.SolidityBase
class Abi13 {
object Events {
object Submission {
const val EVENT_ID: String = "0c5212e9d002fa3e0c9bd8c78b6d4df3e94f4e956761bd40f0859c979600a2e7"
const val EVENT_ID: String =
"0c5212e9d002fa3e0c9bd8c78b6d4df3e94f4e956761bd40f0859c979600a2e7"

fun decode(topics: List<String>): Arguments {
// Decode topics
Expand All @@ -22,15 +23,17 @@ class Abi13 {
}

data class Arguments(
val bytesHash: String,
val stringHash: String,
val tupleHash: String
val bytesHash: String,
val stringHash: String,
val tupleHash: String
)
}
}

data class TupleA(val x: Solidity.UInt256, val y: Solidity.UInt256) : SolidityBase.StaticType {
override fun encode(): String = SolidityBase.encodeFunctionArguments(x, y)
override fun encode(): String {
return SolidityBase.encodeFunctionArguments(x, y)
}

class Decoder : SolidityBase.TypeDecoder<TupleA> {
override fun isDynamic(): Boolean = false
Expand All @@ -40,6 +43,7 @@ class Abi13 {
return TupleA(arg0, arg1)
}
}

companion object {
val DECODER: Decoder = Decoder()
}
Expand Down
Loading

0 comments on commit 5508023

Please sign in to comment.