Skip to content

Commit

Permalink
Get unmanaged realm objects as it will be updated separately
Browse files Browse the repository at this point in the history
  • Loading branch information
tmedetbekov committed Mar 15, 2019
1 parent 2efa2ed commit 36976af
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ class Storage(context: Context, dbName: String, val realmFactory: RealmFactory)

override fun getBlock(headerHash: ByteArray): Block? {
realmFactory.realm.use {
return it.where(Block::class.java).equalTo("headerHash", headerHash).findFirst()
val block = it.where(Block::class.java).equalTo("headerHash", headerHash)
.findFirst() ?: return null

return it.copyFromRealm(block)
}
}

Expand Down Expand Up @@ -165,22 +168,28 @@ class Storage(context: Context, dbName: String, val realmFactory: RealmFactory)

override fun getNewTransaction(hashHex: String): Transaction? {
realmFactory.realm.use {
return it.where(Transaction::class.java)
val transaction = it.where(Transaction::class.java)
.equalTo("hashHexReversed", hashHex)
.equalTo("status", Transaction.Status.NEW)
.findFirst()
.findFirst() ?: return null

return it.copyFromRealm(transaction)
}
}

override fun getNewTransactions(): List<Transaction> {
realmFactory.realm.use {
return it.where(Transaction::class.java).equalTo("status", Transaction.Status.NEW).findAll()
val transactions = it.where(Transaction::class.java).equalTo("status", Transaction.Status.NEW).findAll()
return it.copyFromRealm(transactions)
}
}

override fun getRelayedTransaction(hash: ByteArray): Transaction? {
realmFactory.realm.use {
return it.where(Transaction::class.java).equalTo("hash", hash).findFirst()
val transaction = it.where(Transaction::class.java).equalTo("hash", hash)
.findFirst() ?: return null

return it.copyFromRealm(transaction)
}
}

Expand Down

0 comments on commit 36976af

Please sign in to comment.