Skip to content

Commit 2b8338a

Browse files
committed
Set protected flag in tx via extra data
1 parent c761163 commit 2b8338a

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

merkleiokit/src/main/java/io/horizontalsystems/merkleiokit/MerkleTransactionAdapter.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.content.Context
44
import io.horizontalsystems.ethereumkit.api.core.ApiRpcSyncer
55
import io.horizontalsystems.ethereumkit.api.core.NodeApiProvider
66
import io.horizontalsystems.ethereumkit.core.EthereumKit
7-
import io.horizontalsystems.ethereumkit.core.ITransactionSyncer
87
import io.horizontalsystems.ethereumkit.core.TransactionBuilder
98
import io.horizontalsystems.ethereumkit.core.TransactionManager
109
import io.horizontalsystems.ethereumkit.models.Address
@@ -18,22 +17,33 @@ import java.net.URI
1817

1918
class MerkleTransactionAdapter(
2019
val blockchain: MerkleRpcBlockchain,
21-
val syncer: ITransactionSyncer,
20+
val syncer: MerkleTransactionSyncer,
2221
private val transactionManager: TransactionManager,
2322
) {
2423
fun send(rawTransaction: RawTransaction, signature: Signature): Single<FullTransaction> {
2524
return blockchain.send(rawTransaction, signature)
2625
.map { transactionManager.handle(listOf(it)).first() }
2726
}
2827

28+
fun registerInKit(ethereumKit: EthereumKit) {
29+
ethereumKit.addNonceProvider(blockchain)
30+
ethereumKit.addTransactionSyncer(syncer)
31+
ethereumKit.addExtraDecorator(syncer)
32+
}
33+
2934
companion object {
35+
val protectedKey = "protected"
3036

3137
private val blockchainPathMap = mapOf(
3238
Chain.Ethereum to "eth",
3339
Chain.BinanceSmartChain to "bsc",
3440
Chain.Base to "base"
3541
)
3642

43+
fun isProtected(transaction: FullTransaction): Boolean {
44+
return transaction.extra[protectedKey] == true
45+
}
46+
3747
fun getInstance(
3848
merkleIoPubKey: String,
3949
address: Address,

merkleiokit/src/main/java/io/horizontalsystems/merkleiokit/MerkleTransactionDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ interface MerkleTransactionDao {
1010
@Query("SELECT * FROM MerkleTransactionHash")
1111
fun hashes() : List<MerkleTransactionHash>
1212

13+
@Query("SELECT * FROM MerkleTransactionHash WHERE hash = :hash")
14+
fun hash(hash: ByteArray) : MerkleTransactionHash?
15+
1316
@Insert
1417
fun save(hash: MerkleTransactionHash)
1518

merkleiokit/src/main/java/io/horizontalsystems/merkleiokit/MerkleTransactionHashManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class MerkleTransactionHashManager(private val dao: MerkleTransactionDao) {
44

55
fun hashes() = dao.hashes()
66

7+
fun hash(hash: ByteArray) = dao.hash(hash)
8+
79
fun save(hash: MerkleTransactionHash) = dao.save(hash)
810

911
fun handle(txHashes: List<ByteArray>) = dao.delete(txHashes)

merkleiokit/src/main/java/io/horizontalsystems/merkleiokit/MerkleTransactionSyncer.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.horizontalsystems.merkleiokit
22

3+
import io.horizontalsystems.ethereumkit.core.IExtraDecorator
34
import io.horizontalsystems.ethereumkit.core.ITransactionSyncer
45
import io.horizontalsystems.ethereumkit.core.TransactionManager
56
import io.horizontalsystems.ethereumkit.models.Transaction
@@ -10,7 +11,7 @@ class MerkleTransactionSyncer(
1011
private val manager: MerkleTransactionHashManager,
1112
private val blockchain: MerkleRpcBlockchain,
1213
private val transactionManager: TransactionManager,
13-
) : ITransactionSyncer {
14+
) : ITransactionSyncer, IExtraDecorator {
1415

1516
@OptIn(ExperimentalStdlibApi::class)
1617
override fun getTransactionsSingle(): Single<Pair<List<Transaction>, Boolean>> {
@@ -51,4 +52,14 @@ class MerkleTransactionSyncer(
5152
Pair(failedTxs, false)
5253
}
5354
}
55+
56+
override fun extra(hash: ByteArray): Map<String, Any> {
57+
val merkleTransactionHash = manager.hash(hash)
58+
59+
return if (merkleTransactionHash != null) {
60+
mapOf(MerkleTransactionAdapter.protectedKey to true)
61+
} else {
62+
mapOf()
63+
}
64+
}
5465
}

0 commit comments

Comments
 (0)