[#1287] Remove LightWalletEndpointExt public API

- Closes #1287
- This refactored out all the occurrences of LightWalletEndpointExt and its functions and variables from the SDK’s public API. It preserves it in tests, demo app, and in the PersistableWallet for backward compatibility, although it’s not available from outside of the SDK.
- Changelog updated
This commit is contained in:
Honza Rychnovský 2024-01-08 14:45:47 +01:00 committed by GitHub
parent d8902d11df
commit 68cfd21fe7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 177 additions and 105 deletions

View File

@ -9,6 +9,11 @@ and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- `TransactionOverview.txIdString()` to provide a readable transaction ID to SDK-consuming apps - `TransactionOverview.txIdString()` to provide a readable transaction ID to SDK-consuming apps
### Removed
- `LightWalletEndpointExt` and its functions and variables were removed from the SDK's public APIs entirely. It's
preserved only for testing and wallet Demo app purposes. The calling wallet app should provide its own
`LightWalletEndpoint` instance within `PersistableWallet` or `SdkSynchornizer` APIs.
### Changed ### Changed
- Gradle 8.5 - Gradle 8.5
- Kotlin 1.9.21 - Kotlin 1.9.21

View File

@ -2,9 +2,9 @@ package cash.z.ecc.android.sdk.darkside.test
import androidx.test.core.app.ApplicationProvider import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import cash.z.ecc.android.sdk.ext.Darkside
import cash.z.ecc.android.sdk.model.Account import cash.z.ecc.android.sdk.model.Account
import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.Darkside
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import co.electriccoin.lightwallet.client.internal.DarksideApi import co.electriccoin.lightwallet.client.internal.DarksideApi
import co.electriccoin.lightwallet.client.internal.new import co.electriccoin.lightwallet.client.internal.new

View File

@ -6,10 +6,10 @@ import cash.z.ecc.android.bip39.toSeed
import cash.z.ecc.android.sdk.SdkSynchronizer import cash.z.ecc.android.sdk.SdkSynchronizer
import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.WalletInitMode
import cash.z.ecc.android.sdk.ext.Darkside
import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.internal.Twig
import cash.z.ecc.android.sdk.model.Account import cash.z.ecc.android.sdk.model.Account
import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.Darkside
import cash.z.ecc.android.sdk.model.WalletBalance import cash.z.ecc.android.sdk.model.WalletBalance
import cash.z.ecc.android.sdk.model.Zatoshi import cash.z.ecc.android.sdk.model.Zatoshi
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork

View File

@ -0,0 +1,26 @@
@file:Suppress("ktlint:standard:filename")
package cash.z.ecc.android.sdk.ext
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint
/*
* This is a set of the [LightWalletEndpoint] extension functions used for the darkside tests only and not part of the
* public APIs.
*/
/**
* This is a special localhost value on the Android emulator, which allows it to contact
* the localhost of the computer running the emulator.
*/
private const val COMPUTER_LOCALHOST = "10.0.2.2"
private const val DEFAULT_PORT = 9067
internal val LightWalletEndpoint.Companion.Darkside
get() =
LightWalletEndpoint(
COMPUTER_LOCALHOST,
DEFAULT_PORT,
isSecure = false
)

View File

@ -3,15 +3,15 @@ package cash.z.wallet.sdk.sample.demoapp
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.WalletInitMode
import cash.z.ecc.android.sdk.demoapp.ext.Mainnet
import cash.z.ecc.android.sdk.demoapp.ext.defaultForNetwork
import cash.z.ecc.android.sdk.demoapp.util.fromResources import cash.z.ecc.android.sdk.demoapp.util.fromResources
import cash.z.ecc.android.sdk.ext.convertZecToZatoshi import cash.z.ecc.android.sdk.ext.convertZecToZatoshi
import cash.z.ecc.android.sdk.ext.toHex import cash.z.ecc.android.sdk.ext.toHex
import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.internal.Twig
import cash.z.ecc.android.sdk.model.Account import cash.z.ecc.android.sdk.model.Account
import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.Mainnet
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.model.defaultForNetwork
import cash.z.ecc.android.sdk.tool.DerivationTool import cash.z.ecc.android.sdk.tool.DerivationTool
import co.electriccoin.lightwallet.client.LightWalletClient import co.electriccoin.lightwallet.client.LightWalletClient
import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe

View File

@ -20,9 +20,9 @@ import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController import androidx.navigation.ui.setupWithNavController
import androidx.viewbinding.ViewBinding import androidx.viewbinding.ViewBinding
import cash.z.ecc.android.sdk.demoapp.ext.defaultForNetwork
import cash.z.ecc.android.sdk.demoapp.util.fromResources import cash.z.ecc.android.sdk.demoapp.util.fromResources
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.model.defaultForNetwork
import co.electriccoin.lightwallet.client.LightWalletClient import co.electriccoin.lightwallet.client.LightWalletClient
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint import co.electriccoin.lightwallet.client.model.LightWalletEndpoint
import co.electriccoin.lightwallet.client.new import co.electriccoin.lightwallet.client.new

View File

@ -7,12 +7,12 @@ import cash.z.ecc.android.bip39.Mnemonics
import cash.z.ecc.android.bip39.toSeed import cash.z.ecc.android.bip39.toSeed
import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.WalletInitMode
import cash.z.ecc.android.sdk.demoapp.ext.defaultForNetwork
import cash.z.ecc.android.sdk.demoapp.util.fromResources import cash.z.ecc.android.sdk.demoapp.util.fromResources
import cash.z.ecc.android.sdk.ext.onFirst import cash.z.ecc.android.sdk.ext.onFirst
import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.internal.Twig
import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.model.defaultForNetwork
import co.electriccoin.lightwallet.client.ext.BenchmarkingExt import co.electriccoin.lightwallet.client.ext.BenchmarkingExt
import co.electriccoin.lightwallet.client.fixture.BenchmarkingBlockRangeFixture import co.electriccoin.lightwallet.client.fixture.BenchmarkingBlockRangeFixture
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint import co.electriccoin.lightwallet.client.model.LightWalletEndpoint

View File

@ -0,0 +1,36 @@
@file:Suppress("ktlint:standard:filename")
package cash.z.ecc.android.sdk.demoapp.ext
import cash.z.ecc.android.sdk.model.ZcashNetwork
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint
/*
* This set of extension functions suited for defaults for the Demo app is not part of the SDK's public APIs.
*/
internal fun LightWalletEndpoint.Companion.defaultForNetwork(zcashNetwork: ZcashNetwork): LightWalletEndpoint {
return when (zcashNetwork.id) {
ZcashNetwork.Mainnet.id -> LightWalletEndpoint.Mainnet
ZcashNetwork.Testnet.id -> LightWalletEndpoint.Testnet
else -> error("Unknown network id: ${zcashNetwork.id}")
}
}
private const val DEFAULT_PORT = 9067
internal val LightWalletEndpoint.Companion.Mainnet
get() =
LightWalletEndpoint(
"mainnet.lightwalletd.com",
DEFAULT_PORT,
isSecure = true
)
internal val LightWalletEndpoint.Companion.Testnet
get() =
LightWalletEndpoint(
"lightwalletd.testnet.electriccoin.co",
DEFAULT_PORT,
isSecure = true
)

View File

@ -9,6 +9,7 @@ import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.WalletCoordinator import cash.z.ecc.android.sdk.WalletCoordinator
import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.WalletInitMode
import cash.z.ecc.android.sdk.block.processor.CompactBlockProcessor import cash.z.ecc.android.sdk.block.processor.CompactBlockProcessor
import cash.z.ecc.android.sdk.demoapp.ext.defaultForNetwork
import cash.z.ecc.android.sdk.demoapp.getInstance import cash.z.ecc.android.sdk.demoapp.getInstance
import cash.z.ecc.android.sdk.demoapp.preference.EncryptedPreferenceKeys import cash.z.ecc.android.sdk.demoapp.preference.EncryptedPreferenceKeys
import cash.z.ecc.android.sdk.demoapp.preference.EncryptedPreferenceSingleton import cash.z.ecc.android.sdk.demoapp.preference.EncryptedPreferenceSingleton
@ -25,7 +26,6 @@ import cash.z.ecc.android.sdk.model.WalletBalance
import cash.z.ecc.android.sdk.model.Zatoshi import cash.z.ecc.android.sdk.model.Zatoshi
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.model.ZecSend import cash.z.ecc.android.sdk.model.ZecSend
import cash.z.ecc.android.sdk.model.defaultForNetwork
import cash.z.ecc.android.sdk.model.send import cash.z.ecc.android.sdk.model.send
import cash.z.ecc.android.sdk.tool.DerivationTool import cash.z.ecc.android.sdk.tool.DerivationTool
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint import co.electriccoin.lightwallet.client.model.LightWalletEndpoint

View File

@ -17,11 +17,11 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.WalletInitMode
import cash.z.ecc.android.sdk.demoapp.R import cash.z.ecc.android.sdk.demoapp.R
import cash.z.ecc.android.sdk.demoapp.ext.defaultForNetwork
import cash.z.ecc.android.sdk.fixture.WalletFixture import cash.z.ecc.android.sdk.fixture.WalletFixture
import cash.z.ecc.android.sdk.model.PersistableWallet import cash.z.ecc.android.sdk.model.PersistableWallet
import cash.z.ecc.android.sdk.model.SeedPhrase import cash.z.ecc.android.sdk.model.SeedPhrase
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.model.defaultForNetwork
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint import co.electriccoin.lightwallet.client.model.LightWalletEndpoint
@Preview(name = "Seed") @Preview(name = "Seed")

View File

@ -124,8 +124,20 @@ class PersistableWalletTest {
// Wallet version one deserialized by code supporting version two // Wallet version one deserialized by code supporting version two
val persistableWallet = PersistableWallet.from(json) val persistableWallet = PersistableWallet.from(json)
assertEquals( assertEquals(
LightWalletEndpoint.defaultForNetwork(persistableWallet.network), getLightWalletEndpointForNetwork(persistableWallet.network),
persistableWallet.endpoint persistableWallet.endpoint
) )
} }
@Test
@SmallTest
fun requireSecureMainnet() {
assertTrue(LightWalletEndpoint.Mainnet.isSecure)
}
@Test
@SmallTest
fun requireSecureTestnet() {
assertTrue(LightWalletEndpoint.Testnet.isSecure)
}
} }

