[#939] Eliminate default arguments for Account

* [#939] Eliminate default arguments for Account

* Add Account.DEFAULT to demo-app tests

* Update changelog
This commit is contained in:
Honza Rychnovsky 2023-05-23 14:39:46 +03:00 committed by GitHub
parent 20638afa52
commit 4926e3a24d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 20 deletions

View File

@ -1,4 +1,9 @@
# Change Log # Change Log
## Unreleased
- Synchronizer's functions `getUnifiedAddress`, `getSaplingAddress`, `getTransparentAddress`, and `refreshUtxos` now
do not provide `Account.DEFAULT` value for the account argument. As accounts are not fully supported by the SDK
yet, the caller should explicitly set Account.DEFAULT as the account argument to keep the same behavior.
## 1.17.0-beta01 ## 1.17.0-beta01
- Transparent fund balances are now displayed almost immediately - Transparent fund balances are now displayed almost immediately

View File

@ -71,7 +71,7 @@ class SampleCodeTest {
// Get Address // Get Address
@Test @Test
fun getAddress() = runBlocking { fun getAddress() = runBlocking {
val address = synchronizer.getUnifiedAddress() val address = synchronizer.getUnifiedAddress(Account.DEFAULT)
assertFalse(address.isBlank()) assertFalse(address.isBlank())
log("Address: $address") log("Address: $address")
} }

View File

@ -11,6 +11,7 @@ import cash.z.ecc.android.sdk.demoapp.databinding.FragmentGetAddressBinding
import cash.z.ecc.android.sdk.demoapp.ext.requireApplicationContext import cash.z.ecc.android.sdk.demoapp.ext.requireApplicationContext
import cash.z.ecc.android.sdk.demoapp.util.ProvideAddressBenchmarkTrace import cash.z.ecc.android.sdk.demoapp.util.ProvideAddressBenchmarkTrace
import cash.z.ecc.android.sdk.demoapp.util.fromResources import cash.z.ecc.android.sdk.demoapp.util.fromResources
import cash.z.ecc.android.sdk.model.Account
import cash.z.ecc.android.sdk.model.UnifiedFullViewingKey import cash.z.ecc.android.sdk.model.UnifiedFullViewingKey
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.tool.DerivationTool import cash.z.ecc.android.sdk.tool.DerivationTool
@ -32,21 +33,21 @@ class GetAddressFragment : BaseDemoFragment<FragmentGetAddressBinding>() {
sharedViewModel.synchronizerFlow.filterNotNull().collect { synchronizer -> sharedViewModel.synchronizerFlow.filterNotNull().collect { synchronizer ->
binding.unifiedAddress.apply { binding.unifiedAddress.apply {
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.UNIFIED_ADDRESS_START) reportTraceEvent(ProvideAddressBenchmarkTrace.Event.UNIFIED_ADDRESS_START)
val uaddress = synchronizer.getUnifiedAddress() val uaddress = synchronizer.getUnifiedAddress(Account.DEFAULT)
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.UNIFIED_ADDRESS_END) reportTraceEvent(ProvideAddressBenchmarkTrace.Event.UNIFIED_ADDRESS_END)
text = uaddress text = uaddress
setOnClickListener { copyToClipboard(uaddress) } setOnClickListener { copyToClipboard(uaddress) }
} }
binding.saplingAddress.apply { binding.saplingAddress.apply {
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.SAPLING_ADDRESS_START) reportTraceEvent(ProvideAddressBenchmarkTrace.Event.SAPLING_ADDRESS_START)
val sapling = synchronizer.getSaplingAddress() val sapling = synchronizer.getSaplingAddress(Account.DEFAULT)
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.SAPLING_ADDRESS_END) reportTraceEvent(ProvideAddressBenchmarkTrace.Event.SAPLING_ADDRESS_END)
text = sapling text = sapling
setOnClickListener { copyToClipboard(sapling) } setOnClickListener { copyToClipboard(sapling) }
} }
binding.transparentAddress.apply { binding.transparentAddress.apply {
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.TRANSPARENT_ADDRESS_START) reportTraceEvent(ProvideAddressBenchmarkTrace.Event.TRANSPARENT_ADDRESS_START)
val transparent = synchronizer.getTransparentAddress() val transparent = synchronizer.getTransparentAddress(Account.DEFAULT)
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.TRANSPARENT_ADDRESS_END) reportTraceEvent(ProvideAddressBenchmarkTrace.Event.TRANSPARENT_ADDRESS_END)
text = transparent text = transparent
setOnClickListener { copyToClipboard(transparent) } setOnClickListener { copyToClipboard(transparent) }

View File

@ -23,7 +23,7 @@ ZCASH_ASCII_GPG_KEY=
# Configures whether release is an unstable snapshot, therefore published to the snapshot repository. # Configures whether release is an unstable snapshot, therefore published to the snapshot repository.
IS_SNAPSHOT=true IS_SNAPSHOT=true
LIBRARY_VERSION=1.17.0-beta01 LIBRARY_VERSION=1.18.0-beta01
# Kotlin compiler warnings can be considered errors, failing the build. # Kotlin compiler warnings can be considered errors, failing the build.
ZCASH_IS_TREAT_WARNINGS_AS_ERRORS=true ZCASH_IS_TREAT_WARNINGS_AS_ERRORS=true

View File

@ -67,7 +67,7 @@ class TestnetIntegrationTest : ScopedTest() {
@Test @Test
@Ignore("This test is broken") @Ignore("This test is broken")
fun getAddress() = runBlocking { fun getAddress() = runBlocking {
assertEquals(address, synchronizer.getUnifiedAddress()) assertEquals(address, synchronizer.getUnifiedAddress(Account.DEFAULT))
} }
// This is an extremely slow test; it is disabled so that we can get CI set up // This is an extremely slow test; it is disabled so that we can get CI set up

View File

@ -372,7 +372,7 @@ class SdkSynchronizer private constructor(
suspend fun refreshTransparentBalance() { suspend fun refreshTransparentBalance() {
Twig.debug { "refreshing transparent balance" } Twig.debug { "refreshing transparent balance" }
_transparentBalances.value = processor.getUtxoCacheBalance(getTransparentAddress()) _transparentBalances.value = processor.getUtxoCacheBalance(getTransparentAddress(Account.DEFAULT))
} }
suspend fun isValidAddress(address: String): Boolean { suspend fun isValidAddress(address: String): Boolean {
@ -385,7 +385,7 @@ class SdkSynchronizer private constructor(
// Triggering UTXOs fetch and transparent balance update at the beginning of the block sync right after the app // Triggering UTXOs fetch and transparent balance update at the beginning of the block sync right after the app
// start, as it makes the transparent transactions appearance faster // start, as it makes the transparent transactions appearance faster
launch(CoroutineExceptionHandler(::onCriticalError)) { launch(CoroutineExceptionHandler(::onCriticalError)) {
refreshUtxos() refreshUtxos(Account.DEFAULT)
refreshTransparentBalance() refreshTransparentBalance()
refreshTransactions() refreshTransactions()
} }
@ -487,7 +487,7 @@ class SdkSynchronizer private constructor(
if (shouldRefresh) { if (shouldRefresh) {
Twig.debug { "Triggering utxo refresh since $reason!" } Twig.debug { "Triggering utxo refresh since $reason!" }
refreshUtxos() refreshUtxos(Account.DEFAULT)
Twig.debug { "Triggering balance refresh since $reason!" } Twig.debug { "Triggering balance refresh since $reason!" }
refreshAllBalances() refreshAllBalances()

View File

@ -132,32 +132,32 @@ interface Synchronizer {
/** /**
* Gets the current unified address for the given account. * Gets the current unified address for the given account.
* *
* @param accountId the optional accountId whose address is of interest. By default, the first * @param account the account whose address is of interest. Use Account.DEFAULT to get a result for the first
* account is used. * account.
* *
* @return the current unified address for the given account. * @return the current unified address for the given account.
*/ */
suspend fun getUnifiedAddress(account: Account = Account.DEFAULT): String suspend fun getUnifiedAddress(account: Account): String
/** /**
* Gets the legacy Sapling address corresponding to the current unified address for the given account. * Gets the legacy Sapling address corresponding to the current unified address for the given account.
* *
* @param account the optional accountId whose address is of interest. By default, the first * @param account the account whose address is of interest. Use Account.DEFAULT to get a result for the first
* account is used. * account.
* *
* @return a legacy Sapling address for the given account. * @return a legacy Sapling address for the given account.
*/ */
suspend fun getSaplingAddress(account: Account = Account.DEFAULT): String suspend fun getSaplingAddress(account: Account): String
/** /**
* Gets the legacy transparent address corresponding to the current unified address for the given account. * Gets the legacy transparent address corresponding to the current unified address for the given account.
* *
* @param account the optional accountId whose address is of interest. By default, the first * @param account the account whose address is of interest. Use Account.DEFAULT to get a result for the first
* account is used. * account.
* *
* @return a legacy transparent address for the given account. * @return a legacy transparent address for the given account.
*/ */
suspend fun getTransparentAddress(account: Account = Account.DEFAULT): String suspend fun getTransparentAddress(account: Account): String
/** /**
* Sends zatoshi. * Sends zatoshi.
@ -252,13 +252,14 @@ interface Synchronizer {
/** /**
* Download all UTXOs for the given account addresses and store any new ones in the database. * Download all UTXOs for the given account addresses and store any new ones in the database.
* *
* @param account The Account, for which all addresses blocks will be downloaded. * @param account The Account, for which all addresses blocks will be downloaded. Use Account.DEFAULT to get a
* result for the first account.
* @param since The BlockHeight, from which blocks will be downloaded. * @param since The BlockHeight, from which blocks will be downloaded.
* *
* @return the number of utxos that were downloaded and added to the UTXO table. * @return the number of utxos that were downloaded and added to the UTXO table.
*/ */
suspend fun refreshUtxos( suspend fun refreshUtxos(
account: Account = Account.DEFAULT, account: Account,
since: BlockHeight = network.saplingActivationHeight since: BlockHeight = network.saplingActivationHeight
): Int? ): Int?