Skip to content

Commit 6d971a7

Browse files
authored
Merge pull request #319 from synonymdev/fix/tag-syncing
Attach tags asynchronously
2 parents 4bd661f + 70ea9e3 commit 6d971a7

File tree

10 files changed

+358
-136
lines changed

10 files changed

+358
-136
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"formatVersion": 1,
3+
"database": {
4+
"version": 3,
5+
"identityHash": "e8c2a3893862c335833d1329bd45b666",
6+
"entities": [
7+
{
8+
"tableName": "config",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`walletIndex` INTEGER NOT NULL, PRIMARY KEY(`walletIndex`))",
10+
"fields": [
11+
{
12+
"fieldPath": "walletIndex",
13+
"columnName": "walletIndex",
14+
"affinity": "INTEGER",
15+
"notNull": true
16+
}
17+
],
18+
"primaryKey": {
19+
"autoGenerate": false,
20+
"columnNames": [
21+
"walletIndex"
22+
]
23+
},
24+
"indices": [],
25+
"foreignKeys": []
26+
},
27+
{
28+
"tableName": "tag_metadata",
29+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `paymentHash` TEXT, `txId` TEXT, `address` TEXT NOT NULL, `isReceive` INTEGER NOT NULL, `tags` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`id`))",
30+
"fields": [
31+
{
32+
"fieldPath": "id",
33+
"columnName": "id",
34+
"affinity": "TEXT",
35+
"notNull": true
36+
},
37+
{
38+
"fieldPath": "paymentHash",
39+
"columnName": "paymentHash",
40+
"affinity": "TEXT",
41+
"notNull": false
42+
},
43+
{
44+
"fieldPath": "txId",
45+
"columnName": "txId",
46+
"affinity": "TEXT",
47+
"notNull": false
48+
},
49+
{
50+
"fieldPath": "address",
51+
"columnName": "address",
52+
"affinity": "TEXT",
53+
"notNull": true
54+
},
55+
{
56+
"fieldPath": "isReceive",
57+
"columnName": "isReceive",
58+
"affinity": "INTEGER",
59+
"notNull": true
60+
},
61+
{
62+
"fieldPath": "tags",
63+
"columnName": "tags",
64+
"affinity": "TEXT",
65+
"notNull": true
66+
},
67+
{
68+
"fieldPath": "createdAt",
69+
"columnName": "createdAt",
70+
"affinity": "INTEGER",
71+
"notNull": true
72+
}
73+
],
74+
"primaryKey": {
75+
"autoGenerate": false,
76+
"columnNames": [
77+
"id"
78+
]
79+
},
80+
"indices": [],
81+
"foreignKeys": []
82+
}
83+
],
84+
"views": [],
85+
"setupQueries": [
86+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
87+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'e8c2a3893862c335833d1329bd45b666')"
88+
]
89+
}
90+
}

app/src/main/java/to/bitkit/data/AppDb.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ import dagger.assisted.AssistedInject
1919
import kotlinx.coroutines.coroutineScope
2020
import kotlinx.coroutines.flow.Flow
2121
import to.bitkit.BuildConfig
22-
import to.bitkit.data.dao.InvoiceTagDao
22+
import to.bitkit.data.dao.TagMetadataDao
2323
import to.bitkit.data.entities.ConfigEntity
24-
import to.bitkit.data.entities.InvoiceTagEntity
24+
import to.bitkit.data.entities.TagMetadataEntity
2525
import to.bitkit.data.typeConverters.StringListConverter
2626

