Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing of pending transactions in TransactionManager #253

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix failing of pending transactions in TransactionManager
  • Loading branch information
esen committed Sep 15, 2022
commit 613e9429ef190f844f397d4ce7716aaf92145e61
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ class EthereumKit(
val internalTransactionsSyncer = InternalTransactionSyncer(transactionProvider, transactionStorage)

val decorationManager = DecorationManager(address, transactionStorage)
val transactionManager = TransactionManager(transactionStorage, decorationManager, blockchain, transactionProvider)
val transactionManager = TransactionManager(address, transactionStorage, decorationManager, blockchain, transactionProvider)
val transactionSyncManager = TransactionSyncManager(transactionManager)

transactionSyncManager.add(internalTransactionsSyncer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ interface ITransactionStorage {

fun getPendingTransactions(): List<Transaction>
fun getPendingTransactions(tags: List<List<String>>): List<Transaction>
fun getNonPendingTransactionsByNonces(pendingTransactionNonces: List<Long>): List<Transaction>
fun getNonPendingTransactionsByNonces(from: Address, pendingTransactionNonces: List<Long>): List<Transaction>

fun getLastInternalTransaction(): InternalTransaction?
fun getInternalTransactions(): List<InternalTransaction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.reactivex.subjects.PublishSubject
import java.math.BigInteger

class TransactionManager(
private val address: Address,
private val storage: ITransactionStorage,
private val decorationManager: DecorationManager,
private val blockchain: IBlockchain,
Expand Down Expand Up @@ -100,7 +101,7 @@ class TransactionManager(
if (pendingTransactions.isEmpty()) return listOf()

val pendingTransactionNonces = pendingTransactions.mapNotNull { it.nonce }.toSet().toList()
val nonPendingTransactions = storage.getNonPendingTransactionsByNonces(pendingTransactionNonces)
val nonPendingTransactions = storage.getNonPendingTransactionsByNonces(address, pendingTransactionNonces)
val processedTransactions: MutableList<Transaction> = mutableListOf()

for (nonPendingTransaction in nonPendingTransactions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ interface TransactionDao {
@RawQuery
fun getPending(query: SupportSQLiteQuery): List<Transaction>

@Query("SELECT * FROM `Transaction` WHERE blockNumber IS NOT NULL AND nonce IN (:nonces)")
fun getNonPendingByNonces(nonces: List<Long>): List<Transaction>
@Query("SELECT * FROM `Transaction` WHERE blockNumber IS NOT NULL AND nonce IN (:nonces) AND `from`=:from")
fun getNonPendingByNonces(from: ByteArray, nonces: List<Long>): List<Transaction>

@Query("SELECT * FROM `InternalTransaction`")
fun getInternalTransactions(): List<InternalTransaction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.horizontalsystems.ethereumkit.core.storage

import androidx.sqlite.db.SimpleSQLiteQuery
import io.horizontalsystems.ethereumkit.core.ITransactionStorage
import io.horizontalsystems.ethereumkit.models.Address
import io.horizontalsystems.ethereumkit.models.InternalTransaction
import io.horizontalsystems.ethereumkit.models.Transaction
import io.horizontalsystems.ethereumkit.models.TransactionTag
Expand Down Expand Up @@ -118,8 +119,8 @@ class TransactionStorage(database: TransactionDatabase) : ITransactionStorage {
return transactionDao.getPending(SimpleSQLiteQuery(sqlQuery))
}

override fun getNonPendingTransactionsByNonces(pendingTransactionNonces: List<Long>): List<Transaction> =
transactionDao.getNonPendingByNonces(pendingTransactionNonces)
override fun getNonPendingTransactionsByNonces(from: Address, pendingTransactionNonces: List<Long>): List<Transaction> =
transactionDao.getNonPendingByNonces(from.raw, pendingTransactionNonces)

override fun getLastInternalTransaction(): InternalTransaction? =
transactionDao.getLastInternalTransaction()
Expand Down