Merge branch 'feat_room_db' into develop
This commit is contained in:
commit
a8ff48b984
19 changed files with 359 additions and 0 deletions
|
@ -0,0 +1,16 @@
|
|||
package cy.agorise.bitsybitshareswallet.daos
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import cy.agorise.bitsybitshareswallet.models.Asset
|
||||
|
||||
@Dao
|
||||
interface AssetDao {
|
||||
@Insert
|
||||
fun insert(asset: Asset)
|
||||
|
||||
@Query("SELECT * FROM assets")
|
||||
fun getAllAssets(): LiveData<List<Asset>>
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cy.agorise.bitsybitshareswallet.daos
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import cy.agorise.bitsybitshareswallet.models.Authority
|
||||
|
||||
@Dao
|
||||
interface AuthorityDao {
|
||||
@Insert
|
||||
fun insert(authority: Authority)
|
||||
|
||||
@Query("SELECT * FROM authorities")
|
||||
fun getAllAuthorities(): LiveData<List<Authority>>
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cy.agorise.bitsybitshareswallet.daos
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import cy.agorise.bitsybitshareswallet.models.Balance
|
||||
|
||||
@Dao
|
||||
interface BalanceDao {
|
||||
@Insert
|
||||
fun insert(balance: Balance)
|
||||
|
||||
@Query("SELECT * FROM balances")
|
||||
fun getAllBalances(): LiveData<List<Balance>>
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package cy.agorise.bitsybitshareswallet.daos
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import cy.agorise.bitsybitshareswallet.models.*
|
||||
|
||||
@Database(entities = [
|
||||
Asset::class,
|
||||
Authority::class,
|
||||
Balance::class,
|
||||
BrainKey::class,
|
||||
EquivalentValue::class,
|
||||
Operation::class,
|
||||
Transfer::class,
|
||||
UserAccount::class,
|
||||
UserAccountAuthority::class
|
||||
], version = 1, exportSchema = false)
|
||||
abstract class BitsyDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun assetDao(): AssetDao
|
||||
abstract fun authorityDao(): AuthorityDao
|
||||
abstract fun balanceDao(): BalanceDao
|
||||
abstract fun brainKeyDao(): BrainKeyDao
|
||||
abstract fun equivalentValueDao(): EquivalentValueDao
|
||||
abstract fun operationDao(): OperationDao
|
||||
abstract fun transferDao(): TransferDao
|
||||
abstract fun userAccountDao(): UserAccountDao
|
||||
abstract fun userAccountAuthorityDao(): UserAccountAuthorityDao
|
||||
|
||||
companion object {
|
||||
|
||||
// To make sure there is always only one instance of the database open
|
||||
@Volatile
|
||||
private var INSTANCE: BitsyDatabase? = null
|
||||
|
||||
internal fun getDatabase(context: Context): BitsyDatabase? {
|
||||
if (INSTANCE == null) {
|
||||
synchronized(BitsyDatabase::class.java) {
|
||||
INSTANCE = Room.databaseBuilder(
|
||||
context.applicationContext,
|
||||
BitsyDatabase::class.java, "BiTSyWallet.db"
|
||||
)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
return INSTANCE
|
||||
}
|
||||
|
||||
fun destroyInstance() {
|
||||
INSTANCE = null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cy.agorise.bitsybitshareswallet.daos
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import cy.agorise.bitsybitshareswallet.models.BrainKey
|
||||
|
||||
@Dao
|
||||
interface BrainKeyDao {
|
||||
@Insert
|
||||
fun insert(asset: BrainKeyDao)
|
||||
|
||||
@Query("SELECT * FROM brain_keys")
|
||||
fun getAllBrainKeys(): LiveData<List<BrainKey>>
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cy.agorise.bitsybitshareswallet.daos
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import cy.agorise.bitsybitshareswallet.models.EquivalentValue
|
||||
|
||||
@Dao
|
||||
interface EquivalentValueDao {
|
||||
@Insert
|
||||
fun insert(equivalentValue: EquivalentValue)
|
||||
|
||||
@Query("SELECT * FROM equivalent_values")
|
||||
fun getAllEquivalentValues(): LiveData<List<EquivalentValue>>
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cy.agorise.bitsybitshareswallet.daos
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import cy.agorise.bitsybitshareswallet.models.Operation
|
||||
|
||||
@Dao
|
||||
interface OperationDao {
|
||||
@Insert
|
||||
fun insert(operation: Operation)
|
||||
|
||||
@Query("SELECT * FROM operations")
|
||||
fun getAllOperations(): LiveData<List<Operation>>
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cy.agorise.bitsybitshareswallet.daos
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import cy.agorise.bitsybitshareswallet.models.Transfer
|
||||
|
||||
@Dao
|
||||
interface TransferDao {
|
||||
@Insert
|
||||
fun insert(transfer: Transfer)
|
||||
|
||||
@Query("SELECT * FROM transfers")
|
||||
fun getAllTransfers(): LiveData<List<Transfer>>
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cy.agorise.bitsybitshareswallet.daos
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import cy.agorise.bitsybitshareswallet.models.Authority
|
||||
|
||||
@Dao
|
||||
interface UserAccountAuthorityDao {
|
||||
@Insert
|
||||
fun insert(userAccountAuthorityDao: UserAccountAuthorityDao)
|
||||
|
||||
@Query("SELECT * FROM user_accounts INNER JOIN user_accounts__authorities ON user_accounts.id=user_accounts__authorities.user_account_id WHERE user_accounts__authorities.user_account_id=:userAccountId")
|
||||
fun getAuthoritiesForUserAccount(userAccountId: String): LiveData<List<Authority>>
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cy.agorise.bitsybitshareswallet.daos
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import cy.agorise.bitsybitshareswallet.models.UserAccount
|
||||
|
||||
@Dao
|
||||
interface UserAccountDao {
|
||||
@Insert
|
||||
fun insert(userAccount: UserAccount)
|
||||
|
||||
@Query("SELECT * FROM user_accounts")
|
||||
fun getAllUserAccounts(): LiveData<List<UserAccount>>
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "assets")
|
||||
data class Asset(
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "id") val id: String,
|
||||
@ColumnInfo(name = "symbol") val symbol: String,
|
||||
@ColumnInfo(name = "precision") val precision: Int,
|
||||
@ColumnInfo(name = "description") val description: String,
|
||||
@ColumnInfo(name = "bit_asset_id") val bitAssetId: String
|
||||
)
|
|
@ -0,0 +1,13 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "authorities")
|
||||
data class Authority (
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "id") val id: Long,
|
||||
@ColumnInfo(name = "encrypted_private_key") val encryptedBrainkey: String,
|
||||
@ColumnInfo(name = "user_id") val userId: String
|
||||
)
|
|
@ -0,0 +1,13 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
|
||||
@Entity(tableName = "balances", primaryKeys = ["user_account_id", "asset_id"])
|
||||
// TODO make userAccountId and assetId be ForeignKeys
|
||||
data class Balance(
|
||||
@ColumnInfo(name = "user_account_id") val userAccountId: String,
|
||||
@ColumnInfo(name = "asset_id") val assetId: String,
|
||||
@ColumnInfo(name = "asset_amount") val assetAmount: Long,
|
||||
@ColumnInfo(name = "last_update") val lastUpdate: Long
|
||||
)
|
|
@ -0,0 +1,13 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName="brain_keys")
|
||||
data class BrainKey(
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "public_key") val publicKey: String,
|
||||
@ColumnInfo(name = "encrypted_brain_key") val encryptedBrainKey: String,
|
||||
@ColumnInfo(name = "sequence_number") val sequenceNumber: Long
|
||||
)
|
|
@ -0,0 +1,25 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "equivalent_values",foreignKeys =
|
||||
[ForeignKey(
|
||||
entity = Transfer::class,
|
||||
parentColumns = ["operation_id"],
|
||||
childColumns = ["transfer_id"]
|
||||
), ForeignKey(
|
||||
entity = Asset::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["asset_id"]
|
||||
)]
|
||||
)
|
||||
data class EquivalentValue (
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "id") val id: Long,
|
||||
@ColumnInfo(name = "transfer_id") val transferId: String,
|
||||
@ColumnInfo(name = "value") val value: Long,
|
||||
@ColumnInfo(name = "asset_id") val assetId: String
|
||||
)
|
|
@ -0,0 +1,14 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "operations")
|
||||
data class Operation (
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "id") val id: String,
|
||||
@ColumnInfo(name = "type") val type: Int,
|
||||
@ColumnInfo(name = "timestamp") val timestamp: Long,
|
||||
@ColumnInfo(name = "block_number") val blockNumber: Long
|
||||
)
|
|
@ -0,0 +1,27 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "transfers",foreignKeys =
|
||||
[ForeignKey(
|
||||
entity = Operation::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["operation_id"]
|
||||
)]
|
||||
)
|
||||
data class Transfer (
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "operation_id") val operationId: String,
|
||||
@ColumnInfo(name = "fee_amount") val feeAmount: Long,
|
||||
@ColumnInfo(name = "fee_asset_id") val feeAssetId: String, // TODO should be foreign key to Asset
|
||||
@ColumnInfo(name = "source") val source: String, // TODO should be foreign key to UserAccount
|
||||
@ColumnInfo(name = "destination") val destination: String, // TODO should be foreign key to UserAccount
|
||||
@ColumnInfo(name = "transfer_amount") val transferAmount: Long,
|
||||
@ColumnInfo(name = "transfer_asset_id") val transferAssetId: String, // TODO should be foreign key to Asset
|
||||
@ColumnInfo(name = "memo") val memo: String,
|
||||
@ColumnInfo(name = "memo_from_key") val memoFromKey: String,
|
||||
@ColumnInfo(name = "memo_to_key") val memoToKey: String
|
||||
)
|
|
@ -0,0 +1,14 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "user_accounts")
|
||||
data class UserAccount (
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "id") val id: String,
|
||||
@ColumnInfo(name = "name") val name: String,
|
||||
@ColumnInfo(name = "is_ltm") val isLtm: Boolean,
|
||||
@ColumnInfo(name = "weight_threshold") val weightThreshold: Int
|
||||
)
|
|
@ -0,0 +1,25 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
|
||||
/**
|
||||
* Table to create a N:N relationship between [UserAccount] and [Authority]
|
||||
*/
|
||||
@Entity(tableName = "user_accounts__authorities",
|
||||
primaryKeys = ["user_account_id", "authority_id"],
|
||||
foreignKeys = [ForeignKey(
|
||||
entity = UserAccount::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["user_account_id"]
|
||||
), ForeignKey(
|
||||
entity = Authority::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["authority_id"]
|
||||
)])
|
||||
data class UserAccountAuthority (
|
||||
@ColumnInfo(name = "user_account_id") val userAccountId: String,
|
||||
@ColumnInfo(name = "authority_id") val authorityId: Long,
|
||||
@ColumnInfo(name = "weight") val weight: Int
|
||||
)
|
Loading…
Reference in a new issue