-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Show holds * Show holds on balance details * Reduce shown reserved amount by sum of all holds * Fix conflicts * Code style
- Loading branch information
Showing
80 changed files
with
1,068 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
core-db/src/main/java/io/novafoundation/nova/core_db/dao/HoldsDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.novafoundation.nova.core_db.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import androidx.room.Transaction | ||
import io.novafoundation.nova.core_db.model.BalanceHoldLocal | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
abstract class HoldsDao { | ||
|
||
@Transaction | ||
open suspend fun updateHolds( | ||
holds: List<BalanceHoldLocal>, | ||
metaId: Long, | ||
chainId: String, | ||
chainAssetId: Int | ||
) { | ||
deleteHolds(metaId, chainId, chainAssetId) | ||
|
||
insert(holds) | ||
} | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
protected abstract fun insert(holds: List<BalanceHoldLocal>) | ||
|
||
@Query("DELETE FROM holds WHERE metaId = :metaId AND chainId = :chainId AND assetId = :chainAssetId") | ||
protected abstract fun deleteHolds(metaId: Long, chainId: String, chainAssetId: Int) | ||
|
||
@Query("SELECT * FROM holds WHERE metaId = :metaId") | ||
abstract fun observeHoldsForMetaAccount(metaId: Long): Flow<List<BalanceHoldLocal>> | ||
|
||
@Query("SELECT * FROM holds WHERE metaId = :metaId AND chainId = :chainId AND assetId = :chainAssetId") | ||
abstract fun observeBalanceHolds(metaId: Long, chainId: String, chainAssetId: Int): Flow<List<BalanceHoldLocal>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
core-db/src/main/java/io/novafoundation/nova/core_db/migrations/60_61_AddBalanceHolds.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.novafoundation.nova.core_db.migrations | ||
|
||
import androidx.room.migration.Migration | ||
import androidx.sqlite.db.SupportSQLiteDatabase | ||
|
||
val AddBalanceHolds_60_61 = object : Migration(60, 61) { | ||
override fun migrate(database: SupportSQLiteDatabase) { | ||
database.execSQL( | ||
""" | ||
CREATE TABLE IF NOT EXISTS `holds` ( | ||
`metaId` INTEGER NOT NULL, | ||
`chainId` TEXT NOT NULL, | ||
`assetId` INTEGER NOT NULL, | ||
`amount` TEXT NOT NULL, | ||
`id_module` TEXT NOT NULL, | ||
`id_reason` TEXT NOT NULL, | ||
PRIMARY KEY(`metaId`, `chainId`, `assetId`, `id_module`, `id_reason`), | ||
FOREIGN KEY(`metaId`) REFERENCES `meta_accounts`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , | ||
FOREIGN KEY(`chainId`) REFERENCES `chains`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , | ||
FOREIGN KEY(`assetId`, `chainId`) REFERENCES `chain_assets`(`id`, `chainId`) ON UPDATE NO ACTION ON DELETE CASCADE | ||
) | ||
""".trimIndent() | ||
) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
core-db/src/main/java/io/novafoundation/nova/core_db/model/BalanceHoldLocal.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.novafoundation.nova.core_db.model | ||
|
||
import androidx.room.Embedded | ||
import androidx.room.Entity | ||
import androidx.room.ForeignKey | ||
import io.novafoundation.nova.core_db.model.chain.ChainAssetLocal | ||
import io.novafoundation.nova.core_db.model.chain.ChainLocal | ||
import io.novafoundation.nova.core_db.model.chain.account.MetaAccountLocal | ||
import java.math.BigInteger | ||
|
||
@Entity( | ||
tableName = "holds", | ||
primaryKeys = ["metaId", "chainId", "assetId", "id_module", "id_reason"], | ||
foreignKeys = [ | ||
ForeignKey( | ||
entity = MetaAccountLocal::class, | ||
parentColumns = ["id"], | ||
childColumns = ["metaId"], | ||
onDelete = ForeignKey.CASCADE | ||
), | ||
ForeignKey( | ||
entity = ChainLocal::class, | ||
parentColumns = ["id"], | ||
childColumns = ["chainId"], | ||
onDelete = ForeignKey.CASCADE | ||
), | ||
ForeignKey( | ||
entity = ChainAssetLocal::class, | ||
parentColumns = ["id", "chainId"], | ||
childColumns = ["assetId", "chainId"], | ||
onDelete = ForeignKey.CASCADE | ||
) | ||
], | ||
) | ||
class BalanceHoldLocal( | ||
val metaId: Long, | ||
val chainId: String, | ||
val assetId: Int, | ||
@Embedded(prefix = "id_") val id: HoldIdLocal, | ||
val amount: BigInteger | ||
) { | ||
|
||
class HoldIdLocal(val module: String, val reason: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.