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 ac4b615 commit f95eef0
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.horizontalsystems.ethereumkit.sample.core

import android.util.Log
import io.horizontalsystems.ethereumkit.core.EthereumKit
import io.horizontalsystems.ethereumkit.core.toHexString
import io.horizontalsystems.ethereumkit.models.Address
Expand Down Expand Up @@ -88,7 +87,6 @@ open class EthereumBaseAdapter(private val ethereumKit: EthereumKit) : IAdapter
override fun transactions(fromHash: ByteArray?, limit: Int?): Single<List<TransactionRecord>> {
return ethereumKit.getFullTransactionsAsync(listOf(), fromHash, limit)
.map { transactions ->
Log.v("LALALA in app: transactions count: ", "${transactions.size}")
transactions.map { transactionRecord(it) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,10 @@ class MainViewModel : ViewModel() {
}

private fun updateLastBlockHeight() {
Log.v("LALALA BlockHeight", ethereumKit.lastBlockHeight.toString())
lastBlockHeight.postValue(ethereumKit.lastBlockHeight)
}

private fun updateState() {
Log.v("LALALA State", ethereumAdapter.syncState.toString())
syncState.postValue(ethereumAdapter.syncState)
}

Expand Down Expand Up @@ -291,7 +289,6 @@ class MainViewModel : ViewModel() {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { list: List<TransactionRecord> ->
Log.v("LALALA ETH", list.size.toString())
ethTxs = list
updateTransactionList()
}.let {
Expand All @@ -304,7 +301,6 @@ class MainViewModel : ViewModel() {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { list: List<TransactionRecord> ->
Log.v("LALALA ERC20", list.size.toString())
erc20Txs = list
updateTransactionList()
}.let {
Expand Down
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
@@ -1,6 +1,5 @@
package io.horizontalsystems.ethereumkit.transactionsyncers

import android.util.Log
import io.horizontalsystems.ethereumkit.core.EthereumKit
import io.horizontalsystems.ethereumkit.core.ITransactionSyncer
import io.horizontalsystems.ethereumkit.core.TransactionManager
Expand Down Expand Up @@ -79,7 +78,6 @@ class TransactionSyncManager(
)

private fun handle(transactions: List<Transaction>) {
Log.v("LALALA Transactions count", transactions.size.toString())
val map: MutableMap<String, Transaction> = mutableMapOf()

for (transaction in transactions) {
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 f95eef0

Please sign in to comment.