[#580] ktlint 0.46.1

Update baseline
This commit is contained in:
Carter Jernigan 2022-06-23 08:31:02 -04:00 committed by Carter Jernigan
parent bd2061956b
commit 3fa7a98fbf
33 changed files with 199 additions and 119 deletions

View File

@ -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

View File

@ -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,

View File

@ -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())
}

View File

@ -89,7 +89,6 @@ class ListUtxosFragment : BaseDemoFragment<FragmentListUtxosBinding>() {
}
fun downloadTransactions() {
binding.textStatus.text = "loading..."
binding.textStatus.post {
binding.textStatus.requestFocus()

View File

@ -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

View File

@ -1,3 +1,5 @@
@file:Suppress("ktlint:filename")
package cash.z.ecc.android.sdk.demoapp.util
import android.content.Context

View File

@ -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

View File

@ -28,6 +28,6 @@ import org.junit.runners.Suite
// potentially exclude because these hit external services
ChangeServiceTest::class,
SmokeTest::class,
SmokeTest::class
)
class PullRequestSuite

View File

@ -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
) {

View File

@ -40,7 +40,7 @@ class TestnetIntegrationTest : ScopedTest() {
fun testLatestBlockTest() {
val service = LightWalletGrpcService(
context,
host,
host
)
val height = service.getLatestBlockHeight()
assertTrue(height > saplingActivation)

View File

@ -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)
)
}
}

View File

@ -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"

View File

@ -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)
)
}
}

View File

@ -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)
)
}

View File

@ -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,

View File

@ -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"

View File

@ -36,7 +36,7 @@ class Initializer private constructor(
class Config private constructor(
val viewingKeys: MutableList<UnifiedViewingKey> = mutableListOf(),
var alias: String = ZcashSdk.DEFAULT_ALIAS,
var alias: String = ZcashSdk.DEFAULT_ALIAS
) {
var birthdayHeight: Int? = null
private set

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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" +

View File

@ -1,3 +1,5 @@
@file:Suppress("ktlint:filename")
package cash.z.ecc.android.sdk.internal.ext
internal fun ByteArray.toHexReversed(): String {

View File

@ -1,3 +1,5 @@
@file:Suppress("ktlint:filename")
package cash.z.ecc.android.sdk.internal.ext
import kotlinx.coroutines.Dispatchers

View File

@ -115,7 +115,7 @@ class PagedTransactionRepository private constructor(
rustBackend: RustBackend,
birthday: WalletBirthday,
viewingKeys: List<UnifiedViewingKey>,
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<UnifiedViewingKey>,
viewingKeys: List<UnifiedViewingKey>
) {
maybeCreateDataDb(rustBackend)
maybeInitBlocksTable(rustBackend, birthday)

View File

@ -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
}

View File

@ -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)
}

View File

@ -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<out String>,
extpub: Array<out String>,
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
}
}

View File

@ -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<String>
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<UnifiedViewingKey>
}
}

View File

