Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.horizontalsystems.ethereumkit.network.ConnectionManager
import io.reactivex.Single
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import java.util.*
import java.util.Timer
import kotlin.concurrent.schedule

class ApiRpcSyncer(
Expand Down Expand Up @@ -52,6 +52,14 @@ class ApiRpcSyncer(
stopTimer()
}

override fun pause() {
stopTimer()
}

override fun resume() {
startTimer()
}

override fun <T: Any> single(rpc: JsonRpc<T>): Single<T> =
rpcApiProvider.single(rpc)
//endregion
Expand All @@ -69,6 +77,8 @@ class ApiRpcSyncer(
}

private fun startTimer() {
if (timer != null) return

timer = Timer().apply {
schedule(0, syncInterval * 1000) {
onFireTimer()
Expand All @@ -85,11 +95,9 @@ class ApiRpcSyncer(
rpcApiProvider.single(BlockNumberJsonRpc())
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.subscribe({ lastBlockNumber ->
.subscribe { lastBlockNumber ->
listener?.didUpdateLastBlockHeight(lastBlockNumber)
}, {
state = SyncerState.NotReady(it)
}).let {
}.let {
disposables.add(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ interface IRpcSyncer {

fun start()
fun stop()
fun pause()
fun resume()
fun <T: Any> single(rpc: JsonRpc<T>): Single<T>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ class RpcBlockchain(
syncer.stop()
}

override fun pause() {
syncer.pause()
}

override fun resume() {
syncer.resume()
}

override fun send(rawTransaction: RawTransaction, signature: Signature): Single<Transaction> {
val transaction = transactionBuilder.transaction(rawTransaction, signature)
val encoded = transactionBuilder.encode(rawTransaction, signature)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class WebSocketRpcSyncer(
rpcSocket.stop()
}

override fun pause() = Unit

override fun resume() = Unit

override fun <T: Any> single(rpc: JsonRpc<T>): Single<T> {
return Single.create { emitter ->
send(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ class EthereumKit(
connectionManager.stop()
}

fun onEnterForeground() {
blockchain.resume()
}

fun onEnterBackground() {
blockchain.pause()
}

fun refresh() {
blockchain.refresh()
transactionSyncManager.sync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ interface IBlockchain {
fun start()
fun refresh()
fun stop()
fun pause()
fun resume()
fun syncAccountState()

val syncState: EthereumKit.SyncState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import io.horizontalsystems.ethereumkit.core.IBlockchainListener
import io.horizontalsystems.ethereumkit.core.ISpvStorage
import io.horizontalsystems.ethereumkit.core.TransactionBuilder
import io.horizontalsystems.ethereumkit.crypto.ECKey
import io.horizontalsystems.ethereumkit.models.*
import io.horizontalsystems.ethereumkit.models.Address
import io.horizontalsystems.ethereumkit.models.DefaultBlockParameter
import io.horizontalsystems.ethereumkit.models.GasPrice
import io.horizontalsystems.ethereumkit.models.RawTransaction
import io.horizontalsystems.ethereumkit.models.Signature
import io.horizontalsystems.ethereumkit.models.Transaction
import io.horizontalsystems.ethereumkit.models.TransactionLog
import io.horizontalsystems.ethereumkit.network.INetwork
import io.horizontalsystems.ethereumkit.spv.helpers.RandomHelper
import io.horizontalsystems.ethereumkit.spv.models.AccountStateSpv
Expand All @@ -22,7 +28,11 @@ import io.horizontalsystems.ethereumkit.spv.net.BlockHelper
import io.horizontalsystems.ethereumkit.spv.net.BlockValidator
import io.horizontalsystems.ethereumkit.spv.net.PeerGroup
import io.horizontalsystems.ethereumkit.spv.net.PeerProvider
import io.horizontalsystems.ethereumkit.spv.net.handlers.*
import io.horizontalsystems.ethereumkit.spv.net.handlers.AccountStateTaskHandler
import io.horizontalsystems.ethereumkit.spv.net.handlers.AnnouncedBlockHandler
import io.horizontalsystems.ethereumkit.spv.net.handlers.BlockHeadersTaskHandler
import io.horizontalsystems.ethereumkit.spv.net.handlers.HandshakeTaskHandler
import io.horizontalsystems.ethereumkit.spv.net.handlers.SendTransactionTaskHandler
import io.horizontalsystems.ethereumkit.spv.net.tasks.HandshakeTask
import io.reactivex.Single
import io.reactivex.subjects.PublishSubject
Expand Down Expand Up @@ -61,6 +71,14 @@ class SpvBlockchain(
TODO("not implemented")
}

override fun pause() {
TODO("Not yet implemented")
}

override fun resume() {
TODO("Not yet implemented")
}

override fun refresh() {
TODO("not implemented")
}
Expand Down