diff --git a/erc20kit/src/main/java/io/horizontalsystems/erc20kit/decorations/ApproveEip20Decoration.kt b/erc20kit/src/main/java/io/horizontalsystems/erc20kit/decorations/ApproveEip20Decoration.kt index 8e3e6503..0317e84c 100644 --- a/erc20kit/src/main/java/io/horizontalsystems/erc20kit/decorations/ApproveEip20Decoration.kt +++ b/erc20kit/src/main/java/io/horizontalsystems/erc20kit/decorations/ApproveEip20Decoration.kt @@ -10,10 +10,9 @@ class ApproveEip20Decoration( val contractAddress: Address, val spender: Address, val value: BigInteger -) : TransactionDecoration() { +) : TransactionDecoration { - override fun tags(): List = - listOf(contractAddress.hex, TransactionTag.EIP20_APPROVE) + override fun tags() = listOf(contractAddress.hex, TransactionTag.EIP20_APPROVE) companion object { val signature = ContractEvent( diff --git a/erc20kit/src/main/java/io/horizontalsystems/erc20kit/decorations/OutgoingEip20Decoration.kt b/erc20kit/src/main/java/io/horizontalsystems/erc20kit/decorations/OutgoingEip20Decoration.kt index 4ec320d4..8098be38 100644 --- a/erc20kit/src/main/java/io/horizontalsystems/erc20kit/decorations/OutgoingEip20Decoration.kt +++ b/erc20kit/src/main/java/io/horizontalsystems/erc20kit/decorations/OutgoingEip20Decoration.kt @@ -12,9 +12,14 @@ class OutgoingEip20Decoration( val value: BigInteger, val sentToSelf: Boolean, val tokenInfo: TokenInfo? -) : TransactionDecoration() { +) : TransactionDecoration { - override fun tags(): List = - listOf(contractAddress.hex, TransactionTag.EIP20_TRANSFER, TransactionTag.tokenOutgoing(contractAddress.hex), TransactionTag.OUTGOING) + override fun tags() = listOf( + contractAddress.hex, + TransactionTag.EIP20_TRANSFER, + TransactionTag.tokenOutgoing(contractAddress.hex), + TransactionTag.OUTGOING, + TransactionTag.toAddress(to.hex) + ) } diff --git a/erc20kit/src/main/java/io/horizontalsystems/erc20kit/events/TransferEventInstance.kt b/erc20kit/src/main/java/io/horizontalsystems/erc20kit/events/TransferEventInstance.kt index 7ed14bb4..cecebd13 100644 --- a/erc20kit/src/main/java/io/horizontalsystems/erc20kit/events/TransferEventInstance.kt +++ b/erc20kit/src/main/java/io/horizontalsystems/erc20kit/events/TransferEventInstance.kt @@ -24,6 +24,9 @@ class TransferEventInstance( tags.add(TransactionTag.INCOMING) } + tags.add(TransactionTag.fromAddress(from.hex)) + tags.add(TransactionTag.toAddress(to.hex)) + return tags } diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/TransactionManager.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/TransactionManager.kt index c3e18fd3..a909f4f5 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/TransactionManager.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/TransactionManager.kt @@ -1,7 +1,12 @@ package io.horizontalsystems.ethereumkit.core import io.horizontalsystems.ethereumkit.decorations.DecorationManager -import io.horizontalsystems.ethereumkit.models.* +import io.horizontalsystems.ethereumkit.models.Address +import io.horizontalsystems.ethereumkit.models.FullRpcTransaction +import io.horizontalsystems.ethereumkit.models.FullTransaction +import io.horizontalsystems.ethereumkit.models.Transaction +import io.horizontalsystems.ethereumkit.models.TransactionData +import io.horizontalsystems.ethereumkit.models.TransactionTag import io.reactivex.BackpressureStrategy import io.reactivex.Flowable import io.reactivex.Single @@ -91,12 +96,15 @@ class TransactionManager( val fullTransactions = decorationManager.decorateTransactions(transactions + failedTransactions) val transactionWithTags = mutableListOf() - val allTags: MutableList = mutableListOf() + val allTags = mutableListOf() fullTransactions.forEach { fullTransaction -> - val tags = fullTransaction.decoration.tags().map { TransactionTag(it, fullTransaction.transaction.hash) } - allTags.addAll(tags) - transactionWithTags.add(TransactionWithTags(fullTransaction, tags.map { it.name })) + val tags = fullTransaction.decoration.tags() + val transactionHash = fullTransaction.transaction.hash + val transactionTags = tags.map { TransactionTag(it, transactionHash) } + + allTags.addAll(transactionTags) + transactionWithTags.add(TransactionWithTags(fullTransaction, tags)) } storage.saveTags(allTags) diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/storage/TransactionDatabase.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/storage/TransactionDatabase.kt index 441f0776..279afd37 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/storage/TransactionDatabase.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/storage/TransactionDatabase.kt @@ -1,7 +1,11 @@ package io.horizontalsystems.ethereumkit.core.storage import android.content.Context -import androidx.room.* +import androidx.room.Database +import androidx.room.Room +import androidx.room.RoomDatabase +import androidx.room.TypeConverter +import androidx.room.TypeConverters import io.horizontalsystems.ethereumkit.api.storage.RoomTypeConverters import io.horizontalsystems.ethereumkit.models.InternalTransaction import io.horizontalsystems.ethereumkit.models.Transaction @@ -15,7 +19,7 @@ import io.horizontalsystems.ethereumkit.models.TransactionTag TransactionTag::class, TransactionSyncerState::class ], - version = 12, + version = 13, exportSchema = false ) @TypeConverters(RoomTypeConverters::class, TransactionDatabase.TypeConverters::class) diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/ContractCreationDecoration.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/ContractCreationDecoration.kt index e78b6cb3..be16e277 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/ContractCreationDecoration.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/ContractCreationDecoration.kt @@ -1,7 +1,5 @@ package io.horizontalsystems.ethereumkit.decorations -class ContractCreationDecoration : TransactionDecoration() { - - override fun tags(): List = listOf("contractCreation") - +class ContractCreationDecoration : TransactionDecoration { + override fun tags() = listOf("contractCreation") } diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/IncomingDecoration.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/IncomingDecoration.kt index 6fa74996..b37079e7 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/IncomingDecoration.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/IncomingDecoration.kt @@ -7,9 +7,13 @@ import java.math.BigInteger class IncomingDecoration( val from: Address, val value: BigInteger -) : TransactionDecoration() { +) : TransactionDecoration { - override fun tags(): List = - listOf(TransactionTag.EVM_COIN, TransactionTag.EVM_COIN_INCOMING, TransactionTag.INCOMING) + override fun tags() = listOf( + TransactionTag.EVM_COIN, + TransactionTag.EVM_COIN_INCOMING, + TransactionTag.INCOMING, + TransactionTag.fromAddress(from.hex) + ) } diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/OutgoingDecoration.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/OutgoingDecoration.kt index fc8c4a1e..e4781d02 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/OutgoingDecoration.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/OutgoingDecoration.kt @@ -8,16 +8,16 @@ class OutgoingDecoration( val to: Address, val value: BigInteger, val sentToSelf: Boolean -) : TransactionDecoration() { +) : TransactionDecoration { - override fun tags(): List { - val tags = mutableListOf(TransactionTag.EVM_COIN, TransactionTag.EVM_COIN_OUTGOING, TransactionTag.OUTGOING) + override fun tags() = buildList { + addAll(listOf(TransactionTag.EVM_COIN, TransactionTag.EVM_COIN_OUTGOING, TransactionTag.OUTGOING)) if (sentToSelf) { - tags += listOf(TransactionTag.EVM_COIN_INCOMING, TransactionTag.INCOMING) + addAll(listOf(TransactionTag.EVM_COIN_INCOMING, TransactionTag.INCOMING)) } - return tags + add(TransactionTag.toAddress(to.hex)) } } diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/TransactionDecoration.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/TransactionDecoration.kt index e0e4d527..c9333194 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/TransactionDecoration.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/TransactionDecoration.kt @@ -1,5 +1,5 @@ package io.horizontalsystems.ethereumkit.decorations -open class TransactionDecoration { - open fun tags(): List = listOf() +interface TransactionDecoration { + fun tags(): List } diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/UnknownTransactionDecoration.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/UnknownTransactionDecoration.kt index 1224f51c..b1c69060 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/UnknownTransactionDecoration.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/decorations/UnknownTransactionDecoration.kt @@ -13,48 +13,37 @@ open class UnknownTransactionDecoration( private val value: BigInteger?, open val internalTransactions: List, open val eventInstances: List -) : TransactionDecoration() { +) : TransactionDecoration { - override fun tags(): List = (tagsFromInternalTransactions + tagsFromEventInstances).toSet().toList() + override fun tags(): List = (tagsFromInternalTransactions + tagsFromEventInstances).distinct() - private val tagsFromInternalTransactions: List - get() { - var outgoingValue = if (fromAddress == userAddress) value ?: BigInteger.ZERO else BigInteger.ZERO - for (internalTx in internalTransactions.filter { it.from == userAddress }) { - outgoingValue += internalTx.value - } - - var incomingValue = if (toAddress == userAddress) value ?: BigInteger.ZERO else BigInteger.ZERO - for (internalTx in internalTransactions.filter { it.to == userAddress }) { - incomingValue += internalTx.value - } + private val tagsFromInternalTransactions: List by lazy { + val incomingTxs = internalTransactions.filter { it.to == userAddress } + val outgoingTxs = internalTransactions.filter { it.from == userAddress } - if (incomingValue == BigInteger.ZERO && outgoingValue == BigInteger.ZERO) return listOf() - - val tags = mutableListOf(TransactionTag.EVM_COIN) - - if (incomingValue > outgoingValue) { - tags.add(TransactionTag.EVM_COIN_INCOMING) - tags.add(TransactionTag.INCOMING) - } + var incomingValue = incomingTxs.sumOf { it.value } + var outgoingValue = outgoingTxs.sumOf { it.value } - if (outgoingValue > incomingValue) { - tags.add(TransactionTag.EVM_COIN_OUTGOING) - tags.add(TransactionTag.OUTGOING) + value?.let { + when (userAddress) { + toAddress -> incomingValue += value + fromAddress -> outgoingValue += value } - - return tags } - private val tagsFromEventInstances: List - get() { - val tags: MutableList = mutableListOf() - - for (eventInstance in eventInstances) { - tags.addAll(eventInstance.tags(userAddress)) + when { + incomingValue > outgoingValue -> { + listOf(TransactionTag.EVM_COIN_INCOMING, TransactionTag.INCOMING) } - - return tags + incomingValue < outgoingValue -> { + listOf(TransactionTag.EVM_COIN_OUTGOING, TransactionTag.OUTGOING) + } + else -> listOf() } + } + + private val tagsFromEventInstances: List by lazy { + eventInstances.map { it.tags(userAddress) }.flatten() + } } \ No newline at end of file diff --git a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/models/TransactionTag.kt b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/models/TransactionTag.kt index 1300f3ba..c886504f 100644 --- a/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/models/TransactionTag.kt +++ b/ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/models/TransactionTag.kt @@ -20,6 +20,9 @@ class TransactionTag( fun tokenIncoming(contractAddress: String): String = "${contractAddress}_$INCOMING" fun tokenOutgoing(contractAddress: String): String = "${contractAddress}_$OUTGOING" + + fun fromAddress(address: String): String = "from_$address" + fun toAddress(address: String): String = "to_$address" } } diff --git a/nftkit/src/main/java/io/horizontalsystems/nftkit/decorations/OutgoingEip1155Decoration.kt b/nftkit/src/main/java/io/horizontalsystems/nftkit/decorations/OutgoingEip1155Decoration.kt index a95a322d..e89812f0 100644 --- a/nftkit/src/main/java/io/horizontalsystems/nftkit/decorations/OutgoingEip1155Decoration.kt +++ b/nftkit/src/main/java/io/horizontalsystems/nftkit/decorations/OutgoingEip1155Decoration.kt @@ -13,10 +13,15 @@ class OutgoingEip1155Decoration( val value: BigInteger, val sentToSelf: Boolean, val tokenInfo: TokenInfo?, -) : TransactionDecoration() { +) : TransactionDecoration { - override fun tags(): List = - listOf(contractAddress.hex, EIP1155_TRANSFER, TransactionTag.tokenOutgoing(contractAddress.hex), TransactionTag.OUTGOING) + override fun tags() = listOf( + contractAddress.hex, + EIP1155_TRANSFER, + TransactionTag.tokenOutgoing(contractAddress.hex), + TransactionTag.OUTGOING, + TransactionTag.toAddress(to.hex) + ) companion object { const val EIP1155_TRANSFER = "eip1155Transfer" diff --git a/nftkit/src/main/java/io/horizontalsystems/nftkit/decorations/OutgoingEip721Decoration.kt b/nftkit/src/main/java/io/horizontalsystems/nftkit/decorations/OutgoingEip721Decoration.kt index c49bff1f..299dbf6f 100644 --- a/nftkit/src/main/java/io/horizontalsystems/nftkit/decorations/OutgoingEip721Decoration.kt +++ b/nftkit/src/main/java/io/horizontalsystems/nftkit/decorations/OutgoingEip721Decoration.kt @@ -12,10 +12,15 @@ class OutgoingEip721Decoration( val tokenId: BigInteger, val sentToSelf: Boolean, val tokenInfo: TokenInfo?, -) : TransactionDecoration() { +) : TransactionDecoration { - override fun tags(): List = - listOf(contractAddress.hex, EIP721_TRANSFER, TransactionTag.tokenOutgoing(contractAddress.hex), TransactionTag.OUTGOING) + override fun tags() = listOf( + contractAddress.hex, + EIP721_TRANSFER, + TransactionTag.tokenOutgoing(contractAddress.hex), + TransactionTag.OUTGOING, + TransactionTag.toAddress(to.hex) + ) companion object { const val EIP721_TRANSFER = "eip721Transfer" diff --git a/nftkit/src/main/java/io/horizontalsystems/nftkit/events/Eip1155TransferEventInstance.kt b/nftkit/src/main/java/io/horizontalsystems/nftkit/events/Eip1155TransferEventInstance.kt index 45c14c78..6f33ba63 100644 --- a/nftkit/src/main/java/io/horizontalsystems/nftkit/events/Eip1155TransferEventInstance.kt +++ b/nftkit/src/main/java/io/horizontalsystems/nftkit/events/Eip1155TransferEventInstance.kt @@ -3,6 +3,7 @@ package io.horizontalsystems.nftkit.events import io.horizontalsystems.ethereumkit.contracts.ContractEvent import io.horizontalsystems.ethereumkit.contracts.ContractEventInstance import io.horizontalsystems.ethereumkit.models.Address +import io.horizontalsystems.ethereumkit.models.TransactionTag import io.horizontalsystems.nftkit.models.TokenInfo import java.math.BigInteger @@ -20,14 +21,17 @@ class Eip1155TransferEventInstance( add(contractAddress.hex) if (from == userAddress) { - add("${contractAddress.hex}_outgoing") - add("outgoing") + add(TransactionTag.tokenOutgoing(contractAddress.hex)) + add(TransactionTag.OUTGOING) } if (to == userAddress) { - add("${contractAddress.hex}_incoming") - add("incoming") + add(TransactionTag.tokenIncoming(contractAddress.hex)) + add(TransactionTag.INCOMING) } + + add(TransactionTag.fromAddress(from.hex)) + add(TransactionTag.toAddress(to.hex)) } } diff --git a/nftkit/src/main/java/io/horizontalsystems/nftkit/events/Eip721TransferEventInstance.kt b/nftkit/src/main/java/io/horizontalsystems/nftkit/events/Eip721TransferEventInstance.kt index 689401a7..b7172e9e 100644 --- a/nftkit/src/main/java/io/horizontalsystems/nftkit/events/Eip721TransferEventInstance.kt +++ b/nftkit/src/main/java/io/horizontalsystems/nftkit/events/Eip721TransferEventInstance.kt @@ -3,6 +3,7 @@ package io.horizontalsystems.nftkit.events import io.horizontalsystems.ethereumkit.contracts.ContractEvent import io.horizontalsystems.ethereumkit.contracts.ContractEventInstance import io.horizontalsystems.ethereumkit.models.Address +import io.horizontalsystems.ethereumkit.models.TransactionTag import io.horizontalsystems.nftkit.models.TokenInfo import java.math.BigInteger @@ -18,14 +19,17 @@ class Eip721TransferEventInstance( add(contractAddress.hex) if (from == userAddress) { - add("${contractAddress.hex}_outgoing") - add("outgoing") + add(TransactionTag.tokenOutgoing(contractAddress.hex)) + add(TransactionTag.OUTGOING) } if (to == userAddress) { - add("${contractAddress.hex}_incoming") - add("incoming") + add(TransactionTag.tokenIncoming(contractAddress.hex)) + add(TransactionTag.INCOMING) } + + add(TransactionTag.fromAddress(from.hex)) + add(TransactionTag.toAddress(to.hex)) } companion object { diff --git a/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchDecoration.kt b/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchDecoration.kt index 98c7c2c1..491ff172 100644 --- a/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchDecoration.kt +++ b/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchDecoration.kt @@ -8,7 +8,7 @@ import java.math.BigInteger abstract class OneInchDecoration( open val contractAddress: Address -) : TransactionDecoration() { +) : TransactionDecoration { sealed class Amount(val value: BigInteger) { class Exact(value: BigInteger) : Amount(value) @@ -26,13 +26,16 @@ abstract class OneInchDecoration( } } - override fun tags(): List = - listOf(contractAddress.hex, "swap") + override fun tags() = listOf(contractAddress.hex, TransactionTag.SWAP) - internal fun getTags(token: Token, type: String): List = - when (token) { - is Token.EvmCoin -> listOf("${TransactionTag.EVM_COIN}_$type", TransactionTag.EVM_COIN, type) - is Token.Eip20Coin -> listOf("${token.address.hex}_$type", token.address.hex, type) - } + protected fun getTags(token: Token, type: String) = when (token) { + is Token.EvmCoin -> listOf( + "${TransactionTag.EVM_COIN}_$type", + TransactionTag.EVM_COIN, + type + ) -} \ No newline at end of file + is Token.Eip20Coin -> listOf("${token.address.hex}_$type", token.address.hex, type) + } + +} diff --git a/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchSwapDecoration.kt b/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchSwapDecoration.kt index 5e1fbd48..d6bafeb6 100644 --- a/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchSwapDecoration.kt +++ b/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchSwapDecoration.kt @@ -1,6 +1,7 @@ package io.horizontalsystems.oneinchkit.decorations import io.horizontalsystems.ethereumkit.models.Address +import io.horizontalsystems.ethereumkit.models.TransactionTag import java.math.BigInteger class OneInchSwapDecoration( @@ -15,18 +16,15 @@ class OneInchSwapDecoration( val recipient: Address? ) : OneInchDecoration(contractAddress) { - override fun tags(): List { - val tags = super.tags().toMutableList() - - listOf(contractAddress.hex, "swap") - - tags.addAll(getTags(tokenIn, "outgoing")) + override fun tags() = buildList { + addAll(super.tags()) + addAll(getTags(tokenIn, TransactionTag.OUTGOING)) if (recipient == null) { - tags.addAll(getTags(tokenOut, "incoming")) + addAll(getTags(tokenOut, TransactionTag.INCOMING)) + } else { + add(TransactionTag.toAddress(recipient.hex)) } - - return tags } } diff --git a/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchUnknownDecoration.kt b/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchUnknownDecoration.kt index 52c7fe6b..cccf47af 100644 --- a/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchUnknownDecoration.kt +++ b/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchUnknownDecoration.kt @@ -7,25 +7,21 @@ import java.math.BigInteger class OneInchUnknownDecoration( override val contractAddress: Address, val tokenAmountIn: TokenAmount?, - val tokenAmountOut: TokenAmount? + val tokenAmountOut: TokenAmount?, ) : OneInchDecoration(contractAddress) { class TokenAmount(val token: Token, val value: BigInteger) - override fun tags(): List { - val tags = super.tags().toMutableList() - - listOf(contractAddress.hex, TransactionTag.SWAP) + override fun tags() = buildList { + addAll(super.tags()) if (tokenAmountIn != null) { - tags.addAll(getTags(tokenAmountIn.token, TransactionTag.OUTGOING)) + addAll(getTags(tokenAmountIn.token, TransactionTag.OUTGOING)) } if (tokenAmountOut != null) { - tags.addAll(getTags(tokenAmountOut.token, TransactionTag.INCOMING)) + addAll(getTags(tokenAmountOut.token, TransactionTag.INCOMING)) } - - return tags } } diff --git a/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchUnoswapDecoration.kt b/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchUnoswapDecoration.kt index fe8e9f55..6218a42f 100644 --- a/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchUnoswapDecoration.kt +++ b/oneinchkit/src/main/java/io/horizontalsystems/oneinchkit/decorations/OneInchUnoswapDecoration.kt @@ -14,18 +14,12 @@ class OneInchUnoswapDecoration( val params: Bytes32Array ) : OneInchDecoration(contractAddress) { - override fun tags(): List { - val tags = super.tags().toMutableList() - - listOf(contractAddress.hex, TransactionTag.SWAP) - - tags.addAll(getTags(tokenIn, TransactionTag.OUTGOING)) + override fun tags() = buildList { + addAll(super.tags()) + addAll(getTags(tokenIn, TransactionTag.OUTGOING)) if (tokenOut != null) { - tags.addAll(getTags(tokenOut, TransactionTag.INCOMING)) + addAll(getTags(tokenOut, TransactionTag.INCOMING)) } - - return tags } - } diff --git a/uniswapkit/src/main/java/io/horizontalsystems/uniswapkit/decorations/SwapDecoration.kt b/uniswapkit/src/main/java/io/horizontalsystems/uniswapkit/decorations/SwapDecoration.kt index d1ebce37..6dd957d0 100644 --- a/uniswapkit/src/main/java/io/horizontalsystems/uniswapkit/decorations/SwapDecoration.kt +++ b/uniswapkit/src/main/java/io/horizontalsystems/uniswapkit/decorations/SwapDecoration.kt @@ -14,7 +14,7 @@ class SwapDecoration( val tokenOut: Token, val recipient: Address?, val deadline: BigInteger? -) : TransactionDecoration() { +) : TransactionDecoration { sealed class Amount(val value: BigInteger) { class Exact(value: BigInteger) : Amount(value) @@ -32,16 +32,15 @@ class SwapDecoration( } } - override fun tags(): List { - val tags: MutableList = mutableListOf(contractAddress.hex, "swap") - - tags.addAll(tags(tokenIn, "outgoing")) + override fun tags() = buildList { + addAll(listOf(contractAddress.hex, TransactionTag.SWAP)) + addAll(tags(tokenIn, TransactionTag.OUTGOING)) if (recipient == null) { - tags.addAll(tags(tokenOut, "incoming")) + addAll(tags(tokenOut, TransactionTag.INCOMING)) + } else { + add(TransactionTag.toAddress(recipient.hex)) } - - return tags } private fun tags(token: Token, type: String): List =