Skip to content

Commit

Permalink
Merge pull request #188 from horizontalsystems/fix-clearing-db
Browse files Browse the repository at this point in the history
Fix clearing db
  • Loading branch information
tmedetbekov committed Dec 24, 2018
2 parents 1400103 + d4cc51e commit 6856abd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import io.realm.annotations.RealmModule
@RealmModule(library = true, allClasses = true)
class BitcoinKitModule

class BitcoinKit(words: List<String>, networkType: NetworkType, peerSize: Int = 10, newWallet: Boolean = false, confirmationsThreshold: Int = 6) : KitStateProvider.Listener, DataProvider.Listener {
class BitcoinKit(words: List<String>, networkType: NetworkType, walletId: String? = null, peerSize: Int = 10, newWallet: Boolean = false, confirmationsThreshold: Int = 6) : KitStateProvider.Listener, DataProvider.Listener {

interface Listener {
fun onTransactionsUpdate(bitcoinKit: BitcoinKit, inserted: List<TransactionInfo>, updated: List<TransactionInfo>, deleted: List<Int>)
Expand All @@ -55,7 +55,7 @@ class BitcoinKit(words: List<String>, networkType: NetworkType, peerSize: Int =
private val transactionBuilder: TransactionBuilder
private val dataProvider: DataProvider
private val unspentOutputProvider: UnspentOutputProvider
private val realmFactory = RealmFactory("bitcoinkit-${networkType.name}")
private val realmFactory = RealmFactory("bitcoinkit-${networkType.name}-$walletId")

private val network = when (networkType) {
NetworkType.MainNet -> MainNet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class DataProvider(private val realm: Realm, private val listener: Listener, pri
}

fun clear() {
realm.close()
transactionRealmResults.removeAllChangeListeners()
blockRealmResults.removeAllChangeListeners()
realm.close()
balanceSubjectDisposable.dispose()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class PeerGroup(

fun close() {
running = false
syncStateListener?.onSyncStop()

interrupt()
try {
Expand Down Expand Up @@ -82,6 +81,8 @@ class PeerGroup(
}
}

syncStateListener?.onSyncStop()
blockSyncer = null
logger.info("Closing all peer connections...")

peerManager.disconnectAll()
Expand Down

0 comments on commit 6856abd

Please sign in to comment.