diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/daos/AssetDao.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/daos/AssetDao.kt new file mode 100644 index 0000000..2970c84 --- /dev/null +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/daos/AssetDao.kt @@ -0,0 +1,17 @@ +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 { + + @Query("SELECT * FROM assets") + fun getAllAssets(): LiveData> + + @Insert + fun insert(asset: Asset) +} diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/daos/BitsyDatabase.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/daos/BitsyDatabase.kt new file mode 100644 index 0000000..6c5ab53 --- /dev/null +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/daos/BitsyDatabase.kt @@ -0,0 +1,38 @@ +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.Asset + +@Database(entities = [Asset::class], version = 1, exportSchema = false) +abstract class BitsyDatabase : RoomDatabase() { + + abstract fun assetDao(): AssetDao + + 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 + } + } +} diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/models/Asset.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/models/Asset.kt new file mode 100644 index 0000000..e0c03b9 --- /dev/null +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/models/Asset.kt @@ -0,0 +1,23 @@ +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 = "issuer") val issuer: String, + @ColumnInfo(name = "description") val description: String, + @ColumnInfo(name = "max_supply") val maxSupply: Long, // TODO verify type + @ColumnInfo(name = "market_fee_percent") val marketFeePercent: Float, // TODO verify type + @ColumnInfo(name = "max_market_fee") val maxMarketFee: Float, // TODO verify type + @ColumnInfo(name = "issuer_permissions") val issuerPermissions: Int, + @ColumnInfo(name = "flags") val flags: Int, + @ColumnInfo(name = "asset_type") val assetType: Int, + @ColumnInfo(name = "bit_asset_id") val bitAssetId: String, + @ColumnInfo(name = "holders_count") val holdersCount: Int +)