-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Version 1.7.2206 #97
Version 1.7.2206 #97
Changes from 52 commits
a34cbc6
24f0dc2
fc43d22
67388b6
23b5e8c
816d4fa
c3c0d8e
03926c6
fce2f95
e8412b9
5f9ae6a
117fa6f
54afebc
0e38c21
832fb07
1ca5a90
c5ab391
711cfc4
5e8a599
337756b
d270881
b87d8e6
381c0c2
24d0aeb
fe0a0c6
f6ac264
82077a2
d402dde
4760fd4
cc6b1c7
e766218
c55ae0e
69bc99c
b1021b3
71bfd25
a6e29db
5e74c06
607b421
a378f5a
e7e8b81
e682213
e148426
bb7afe2
333fac8
42f9e0d
706d8ea
c89c2f5
e6c7a2f
b79981d
dbdc7ab
5ce2b2e
8edd1d3
9fa31e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.ergoplatform.android.tokens | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
|
||
@Dao | ||
interface TokenDbDao { | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insertTokenPrices(vararg tokenPrices: TokenPriceDbEntity) | ||
|
||
@Query("DELETE FROM token_price") | ||
suspend fun deleteAllTokenPrices() | ||
|
||
@Query("SELECT * FROM token_price") | ||
suspend fun getAllTokenPrices(): List<TokenPriceDbEntity> | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insertOrUpdateTokenInformation(vararg tokenInfo: TokenInformationDbEntity) | ||
|
||
@Query("DELETE FROM token_info WHERE updated_ms < :thresholdMs") | ||
suspend fun deleteOutdatedTokenInformation(thresholdMs: Long) | ||
|
||
@Query("SELECT * FROM token_info WHERE tokenId = :tokenId") | ||
suspend fun getTokenInformation(tokenId: String): TokenInformationDbEntity? | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.ergoplatform.android.tokens | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import org.ergoplatform.persistance.GENUINE_UNKNOWN | ||
import org.ergoplatform.persistance.TokenInformation | ||
import org.ergoplatform.persistance.TokenPrice | ||
import java.math.BigDecimal | ||
|
||
@Entity(tableName = "token_price") | ||
data class TokenPriceDbEntity( | ||
@PrimaryKey val tokenId: String, | ||
@ColumnInfo(name = "display_name") val displayName: String?, | ||
@ColumnInfo(name = "source") val priceSource: String, | ||
@ColumnInfo(name = "erg_value") val ergValue: String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just out of curiosity, why not Long type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The token erg value can be fractional even compared to nanoergs, and actually is for most tokens. I have experimented with long value/decimals but had problems in deciding how many decimals should actually be used. Since JS developers settled to handle all of these types of values as strings and these are usually our sources, I decided to follow this practice for this application. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just out of curiosity, why not a numeric type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doublicate of former comment? |
||
) { | ||
fun toModel(): TokenPrice { | ||
return TokenPrice( | ||
tokenId, | ||
displayName, | ||
priceSource, | ||
BigDecimal(ergValue) | ||
) | ||
} | ||
} | ||
|
||
fun TokenPrice.toDbEntity(): TokenPriceDbEntity { | ||
return TokenPriceDbEntity( | ||
tokenId, | ||
displayName, | ||
priceSource, | ||
ergValue.toString() | ||
) | ||
} | ||
|
||
@Entity(tableName = "token_info") | ||
data class TokenInformationDbEntity( | ||
@PrimaryKey val tokenId: String, | ||
@ColumnInfo(name = "issuing_box") val issuingBoxId: String, | ||
@ColumnInfo(name = "minting_tx") val mintingTxId: String, | ||
@ColumnInfo(name = "display_name") val displayName: String, | ||
@ColumnInfo(name = "description") val description: String, | ||
@ColumnInfo(name = "decimals") val decimals: Int, | ||
@ColumnInfo(name = "full_supply") val fullSupply: Long, | ||
@ColumnInfo(name = "reg7") val reg7hex: String?, | ||
@ColumnInfo(name = "reg8") val reg8hex: String?, | ||
@ColumnInfo(name = "reg9") val reg9hex: String?, | ||
@ColumnInfo(name = "genuine_flag") val genuineFlag: Int = GENUINE_UNKNOWN, | ||
@ColumnInfo(name = "issuer_link") val issuerLink: String? = null, | ||
@ColumnInfo(name = "thumbnail_bytes") val thumbnailBytes: ByteArray? = null, | ||
@ColumnInfo(name = "thunbnail_type") val thumbnailType: Int, | ||
@ColumnInfo(name = "updated_ms") val updatedMs: Long | ||
) { | ||
fun toModel(): TokenInformation { | ||
return TokenInformation( | ||
tokenId, | ||
issuingBoxId, | ||
mintingTxId, | ||
displayName, | ||
description, | ||
decimals, | ||
fullSupply, | ||
reg7hex, | ||
reg8hex, | ||
reg9hex, | ||
genuineFlag, | ||
issuerLink, | ||
thumbnailBytes, | ||
thumbnailType, | ||
updatedMs | ||
) | ||
} | ||
} | ||
|
||
fun TokenInformation.toDbEntity(): TokenInformationDbEntity { | ||
return TokenInformationDbEntity( | ||
tokenId, | ||
issuingBoxId, | ||
mintingTxId, | ||
displayName, | ||
description, | ||
decimals, | ||
fullSupply, | ||
reg7hex, | ||
reg8hex, | ||
reg9hex, | ||
genuineFlag, | ||
issuerLink, | ||
thumbnailBytes, | ||
thumbnailType, | ||
updatedMs | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to make this SQL statements multi-line strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is, but the statements are a 1:1 copy of the generated code from Room and I'd rather leave it this way. I'll make the explaining comment more eye-catching