From 3fa7a98fbfe7a88704f6bf3a40d463e93dfc9776 Mon Sep 17 00:00:00 2001 From: Carter Jernigan Date: Thu, 23 Jun 2022 08:31:02 -0400 Subject: [PATCH] [#580] ktlint 0.46.1 Update baseline --- .../darkside/test/DarksideTestCoordinator.kt | 2 +- .../android/sdk/darkside/test/TestWallet.kt | 2 +- .../sdk/sample/demoapp/SampleCodeTest.kt | 16 +- .../demos/listutxos/ListUtxosFragment.kt | 1 - .../android/sdk/demoapp/ext/FragmentExt.kt | 5 +- .../android/sdk/demoapp/util/NetworkExt.kt | 2 + gradle.properties | 2 +- .../z/ecc/android/sdk/PullRequestSuite.kt | 2 +- .../ecc/android/sdk/integration/SanityTest.kt | 2 +- .../sdk/integration/TestnetIntegrationTest.kt | 2 +- .../integration/service/ChangeServiceTest.kt | 3 +- .../PersistentTransactionManagerTest.kt | 1 + .../z/ecc/android/sdk/jni/BranchIdTest.kt | 2 +- .../z/ecc/android/sdk/jni/TransparentTest.kt | 2 +- .../cash/z/ecc/android/sdk/util/TestWallet.kt | 2 +- .../z/ecc/fixture/WalletBirthdayFixture.kt | 1 + .../cash/z/ecc/android/sdk/Initializer.kt | 2 +- .../cash/z/ecc/android/sdk/SdkSynchronizer.kt | 2 +- .../sdk/block/CompactBlockProcessor.kt | 2 +- .../ecc/android/sdk/db/entity/Transactions.kt | 3 +- .../cash/z/ecc/android/sdk/db/entity/Utxo.kt | 2 +- .../z/ecc/android/sdk/exception/Exceptions.kt | 158 ++++++++++++------ .../ecc/android/sdk/internal/ext/BlockExt.kt | 2 + .../z/ecc/android/sdk/internal/ext/FileExt.kt | 2 + .../transaction/PagedTransactionRepository.kt | 4 +- .../PersistentTransactionManager.kt | 1 + .../transaction/WalletTransactionEncoder.kt | 3 +- .../cash/z/ecc/android/sdk/jni/RustBackend.kt | 44 ++--- .../ecc/android/sdk/jni/RustBackendWelding.kt | 10 +- .../z/ecc/android/sdk/tool/DerivationTool.kt | 6 +- .../android/sdk/tool/WalletBirthdayTool.kt | 5 +- .../src/test/java/cash/z/wallet/TestUtils.kt | 2 + tools/detekt-baseline.xml | 23 +-- 33 files changed, 199 insertions(+), 119 deletions(-) diff --git a/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/DarksideTestCoordinator.kt b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/DarksideTestCoordinator.kt index 9bdfd6ad..24652d41 100644 --- a/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/DarksideTestCoordinator.kt +++ b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/DarksideTestCoordinator.kt @@ -23,7 +23,7 @@ class DarksideTestCoordinator(val wallet: TestWallet) { startHeight: Int = DEFAULT_START_HEIGHT, host: String = COMPUTER_LOCALHOST, network: ZcashNetwork = ZcashNetwork.Mainnet, - port: Int = network.defaultPort, + port: Int = network.defaultPort ) : this(TestWallet(seedPhrase, alias, network, host, startHeight = startHeight, port = port)) private val targetHeight = 663250 diff --git a/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/TestWallet.kt b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/TestWallet.kt index d9200b79..3490a5ac 100644 --- a/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/TestWallet.kt +++ b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test/TestWallet.kt @@ -37,7 +37,7 @@ class TestWallet( val network: ZcashNetwork = ZcashNetwork.Testnet, val host: String = network.defaultHost, startHeight: Int? = null, - val port: Int = network.defaultPort, + val port: Int = network.defaultPort ) { constructor( backup: Backups, diff --git a/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt b/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt index d687c9e9..ffaf4a87 100644 --- a/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt +++ b/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt @@ -29,22 +29,30 @@ class SampleCodeTest { // /////////////////////////////////////////////////// // Seed derivation - @Ignore("This test is not implemented") @Test fun createBip39Seed_fromSeedPhrase() { + @Ignore("This test is not implemented") + @Test + fun createBip39Seed_fromSeedPhrase() { // TODO: log(seedPhrase.asRawEntropy().asBip39seed()) } - @Ignore("This test is not implemented") @Test fun createRawEntropy() { + @Ignore("This test is not implemented") + @Test + fun createRawEntropy() { // TODO: call: Mnemonic::from_phrase(seed_phrase, Language::English).unwrap().entropy() // log(seedPhrase.asRawEntropy()) } - @Ignore("This test is not implemented") @Test fun createBip39Seed_fromRawEntropy() { + @Ignore("This test is not implemented") + @Test + fun createBip39Seed_fromRawEntropy() { // get the 64 byte bip39 entropy // TODO: call: bip39::Seed::new(&Mnemonic::from_entropy(&seed_bytes, Language::English).unwrap(), "") // log(rawEntropy.asBip39Seed()) } - @Ignore("This test is not implemented") @Test fun deriveSeedPhraseFrom() { + @Ignore("This test is not implemented") + @Test + fun deriveSeedPhraseFrom() { // TODO: let mnemonic = Mnemonic::from_entropy(entropy, Language::English).unwrap(); // log(entropy.asSeedPhrase()) } diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/listutxos/ListUtxosFragment.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/listutxos/ListUtxosFragment.kt index 4e911c68..7ba37a9a 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/listutxos/ListUtxosFragment.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/listutxos/ListUtxosFragment.kt @@ -89,7 +89,6 @@ class ListUtxosFragment : BaseDemoFragment() { } fun downloadTransactions() { - binding.textStatus.text = "loading..." binding.textStatus.post { binding.textStatus.requestFocus() diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ext/FragmentExt.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ext/FragmentExt.kt index 6dd54f70..433e6178 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ext/FragmentExt.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/ext/FragmentExt.kt @@ -1,9 +1,12 @@ +@file:Suppress("ktlint:filename") + package cash.z.ecc.android.sdk.demoapp.ext +import android.content.Context import androidx.fragment.app.Fragment /** * A safer alternative to [Fragment.requireContext], as it avoids leaking Fragment or Activity context * when Application context is often sufficient. */ -fun Fragment.requireApplicationContext() = requireContext().applicationContext +fun Fragment.requireApplicationContext(): Context = requireContext().applicationContext diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/util/NetworkExt.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/util/NetworkExt.kt index 1b63a8b1..9c8bc764 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/util/NetworkExt.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/util/NetworkExt.kt @@ -1,3 +1,5 @@ +@file:Suppress("ktlint:filename") + package cash.z.ecc.android.sdk.demoapp.util import android.content.Context diff --git a/gradle.properties b/gradle.properties index d81bb05d..813a8c5c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -71,7 +71,7 @@ EMULATOR_WTF_GRADLE_PLUGIN_VERSION=0.0.10 FLANK_VERSION=22.03.0 FULLADLE_VERSION=0.17.4 GRADLE_VERSIONS_PLUGIN_VERSION=0.42.0 -KTLINT_VERSION=0.45.2 +KTLINT_VERSION=0.46.1 KSP_VERSION=1.6.21-1.0.6 MAVEN_PUBLISH_GRADLE_PLUGIN=0.20.0 PROTOBUF_GRADLE_PLUGIN_VERSION=0.8.18 diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/PullRequestSuite.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/PullRequestSuite.kt index 185bc594..3a5cd229 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/PullRequestSuite.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/PullRequestSuite.kt @@ -28,6 +28,6 @@ import org.junit.runners.Suite // potentially exclude because these hit external services ChangeServiceTest::class, - SmokeTest::class, + SmokeTest::class ) class PullRequestSuite diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/SanityTest.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/SanityTest.kt index 98638160..35ff650f 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/SanityTest.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/SanityTest.kt @@ -23,7 +23,7 @@ class SanityTest( private val wallet: TestWallet, private val extfvk: String, private val extpub: String, - private val birthday: Int, + private val birthday: Int ) { diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/TestnetIntegrationTest.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/TestnetIntegrationTest.kt index e055e252..d0f26647 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/TestnetIntegrationTest.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/TestnetIntegrationTest.kt @@ -40,7 +40,7 @@ class TestnetIntegrationTest : ScopedTest() { fun testLatestBlockTest() { val service = LightWalletGrpcService( context, - host, + host ) val height = service.getLatestBlockHeight() assertTrue(height > saplingActivation) diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/service/ChangeServiceTest.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/service/ChangeServiceTest.kt index dcf38dde..898e2964 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/service/ChangeServiceTest.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/integration/service/ChangeServiceTest.kt @@ -129,7 +129,8 @@ class ChangeServiceTest : ScopedTest() { (caughtException as ChainInfoNotMatching).propertyNames.let { props -> arrayOf("saplingActivationHeight", "chainName").forEach { assertTrue( - "$it should be a non-matching property but properties were [$props]", props.contains(it, true) + "$it should be a non-matching property but properties were [$props]", + props.contains(it, true) ) } } diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManagerTest.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManagerTest.kt index 890ba2e5..6c5c484a 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManagerTest.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManagerTest.kt @@ -39,6 +39,7 @@ import org.mockito.MockitoAnnotations class PersistentTransactionManagerTest : ScopedTest() { @Mock lateinit var mockEncoder: TransactionEncoder + @Mock lateinit var mockService: LightWalletService val pendingDbName = "PersistentTxMgrTest_Pending.db" diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/jni/BranchIdTest.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/jni/BranchIdTest.kt index eb37fe50..58133318 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/jni/BranchIdTest.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/jni/BranchIdTest.kt @@ -57,7 +57,7 @@ class BranchIdTest( arrayOf("Sapling", 280_000, 1991772603L, "76b809bb", testnetBackend), arrayOf("Blossom", 584_000, 733220448L, "2bb40e60", testnetBackend), arrayOf("Heartwood", 903_800, 4122551051L, "f5b9230b", testnetBackend), - arrayOf("Canopy", 1_028_500, 3925833126L, "e9ff75a6", testnetBackend), + arrayOf("Canopy", 1_028_500, 3925833126L, "e9ff75a6", testnetBackend) ) } } diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/jni/TransparentTest.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/jni/TransparentTest.kt index 559de7d1..901a8821 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/jni/TransparentTest.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/jni/TransparentTest.kt @@ -75,7 +75,7 @@ class TransparentTest(val expected: Expected, val network: ZcashNetwork) { @Parameterized.Parameters fun data() = listOf( arrayOf(ExpectedTestnet, ZcashNetwork.Testnet), - arrayOf(ExpectedMainnet, ZcashNetwork.Mainnet), + arrayOf(ExpectedMainnet, ZcashNetwork.Mainnet) ) } diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TestWallet.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TestWallet.kt index 970ad42b..4efe0cbd 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TestWallet.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/android/sdk/util/TestWallet.kt @@ -37,7 +37,7 @@ class TestWallet( val network: ZcashNetwork = ZcashNetwork.Testnet, val host: String = network.defaultHost, startHeight: Int? = null, - val port: Int = network.defaultPort, + val port: Int = network.defaultPort ) { constructor( backup: Backups, diff --git a/sdk-lib/src/androidTest/java/cash/z/ecc/fixture/WalletBirthdayFixture.kt b/sdk-lib/src/androidTest/java/cash/z/ecc/fixture/WalletBirthdayFixture.kt index 997aed21..b1c25857 100644 --- a/sdk-lib/src/androidTest/java/cash/z/ecc/fixture/WalletBirthdayFixture.kt +++ b/sdk-lib/src/androidTest/java/cash/z/ecc/fixture/WalletBirthdayFixture.kt @@ -15,6 +15,7 @@ object WalletBirthdayFixture { const val HEIGHT = 1500000 const val HASH = "00000000019e5b25a95c7607e7789eb326fddd69736970ebbe1c7d00247ef902" const val EPOCH_SECONDS = 1639913234L + @Suppress("MaxLineLength") const val TREE = "01ce183032b16ed87fcc5052a42d908376526126346567773f55bc58a63e4480160013000001bae5112769a07772345dd402039f2949c457478fe9327363ff631ea9d78fb80d0177c0b6c21aa9664dc255336ed450914088108c38a9171c85875b4e53d31b3e140171add6f9129e124651ca894aa842a3c71b1738f3ee2b7ba829106524ef51e62101f9cebe2141ee9d0a3f3a3e28bce07fa6b6e1c7b42c01cc4fe611269e9d52da540001d0adff06de48569129bd2a211e3253716362da97270d3504d9c1b694689ebe3c0122aaaea90a7fa2773b8166937310f79a4278b25d759128adf3138d052da3725b0137fb2cbc176075a45db2a3c32d3f78e669ff2258fd974e99ec9fb314d7fd90180165aaee3332ea432d13a9398c4863b38b8a7a491877a5c46b0802dcd88f7e324301a9a262f8b92efc2e0e3e4bd1207486a79d62e87b4ab9cc41814d62a23c4e28040001e3c4ee998682df5c5e230d6968e947f83d0c03682f0cfc85f1e6ec8e8552c95a000155989fed7a8cc7a0d479498d6881ca3bafbe05c7095110f85c64442d6a06c25c0185cd8c141e620eda0ca0516f42240aedfabdf9189c8c6ac834b7bdebc171331d01ecceb776c043662617d62646ee60985521b61c0b860f3a9731e66ef74ed8fb320118f64df255c9c43db708255e7bf6bffd481e5c2f38fe9ed8f3d189f7f9cf2644" diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/Initializer.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/Initializer.kt index 24f8767a..d501329b 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/Initializer.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/Initializer.kt @@ -36,7 +36,7 @@ class Initializer private constructor( class Config private constructor( val viewingKeys: MutableList = mutableListOf(), - var alias: String = ZcashSdk.DEFAULT_ALIAS, + var alias: String = ZcashSdk.DEFAULT_ALIAS ) { var birthdayHeight: Int? = null private set diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/SdkSynchronizer.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/SdkSynchronizer.kt index 217275cb..97ab7811 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/SdkSynchronizer.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/SdkSynchronizer.kt @@ -767,7 +767,7 @@ object DefaultSynchronizerFactory { fun new( repository: TransactionRepository, txManager: OutboundTransactionManager, - processor: CompactBlockProcessor, + processor: CompactBlockProcessor ): Synchronizer { // call the actual constructor now that all dependencies have been injected // alternatively, this entire object graph can be supplied by Dagger diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/block/CompactBlockProcessor.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/block/CompactBlockProcessor.kt index 2adfe2c8..8e7362fd 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/block/CompactBlockProcessor.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/block/CompactBlockProcessor.kt @@ -679,7 +679,7 @@ class CompactBlockProcessor( } else { updateProgress( lastScannedHeight = targetHeight, - lastScanRange = (targetHeight + 1)..currentInfo.networkBlockHeight, + lastScanRange = (targetHeight + 1)..currentInfo.networkBlockHeight ) _progress.send(0) val range = (targetHeight + 1)..lastScannedHeight diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/db/entity/Transactions.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/db/entity/Transactions.kt index 658fc80f..77278b99 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/db/entity/Transactions.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/db/entity/Transactions.kt @@ -12,7 +12,8 @@ import cash.z.ecc.android.sdk.model.Zatoshi // @Entity( - primaryKeys = ["id_tx"], tableName = "transactions", + primaryKeys = ["id_tx"], + tableName = "transactions", foreignKeys = [ ForeignKey( entity = Block::class, diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/db/entity/Utxo.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/db/entity/Utxo.kt index ccdade71..033d174b 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/db/entity/Utxo.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/db/entity/Utxo.kt @@ -39,7 +39,7 @@ data class Utxo( * A reference to the transaction this note was later spent in */ @ColumnInfo(name = "spent_in_tx") - val spent: Int? = 0, + val spent: Int? = 0 ) { override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/exception/Exceptions.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/exception/Exceptions.kt index 395de7d4..5d41d5a7 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/exception/Exceptions.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/exception/Exceptions.kt @@ -15,7 +15,8 @@ open class SdkException(message: String, cause: Throwable?) : RuntimeException(m * Exceptions thrown in the Rust layer of the SDK. We may not always be able to surface details about this * exception so it's important for the SDK to provide helpful messages whenever these errors are encountered. */ -sealed class RustLayerException(message: String, cause: Throwable? = null) : SdkException(message, cause) { +sealed class RustLayerException(message: String, cause: Throwable? = null) : + SdkException(message, cause) { class BalanceException(cause: Throwable) : RustLayerException( "Error while requesting the current balance over " + "JNI. This might mean that the database has been corrupted and needs to be rebuilt. Verify that " + @@ -27,11 +28,13 @@ sealed class RustLayerException(message: String, cause: Throwable? = null) : Sdk /** * User-facing exceptions thrown by the transaction repository. */ -sealed class RepositoryException(message: String, cause: Throwable? = null) : SdkException(message, cause) { +sealed class RepositoryException(message: String, cause: Throwable? = null) : + SdkException(message, cause) { object FalseStart : RepositoryException( "The channel is closed. Note that once a repository has stopped it " + "cannot be restarted. Verify that the repository is not being restarted." ) + object Unprepared : RepositoryException( "Unprepared repository: Data cannot be accessed before the repository is prepared." + " Ensure that things have been properly initialized. If you see this error it most" + @@ -46,11 +49,13 @@ sealed class RepositoryException(message: String, cause: Throwable? = null) : Sd * High-level exceptions thrown by the synchronizer, which do not fall within the umbrella of a * child component. */ -sealed class SynchronizerException(message: String, cause: Throwable? = null) : SdkException(message, cause) { +sealed class SynchronizerException(message: String, cause: Throwable? = null) : + SdkException(message, cause) { object FalseStart : SynchronizerException( "This synchronizer was already started. Multiple calls to start are not" + "allowed and once a synchronizer has stopped it cannot be restarted." ) + object NotYetStarted : SynchronizerException( "The synchronizer has not yet started. Verify that" + " start has been called prior to this operation and that the coroutineScope is not" + @@ -61,12 +66,16 @@ sealed class SynchronizerException(message: String, cause: Throwable? = null) : /** * Potentially user-facing exceptions that occur while processing compact blocks. */ -sealed class CompactBlockProcessorException(message: String, cause: Throwable? = null) : SdkException(message, cause) { +sealed class CompactBlockProcessorException(message: String, cause: Throwable? = null) : + SdkException(message, cause) { class DataDbMissing(path: String) : CompactBlockProcessorException( "No data db file found at path $path. Verify " + "that the data DB has been initialized via `rustBackend.initDataDb(path)`" ) - open class ConfigurationException(message: String, cause: Throwable?) : CompactBlockProcessorException(message, cause) + + open class ConfigurationException(message: String, cause: Throwable?) : + CompactBlockProcessorException(message, cause) + class FileInsteadOfPath(fileName: String) : ConfigurationException( "Invalid Path: the given path appears to be a" + " file name instead of a path: $fileName. The RustBackend expects the absolutePath to the database rather" + @@ -74,100 +83,137 @@ sealed class CompactBlockProcessorException(message: String, cause: Throwable? = " So pass in context.getDatabasePath(dbFileName).absolutePath instead of just dbFileName alone.", null ) + class FailedReorgRepair(message: String) : CompactBlockProcessorException(message) class FailedDownload(cause: Throwable? = null) : CompactBlockProcessorException( "Error while downloading blocks. This most " + "likely means the server is down or slow to respond. See logs for details.", cause ) + class FailedScan(cause: Throwable? = null) : CompactBlockProcessorException( "Error while scanning blocks. This most " + "likely means a block was missed or a reorg was mishandled. See logs for details.", cause ) - class Disconnected(cause: Throwable? = null) : CompactBlockProcessorException("Disconnected Error. Unable to download blocks due to ${cause?.message}", cause) + + class Disconnected(cause: Throwable? = null) : CompactBlockProcessorException( + "Disconnected Error. Unable to download blocks due to ${cause?.message}", + cause + ) + object Uninitialized : CompactBlockProcessorException( "Cannot process blocks because the wallet has not been" + " initialized. Verify that the seed phrase was properly created or imported. If so, then this problem" + " can be fixed by re-importing the wallet." ) + object NoAccount : CompactBlockProcessorException( "Attempting to scan without an account. This is probably a setup error or a race condition." ) - open class EnhanceTransactionError(message: String, val height: Int, cause: Throwable) : CompactBlockProcessorException(message, cause) { - class EnhanceTxDownloadError(height: Int, cause: Throwable) : EnhanceTransactionError("Error while attempting to download a transaction to enhance", height, cause) - class EnhanceTxDecryptError(height: Int, cause: Throwable) : EnhanceTransactionError("Error while attempting to decrypt and store a transaction to enhance", height, cause) + open class EnhanceTransactionError(message: String, val height: Int, cause: Throwable) : + CompactBlockProcessorException(message, cause) { + class EnhanceTxDownloadError(height: Int, cause: Throwable) : EnhanceTransactionError( + "Error while attempting to download a transaction to enhance", + height, + cause + ) + + class EnhanceTxDecryptError(height: Int, cause: Throwable) : EnhanceTransactionError( + "Error while attempting to decrypt and store a transaction to enhance", + height, + cause + ) } - class MismatchedNetwork(clientNetwork: String?, serverNetwork: String?) : CompactBlockProcessorException( - "Incompatible server: this client expects a server using $clientNetwork but it was $serverNetwork! Try updating the client or switching servers." - ) + class MismatchedNetwork(clientNetwork: String?, serverNetwork: String?) : + CompactBlockProcessorException( + "Incompatible server: this client expects a server using $clientNetwork but it was $serverNetwork! Try updating the client or switching servers." + ) - class MismatchedBranch(clientBranch: String?, serverBranch: String?, networkName: String?) : CompactBlockProcessorException( - "Incompatible server: this client expects a server following consensus branch $clientBranch on $networkName but it was $serverBranch! Try updating the client or switching servers." - ) + class MismatchedBranch(clientBranch: String?, serverBranch: String?, networkName: String?) : + CompactBlockProcessorException( + "Incompatible server: this client expects a server following consensus branch $clientBranch on $networkName but it was $serverBranch! Try updating the client or switching servers." + ) } /** * Exceptions related to the wallet's birthday. */ -sealed class BirthdayException(message: String, cause: Throwable? = null) : SdkException(message, cause) { +sealed class BirthdayException(message: String, cause: Throwable? = null) : + SdkException(message, cause) { object UninitializedBirthdayException : BirthdayException( "Error the birthday cannot be" + " accessed before it is initialized. Verify that the new, import or open functions" + " have been called on the initializer." ) + class MissingBirthdayFilesException(directory: String) : BirthdayException( "Cannot initialize wallet because no birthday files were found in the $directory directory." ) - class ExactBirthdayNotFoundException(height: Int, nearestMatch: Int? = null) : BirthdayException( - "Unable to find birthday that exactly matches $height.${ - if (nearestMatch != null) - " An exact match was request but the nearest match found was $nearestMatch." - else "" - }" - ) + + class ExactBirthdayNotFoundException(height: Int, nearestMatch: Int? = null) : + BirthdayException( + "Unable to find birthday that exactly matches $height.${ + if (nearestMatch != null) { + " An exact match was request but the nearest match found was $nearestMatch." + } else { + "" + } + }" + ) + class BirthdayFileNotFoundException(directory: String, height: Int?) : BirthdayException( "Unable to find birthday file for $height verify that $directory/$height.json exists." ) - class MalformattedBirthdayFilesException(directory: String, file: String, cause: Throwable?) : BirthdayException( - "Failed to parse file $directory/$file verify that it is formatted as #####.json, " + - "where the first portion is an Int representing the height of the tree contained in the file", - cause - ) + + class MalformattedBirthdayFilesException(directory: String, file: String, cause: Throwable?) : + BirthdayException( + "Failed to parse file $directory/$file verify that it is formatted as #####.json, " + + "where the first portion is an Int representing the height of the tree contained in the file", + cause + ) } /** * Exceptions thrown by the initializer. */ -sealed class InitializerException(message: String, cause: Throwable? = null) : SdkException(message, cause) { - class FalseStart(cause: Throwable?) : InitializerException("Failed to initialize accounts due to: $cause", cause) +sealed class InitializerException(message: String, cause: Throwable? = null) : + SdkException(message, cause) { + class FalseStart(cause: Throwable?) : + InitializerException("Failed to initialize accounts due to: $cause", cause) + class AlreadyInitializedException(cause: Throwable, dbPath: String) : InitializerException( "Failed to initialize the blocks table" + " because it already exists in $dbPath", cause ) + object MissingBirthdayException : InitializerException( "Expected a birthday for this wallet but failed to find one. This usually means that " + "wallet setup did not happen correctly. A workaround might be to interpret the " + "birthday, based on the contents of the wallet data but it is probably better " + "not to mask this error because the root issue should be addressed." ) + object MissingViewingKeyException : InitializerException( "Expected a unified viewingKey for this wallet but failed to find one. This usually means" + " that wallet setup happened incorrectly. A workaround might be to derive the" + " unified viewingKey from the seed or seedPhrase, if they exist, but it is probably" + " better not to mask this error because the root issue should be addressed." ) - class MissingAddressException(description: String, cause: Throwable? = null) : InitializerException( - "Expected a $description address for this wallet but failed to find one. This usually" + - " means that wallet setup happened incorrectly. If this problem persists, a" + - " workaround might be to go to settings and WIPE the wallet and rescan. Doing so" + - " will restore any missing address information. Meanwhile, please report that" + - " this happened so that the root issue can be uncovered and corrected." + - if (cause != null) "\nCaused by: $cause" else "" - ) + + class MissingAddressException(description: String, cause: Throwable? = null) : + InitializerException( + "Expected a $description address for this wallet but failed to find one. This usually" + + " means that wallet setup happened incorrectly. If this problem persists, a" + + " workaround might be to go to settings and WIPE the wallet and rescan. Doing so" + + " will restore any missing address information. Meanwhile, please report that" + + " this happened so that the root issue can be uncovered and corrected." + + if (cause != null) "\nCaused by: $cause" else "" + ) + object DatabasePathException : InitializerException( "Critical failure to locate path for storing databases. Perhaps this device prevents" + @@ -175,10 +221,11 @@ sealed class InitializerException(message: String, cause: Throwable? = null) : S " data." ) - class InvalidBirthdayHeightException(height: Int?, network: ZcashNetwork) : InitializerException( - "Invalid birthday height of $height. The birthday height must be at least the height of" + - " Sapling activation on ${network.networkName} (${network.saplingActivationHeight})." - ) + class InvalidBirthdayHeightException(height: Int?, network: ZcashNetwork) : + InitializerException( + "Invalid birthday height of $height. The birthday height must be at least the height of" + + " Sapling activation on ${network.networkName} (${network.saplingActivationHeight})." + ) object MissingDefaultBirthdayException : InitializerException( "The birthday height is missing and it is unclear which value to use as a default." @@ -188,13 +235,15 @@ sealed class InitializerException(message: String, cause: Throwable? = null) : S /** * Exceptions thrown while interacting with lightwalletd. */ -sealed class LightWalletException(message: String, cause: Throwable? = null) : SdkException(message, cause) { +sealed class LightWalletException(message: String, cause: Throwable? = null) : + SdkException(message, cause) { object InsecureConnection : LightWalletException( "Error: attempted to connect to lightwalletd" + " with an insecure connection! Plaintext connections are only allowed when the" + " resource value for 'R.bool.lightwalletd_allow_very_insecure_connections' is true" + " because this choice should be explicit." ) + class ConsensusBranchException(sdkBranch: String, lwdBranch: String) : LightWalletException( "Error: the lightwalletd server is using a consensus branch" + @@ -204,11 +253,18 @@ sealed class LightWalletException(message: String, cause: Throwable? = null) : S " update the SDK to match lightwalletd or use a lightwalletd that matches the SDK." ) - open class ChangeServerException(message: String, cause: Throwable? = null) : SdkException(message, cause) { - class ChainInfoNotMatching(val propertyNames: String, val expectedInfo: Service.LightdInfo, val actualInfo: Service.LightdInfo) : ChangeServerException( + open class ChangeServerException(message: String, cause: Throwable? = null) : + SdkException(message, cause) { + class ChainInfoNotMatching( + val propertyNames: String, + val expectedInfo: Service.LightdInfo, + val actualInfo: Service.LightdInfo + ) : ChangeServerException( "Server change error: the $propertyNames values did not match." ) - class StatusException(val status: Status, cause: Throwable? = null) : SdkException(status.toMessage(), cause) { + + class StatusException(val status: Status, cause: Throwable? = null) : + SdkException(status.toMessage(), cause) { companion object { private fun Status.toMessage(): String { return when (this.code) { @@ -226,22 +282,28 @@ sealed class LightWalletException(message: String, cause: Throwable? = null) : S /** * Potentially user-facing exceptions thrown while encoding transactions. */ -sealed class TransactionEncoderException(message: String, cause: Throwable? = null) : SdkException(message, cause) { - class FetchParamsException(message: String) : TransactionEncoderException("Failed to fetch params due to: $message") +sealed class TransactionEncoderException(message: String, cause: Throwable? = null) : + SdkException(message, cause) { + class FetchParamsException(message: String) : + TransactionEncoderException("Failed to fetch params due to: $message") + object MissingParamsException : TransactionEncoderException( "Cannot send funds due to missing spend or output params and attempting to download them failed." ) + class TransactionNotFoundException(transactionId: Long) : TransactionEncoderException( "Unable to find transactionId " + "$transactionId in the repository. This means the wallet created a transaction and then returned a row ID " + "that does not actually exist. This is a scenario where the wallet should have thrown an exception but failed " + "to do so." ) + class TransactionNotEncodedException(transactionId: Long) : TransactionEncoderException( "The transaction returned by the wallet," + " with id $transactionId, does not have any raw data. This is a scenario where the wallet should have thrown" + " an exception but failed to do so." ) + class IncompleteScanException(lastScannedHeight: Int) : TransactionEncoderException( "Cannot" + " create spending transaction because scanning is incomplete. We must scan up to the" + diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/ext/BlockExt.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/ext/BlockExt.kt index e0be3d03..2eb46082 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/ext/BlockExt.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/ext/BlockExt.kt @@ -1,3 +1,5 @@ +@file:Suppress("ktlint:filename") + package cash.z.ecc.android.sdk.internal.ext internal fun ByteArray.toHexReversed(): String { diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/ext/FileExt.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/ext/FileExt.kt index a717fcd8..958b665b 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/ext/FileExt.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/ext/FileExt.kt @@ -1,3 +1,5 @@ +@file:Suppress("ktlint:filename") + package cash.z.ecc.android.sdk.internal.ext import kotlinx.coroutines.Dispatchers diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PagedTransactionRepository.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PagedTransactionRepository.kt index bd7fc4cf..1e9c1c5f 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PagedTransactionRepository.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PagedTransactionRepository.kt @@ -115,7 +115,7 @@ class PagedTransactionRepository private constructor( rustBackend: RustBackend, birthday: WalletBirthday, viewingKeys: List, - overwriteVks: Boolean = false, + overwriteVks: Boolean = false ): PagedTransactionRepository { initMissingDatabases(rustBackend, birthday, viewingKeys) @@ -156,7 +156,7 @@ class PagedTransactionRepository private constructor( private suspend fun initMissingDatabases( rustBackend: RustBackend, birthday: WalletBirthday, - viewingKeys: List, + viewingKeys: List ) { maybeCreateDataDb(rustBackend) maybeInitBlocksTable(rustBackend, birthday) diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManager.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManager.kt index 5566eecb..cdc1c90a 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManager.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManager.kt @@ -307,6 +307,7 @@ class PersistentTransactionManager( companion object { /** Error code for an error while encoding a transaction */ const val ERROR_ENCODING = 2000 + /** Error code for an error while submitting a transaction */ const val ERROR_SUBMITTING = 3000 } diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/WalletTransactionEncoder.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/WalletTransactionEncoder.kt index 47f00500..54edaad5 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/WalletTransactionEncoder.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/WalletTransactionEncoder.kt @@ -82,8 +82,9 @@ class WalletTransactionEncoder( override suspend fun getConsensusBranchId(): Long { val height = repository.lastScannedHeight() - if (height < rustBackend.network.saplingActivationHeight) + if (height < rustBackend.network.saplingActivationHeight) { throw TransactionEncoderException.IncompleteScanException(height) + } return rustBackend.getBranchIdForHeight(height) } diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/jni/RustBackend.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/jni/RustBackend.kt index e7634ea2..6c5500d4 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/jni/RustBackend.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/jni/RustBackend.kt @@ -159,7 +159,7 @@ class RustBackend private constructor() : RustBackendWelding { validateCombinedChain( pathCacheDb, pathDataDb, - networkId = network.id, + networkId = network.id ) } @@ -234,7 +234,7 @@ class RustBackend private constructor() : RustBackendWelding { memo ?: ByteArray(0), "$pathParamsDir/$SPEND_PARAM_FILE_NAME", "$pathParamsDir/$OUTPUT_PARAM_FILE_NAME", - networkId = network.id, + networkId = network.id ) } @@ -253,7 +253,7 @@ class RustBackend private constructor() : RustBackendWelding { memo ?: ByteArray(0), "$pathParamsDir/$SPEND_PARAM_FILE_NAME", "$pathParamsDir/$OUTPUT_PARAM_FILE_NAME", - networkId = network.id, + networkId = network.id ) } } @@ -280,7 +280,7 @@ class RustBackend private constructor() : RustBackendWelding { override suspend fun clearUtxos( tAddress: String, - aboveHeight: Int, + aboveHeight: Int ): Boolean = withContext(SdkDispatchers.DATABASE_IO) { clearUtxos( pathDataDb, @@ -390,7 +390,7 @@ class RustBackend private constructor() : RustBackendWelding { dbDataPath: String, extfvk: Array, extpub: Array, - networkId: Int, + networkId: Int ): Boolean @JvmStatic @@ -400,14 +400,14 @@ class RustBackend private constructor() : RustBackendWelding { hash: String, time: Long, saplingTree: String, - networkId: Int, + networkId: Int ): Boolean @JvmStatic private external fun getShieldedAddress( dbDataPath: String, account: Int, - networkId: Int, + networkId: Int ): String @JvmStatic @@ -423,49 +423,49 @@ class RustBackend private constructor() : RustBackendWelding { private external fun getVerifiedBalance( dbDataPath: String, account: Int, - networkId: Int, + networkId: Int ): Long @JvmStatic private external fun getReceivedMemoAsUtf8( dbDataPath: String, idNote: Long, - networkId: Int, + networkId: Int ): String @JvmStatic private external fun getSentMemoAsUtf8( dbDataPath: String, dNote: Long, - networkId: Int, + networkId: Int ): String @JvmStatic private external fun validateCombinedChain( dbCachePath: String, dbDataPath: String, - networkId: Int, + networkId: Int ): Int @JvmStatic private external fun getNearestRewindHeight( dbDataPath: String, height: Int, - networkId: Int, + networkId: Int ): Int @JvmStatic private external fun rewindToHeight( dbDataPath: String, height: Int, - networkId: Int, + networkId: Int ): Boolean @JvmStatic private external fun scanBlocks( dbCachePath: String, dbDataPath: String, - networkId: Int, + networkId: Int ): Boolean @JvmStatic @@ -473,14 +473,14 @@ class RustBackend private constructor() : RustBackendWelding { dbCachePath: String, dbDataPath: String, limit: Int, - networkId: Int, + networkId: Int ): Boolean @JvmStatic private external fun decryptAndStoreTransaction( dbDataPath: String, tx: ByteArray, - networkId: Int, + networkId: Int ) @JvmStatic @@ -494,7 +494,7 @@ class RustBackend private constructor() : RustBackendWelding { memo: ByteArray, spendParamsPath: String, outputParamsPath: String, - networkId: Int, + networkId: Int ): Long @JvmStatic @@ -506,7 +506,7 @@ class RustBackend private constructor() : RustBackendWelding { memo: ByteArray, spendParamsPath: String, outputParamsPath: String, - networkId: Int, + networkId: Int ): Long @JvmStatic @@ -524,7 +524,7 @@ class RustBackend private constructor() : RustBackendWelding { script: ByteArray, value: Long, height: Int, - networkId: Int, + networkId: Int ): Boolean @JvmStatic @@ -532,21 +532,21 @@ class RustBackend private constructor() : RustBackendWelding { dbDataPath: String, tAddress: String, aboveHeight: Int, - networkId: Int, + networkId: Int ): Boolean @JvmStatic private external fun getVerifiedTransparentBalance( pathDataDb: String, taddr: String, - networkId: Int, + networkId: Int ): Long @JvmStatic private external fun getTotalTransparentBalance( pathDataDb: String, taddr: String, - networkId: Int, + networkId: Int ): Long } } diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/jni/RustBackendWelding.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/jni/RustBackendWelding.kt index 80711ad4..72b896f5 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/jni/RustBackendWelding.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/jni/RustBackendWelding.kt @@ -91,20 +91,20 @@ interface RustBackendWelding { suspend fun deriveShieldedAddress( seed: ByteArray, network: ZcashNetwork, - accountIndex: Int = 0, + accountIndex: Int = 0 ): String suspend fun deriveSpendingKeys( seed: ByteArray, network: ZcashNetwork, - numberOfAccounts: Int = 1, + numberOfAccounts: Int = 1 ): Array suspend fun deriveTransparentAddress( seed: ByteArray, network: ZcashNetwork, account: Int = 0, - index: Int = 0, + index: Int = 0 ): String suspend fun deriveTransparentAddressFromPublicKey( @@ -121,7 +121,7 @@ interface RustBackendWelding { seed: ByteArray, network: ZcashNetwork, account: Int = 0, - index: Int = 0, + index: Int = 0 ): String suspend fun deriveViewingKey( @@ -132,7 +132,7 @@ interface RustBackendWelding { suspend fun deriveUnifiedViewingKeys( seed: ByteArray, network: ZcashNetwork, - numberOfAccounts: Int = 1, + numberOfAccounts: Int = 1 ): Array } } diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/tool/DerivationTool.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/tool/DerivationTool.kt index 8a8ed9e5..9ab1b981 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/tool/DerivationTool.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/tool/DerivationTool.kt @@ -117,14 +117,14 @@ class DerivationTool { private external fun deriveExtendedSpendingKeys( seed: ByteArray, numberOfAccounts: Int, - networkId: Int, + networkId: Int ): Array @JvmStatic private external fun deriveUnifiedViewingKeysFromSeed( seed: ByteArray, numberOfAccounts: Int, - networkId: Int, + networkId: Int ): Array> @JvmStatic @@ -134,7 +134,7 @@ class DerivationTool { private external fun deriveShieldedAddressFromSeed( seed: ByteArray, accountIndex: Int, - networkId: Int, + networkId: Int ): String @JvmStatic diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/tool/WalletBirthdayTool.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/tool/WalletBirthdayTool.kt index cd573125..f125cf7f 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/tool/WalletBirthdayTool.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/tool/WalletBirthdayTool.kt @@ -43,11 +43,12 @@ object WalletBirthdayTool { */ suspend fun loadExact(context: Context, network: ZcashNetwork, birthdayHeight: Int) = loadNearest(context, network, birthdayHeight).also { - if (it.height != birthdayHeight) + if (it.height != birthdayHeight) { throw BirthdayException.ExactBirthdayNotFoundException( birthdayHeight, it.height ) + } } // Converting this to suspending will then propagate @@ -97,7 +98,7 @@ object WalletBirthdayTool { private suspend fun getFilteredFileNames( context: Context, directory: String, - birthdayHeight: Int? = null, + birthdayHeight: Int? = null ): List { val unfilteredTreeFiles = listBirthdayDirectoryContents(context, directory) if (unfilteredTreeFiles.isNullOrEmpty()) { diff --git a/sdk-lib/src/test/java/cash/z/wallet/TestUtils.kt b/sdk-lib/src/test/java/cash/z/wallet/TestUtils.kt index bf078f72..b7b49643 100644 --- a/sdk-lib/src/test/java/cash/z/wallet/TestUtils.kt +++ b/sdk-lib/src/test/java/cash/z/wallet/TestUtils.kt @@ -1,3 +1,5 @@ +@file:Suppress("ktlint:filename") + package cash.z.wallet import org.mockito.Mockito diff --git a/tools/detekt-baseline.xml b/tools/detekt-baseline.xml index 366119ec..593d0ffb 100644 --- a/tools/detekt-baseline.xml +++ b/tools/detekt-baseline.xml @@ -2,7 +2,6 @@ - ComplexCondition:WalletTypes.kt$WalletBalance$totalZatoshi == -1L && other.totalZatoshi == -1L && availableZatoshi == -1L && other.availableZatoshi == -1L ComplexMethod:SdkSynchronizer.kt$SdkSynchronizer$private suspend fun refreshPendingTransactions() ComplexMethod:SendFragment.kt$SendFragment$private fun onPendingTxUpdated(pendingTransaction: PendingTransaction?) ComplexMethod:Transactions.kt$ConfirmedTransaction$override fun equals(other: Any?): Boolean @@ -52,11 +51,11 @@ LongParameterList:Initializer.kt$Initializer$( val context: Context, val rustBackend: RustBackend, val network: ZcashNetwork, val alias: String, val host: String, val port: Int, val viewingKeys: List<UnifiedViewingKey>, val overwriteVks: Boolean, val birthday: WalletBirthday ) LongParameterList:Initializer.kt$Initializer.Config$( seed: ByteArray, birthdayHeight: Int? = null, network: ZcashNetwork, host: String = network.defaultHost, port: Int = network.defaultPort, alias: String = ZcashSdk.DEFAULT_ALIAS ) LongParameterList:Initializer.kt$Initializer.Config$( viewingKey: UnifiedViewingKey, birthdayHeight: Int? = null, network: ZcashNetwork, host: String = network.defaultHost, port: Int = network.defaultPort, alias: String = ZcashSdk.DEFAULT_ALIAS ) - LongParameterList:PagedTransactionRepository.kt$PagedTransactionRepository.Companion$( appContext: Context, pageSize: Int = 10, rustBackend: RustBackend, birthday: WalletBirthday, viewingKeys: List<UnifiedViewingKey>, overwriteVks: Boolean = false, ) - LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, account: Int, extsk: String, tsk: String, memo: ByteArray, spendParamsPath: String, outputParamsPath: String, networkId: Int, ) - LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, consensusBranchId: Long, account: Int, extsk: String, to: String, value: Long, memo: ByteArray, spendParamsPath: String, outputParamsPath: String, networkId: Int, ) - LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, height: Int, hash: String, time: Long, saplingTree: String, networkId: Int, ) - LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, tAddress: String, txId: ByteArray, index: Int, script: ByteArray, value: Long, height: Int, networkId: Int, ) + LongParameterList:PagedTransactionRepository.kt$PagedTransactionRepository.Companion$( appContext: Context, pageSize: Int = 10, rustBackend: RustBackend, birthday: WalletBirthday, viewingKeys: List<UnifiedViewingKey>, overwriteVks: Boolean = false ) + LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, account: Int, extsk: String, tsk: String, memo: ByteArray, spendParamsPath: String, outputParamsPath: String, networkId: Int ) + LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, consensusBranchId: Long, account: Int, extsk: String, to: String, value: Long, memo: ByteArray, spendParamsPath: String, outputParamsPath: String, networkId: Int ) + LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, height: Int, hash: String, time: Long, saplingTree: String, networkId: Int ) + LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, tAddress: String, txId: ByteArray, index: Int, script: ByteArray, value: Long, height: Int, networkId: Int ) LongParameterList:RustBackendWelding.kt$RustBackendWelding$( consensusBranchId: Long, account: Int, extsk: String, to: String, value: Long, memo: ByteArray? = byteArrayOf() ) LongParameterList:RustBackendWelding.kt$RustBackendWelding$( tAddress: String, txId: ByteArray, index: Int, script: ByteArray, value: Long, height: Int ) MagicNumber:BatchMetrics.kt$BatchMetrics$1000.0f @@ -121,7 +120,6 @@ MagicNumber:WalletTypes.kt$ZcashNetwork.Testnet$9067 MagicNumber:ZcashSdk.kt$ZcashSdk$10 MagicNumber:ZcashSdk.kt$ZcashSdk$100 - MagicNumber:ZcashSdk.kt$ZcashSdk$100_000_000L MagicNumber:ZcashSdk.kt$ZcashSdk$150 MagicNumber:ZcashSdk.kt$ZcashSdk$1_000L MagicNumber:ZcashSdk.kt$ZcashSdk$20 @@ -178,8 +176,8 @@ MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.Companion$"https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/basic-reorg/before-reorg.txt" MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.Companion$"still champion voice habit trend flight survey between bitter process artefact blind carbon truly provide dizzy crush flush breeze blouse charge solid fish spread" MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.DarksideChainMaker$. - MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.DarksideTestValidator$assertTrue("invalid available balance. Expected a minimum of $available but found ${balance.availableZatoshi}", available <= balance.availableZatoshi) - MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.DarksideTestValidator$assertTrue("invalid total balance. Expected a minimum of $total but found ${balance.totalZatoshi}", total <= balance.totalZatoshi) + MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.DarksideTestValidator$assertTrue("invalid available balance. Expected a minimum of $available but found ${balance?.available}", available <= balance?.available?.value!!) + MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.DarksideTestValidator$assertTrue("invalid total balance. Expected a minimum of $total but found ${balance?.total}", total <= balance?.total?.value!!) MaxLineLength:DarksideTestPrerequisites.kt$DarksideTestPrerequisites$"Darkside tests are configured to only run on the Android Emulator. Please see https://github.com/zcash/zcash-android-wallet-sdk/blob/master/docs/tests/Darkside.md" MaxLineLength:DemoConstants.kt$DemoConstants$"wish puppy smile loan doll curve hole maze file ginger hair nose key relax knife witness cannon grab despair throw review deal slush frame" MaxLineLength:DemoConstants.kt$DemoConstants$// corresponds to seed: urban kind wise collect social marble riot primary craft lucky head cause syrup odor artist decorate rhythm phone style benefit portion bus truck top @@ -317,7 +315,6 @@ MaxLineLength:TestExtensions.kt$Transactions$"https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/transactions/sent/ff6ea36765dc29793775c7aa71de19fca039c5b5b873a0497866e9c4bc48af01.txt" MaxLineLength:TestExtensions.kt$Transactions$"https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/transactions/t-shielded-spend.txt" MaxLineLength:TestWallet.kt$TestWallet$suspend - MaxLineLength:TestWallet.kt$TestWallet$twig("FOUND utxo balance of total: ${walletBalance.totalZatoshi} available: ${walletBalance.availableZatoshi}") MaxLineLength:TestWallet.kt$TestWallet.Backups$ALICE : Backups MaxLineLength:TestWallet.kt$TestWallet.Backups$DEV_WALLET : Backups MaxLineLength:TestWallet.kt$TestWallet.Backups$SAMPLE_WALLET : Backups @@ -329,7 +326,7 @@ MaxLineLength:TransparentRestoreSample.kt$TransparentRestoreSample$// Assert.assertTrue("Not enough funds to run sample. Expected at least $TX_VALUE Zatoshi but found $value. Try adding funds to $address", value >= TX_VALUE) MaxLineLength:TransparentRestoreSample.kt$TransparentRestoreSample$// twig("FOUND utxo balance of total: ${walletBalance.totalZatoshi} available: ${walletBalance.availableZatoshi}") MaxLineLength:TransparentRestoreSample.kt$TransparentRestoreSample$// walletA.send(TX_VALUE, walletA.transparentAddress, "${TransparentRestoreSample::class.java.simpleName} z->t") - MaxLineLength:TransparentRestoreSample.kt$TransparentRestoreSample$Assert.assertTrue("Not enough funds to run sample. Expected some Zatoshi but found ${tbalance.availableZatoshi}. Try adding funds to $address", tbalance.availableZatoshi > 0) + MaxLineLength:TransparentRestoreSample.kt$TransparentRestoreSample$Assert.assertTrue("Not enough funds to run sample. Expected some Zatoshi but found ${tbalance.available}. Try adding funds to $address", tbalance.available.value > 0) MaxLineLength:TransparentRestoreSample.kt$TransparentRestoreSample$val walletSandbox = TestWallet(TestWallet.Backups.SAMPLE_WALLET.seedPhrase, "WalletC", Testnet, startHeight = 1330190) MaxLineLength:TransparentTest.kt$TransparentTest$assertEquals(expected.tAddr, DerivationTool.deriveTransparentAddressFromPublicKey(uvk.extpub, network = network)) MaxLineLength:TransparentTest.kt$TransparentTest.Companion$const val PHRASE = "deputy visa gentle among clean scout farm drive comfort patch skin salt ranch cool ramp warrior drink narrow normal lunch behind salt deal person" @@ -338,7 +335,6 @@ MaxLineLength:WalletBirthdayTool.kt$WalletBirthdayTool$* @param treeFiles A list of files, sorted in descending order based on `int` value of the first part of the filename. MaxLineLength:WalletService.kt$var duration = Math.pow(initialDelayMillis.toDouble(), (sequence.toDouble() / 4.0)).toLong() + Random.nextLong(1000L) MaxLineLength:WalletService.kt$var sequence = 0 // count up to the max and then reset to half. So that we don't repeat the max but we also don't repeat too much. - MaxLineLength:WalletTypes.kt$ZcashNetwork$enum MaxLineLength:ZcashSdk.kt$ZcashSdk$* MaxLineLength:build.gradle.kts$// Tricky: fix: By default, the kotlin_module name will not include the version (in classes.jar/META-INF). Instead it has a colon, which breaks compilation on Windows. This is one way to set it explicitly to the proper value. See https://github.com/zcash/zcash-android-wallet-sdk/issues/222 for more info. MaxLineLength:build.gradle.kts$// solves error: Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules jetified-guava-26.0-android.jar (com.google.guava:guava:26.0-android) and listenablefuture-1.0.jar (com.google.guava:listenablefuture:1.0) @@ -361,13 +357,11 @@ MayBeConst:ZcashSdk.kt$ZcashSdk$/** * Estimate of the time between blocks. */ val BLOCK_INTERVAL_MILLIS = 75_000L MayBeConst:ZcashSdk.kt$ZcashSdk$/** * File name for the sapling output params */ val OUTPUT_PARAM_FILE_NAME = "sapling-output.params" MayBeConst:ZcashSdk.kt$ZcashSdk$/** * File name for the sappling spend params */ val SPEND_PARAM_FILE_NAME = "sapling-spend.params" - MayBeConst:ZcashSdk.kt$ZcashSdk$/** * Miner's fee in zatoshi. */ val MINERS_FEE_ZATOSHI = 1_000L MayBeConst:ZcashSdk.kt$ZcashSdk$/** * The Url that is used by default in zcashd. * We'll want to make this externally configurable, rather than baking it into the SDK but * this will do for now, since we're using a cloudfront URL that already redirects. */ val CLOUD_PARAM_DIR_URL = "https://z.cash/downloads/" MayBeConst:ZcashSdk.kt$ZcashSdk$/** * The amount of blocks ahead of the current height where new transactions are set to expire. This value is controlled * by the rust backend but it is helpful to know what it is set to and should be kept in sync. */ val EXPIRY_OFFSET = 20 MayBeConst:ZcashSdk.kt$ZcashSdk$/** * The default maximum amount of time to wait during retry backoff intervals. Failed loops will never wait longer than * this before retyring. */ val MAX_BACKOFF_INTERVAL = 600_000L MayBeConst:ZcashSdk.kt$ZcashSdk$/** * The default memo to use when shielding transparent funds. */ val DEFAULT_SHIELD_FUNDS_MEMO_PREFIX = "shielding:" MayBeConst:ZcashSdk.kt$ZcashSdk$/** * The maximum length of a memo. */ val MAX_MEMO_SIZE = 512 - MayBeConst:ZcashSdk.kt$ZcashSdk$/** * The number of zatoshi that equal 1 ZEC. */ val ZATOSHI_PER_ZEC = 100_000_000L MayBeConst:ZcashSdk.kt$ZcashSdk$/** * The theoretical maximum number of blocks in a reorg, due to other bottlenecks in the protocol design. */ val MAX_REORG_SIZE = 100 MayBeConst:ZcashSdk.kt$ZcashSdk$val DB_CACHE_NAME = "Cache.db" MayBeConst:ZcashSdk.kt$ZcashSdk$val DB_DATA_NAME = "Data.db" @@ -467,6 +461,5 @@ UtilityClassWithPublicConstructor:DerivationTool.kt$DerivationTool UtilityClassWithPublicConstructor:Placeholders.kt$SeedGenerator UtilityClassWithPublicConstructor:SaplingParamTool.kt$SaplingParamTool - VariableNaming:build.gradle.kts$val ARTIFACT_ID = project.property("POM_ARTIFACT_ID").toString()