Skip to content

Commit

Permalink
Add OneInchUnknownDecoration
Browse files Browse the repository at this point in the history
  • Loading branch information
esen committed Apr 14, 2022
1 parent 111c5fe commit 8574c26
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,68 +39,5 @@ class Eip20TransactionDecorator(

return null
}
//
// override fun decorate(transactionData: TransactionData): ContractMethodDecoration? =
// when (val contractMethod = contractMethodFactories.createMethodFromInput(transactionData.input)) {
// is TransferMethod -> TransferMethodDecoration(contractMethod.to, contractMethod.value)
// is ApproveMethod -> ApproveMethodDecoration(contractMethod.spender, contractMethod.value)
// else -> null
// }
//
// override fun decorate(fullTransaction: FullTransaction, fullRpcTransaction: FullRpcTransaction) {
// decorateMain(fullTransaction)
// decorateLogs(fullTransaction, fullRpcTransaction.rpcReceipt.logs)
// }
//
// override fun decorateTransactions(fullTransactions: Map<String, FullTransaction>) {
// for (fullTransaction in fullTransactions.values) {
// decorateMain(fullTransaction)
// }
//
// decorateEvents(fullTransactions)
// }
//
// private fun decorateMain(fullTransaction: FullTransaction) {
// val transactionData = fullTransaction.transactionData ?: return
// val decoration = decorate(transactionData) ?: return
//
// fullTransaction.mainDecoration = decoration
// }
//
// private fun decorateLogs(fullTransaction: FullTransaction, logs: List<TransactionLog>) {
// val eventDecorations = logs.mapNotNull { log ->
// val event = log.getErc20EventInstance() ?: return@mapNotNull null
//
// when (event) {
// is TransferEventInstance -> {
// if (event.from == userAddress || event.to == userAddress) {
// return@mapNotNull event
// }
// }
// is ApproveEventInstance -> {
// if (event.owner == userAddress || event.spender == userAddress) {
// return@mapNotNull event
// }
// }
// }
//
// return@mapNotNull null
// }
//
// fullTransaction.eventDecorations.addAll(eventDecorations)
// }
//
// private fun decorateEvents(fullTransactions: Map<String, FullTransaction>) {
// val erc20Events = if (fullTransactions.size > 100) {
// storage.getEvents()
// } else {
// storage.getEventsByHashes(fullTransactions.values.map { it.transaction.hash })
// }
//
// for (event in erc20Events) {
// val decoration = TransferEventInstance(event.contractAddress, event.from, event.to, event.value, event.tokenName, event.tokenSymbol, event.tokenDecimal)
// fullTransactions[event.hashString]?.eventDecorations?.add(decoration)
// }
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import io.horizontalsystems.ethereumkit.models.InternalTransaction
import io.horizontalsystems.ethereumkit.models.TransactionTag
import java.math.BigInteger

class UnknownTransactionDecoration(private val userAddress: Address, private val value: BigInteger?, val internalTransactions: List<InternalTransaction>, val eventInstances: List<ContractEventInstance>) : TransactionDecoration() {
open class UnknownTransactionDecoration(
private val userAddress: Address,
private val value: BigInteger?,
open val internalTransactions: List<InternalTransaction>,
open val eventInstances: List<ContractEventInstance>
) : TransactionDecoration() {

override fun tags(): List<String> =
(tagsFromInternalTransactions + tagsFromEventInstances).toSet().toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class OneInchTransactionDecorator(
}

is OneInchV4Method -> {
return OneInchDecoration(to)
return OneInchUnknownDecoration(to, address, value, internalTransactions, eventInstances)
}

else -> return null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.horizontalsystems.oneinchkit.decorations

import io.horizontalsystems.ethereumkit.contracts.ContractEventInstance
import io.horizontalsystems.ethereumkit.decorations.UnknownTransactionDecoration
import io.horizontalsystems.ethereumkit.models.Address
import io.horizontalsystems.ethereumkit.models.InternalTransaction
import java.math.BigInteger

class OneInchUnknownDecoration(
val contractAddress: Address,
private val userAddress: Address,
val value: BigInteger,
override val internalTransactions: List<InternalTransaction>,
override val eventInstances: List<ContractEventInstance>
) : UnknownTransactionDecoration(userAddress, value, internalTransactions, eventInstances) {

override fun tags(): List<String> {
val tags = super.tags().toMutableList()

tags.add(contractAddress.hex)
tags.add("swap")

return tags
}

}

0 comments on commit 8574c26

Please sign in to comment.