Unify new clients instances name

This commit is contained in:
Honza 2023-01-29 18:37:44 +01:00
parent f569677fec
commit e2d1d93ac2
11 changed files with 31 additions and 33 deletions

View File

@ -106,7 +106,7 @@ package cash.z.ecc.android.sdk.darkside.reorgs // package cash.z.ecc.android.sdk
// lightwalletd.getBlockRange(height..height).first() // lightwalletd.getBlockRange(height..height).first()
// //
// private val lightwalletd // private val lightwalletd
// get() = (synchronizer as SdkSynchronizer).processor.downloader.lightwalletService // get() = (synchronizer as SdkSynchronizer).processor.downloader.lightWalletClient
// //
// companion object { // companion object {
// private const val port = 9067 // private const val port = 9067

View File

@ -82,8 +82,8 @@ class SampleCodeTest {
// Query latest block height // Query latest block height
@Test @Test
fun getLatestBlockHeightTest() { fun getLatestBlockHeightTest() {
val lightwalletService = BlockingLightWalletClient.new(context, lightwalletdHost) val lightwalletClient = BlockingLightWalletClient.new(context, lightwalletdHost)
log("Latest Block: ${lightwalletService.getLatestBlockHeight()}") log("Latest Block: ${lightwalletClient.getLatestBlockHeight()}")
} }
// /////////////////////////////////////////////////// // ///////////////////////////////////////////////////
@ -103,8 +103,8 @@ class SampleCodeTest {
).value ).value
) )
) )
val lightwalletService = BlockingLightWalletClient.new(context, lightwalletdHost) val lightwalletClient = BlockingLightWalletClient.new(context, lightwalletdHost)
val blocks = lightwalletService.getBlockRange(blockRange) val blocks = lightwalletClient.getBlockRange(blockRange)
assertEquals(blockRange.endInclusive.value - blockRange.start.value, blocks.count()) assertEquals(blockRange.endInclusive.value - blockRange.start.value, blocks.count())
blocks.forEachIndexed { i, block -> blocks.forEachIndexed { i, block ->

View File

@ -23,11 +23,11 @@ import kotlinx.coroutines.launch
abstract class BaseDemoFragment<T : ViewBinding> : Fragment() { abstract class BaseDemoFragment<T : ViewBinding> : Fragment() {
/** /**
* Since the lightwalletService is not a component that apps typically use, directly, we provide * Since the lightwalletClient is not a component that apps typically use, directly, we provide
* this from one place. Everything that can be done with the service can/should be done with the * this from one place. Everything that can be done with the service can/should be done with the
* synchronizer because it wraps the service. * synchronizer because it wraps the service.
*/ */
val lightWalletService get() = mainActivity()?.lightwalletClient val lightWalletClient get() = mainActivity()?.lightwalletClient
// contains view information provided by the user // contains view information provided by the user
val sharedViewModel: SharedViewModel by activityViewModels() val sharedViewModel: SharedViewModel by activityViewModels()

View File

@ -19,7 +19,7 @@ import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe
import kotlin.math.min import kotlin.math.min
/** /**
* Retrieves a compact block from the lightwalletd service and displays basic information about it. * Retrieves a compact block from the lightwalletd server and displays basic information about it.
* This demonstrates the basic ability to connect to the server, request a compact block and parse * This demonstrates the basic ability to connect to the server, request a compact block and parse
* the response. * the response.
*/ */
@ -27,7 +27,7 @@ class GetBlockFragment : BaseDemoFragment<FragmentGetBlockBinding>() {
private fun setBlockHeight(blockHeight: BlockHeight) { private fun setBlockHeight(blockHeight: BlockHeight) {
val blocks = val blocks =
lightWalletService?.getBlockRange( lightWalletClient?.getBlockRange(
BlockHeightUnsafe(blockHeight.value)..BlockHeightUnsafe( BlockHeightUnsafe(blockHeight.value)..BlockHeightUnsafe(
blockHeight.value blockHeight.value
) )

View File

@ -18,7 +18,7 @@ import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe
import kotlin.math.max import kotlin.math.max
/** /**
* Retrieves a range of compact block from the lightwalletd service and displays basic information * Retrieves a range of compact block from the lightwalletd server and displays basic information
* about them. This demonstrates the basic ability to connect to the server, request a range of * about them. This demonstrates the basic ability to connect to the server, request a range of
* compact block and parse the response. This could be augmented to display metadata about certain * compact block and parse the response. This could be augmented to display metadata about certain
* block ranges for instance, to find the block with the most shielded transactions in a range. * block ranges for instance, to find the block with the most shielded transactions in a range.
@ -28,7 +28,7 @@ class GetBlockRangeFragment : BaseDemoFragment<FragmentGetBlockRangeBinding>() {
private fun setBlockRange(blockRange: ClosedRange<BlockHeight>) { private fun setBlockRange(blockRange: ClosedRange<BlockHeight>) {
val start = System.currentTimeMillis() val start = System.currentTimeMillis()
val blocks = val blocks =
lightWalletService?.getBlockRange( lightWalletClient?.getBlockRange(
BlockHeightUnsafe(blockRange.start.value)..BlockHeightUnsafe( BlockHeightUnsafe(blockRange.start.value)..BlockHeightUnsafe(
blockRange.endInclusive.value blockRange.endInclusive.value
) )

View File

@ -15,7 +15,7 @@ class GetLatestHeightFragment : BaseDemoFragment<FragmentGetLatestHeightBinding>
private fun displayLatestHeight() { private fun displayLatestHeight() {
// note: this is a blocking call, a real app wouldn't do this on the main thread // note: this is a blocking call, a real app wouldn't do this on the main thread
// instead, a production app would leverage the synchronizer like in the other demos // instead, a production app would leverage the synchronizer like in the other demos
binding.textInfo.text = lightWalletService?.getLatestBlockHeight().toString() binding.textInfo.text = lightWalletClient?.getLatestBlockHeight().toString()
} }
// //

View File

@ -85,7 +85,7 @@ class ListUtxosFragment : BaseDemoFragment<FragmentListUtxosBinding>() {
?: getUxtoEndHeight(requireApplicationContext()).value ?: getUxtoEndHeight(requireApplicationContext()).value
var allStart = now var allStart = now
twig("loading transactions in range $startToUse..$endToUse") twig("loading transactions in range $startToUse..$endToUse")
val txids = lightWalletService?.getTAddressTransactions( val txids = lightWalletClient?.getTAddressTransactions(
addressToUse, addressToUse,
BlockHeightUnsafe(startToUse)..BlockHeightUnsafe(endToUse) BlockHeightUnsafe(startToUse)..BlockHeightUnsafe(endToUse)
) )

View File

@ -38,14 +38,14 @@ This is generally not considered part of the public API, and much of the interna
## Components ## Components
| Component | Summary | | Component | Summary |
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | |--------------------------------|-------------------------------------------------------------------------------------------|
| **LightWalletService** | Service used for requesting compact blocks | | **LightWalletClient** | Component used for requesting compact blocks |
| **CompactBlockStore** | Stores compact blocks that have been downloaded from the `LightWalletService` | | **CompactBlockStore** | Stores compact blocks that have been downloaded from the `LightWalletClient` |
| **CompactBlockProcessor** | Validates and scans the compact blocks in the `CompactBlockStore` for transaction details | | **CompactBlockProcessor** | Validates and scans the compact blocks in the `CompactBlockStore` for transaction details |
| **OutboundTransactionManager** | Creates, Submits and manages transactions for spending funds | | **OutboundTransactionManager** | Creates, Submits and manages transactions for spending funds |
| **DerivationTool** | Utilities for deriving keys and addresses | | **DerivationTool** | Utilities for deriving keys and addresses |
| **RustBackend** | Wraps and simplifies the rust library and exposes its functionality to the Kotlin SDK | | **RustBackend** | Wraps and simplifies the rust library and exposes its functionality to the Kotlin SDK |
## Checkpoints ## Checkpoints
To improve the speed of syncing with the Zcash network, the SDK contains a series of embedded checkpoints. These should be updated periodically, as new transactions are added to the network. Checkpoints are stored under the [sdk-lib's assets](../sdk-lib/src/main/assets/co.electriccoin.zcash/checkpoint) directory as JSON files. Checkpoints for both mainnet and testnet are bundled into the SDK. To improve the speed of syncing with the Zcash network, the SDK contains a series of embedded checkpoints. These should be updated periodically, as new transactions are added to the network. Checkpoints are stored under the [sdk-lib's assets](../sdk-lib/src/main/assets/co.electriccoin.zcash/checkpoint) directory as JSON files. Checkpoints for both mainnet and testnet are bundled into the SDK.

View File

@ -22,7 +22,7 @@ import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds import kotlin.time.Duration.Companion.seconds
/** /**
* Implementation of LightwalletService using gRPC for requests to lightwalletd. * Implementation of BlockingLightWalletClient using gRPC for requests to lightwalletd.
* *
* @property channel the channel to use for communicating with the lightwalletd server. * @property channel the channel to use for communicating with the lightwalletd server.
* @property singleRequestTimeout the timeout to use for non-streaming requests. When a new stub * @property singleRequestTimeout the timeout to use for non-streaming requests. When a new stub

View File

@ -24,7 +24,7 @@ import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds import kotlin.time.Duration.Companion.seconds
/** /**
* Implementation of LightwalletService using gRPC for requests to lightwalletd. * Implementation of CoroutineLightWalletClient using gRPC for requests to lightwalletd.
* *
* @property channel the channel to use for communicating with the lightwalletd server. * @property channel the channel to use for communicating with the lightwalletd server.
* @property singleRequestTimeout the timeout to use for non-streaming requests. When a new stub * @property singleRequestTimeout the timeout to use for non-streaming requests. When a new stub
@ -42,8 +42,6 @@ internal class CoroutineLightWalletClientImpl private constructor(
private var channel = channelFactory.newChannel(lightWalletEndpoint) private var channel = channelFactory.newChannel(lightWalletEndpoint)
/* LightWalletService implementation */
override fun getBlockRange(heightRange: ClosedRange<BlockHeightUnsafe>): Flow<CompactFormats.CompactBlock> { override fun getBlockRange(heightRange: ClosedRange<BlockHeightUnsafe>): Flow<CompactFormats.CompactBlock> {
require(!heightRange.isEmpty()) { require(!heightRange.isEmpty()) {
"${Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE} range: $heightRange." // NON-NLS "${Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE} range: $heightRange." // NON-NLS

View File

@ -15,11 +15,11 @@ import kotlinx.coroutines.withContext
/** /**
* Serves as a source of compact blocks received from the light wallet server. Once started, it will use the given * Serves as a source of compact blocks received from the light wallet server. Once started, it will use the given
* lightwallet service to request all the appropriate blocks and compact block store to persist them. By delegating to * lightWallet client to request all the appropriate blocks and compact block store to persist them. By delegating to
* these dependencies, the downloader remains agnostic to the particular implementation of how to retrieve and store * these dependencies, the downloader remains agnostic to the particular implementation of how to retrieve and store
* data; although, by default the SDK uses gRPC and SQL. * data; although, by default the SDK uses gRPC and SQL.
* *
* @property lightWalletClient the service used for requesting compact blocks * @property lightWalletClient the client used for requesting compact blocks
* @property compactBlockStore responsible for persisting the compact blocks that are received * @property compactBlockStore responsible for persisting the compact blocks that are received
*/ */
open class CompactBlockDownloader private constructor(val compactBlockRepository: CompactBlockRepository) { open class CompactBlockDownloader private constructor(val compactBlockRepository: CompactBlockRepository) {
@ -28,20 +28,20 @@ open class CompactBlockDownloader private constructor(val compactBlockRepository
private set private set
constructor( constructor(
lightWalletService: BlockingLightWalletClient, lightWalletClient: BlockingLightWalletClient,
compactBlockRepository: CompactBlockRepository compactBlockRepository: CompactBlockRepository
) : this(compactBlockRepository) { ) : this(compactBlockRepository) {
this.lightWalletClient = lightWalletService this.lightWalletClient = lightWalletClient
} }
/** /**
* Requests the given range of blocks from the lightwalletService and then persists them to the * Requests the given range of blocks from the lightWalletClient and then persists them to the
* compactBlockStore. * compactBlockStore.
* *
* @param heightRange the inclusive range of heights to request. For example 10..20 would * @param heightRange the inclusive range of heights to request. For example 10..20 would
* request 11 blocks (including block 10 and block 20). * request 11 blocks (including block 10 and block 20).
* *
* @return the number of blocks that were returned in the results from the lightwalletService. * @return the number of blocks that were returned in the results from the lightWalletClient.
*/ */
suspend fun downloadBlockRange(heightRange: ClosedRange<BlockHeight>): Int = withContext(IO) { suspend fun downloadBlockRange(heightRange: ClosedRange<BlockHeight>): Int = withContext(IO) {
val result = lightWalletClient.getBlockRange( val result = lightWalletClient.getBlockRange(
@ -62,7 +62,7 @@ open class CompactBlockDownloader private constructor(val compactBlockRepository
compactBlockRepository.rewindTo(height) compactBlockRepository.rewindTo(height)
/** /**
* Return the latest block height known by the lightwalletService. * Return the latest block height known by the lightWalletClient.
* *
* @return the latest block height. * @return the latest block height.
*/ */
@ -83,7 +83,7 @@ open class CompactBlockDownloader private constructor(val compactBlockRepository
is Response.Success -> return@withContext response.result is Response.Success -> return@withContext response.result
else -> { else -> {
lightWalletClient.reconnect() lightWalletClient.reconnect()
twig("WARNING: reconnecting to service in response to failure (retry #${it + 1})") twig("WARNING: reconnecting to server in response to failure (retry #${it + 1})")
} }
} }
} }