Refactor to support new app.
This commit is contained in:
parent
88aeb4f5ac
commit
596bea0158
|
@ -4,13 +4,13 @@ import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import cash.z.wallet.sdk.block.CompactBlockDbStore
|
import cash.z.wallet.sdk.block.CompactBlockDbStore
|
||||||
import cash.z.wallet.sdk.block.CompactBlockDownloader
|
import cash.z.wallet.sdk.block.CompactBlockDownloader
|
||||||
import cash.z.wallet.sdk.block.CompactBlockProcessor
|
import cash.z.wallet.sdk.block.CompactBlockProcessor
|
||||||
import cash.z.wallet.sdk.transaction.PollingTransactionRepository
|
//import cash.z.wallet.sdk.transaction.PollingTransactionRepository
|
||||||
import cash.z.wallet.sdk.ext.TroubleshootingTwig
|
import cash.z.wallet.sdk.ext.TroubleshootingTwig
|
||||||
import cash.z.wallet.sdk.ext.Twig
|
import cash.z.wallet.sdk.ext.Twig
|
||||||
import cash.z.wallet.sdk.ext.SampleSeedProvider
|
import cash.z.wallet.sdk.ext.SampleSeedProvider
|
||||||
import cash.z.wallet.sdk.ext.SampleSpendingKeyProvider
|
import cash.z.wallet.sdk.ext.SampleSpendingKeyProvider
|
||||||
import cash.z.wallet.sdk.jni.RustBackend
|
import cash.z.wallet.sdk.jni.RustBackend
|
||||||
import cash.z.wallet.sdk.secure.Wallet
|
//import cash.z.wallet.sdk.secure.Wallet
|
||||||
import cash.z.wallet.sdk.service.LightWalletGrpcService
|
import cash.z.wallet.sdk.service.LightWalletGrpcService
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.AfterClass
|
import org.junit.AfterClass
|
||||||
|
@ -30,7 +30,7 @@ class IntegrationTest {
|
||||||
|
|
||||||
private lateinit var downloader: CompactBlockDownloader
|
private lateinit var downloader: CompactBlockDownloader
|
||||||
private lateinit var processor: CompactBlockProcessor
|
private lateinit var processor: CompactBlockProcessor
|
||||||
private lateinit var wallet: Wallet
|
// private lateinit var wallet: Wallet
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
|
@ -48,20 +48,20 @@ class IntegrationTest {
|
||||||
|
|
||||||
@Test(timeout = 120_000L)
|
@Test(timeout = 120_000L)
|
||||||
fun testSync() = runBlocking<Unit> {
|
fun testSync() = runBlocking<Unit> {
|
||||||
val rustBackend = RustBackend.init(context)
|
// val rustBackend = RustBackend.init(context)
|
||||||
|
|
||||||
val lightwalletService = LightWalletGrpcService(context,"192.168.1.134")
|
val lightwalletService = LightWalletGrpcService(context,"192.168.1.134")
|
||||||
val compactBlockStore = CompactBlockDbStore(context)
|
// val compactBlockStore = CompactBlockDbStore(context)
|
||||||
|
|
||||||
downloader = CompactBlockDownloader(lightwalletService, compactBlockStore)
|
// downloader = CompactBlockDownloader(lightwalletService, compactBlockStore)
|
||||||
processor = CompactBlockProcessor(downloader, repository, rustBackend)
|
// processor = CompactBlockProcessor(downloader, repository, rustBackend)
|
||||||
repository = PollingTransactionRepository(context, dataDbName, 10_000L)
|
// repository = PollingTransactionRepository(context, dataDbName, 10_000L)
|
||||||
wallet = Wallet(
|
// wallet = Wallet(
|
||||||
context,
|
// context,
|
||||||
rustBackend,
|
// rustBackend,
|
||||||
SampleSeedProvider("dummyseed"),
|
// SampleSeedProvider("dummyseed"),
|
||||||
SampleSpendingKeyProvider("dummyseed")
|
// SampleSpendingKeyProvider("dummyseed")
|
||||||
)
|
// )
|
||||||
|
|
||||||
// repository.start(this)
|
// repository.start(this)
|
||||||
// synchronizer = SdkSynchronizer(wallet, repository, , processor)
|
// synchronizer = SdkSynchronizer(wallet, repository, , processor)
|
||||||
|
@ -78,12 +78,12 @@ class IntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private lateinit var synchronizer: Synchronizer
|
// private lateinit var synchronizer: Synchronizer
|
||||||
private lateinit var repository: PollingTransactionRepository
|
// private lateinit var repository: PollingTransactionRepository
|
||||||
@AfterClass
|
@AfterClass
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
repository.stop()
|
// repository.stop()
|
||||||
synchronizer.stop()
|
// synchronizer.stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,6 +19,8 @@ import java.io.InputStreamReader
|
||||||
*/
|
*/
|
||||||
class Initializer(
|
class Initializer(
|
||||||
appContext: Context,
|
appContext: Context,
|
||||||
|
val host: String = ZcashSdk.DEFAULT_LIGHTWALLETD_HOST,
|
||||||
|
val port: Int = ZcashSdk.DEFAULT_LIGHTWALLETD_PORT,
|
||||||
private val alias: String = ZcashSdk.DEFAULT_DB_NAME_PREFIX
|
private val alias: String = ZcashSdk.DEFAULT_DB_NAME_PREFIX
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
|
|
|
@ -311,6 +311,7 @@ class SdkSynchronizer internal constructor(
|
||||||
fun Synchronizer(
|
fun Synchronizer(
|
||||||
appContext: Context,
|
appContext: Context,
|
||||||
lightwalletdHost: String = ZcashSdk.DEFAULT_LIGHTWALLETD_HOST,
|
lightwalletdHost: String = ZcashSdk.DEFAULT_LIGHTWALLETD_HOST,
|
||||||
|
lightwalletdPort: Int = ZcashSdk.DEFAULT_LIGHTWALLETD_PORT,
|
||||||
seed: ByteArray? = null,
|
seed: ByteArray? = null,
|
||||||
birthday: Initializer.WalletBirthday? = null
|
birthday: Initializer.WalletBirthday? = null
|
||||||
): Synchronizer {
|
): Synchronizer {
|
||||||
|
@ -331,9 +332,14 @@ fun Synchronizer(
|
||||||
initializer.import(seed, birthday, overwrite = true)
|
initializer.import(seed, birthday, overwrite = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Synchronizer(appContext, lightwalletdHost, initializer.rustBackend)
|
return Synchronizer(appContext, initializer.rustBackend, lightwalletdHost, lightwalletdPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Synchronizer(
|
||||||
|
appContext: Context,
|
||||||
|
initializer: Initializer
|
||||||
|
) = Synchronizer(appContext, initializer.rustBackend, initializer.host, initializer.port)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor function for building a Synchronizer in the most flexible way possible. This allows
|
* Constructor function for building a Synchronizer in the most flexible way possible. This allows
|
||||||
* a wallet maker to customize any subcomponent of the Synchronzier.
|
* a wallet maker to customize any subcomponent of the Synchronzier.
|
||||||
|
@ -341,12 +347,13 @@ fun Synchronizer(
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
fun Synchronizer(
|
fun Synchronizer(
|
||||||
appContext: Context,
|
appContext: Context,
|
||||||
lightwalletdHost: String,
|
|
||||||
rustBackend: RustBackend,
|
rustBackend: RustBackend,
|
||||||
|
lightwalletdHost: String = ZcashSdk.DEFAULT_LIGHTWALLETD_HOST,
|
||||||
|
lightwalletdPort: Int = ZcashSdk.DEFAULT_LIGHTWALLETD_PORT,
|
||||||
ledger: TransactionRepository =
|
ledger: TransactionRepository =
|
||||||
PagedTransactionRepository(appContext, 10, rustBackend.dbDataPath),
|
PagedTransactionRepository(appContext, 10, rustBackend.dbDataPath),
|
||||||
blockStore: CompactBlockStore = CompactBlockDbStore(appContext, rustBackend.dbCachePath),
|
blockStore: CompactBlockStore = CompactBlockDbStore(appContext, rustBackend.dbCachePath),
|
||||||
service: LightWalletService = LightWalletGrpcService(appContext, lightwalletdHost),
|
service: LightWalletService = LightWalletGrpcService(appContext, lightwalletdHost, lightwalletdPort),
|
||||||
encoder: TransactionEncoder = WalletTransactionEncoder(rustBackend, ledger),
|
encoder: TransactionEncoder = WalletTransactionEncoder(rustBackend, ledger),
|
||||||
downloader: CompactBlockDownloader = CompactBlockDownloader(service, blockStore),
|
downloader: CompactBlockDownloader = CompactBlockDownloader(service, blockStore),
|
||||||
manager: OutboundTransactionManager =
|
manager: OutboundTransactionManager =
|
||||||
|
|
|
@ -66,7 +66,7 @@ open class ZcashSdkCommon {
|
||||||
/**
|
/**
|
||||||
* The default port to use for connecting to lightwalletd instances.
|
* The default port to use for connecting to lightwalletd instances.
|
||||||
*/
|
*/
|
||||||
open val LIGHTWALLETD_PORT = 9067
|
open val DEFAULT_LIGHTWALLETD_PORT = 9067
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default host to use for lightwalletd.
|
* The default host to use for lightwalletd.
|
||||||
|
|
|
@ -3,7 +3,8 @@ package cash.z.wallet.sdk.service
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import cash.z.wallet.sdk.R
|
import cash.z.wallet.sdk.R
|
||||||
import cash.z.wallet.sdk.exception.LightwalletException
|
import cash.z.wallet.sdk.exception.LightwalletException
|
||||||
import cash.z.wallet.sdk.ext.ZcashSdk.LIGHTWALLETD_PORT
|
import cash.z.wallet.sdk.ext.ZcashSdk.DEFAULT_LIGHTWALLETD_PORT
|
||||||
|
import cash.z.wallet.sdk.ext.twig
|
||||||
import cash.z.wallet.sdk.rpc.CompactFormats
|
import cash.z.wallet.sdk.rpc.CompactFormats
|
||||||
import cash.z.wallet.sdk.rpc.CompactTxStreamerGrpc
|
import cash.z.wallet.sdk.rpc.CompactTxStreamerGrpc
|
||||||
import cash.z.wallet.sdk.rpc.Service
|
import cash.z.wallet.sdk.rpc.Service
|
||||||
|
@ -31,7 +32,7 @@ class LightWalletGrpcService private constructor(
|
||||||
constructor(
|
constructor(
|
||||||
appContext: Context,
|
appContext: Context,
|
||||||
host: String,
|
host: String,
|
||||||
port: Int = LIGHTWALLETD_PORT,
|
port: Int = DEFAULT_LIGHTWALLETD_PORT,
|
||||||
usePlaintext: Boolean = !appContext.resources.getBoolean(R.bool.is_mainnet)
|
usePlaintext: Boolean = !appContext.resources.getBoolean(R.bool.is_mainnet)
|
||||||
) : this(createDefaultChannel(appContext, host, port, usePlaintext))
|
) : this(createDefaultChannel(appContext, host, port, usePlaintext))
|
||||||
|
|
||||||
|
@ -94,6 +95,7 @@ class LightWalletGrpcService private constructor(
|
||||||
port: Int,
|
port: Int,
|
||||||
usePlaintext: Boolean
|
usePlaintext: Boolean
|
||||||
): ManagedChannel {
|
): ManagedChannel {
|
||||||
|
twig("Creating connection to $host:$port")
|
||||||
return AndroidChannelBuilder
|
return AndroidChannelBuilder
|
||||||
.forAddress(host, port)
|
.forAddress(host, port)
|
||||||
.context(appContext)
|
.context(appContext)
|
||||||
|
|
|
@ -17,7 +17,7 @@ object ZcashSdk : ZcashSdkCommon() {
|
||||||
/**
|
/**
|
||||||
* The default port to use for connecting to lightwalletd instances.
|
* The default port to use for connecting to lightwalletd instances.
|
||||||
*/
|
*/
|
||||||
override val LIGHTWALLETD_PORT = 443
|
override val DEFAULT_LIGHTWALLETD_PORT = 443
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default host to use for lightwalletd.
|
* The default host to use for lightwalletd.
|
||||||
|
|
Loading…
Reference in New Issue