@ -117,14 +117,14 @@ class DerivationTool {
private external fun deriveExtendedSpendingKeys(
seed: ByteArray,
numberOfAccounts: Int,
networkId: Int,
networkId: Int
): Array<String>
@JvmStatic
private external fun deriveUnifiedViewingKeysFromSeed(
seed: ByteArray,
numberOfAccounts: Int,
networkId: Int,
networkId: Int
): Array<Array<String>>
@JvmStatic
@ -134,7 +134,7 @@ class DerivationTool {
private external fun deriveShieldedAddressFromSeed(
seed: ByteArray,
accountIndex: Int,
networkId: Int,
networkId: Int
): String
@JvmStatic

View File

@ -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<String> {
val unfilteredTreeFiles = listBirthdayDirectoryContents(context, directory)
if (unfilteredTreeFiles.isNullOrEmpty()) {

View File

@ -1,3 +1,5 @@
@file:Suppress("ktlint:filename")
package cash.z.wallet
import org.mockito.Mockito

View File

@ -2,7 +2,6 @@
<SmellBaseline>
<ManuallySuppressedIssues/>
<CurrentIssues>
<ID>ComplexCondition:WalletTypes.kt$WalletBalance$totalZatoshi == -1L &amp;&amp; other.totalZatoshi == -1L &amp;&amp; availableZatoshi == -1L &amp;&amp; other.availableZatoshi == -1L</ID>
<ID>ComplexMethod:SdkSynchronizer.kt$SdkSynchronizer$private suspend fun refreshPendingTransactions()</ID>
<ID>ComplexMethod:SendFragment.kt$SendFragment$private fun onPendingTxUpdated(pendingTransaction: PendingTransaction?)</ID>
<ID>ComplexMethod:Transactions.kt$ConfirmedTransaction$override fun equals(other: Any?): Boolean</ID>
@ -52,11 +51,11 @@
<ID>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&lt;UnifiedViewingKey>, val overwriteVks: Boolean, val birthday: WalletBirthday )</ID>
<ID>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 )</ID>
<ID>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 )</ID>
<ID>LongParameterList:PagedTransactionRepository.kt$PagedTransactionRepository.Companion$( appContext: Context, pageSize: Int = 10, rustBackend: RustBackend, birthday: WalletBirthday, viewingKeys: List&lt;UnifiedViewingKey>, overwriteVks: Boolean = false, )</ID>
<ID>LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, account: Int, extsk: String, tsk: String, memo: ByteArray, spendParamsPath: String, outputParamsPath: String, networkId: Int, )</ID>
<ID>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, )</ID>
<ID>LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, height: Int, hash: String, time: Long, saplingTree: String, networkId: Int, )</ID>
<ID>LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, tAddress: String, txId: ByteArray, index: Int, script: ByteArray, value: Long, height: Int, networkId: Int, )</ID>
<ID>LongParameterList:PagedTransactionRepository.kt$PagedTransactionRepository.Companion$( appContext: Context, pageSize: Int = 10, rustBackend: RustBackend, birthday: WalletBirthday, viewingKeys: List&lt;UnifiedViewingKey>, overwriteVks: Boolean = false )</ID>
<ID>LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, account: Int, extsk: String, tsk: String, memo: ByteArray, spendParamsPath: String, outputParamsPath: String, networkId: Int )</ID>
<ID>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 )</ID>
<ID>LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, height: Int, hash: String, time: Long, saplingTree: String, networkId: Int )</ID>
<ID>LongParameterList:RustBackend.kt$RustBackend.Companion$( dbDataPath: String, tAddress: String, txId: ByteArray, index: Int, script: ByteArray, value: Long, height: Int, networkId: Int )</ID>
<ID>LongParameterList:RustBackendWelding.kt$RustBackendWelding$( consensusBranchId: Long, account: Int, extsk: String, to: String, value: Long, memo: ByteArray? = byteArrayOf() )</ID>
<ID>LongParameterList:RustBackendWelding.kt$RustBackendWelding$( tAddress: String, txId: ByteArray, index: Int, script: ByteArray, value: Long, height: Int )</ID>
<ID>MagicNumber:BatchMetrics.kt$BatchMetrics$1000.0f</ID>
@ -121,7 +120,6 @@
<ID>MagicNumber:WalletTypes.kt$ZcashNetwork.Testnet$9067</ID>
<ID>MagicNumber:ZcashSdk.kt$ZcashSdk$10</ID>
<ID>MagicNumber:ZcashSdk.kt$ZcashSdk$100</ID>
<ID>MagicNumber:ZcashSdk.kt$ZcashSdk$100_000_000L</ID>
<ID>MagicNumber:ZcashSdk.kt$ZcashSdk$150</ID>
<ID>MagicNumber:ZcashSdk.kt$ZcashSdk$1_000L</ID>
<ID>MagicNumber:ZcashSdk.kt$ZcashSdk$20</ID>
@ -178,8 +176,8 @@
<ID>MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.Companion$"https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/basic-reorg/before-reorg.txt"</ID>
<ID>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"</ID>
<ID>MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.DarksideChainMaker$.</ID>
<ID>MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.DarksideTestValidator$assertTrue("invalid available balance. Expected a minimum of $available but found ${balance.availableZatoshi}", available &lt;= balance.availableZatoshi)</ID>
<ID>MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.DarksideTestValidator$assertTrue("invalid total balance. Expected a minimum of $total but found ${balance.totalZatoshi}", total &lt;= balance.totalZatoshi)</ID>
<ID>MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.DarksideTestValidator$assertTrue("invalid available balance. Expected a minimum of $available but found ${balance?.available}", available &lt;= balance?.available?.value!!)</ID>
<ID>MaxLineLength:DarksideTestCoordinator.kt$DarksideTestCoordinator.DarksideTestValidator$assertTrue("invalid total balance. Expected a minimum of $total but found ${balance?.total}", total &lt;= balance?.total?.value!!)</ID>
<ID>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"</ID>
<ID>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"</ID>
<ID>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</ID>
@ -317,7 +315,6 @@
<ID>MaxLineLength:TestExtensions.kt$Transactions$"https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/transactions/sent/ff6ea36765dc29793775c7aa71de19fca039c5b5b873a0497866e9c4bc48af01.txt"</ID>
<ID>MaxLineLength:TestExtensions.kt$Transactions$"https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/transactions/t-shielded-spend.txt"</ID>
<ID>MaxLineLength:TestWallet.kt$TestWallet$suspend</ID>
<ID>MaxLineLength:TestWallet.kt$TestWallet$twig("FOUND utxo balance of total: ${walletBalance.totalZatoshi} available: ${walletBalance.availableZatoshi}")</ID>
<ID>MaxLineLength:TestWallet.kt$TestWallet.Backups$ALICE : Backups</ID>
<ID>MaxLineLength:TestWallet.kt$TestWallet.Backups$DEV_WALLET : Backups</ID>
<ID>MaxLineLength:TestWallet.kt$TestWallet.Backups$SAMPLE_WALLET : Backups</ID>
@ -329,7 +326,7 @@
<ID>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)</ID>
<ID>MaxLineLength:TransparentRestoreSample.kt$TransparentRestoreSample$// twig("FOUND utxo balance of total: ${walletBalance.totalZatoshi} available: ${walletBalance.availableZatoshi}")</ID>
<ID>MaxLineLength:TransparentRestoreSample.kt$TransparentRestoreSample$// walletA.send(TX_VALUE, walletA.transparentAddress, "${TransparentRestoreSample::class.java.simpleName} z->t")</ID>
<ID>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)</ID>
<ID>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)</ID>
<ID>MaxLineLength:TransparentRestoreSample.kt$TransparentRestoreSample$val walletSandbox = TestWallet(TestWallet.Backups.SAMPLE_WALLET.seedPhrase, "WalletC", Testnet, startHeight = 1330190)</ID>
<ID>MaxLineLength:TransparentTest.kt$TransparentTest$assertEquals(expected.tAddr, DerivationTool.deriveTransparentAddressFromPublicKey(uvk.extpub, network = network))</ID>
<ID>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"</ID>
@ -338,7 +335,6 @@
<ID>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.</ID>
<ID>MaxLineLength:WalletService.kt$var duration = Math.pow(initialDelayMillis.toDouble(), (sequence.toDouble() / 4.0)).toLong() + Random.nextLong(1000L)</ID>
<ID>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.</ID>
<ID>MaxLineLength:WalletTypes.kt$ZcashNetwork$enum</ID>
<ID>MaxLineLength:ZcashSdk.kt$ZcashSdk$*</ID>
<ID>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.</ID>
<ID>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)</ID>
@ -361,13 +357,11 @@
<ID>MayBeConst:ZcashSdk.kt$ZcashSdk$/** * Estimate of the time between blocks. */ val BLOCK_INTERVAL_MILLIS = 75_000L</ID>
<ID>MayBeConst:ZcashSdk.kt$ZcashSdk$/** * File name for the sapling output params */ val OUTPUT_PARAM_FILE_NAME = "sapling-output.params"</ID>
<ID>MayBeConst:ZcashSdk.kt$ZcashSdk$/** * File name for the sappling spend params */ val SPEND_PARAM_FILE_NAME = "sapling-spend.params"</ID>
<ID>MayBeConst:ZcashSdk.kt$ZcashSdk$/** * Miner's fee in zatoshi. */ val MINERS_FEE_ZATOSHI = 1_000L</ID>
<ID>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/"</ID>
<ID>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</ID>
<ID>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</ID>
<ID>MayBeConst:ZcashSdk.kt$ZcashSdk$/** * The default memo to use when shielding transparent funds. */ val DEFAULT_SHIELD_FUNDS_MEMO_PREFIX = "shielding:"</ID>
<ID>MayBeConst:ZcashSdk.kt$ZcashSdk$/** * The maximum length of a memo. */ val MAX_MEMO_SIZE = 512</ID>
<ID>MayBeConst:ZcashSdk.kt$ZcashSdk$/** * The number of zatoshi that equal 1 ZEC. */ val ZATOSHI_PER_ZEC = 100_000_000L</ID>
<ID>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</ID>
<ID>MayBeConst:ZcashSdk.kt$ZcashSdk$val DB_CACHE_NAME = "Cache.db"</ID>
<ID>MayBeConst:ZcashSdk.kt$ZcashSdk$val DB_DATA_NAME = "Data.db"</ID>
@ -467,6 +461,5 @@
<ID>UtilityClassWithPublicConstructor:DerivationTool.kt$DerivationTool</ID>
<ID>UtilityClassWithPublicConstructor:Placeholders.kt$SeedGenerator</ID>
<ID>UtilityClassWithPublicConstructor:SaplingParamTool.kt$SaplingParamTool</ID>
<ID>VariableNaming:build.gradle.kts$val ARTIFACT_ID = project.property("POM_ARTIFACT_ID").toString()</ID>
</CurrentIssues>
</SmellBaseline>