View File

@ -14,7 +14,7 @@ import org.json.JSONObject
* Represents everything needed to save and restore a wallet. * Represents everything needed to save and restore a wallet.
* *
* @param network the network in which the wallet operates * @param network the network in which the wallet operates
* @param endpoint the endpoint with witch the wallet communicates * @param endpoint the endpoint with which the wallet communicates
* @param birthday the birthday of the wallet * @param birthday the birthday of the wallet
* @param seedPhrase the seed phrase of the wallet * @param seedPhrase the seed phrase of the wallet
* @param walletInitMode required parameter with one of [WalletInitMode] values. Use [WalletInitMode.NewWallet] when * @param walletInitMode required parameter with one of [WalletInitMode] values. Use [WalletInitMode.NewWallet] when
@ -25,7 +25,7 @@ import org.json.JSONObject
*/ */
data class PersistableWallet( data class PersistableWallet(
val network: ZcashNetwork, val network: ZcashNetwork,
val endpoint: LightWalletEndpoint = LightWalletEndpoint.defaultForNetwork(network), val endpoint: LightWalletEndpoint,
val birthday: BlockHeight?, val birthday: BlockHeight?,
val seedPhrase: SeedPhrase, val seedPhrase: SeedPhrase,
val walletInitMode: WalletInitMode val walletInitMode: WalletInitMode
@ -82,7 +82,7 @@ data class PersistableWallet(
when (val version = getVersion(jsonObject)) { when (val version = getVersion(jsonObject)) {
VERSION_1 -> { VERSION_1 -> {
endpoint = LightWalletEndpoint.defaultForNetwork(network) endpoint = getLightWalletEndpointForNetwork(network)
} }
VERSION_2 -> { VERSION_2 -> {
endpoint = getEndpoint(jsonObject) endpoint = getEndpoint(jsonObject)
@ -139,7 +139,7 @@ data class PersistableWallet(
* @return A new PersistableWallet with a random seed phrase. * @return A new PersistableWallet with a random seed phrase.
* *
* @param zcashNetwork the network in which the wallet operates * @param zcashNetwork the network in which the wallet operates
* @param endpoint the endpoint with witch the wallet communicates * @param endpoint the endpoint with which the wallet communicates
* @param walletInitMode required parameter with one of [WalletInitMode] values. Use [WalletInitMode.NewWallet] * @param walletInitMode required parameter with one of [WalletInitMode] values. Use [WalletInitMode.NewWallet]
* when starting synchronizer for a newly created wallet. Or use [WalletInitMode.RestoreWallet] when * when starting synchronizer for a newly created wallet. Or use [WalletInitMode.RestoreWallet] when
* restoring an existing wallet that was created at some point in the past. Or use the last [WalletInitMode * restoring an existing wallet that was created at some point in the past. Or use the last [WalletInitMode
@ -149,7 +149,7 @@ data class PersistableWallet(
suspend fun new( suspend fun new(
application: Application, application: Application,
zcashNetwork: ZcashNetwork, zcashNetwork: ZcashNetwork,
endpoint: LightWalletEndpoint = LightWalletEndpoint.defaultForNetwork(zcashNetwork), endpoint: LightWalletEndpoint,
walletInitMode: WalletInitMode walletInitMode: WalletInitMode
): PersistableWallet { ): PersistableWallet {
val birthday = BlockHeight.ofLatestCheckpoint(application, zcashNetwork) val birthday = BlockHeight.ofLatestCheckpoint(application, zcashNetwork)
@ -200,3 +200,33 @@ private suspend fun newMnemonic() =
} }
private suspend fun newSeedPhrase() = SeedPhrase(newMnemonic().map { it.concatToString() }) private suspend fun newSeedPhrase() = SeedPhrase(newMnemonic().map { it.concatToString() })
/*
* The following functions and variables are package private only and preserved to support backward compatibility for
* [PersistableWallet] and testing purposes.
*/
internal fun getLightWalletEndpointForNetwork(zcashNetwork: ZcashNetwork): LightWalletEndpoint {
return when (zcashNetwork.id) {
ZcashNetwork.Mainnet.id -> LightWalletEndpoint.Mainnet
ZcashNetwork.Testnet.id -> LightWalletEndpoint.Testnet
else -> error("Unknown network id: ${zcashNetwork.id}")
}
}
private const val DEFAULT_PORT = 9067
internal val LightWalletEndpoint.Companion.Mainnet
get() =
LightWalletEndpoint(
"mainnet.lightwalletd.com",
DEFAULT_PORT,
isSecure = true
)
internal val LightWalletEndpoint.Companion.Testnet
get() =
LightWalletEndpoint(
"lightwalletd.testnet.electriccoin.co",
DEFAULT_PORT,
isSecure = true
)

View File

@ -0,0 +1,38 @@
@file:Suppress("ktlint:standard:filename")
package cash.z.ecc.android.sdk.fixture
import cash.z.ecc.android.sdk.model.ZcashNetwork
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint
/*
* This is a set of extension functions for testing purposes only.
*/
object LightWalletEndpointFixture {
private const val DEFAULT_PORT = 9067
val LightWalletEndpoint.Companion.Mainnet
get() =
LightWalletEndpoint(
"mainnet.lightwalletd.com",
DEFAULT_PORT,
isSecure = true
)
val LightWalletEndpoint.Companion.Testnet
get() =
LightWalletEndpoint(
"lightwalletd.testnet.electriccoin.co",
DEFAULT_PORT,
isSecure = true
)
fun newEndpointForNetwork(zcashNetwork: ZcashNetwork): LightWalletEndpoint {
return when (zcashNetwork.id) {
ZcashNetwork.Mainnet.id -> LightWalletEndpoint.Mainnet
ZcashNetwork.Testnet.id -> LightWalletEndpoint.Testnet
else -> error("Unknown network id: ${zcashNetwork.id}")
}
}
}

View File

@ -7,7 +7,6 @@ import cash.z.ecc.android.sdk.annotation.TestPurpose
import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.internal.Twig
import cash.z.ecc.android.sdk.internal.block.CompactBlockDownloader import cash.z.ecc.android.sdk.internal.block.CompactBlockDownloader
import cash.z.ecc.android.sdk.internal.repository.CompactBlockRepository import cash.z.ecc.android.sdk.internal.repository.CompactBlockRepository
import cash.z.ecc.android.sdk.model.Mainnet
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.test.ScopedTest import cash.z.ecc.android.sdk.test.ScopedTest
import co.electriccoin.lightwallet.client.LightWalletClient import co.electriccoin.lightwallet.client.LightWalletClient
@ -15,7 +14,6 @@ import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint import co.electriccoin.lightwallet.client.model.LightWalletEndpoint
import co.electriccoin.lightwallet.client.model.Response import co.electriccoin.lightwallet.client.model.Response
import co.electriccoin.lightwallet.client.new import co.electriccoin.lightwallet.client.new
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import org.junit.After import org.junit.After
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
@ -31,7 +29,7 @@ import kotlin.test.Ignore
@SmallTest @SmallTest
class ChangeServiceTest : ScopedTest() { class ChangeServiceTest : ScopedTest() {
val network = ZcashNetwork.Mainnet val network = ZcashNetwork.Mainnet
val lightWalletEndpoint = LightWalletEndpoint.Mainnet val lightWalletEndpoint = LightWalletEndpoint("mainnet.lightwalletd.com", 9067, true)
private val eccEndpoint = LightWalletEndpoint("lightwalletd.electriccoin.co", 9087, true) private val eccEndpoint = LightWalletEndpoint("lightwalletd.electriccoin.co", 9087, true)
@Mock @Mock
@ -60,8 +58,7 @@ class ChangeServiceTest : ScopedTest() {
} }
@Test @Test
@OptIn(ExperimentalCoroutinesApi::class) @Ignore("Disabled as not working currently")
@Ignore
fun testSanityCheck() = fun testSanityCheck() =
runTest { runTest {
// Test the result, only if there is no server communication problem. // Test the result, only if there is no server communication problem.

View File

@ -5,10 +5,9 @@ import androidx.test.platform.app.InstrumentationRegistry
import cash.z.ecc.android.bip39.Mnemonics import cash.z.ecc.android.bip39.Mnemonics
import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.WalletInitMode
import cash.z.ecc.android.sdk.fixture.LightWalletEndpointFixture
import cash.z.ecc.android.sdk.fixture.WalletFixture import cash.z.ecc.android.sdk.fixture.WalletFixture
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.model.defaultForNetwork
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import java.util.UUID import java.util.UUID
import kotlin.test.Test import kotlin.test.Test
@ -28,7 +27,7 @@ class SdkSynchronizerTest {
InstrumentationRegistry.getInstrumentation().context, InstrumentationRegistry.getInstrumentation().context,
ZcashNetwork.Mainnet, ZcashNetwork.Mainnet,
alias, alias,
LightWalletEndpoint.defaultForNetwork(ZcashNetwork.Mainnet), LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet),
Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(), Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(),
birthday = null, birthday = null,
// Using existing wallet init mode as simplification for the test // Using existing wallet init mode as simplification for the test
@ -39,7 +38,7 @@ class SdkSynchronizerTest {
InstrumentationRegistry.getInstrumentation().context, InstrumentationRegistry.getInstrumentation().context,
ZcashNetwork.Mainnet, ZcashNetwork.Mainnet,
alias, alias,
LightWalletEndpoint.defaultForNetwork(ZcashNetwork.Mainnet), LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet),
Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(), Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(),
birthday = null, birthday = null,
// Using existing wallet init mode as simplification for the test // Using existing wallet init mode as simplification for the test
@ -64,7 +63,7 @@ class SdkSynchronizerTest {
InstrumentationRegistry.getInstrumentation().context, InstrumentationRegistry.getInstrumentation().context,
ZcashNetwork.Mainnet, ZcashNetwork.Mainnet,
alias, alias,
LightWalletEndpoint.defaultForNetwork(ZcashNetwork.Mainnet), LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet),
Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(), Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(),
birthday = null, birthday = null,
// Using existing wallet init mode as simplification for the test // Using existing wallet init mode as simplification for the test
@ -76,7 +75,7 @@ class SdkSynchronizerTest {
InstrumentationRegistry.getInstrumentation().context, InstrumentationRegistry.getInstrumentation().context,
ZcashNetwork.Mainnet, ZcashNetwork.Mainnet,
alias, alias,
LightWalletEndpoint.defaultForNetwork(ZcashNetwork.Mainnet), LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet),
Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(), Mnemonics.MnemonicCode(WalletFixture.SEED_PHRASE).toEntropy(),
birthday = null, birthday = null,
// Using existing wallet init mode as simplification for the test // Using existing wallet init mode as simplification for the test

View File

@ -4,15 +4,14 @@ import androidx.test.platform.app.InstrumentationRegistry
import cash.z.ecc.android.sdk.CloseableSynchronizer import cash.z.ecc.android.sdk.CloseableSynchronizer
import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.WalletInitMode
import cash.z.ecc.android.sdk.fixture.LightWalletEndpointFixture
import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.internal.Twig
import cash.z.ecc.android.sdk.internal.ext.deleteSuspend import cash.z.ecc.android.sdk.internal.ext.deleteSuspend
import cash.z.ecc.android.sdk.internal.model.Checkpoint import cash.z.ecc.android.sdk.internal.model.Checkpoint
import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.model.defaultForNetwork
import cash.z.ecc.android.sdk.test.readFileLinesInFlow import cash.z.ecc.android.sdk.test.readFileLinesInFlow
import cash.z.ecc.android.sdk.tool.CheckpointTool import cash.z.ecc.android.sdk.tool.CheckpointTool
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
@ -96,9 +95,7 @@ class BalancePrinterUtil {
Synchronizer.new( Synchronizer.new(
context, context,
network, network,
lightWalletEndpoint = lightWalletEndpoint = LightWalletEndpointFixture.newEndpointForNetwork(network),
LightWalletEndpoint
.defaultForNetwork(network),
seed = seed, seed = seed,
birthday = birthdayHeight, birthday = birthdayHeight,
// Using existing wallet init mode as simplification for the test // Using existing wallet init mode as simplification for the test

View File

@ -5,10 +5,9 @@ import cash.z.ecc.android.sdk.CloseableSynchronizer
import cash.z.ecc.android.sdk.SdkSynchronizer import cash.z.ecc.android.sdk.SdkSynchronizer
import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.WalletInitMode
import cash.z.ecc.android.sdk.fixture.LightWalletEndpointFixture
import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.model.defaultForNetwork
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
@ -69,9 +68,7 @@ class DataDbScannerUtil {
Synchronizer.newBlocking( Synchronizer.newBlocking(
context, context,
ZcashNetwork.Mainnet, ZcashNetwork.Mainnet,
lightWalletEndpoint = lightWalletEndpoint = LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet),
LightWalletEndpoint
.defaultForNetwork(ZcashNetwork.Mainnet),
seed = byteArrayOf(), seed = byteArrayOf(),
birthday = birthday =
BlockHeight.new( BlockHeight.new(

View File

@ -6,12 +6,12 @@ import cash.z.ecc.android.bip39.toSeed
import cash.z.ecc.android.sdk.SdkSynchronizer import cash.z.ecc.android.sdk.SdkSynchronizer
import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.WalletInitMode import cash.z.ecc.android.sdk.WalletInitMode
import cash.z.ecc.android.sdk.fixture.LightWalletEndpointFixture
import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.internal.Twig
import cash.z.ecc.android.sdk.internal.deriveUnifiedSpendingKey import cash.z.ecc.android.sdk.internal.deriveUnifiedSpendingKey
import cash.z.ecc.android.sdk.internal.jni.RustDerivationTool import cash.z.ecc.android.sdk.internal.jni.RustDerivationTool
import cash.z.ecc.android.sdk.model.Account import cash.z.ecc.android.sdk.model.Account
import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.Testnet
import cash.z.ecc.android.sdk.model.WalletBalance import cash.z.ecc.android.sdk.model.WalletBalance
import cash.z.ecc.android.sdk.model.Zatoshi import cash.z.ecc.android.sdk.model.Zatoshi
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
@ -35,7 +35,7 @@ class TestWallet(
val seedPhrase: String, val seedPhrase: String,
val alias: String = "TestWallet", val alias: String = "TestWallet",
val network: ZcashNetwork = ZcashNetwork.Testnet, val network: ZcashNetwork = ZcashNetwork.Testnet,
val endpoint: LightWalletEndpoint = LightWalletEndpoint.Testnet, val endpoint: LightWalletEndpoint = LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Testnet),
startHeight: BlockHeight? = null startHeight: BlockHeight? = null
) { ) {
constructor( constructor(

View File

@ -1,10 +1,10 @@
package cash.z.ecc.android.sdk.util package cash.z.ecc.android.sdk.util
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import cash.z.ecc.android.sdk.fixture.LightWalletEndpointFixture
import cash.z.ecc.android.sdk.internal.Twig import cash.z.ecc.android.sdk.internal.Twig
import cash.z.ecc.android.sdk.internal.model.ext.from import cash.z.ecc.android.sdk.internal.model.ext.from
import cash.z.ecc.android.sdk.model.BlockHeight import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.Mainnet
import cash.z.ecc.android.sdk.model.ZcashNetwork import cash.z.ecc.android.sdk.model.ZcashNetwork
import co.electriccoin.lightwallet.client.LightWalletClient import co.electriccoin.lightwallet.client.LightWalletClient
import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe
@ -15,7 +15,8 @@ import org.junit.Test
class TransactionCounterUtil { class TransactionCounterUtil {
private val context = InstrumentationRegistry.getInstrumentation().context private val context = InstrumentationRegistry.getInstrumentation().context
private val lightWalletClient = LightWalletClient.new(context, LightWalletEndpoint.Mainnet) private val endpoint: LightWalletEndpoint = LightWalletEndpointFixture.newEndpointForNetwork(ZcashNetwork.Mainnet)
private val lightWalletClient = LightWalletClient.new(context, endpoint)
@Test @Test
@Ignore("This test is broken") @Ignore("This test is broken")

View File

@ -1,49 +0,0 @@
@file:Suppress("ktlint:standard:filename")
package cash.z.ecc.android.sdk.model
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint
/*
* This is a set of extension functions currently, because we expect them to change in the future.
*/
fun LightWalletEndpoint.Companion.defaultForNetwork(zcashNetwork: ZcashNetwork): LightWalletEndpoint {
return when (zcashNetwork.id) {
ZcashNetwork.Mainnet.id -> LightWalletEndpoint.Mainnet
ZcashNetwork.Testnet.id -> LightWalletEndpoint.Testnet
else -> error("Unknown network id: ${zcashNetwork.id}")
}
}
/**
* This is a special localhost value on the Android emulator, which allows it to contact
* the localhost of the computer running the emulator.
*/
private const val COMPUTER_LOCALHOST = "10.0.2.2"
private const val DEFAULT_PORT = 9067
val LightWalletEndpoint.Companion.Mainnet
get() =
LightWalletEndpoint(
"mainnet.lightwalletd.com",
DEFAULT_PORT,
isSecure = true
)
val LightWalletEndpoint.Companion.Testnet
get() =
LightWalletEndpoint(
"lightwalletd.testnet.electriccoin.co",
DEFAULT_PORT,
isSecure = true
)
val LightWalletEndpoint.Companion.Darkside
get() =
LightWalletEndpoint(
COMPUTER_LOCALHOST,
DEFAULT_PORT,
isSecure = false
)

View File

@ -1,17 +0,0 @@
package cash.z.ecc.android.sdk.model
import co.electriccoin.lightwallet.client.model.LightWalletEndpoint
import org.junit.Test
import kotlin.test.assertTrue
class LightWalletEndpointTest {
@Test
fun requireSecureMainnet() {
assertTrue(LightWalletEndpoint.Mainnet.isSecure)
}
@Test
fun requireSecureTestnet() {
assertTrue(LightWalletEndpoint.Testnet.isSecure)
}
}