2727
@Database(
2828
entities = [
2929
ConfigEntity::class,
30-
InvoiceTagEntity::class,
30+
TagMetadataEntity::class,
3131
],
32-
version = 2,
32+
version = 3,
3333
)
3434
@TypeConverters(StringListConverter::class)
3535
abstract class AppDb : RoomDatabase() {
3636
abstract fun configDao(): ConfigDao
37-
abstract fun invoiceTagDao(): InvoiceTagDao
37+
abstract fun tagMetadataDao(): TagMetadataDao
3838

3939
companion object {
4040
private const val DB_NAME = "${BuildConfig.APPLICATION_ID}.sqlite"

app/src/main/java/to/bitkit/data/dao/InvoiceTagDao.kt

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package to.bitkit.data.dao
2+
3+
import androidx.room.Dao
4+
import androidx.room.Delete
5+
import androidx.room.Insert
6+
import androidx.room.OnConflictStrategy
7+
import androidx.room.Query
8+
import to.bitkit.data.entities.TagMetadataEntity
9+
10+
@Dao
11+
interface TagMetadataDao {
12+
13+
@Insert(onConflict = OnConflictStrategy.REPLACE)
14+
suspend fun saveTagMetadata(tagMetadata: TagMetadataEntity)
15+
16+
@Query("SELECT * FROM tag_metadata")
17+
suspend fun getAll(): List<TagMetadataEntity>
18+
19+
// Search by payment hash (for invoices)
20+
@Query("SELECT * FROM tag_metadata WHERE paymentHash = :paymentHash LIMIT 1")
21+
suspend fun searchByPaymentHash(paymentHash: String): TagMetadataEntity?
22+
23+
// Search by transaction ID
24+
@Query("SELECT * FROM tag_metadata WHERE txId = :txId LIMIT 1")
25+
suspend fun searchByTxId(txId: String): TagMetadataEntity?
26+
27+
// Search by address
28+
@Query("SELECT * FROM tag_metadata WHERE address = :address ORDER BY createdAt DESC LIMIT 1")
29+
suspend fun searchByAddress(address: String): TagMetadataEntity?
30+
31+
// Search by primary key (id)
32+
@Query("SELECT * FROM tag_metadata WHERE id = :id LIMIT 1")
33+
suspend fun searchById(id: String): TagMetadataEntity?
34+
35+
// Get all receive transactions
36+
@Query("SELECT * FROM tag_metadata WHERE isReceive = 1")
37+
suspend fun getAllReceiveTransactions(): List<TagMetadataEntity>
38+
39+
// Get all send transactions
40+
@Query("SELECT * FROM tag_metadata WHERE isReceive = 0")
41+
suspend fun getAllSendTransactions(): List<TagMetadataEntity>
42+
43+
@Delete
44+
suspend fun deleteTagMetadata(tagMetadata: TagMetadataEntity)
45+
46+
@Query("DELETE FROM tag_metadata WHERE paymentHash = :paymentHash")
47+
suspend fun deleteByPaymentHash(paymentHash: String)
48+
49+
@Query("DELETE FROM tag_metadata WHERE txId = :txId")
50+
suspend fun deleteByTxId(txId: String)
51+
52+
@Query("DELETE FROM tag_metadata WHERE id = :id")
53+
suspend fun deleteById(id: String)
54+
55+
@Query("DELETE FROM tag_metadata")
56+
suspend fun deleteAll()
57+
58+
@Query("DELETE FROM tag_metadata WHERE createdAt < :expirationTimeStamp")
59+
suspend fun deleteExpired(expirationTimeStamp: Long)
60+
}

app/src/main/java/to/bitkit/data/entities/InvoiceTagEntity.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package to.bitkit.data.entities
2+
3+
import androidx.room.Entity
4+
import androidx.room.PrimaryKey
5+
6+
@Entity(tableName = "tag_metadata")
7+
/**
8+
* @param id This will be paymentHash, txId, or address depending on context
9+
* @param txId on-chain transaction id
10+
* @param address on-chain address
11+
* @param isReceive true for receive, false for send
12+
* */
13+
data class TagMetadataEntity(
14+
@PrimaryKey val id: String,
15+
val paymentHash: String? = null,
16+
val txId: String? = null,
17+
val address: String,
18+
val isReceive: Boolean,
19+
val tags: List<String>,
20+
val createdAt: Long,
21+
)

0 commit comments

Comments
 (0)