Add address information to notes query and other cleanup
This commit is contained in:
parent
4cbdd2ab27
commit
0ed5731ff4
|
@ -38,7 +38,7 @@ apply plugin: 'com.github.dcendents.android-maven'
|
||||||
apply plugin: 'com.getkeepsafe.dexcount'
|
apply plugin: 'com.getkeepsafe.dexcount'
|
||||||
|
|
||||||
group = 'cash.z.android.wallet'
|
group = 'cash.z.android.wallet'
|
||||||
version = '1.6.0'
|
version = '1.7.3'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
@ -51,7 +51,7 @@ android {
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode = 1_06_00
|
versionCode = 1_07_03
|
||||||
versionName = version
|
versionName = version
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
|
@ -74,7 +74,10 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility 1.8
|
||||||
|
targetCompatibility 1.8
|
||||||
|
}
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
// Allow the use of Result objects understanding that if the API changes, we'll have to fix it before upgrading our kotlin version
|
// Allow the use of Result objects understanding that if the API changes, we'll have to fix it before upgrading our kotlin version
|
||||||
freeCompilerArgs = ["-Xallow-result-return-type"]
|
freeCompilerArgs = ["-Xallow-result-return-type"]
|
||||||
|
|
|
@ -52,17 +52,16 @@ class IntegrationTest {
|
||||||
wallet = Wallet(converter, context.getDatabasePath(dataDbName).absolutePath, context.cacheDir.absolutePath, arrayOf(0), SampleSeedProvider("dummyseed"), SampleSpendingKeyProvider("dummyseed"), logger)
|
wallet = Wallet(converter, context.getDatabasePath(dataDbName).absolutePath, context.cacheDir.absolutePath, arrayOf(0), SampleSeedProvider("dummyseed"), SampleSpendingKeyProvider("dummyseed"), logger)
|
||||||
|
|
||||||
// repository.start(this)
|
// repository.start(this)
|
||||||
synchronizer = Synchronizer(
|
synchronizer = SdkSynchronizer(
|
||||||
downloader,
|
downloader,
|
||||||
processor,
|
processor,
|
||||||
repository,
|
repository,
|
||||||
ActiveTransactionManager(repository, downloader.connection, wallet, logger),
|
ActiveTransactionManager(repository, downloader.connection, wallet, logger),
|
||||||
wallet,
|
wallet,
|
||||||
1000,
|
1000
|
||||||
logger
|
|
||||||
).start(this)
|
).start(this)
|
||||||
|
|
||||||
for(i in synchronizer.downloader.progress()) {
|
for(i in synchronizer.progress()) {
|
||||||
logger.twig("made progress: $i")
|
logger.twig("made progress: $i")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ interface TransactionDao {
|
||||||
transactions.raw IS NOT NULL AS isSend,
|
transactions.raw IS NOT NULL AS isSend,
|
||||||
transactions.block IS NOT NULL AS isMined,
|
transactions.block IS NOT NULL AS isMined,
|
||||||
blocks.time AS timeInSeconds,
|
blocks.time AS timeInSeconds,
|
||||||
|
sent_notes.address AS address,
|
||||||
CASE
|
CASE
|
||||||
WHEN transactions.raw IS NOT NULL THEN sent_notes.value
|
WHEN transactions.raw IS NOT NULL THEN sent_notes.value
|
||||||
ELSE received_notes.value
|
ELSE received_notes.value
|
||||||
|
@ -53,5 +54,6 @@ data class WalletTransaction(
|
||||||
val height: Int? = null,
|
val height: Int? = null,
|
||||||
val isSend: Boolean = false,
|
val isSend: Boolean = false,
|
||||||
val timeInSeconds: Long = 0L,
|
val timeInSeconds: Long = 0L,
|
||||||
|
val address: String? = null,
|
||||||
val isMined: Boolean = false
|
val isMined: Boolean = false
|
||||||
)
|
)
|
|
@ -279,6 +279,8 @@ interface ActiveTransaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class TransactionState(val order: Int) {
|
sealed class TransactionState(val order: Int) {
|
||||||
|
val timestamp: Long = System.currentTimeMillis()
|
||||||
|
|
||||||
object Creating : TransactionState(0)
|
object Creating : TransactionState(0)
|
||||||
|
|
||||||
/** @param txId row in the database where the raw transaction has been stored, temporarily, by the rust lib */
|
/** @param txId row in the database where the raw transaction has been stored, temporarily, by the rust lib */
|
||||||
|
@ -286,13 +288,25 @@ sealed class TransactionState(val order: Int) {
|
||||||
|
|
||||||
object SendingToNetwork : TransactionState(20)
|
object SendingToNetwork : TransactionState(20)
|
||||||
|
|
||||||
class AwaitingConfirmations(val confirmationCount: Int) : TransactionState(30)
|
class AwaitingConfirmations(val confirmationCount: Int) : TransactionState(30) {
|
||||||
|
override fun toString(): String {
|
||||||
|
return "${super.toString()}($confirmationCount)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
object Cancelled : TransactionState(-1)
|
object Cancelled : TransactionState(-1)
|
||||||
/** @param failedStep the state of this transaction at the time, prior to failure */
|
/** @param failedStep the state of this transaction at the time, prior to failure */
|
||||||
class Failure(val failedStep: TransactionState?, val reason: String = "") : TransactionState(-2)
|
class Failure(val failedStep: TransactionState?, val reason: String = "") : TransactionState(-2) {
|
||||||
|
override fun toString(): String {
|
||||||
|
return "${super.toString()}($failedStep) : $reason"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun isActive(): Boolean {
|
fun isActive(): Boolean {
|
||||||
return order > 0
|
return order > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return javaClass.simpleName
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -46,10 +46,10 @@ open class MockSynchronizer(
|
||||||
|
|
||||||
private val forge = Forge()
|
private val forge = Forge()
|
||||||
|
|
||||||
private val balanceChannel = ConflatedBroadcastChannel(0L)
|
private val balanceChannel = ConflatedBroadcastChannel<Long>()
|
||||||
private val activeTransactionsChannel = ConflatedBroadcastChannel<Map<ActiveTransaction, TransactionState>>(mutableMapOf())
|
private val activeTransactionsChannel = ConflatedBroadcastChannel<Map<ActiveTransaction, TransactionState>>(mutableMapOf())
|
||||||
private val transactionsChannel = ConflatedBroadcastChannel<List<WalletTransaction>>(listOf())
|
private val transactionsChannel = ConflatedBroadcastChannel<List<WalletTransaction>>(listOf())
|
||||||
private val progressChannel = ConflatedBroadcastChannel(0)
|
private val progressChannel = ConflatedBroadcastChannel<Int>()
|
||||||
|
|
||||||
override fun start(parentScope: CoroutineScope): Synchronizer {
|
override fun start(parentScope: CoroutineScope): Synchronizer {
|
||||||
Twig.sprout("mock")
|
Twig.sprout("mock")
|
||||||
|
@ -168,7 +168,6 @@ open class MockSynchronizer(
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* creators */
|
/* creators */
|
||||||
|
|
||||||
private inner class Forge {
|
private inner class Forge {
|
||||||
|
|
|
@ -169,7 +169,7 @@ inline fun BigDecimal?.toUsd(decimals: Int = USD_FORMATTER.maximumFractionDigits
|
||||||
*/
|
*/
|
||||||
inline fun BigDecimal?.convertZecToUsd(zecPrice: BigDecimal): BigDecimal {
|
inline fun BigDecimal?.convertZecToUsd(zecPrice: BigDecimal): BigDecimal {
|
||||||
if(this == null) return BigDecimal.ZERO
|
if(this == null) return BigDecimal.ZERO
|
||||||
if(this < BigDecimal.ZERO) throw IllegalArgumentException("Invalid ZEC value: $zecPrice. ZEC is represented by notes and cannot be negative")
|
if(this < BigDecimal.ZERO) throw IllegalArgumentException("Invalid ZEC value: ${zecPrice.toDouble()}. ZEC is represented by notes and cannot be negative")
|
||||||
return this.multiply(zecPrice, MathContext.DECIMAL128)
|
return this.multiply(zecPrice, MathContext.DECIMAL128)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ inline fun BigDecimal?.convertZecToUsd(zecPrice: BigDecimal): BigDecimal {
|
||||||
*/
|
*/
|
||||||
inline fun BigDecimal?.convertUsdToZec(zecPrice: BigDecimal): BigDecimal {
|
inline fun BigDecimal?.convertUsdToZec(zecPrice: BigDecimal): BigDecimal {
|
||||||
if(this == null) return BigDecimal.ZERO
|
if(this == null) return BigDecimal.ZERO
|
||||||
if(this < BigDecimal.ZERO) throw IllegalArgumentException("Invalid USD value: $zecPrice. Converting this would result in negative ZEC and ZEC is represented by notes and cannot be negative")
|
if(this < BigDecimal.ZERO) throw IllegalArgumentException("Invalid USD value: ${zecPrice.toDouble()}. Converting this would result in negative ZEC and ZEC is represented by notes and cannot be negative")
|
||||||
return this.divide(zecPrice, MathContext.DECIMAL128)
|
return this.divide(zecPrice, MathContext.DECIMAL128)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package cash.z.wallet.sdk.secure
|
package cash.z.wallet.sdk.secure
|
||||||
|
|
||||||
import cash.z.wallet.sdk.data.SilentTwig
|
import cash.z.wallet.sdk.data.*
|
||||||
import cash.z.wallet.sdk.data.Twig
|
|
||||||
import cash.z.wallet.sdk.data.twigTask
|
|
||||||
import cash.z.wallet.sdk.exception.WalletException
|
import cash.z.wallet.sdk.exception.WalletException
|
||||||
import cash.z.wallet.sdk.ext.masked
|
import cash.z.wallet.sdk.ext.masked
|
||||||
import cash.z.wallet.sdk.jni.JniConverter
|
import cash.z.wallet.sdk.jni.JniConverter
|
||||||
|
@ -27,9 +25,8 @@ class Wallet(
|
||||||
/** indexes of accounts ids. In the reference wallet, we only work with account 0 */
|
/** indexes of accounts ids. In the reference wallet, we only work with account 0 */
|
||||||
private val accountIds: Array<Int> = arrayOf(0),
|
private val accountIds: Array<Int> = arrayOf(0),
|
||||||
private val seedProvider: ReadOnlyProperty<Any?, ByteArray>,
|
private val seedProvider: ReadOnlyProperty<Any?, ByteArray>,
|
||||||
spendingKeyProvider: ReadWriteProperty<Any?, String>,
|
spendingKeyProvider: ReadWriteProperty<Any?, String>
|
||||||
logger: Twig = SilentTwig()
|
) {
|
||||||
) : Twig by logger {
|
|
||||||
var spendingKeyStore by spendingKeyProvider
|
var spendingKeyStore by spendingKeyProvider
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -44,6 +41,9 @@ class Wallet(
|
||||||
fun initialize(firstRunStartHeight: Int = 280000): Int {
|
fun initialize(firstRunStartHeight: Int = 280000): Int {
|
||||||
twig("Initializing wallet for first run")
|
twig("Initializing wallet for first run")
|
||||||
converter.initDataDb(dbDataPath)
|
converter.initDataDb(dbDataPath)
|
||||||
|
//TODO: pass this into the synchronizer and leverage it here
|
||||||
|
converter.initBlocksTable(dbDataPath, 421720, 1550762014, "015495a30aef9e18b9c774df6a9fcd583748c8bba1a6348e70f59bc9f0c2bc673b000f00000000018054b75173b577dc36f2c80dfc41f83d6716557597f74ec54436df32d4466d57000120f1825067a52ca973b07431199d5866a0d46ef231d08aa2f544665936d5b4520168d782e3d028131f59e9296c75de5a101898c5e53108e45baa223c608d6c3d3d01fb0a8d465b57c15d793c742df9470b116ddf06bd30d42123fdb7becef1fd63640001a86b141bdb55fd5f5b2e880ea4e07caf2bbf1ac7b52a9f504977913068a917270001dd960b6c11b157d1626f0768ec099af9385aea3f31c91111a8c5b899ffb99e6b0192acd61b1853311b0bf166057ca433e231c93ab5988844a09a91c113ebc58e18019fbfd76ad6d98cafa0174391546e7022afe62e870e20e16d57c4c419a5c2bb69")
|
||||||
|
|
||||||
// securely store the spendingkey by leveraging the utilities provided during construction
|
// securely store the spendingkey by leveraging the utilities provided during construction
|
||||||
val seed by seedProvider
|
val seed by seedProvider
|
||||||
val accountSpendingKeys = converter.initAccountsTable(dbDataPath, seed, 1)
|
val accountSpendingKeys = converter.initAccountsTable(dbDataPath, seed, 1)
|
||||||
|
@ -54,7 +54,7 @@ class Wallet(
|
||||||
// TODO: then use that to determine firstRunStartHeight
|
// TODO: then use that to determine firstRunStartHeight
|
||||||
|
|
||||||
// val firstRunStartHeight = 405410
|
// val firstRunStartHeight = 405410
|
||||||
return firstRunStartHeight
|
return 421720
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAddress(accountId: Int = accountIds[0]): String {
|
fun getAddress(accountId: Int = accountIds[0]): String {
|
||||||
|
@ -79,7 +79,7 @@ class Wallet(
|
||||||
suspend fun createRawSendTransaction(value: Long, toAddress: String, memo: String = "", fromAccountId: Int = accountIds[0]): Long =
|
suspend fun createRawSendTransaction(value: Long, toAddress: String, memo: String = "", fromAccountId: Int = accountIds[0]): Long =
|
||||||
withContext(IO) {
|
withContext(IO) {
|
||||||
var result = -1L
|
var result = -1L
|
||||||
twigTask("creating raw transaction to send $value zatoshi to ${toAddress.masked()}") {
|
Bush.trunk.twigTask("creating raw transaction to send $value zatoshi to ${toAddress.masked()}") {
|
||||||
result = runCatching {
|
result = runCatching {
|
||||||
ensureParams(paramDestinationDir)
|
ensureParams(paramDestinationDir)
|
||||||
twig("params exist at $paramDestinationDir! attempting to send...")
|
twig("params exist at $paramDestinationDir! attempting to send...")
|
||||||
|
@ -139,7 +139,7 @@ class Wallet(
|
||||||
}
|
}
|
||||||
if (hadError) {
|
if (hadError) {
|
||||||
try {
|
try {
|
||||||
twigTask("attempting to download missing params") {
|
Bush.trunk.twigTask("attempting to download missing params") {
|
||||||
fetchParams(destinationDir)
|
fetchParams(destinationDir)
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
|
|
Loading…
Reference in New Issue