Unify new clients instances name
This commit is contained in:
parent
f569677fec
commit
e2d1d93ac2
|
@ -106,7 +106,7 @@ package cash.z.ecc.android.sdk.darkside.reorgs // package cash.z.ecc.android.sdk
|
|||
// lightwalletd.getBlockRange(height..height).first()
|
||||
//
|
||||
// private val lightwalletd
|
||||
// get() = (synchronizer as SdkSynchronizer).processor.downloader.lightwalletService
|
||||
// get() = (synchronizer as SdkSynchronizer).processor.downloader.lightWalletClient
|
||||
//
|
||||
// companion object {
|
||||
// private const val port = 9067
|
||||
|
|
|
@ -82,8 +82,8 @@ class SampleCodeTest {
|
|||
// Query latest block height
|
||||
@Test
|
||||
fun getLatestBlockHeightTest() {
|
||||
val lightwalletService = BlockingLightWalletClient.new(context, lightwalletdHost)
|
||||
log("Latest Block: ${lightwalletService.getLatestBlockHeight()}")
|
||||
val lightwalletClient = BlockingLightWalletClient.new(context, lightwalletdHost)
|
||||
log("Latest Block: ${lightwalletClient.getLatestBlockHeight()}")
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
|
@ -103,8 +103,8 @@ class SampleCodeTest {
|
|||
).value
|
||||
)
|
||||
)
|
||||
val lightwalletService = BlockingLightWalletClient.new(context, lightwalletdHost)
|
||||
val blocks = lightwalletService.getBlockRange(blockRange)
|
||||
val lightwalletClient = BlockingLightWalletClient.new(context, lightwalletdHost)
|
||||
val blocks = lightwalletClient.getBlockRange(blockRange)
|
||||
assertEquals(blockRange.endInclusive.value - blockRange.start.value, blocks.count())
|
||||
|
||||
blocks.forEachIndexed { i, block ->
|
||||
|
|
|
@ -23,11 +23,11 @@ import kotlinx.coroutines.launch
|
|||
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
|
||||
* synchronizer because it wraps the service.
|
||||
*/
|
||||
val lightWalletService get() = mainActivity()?.lightwalletClient
|
||||
val lightWalletClient get() = mainActivity()?.lightwalletClient
|
||||
|
||||
// contains view information provided by the user
|
||||
val sharedViewModel: SharedViewModel by activityViewModels()
|
||||
|
|
|
@ -19,7 +19,7 @@ import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe
|
|||
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
|
||||
* the response.
|
||||
*/
|
||||
|
@ -27,7 +27,7 @@ class GetBlockFragment : BaseDemoFragment<FragmentGetBlockBinding>() {
|
|||
|
||||
private fun setBlockHeight(blockHeight: BlockHeight) {
|
||||
val blocks =
|
||||
lightWalletService?.getBlockRange(
|
||||
lightWalletClient?.getBlockRange(
|
||||
BlockHeightUnsafe(blockHeight.value)..BlockHeightUnsafe(
|
||||
blockHeight.value
|
||||
)
|
||||
|
|
|
@ -18,7 +18,7 @@ import co.electriccoin.lightwallet.client.model.BlockHeightUnsafe
|
|||
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
|
||||
* 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.
|
||||
|
@ -28,7 +28,7 @@ class GetBlockRangeFragment : BaseDemoFragment<FragmentGetBlockRangeBinding>() {
|
|||
private fun setBlockRange(blockRange: ClosedRange<BlockHeight>) {
|
||||
val start = System.currentTimeMillis()
|
||||
val blocks =
|
||||
lightWalletService?.getBlockRange(
|
||||
lightWalletClient?.getBlockRange(
|
||||
BlockHeightUnsafe(blockRange.start.value)..BlockHeightUnsafe(
|
||||
blockRange.endInclusive.value
|
||||
)
|
||||
|
|
|
@ -15,7 +15,7 @@ class GetLatestHeightFragment : BaseDemoFragment<FragmentGetLatestHeightBinding>
|
|||
private fun displayLatestHeight() {
|
||||
// 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
|
||||
binding.textInfo.text = lightWalletService?.getLatestBlockHeight().toString()
|
||||
binding.textInfo.text = lightWalletClient?.getLatestBlockHeight().toString()
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -85,7 +85,7 @@ class ListUtxosFragment : BaseDemoFragment<FragmentListUtxosBinding>() {
|
|||
?: getUxtoEndHeight(requireApplicationContext()).value
|
||||
var allStart = now
|
||||
twig("loading transactions in range $startToUse..$endToUse")
|
||||
val txids = lightWalletService?.getTAddressTransactions(
|
||||
val txids = lightWalletClient?.getTAddressTransactions(
|
||||
addressToUse,
|
||||
BlockHeightUnsafe(startToUse)..BlockHeightUnsafe(endToUse)
|
||||
)
|
||||
|
|
|
@ -38,14 +38,14 @@ This is generally not considered part of the public API, and much of the interna
|
|||
|
||||
## Components
|
||||
|
||||
| Component | Summary |
|
||||
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **LightWalletService** | Service used for requesting compact blocks |
|
||||
| **CompactBlockStore** | Stores compact blocks that have been downloaded from the `LightWalletService` |
|
||||
| **CompactBlockProcessor** | Validates and scans the compact blocks in the `CompactBlockStore` for transaction details |
|
||||
| **OutboundTransactionManager** | Creates, Submits and manages transactions for spending funds |
|
||||
| **DerivationTool** | Utilities for deriving keys and addresses |
|
||||
| **RustBackend** | Wraps and simplifies the rust library and exposes its functionality to the Kotlin SDK |
|
||||
| Component | Summary |
|
||||
|--------------------------------|-------------------------------------------------------------------------------------------|
|
||||
| **LightWalletClient** | Component used for requesting compact blocks |
|
||||
| **CompactBlockStore** | Stores compact blocks that have been downloaded from the `LightWalletClient` |
|
||||
| **CompactBlockProcessor** | Validates and scans the compact blocks in the `CompactBlockStore` for transaction details |
|
||||
| **OutboundTransactionManager** | Creates, Submits and manages transactions for spending funds |
|
||||
| **DerivationTool** | Utilities for deriving keys and addresses |
|
||||
| **RustBackend** | Wraps and simplifies the rust library and exposes its functionality to the Kotlin SDK |
|
||||
|
||||
## 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.
|
||||
|
|
|
@ -22,7 +22,7 @@ import kotlin.time.Duration
|
|||
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 singleRequestTimeout the timeout to use for non-streaming requests. When a new stub
|
||||
|
|
|
@ -24,7 +24,7 @@ import kotlin.time.Duration
|
|||
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 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)
|
||||
|
||||
/* LightWalletService implementation */
|
||||
|
||||
override fun getBlockRange(heightRange: ClosedRange<BlockHeightUnsafe>): Flow<CompactFormats.CompactBlock> {
|
||||
require(!heightRange.isEmpty()) {
|
||||
"${Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE} range: $heightRange." // NON-NLS
|
||||
|
|
|
@ -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
|
||||
* 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
|
||||
* 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
|
||||
*/
|
||||
open class CompactBlockDownloader private constructor(val compactBlockRepository: CompactBlockRepository) {
|
||||
|
@ -28,20 +28,20 @@ open class CompactBlockDownloader private constructor(val compactBlockRepository
|
|||
private set
|
||||
|
||||
constructor(
|
||||
lightWalletService: BlockingLightWalletClient,
|
||||
lightWalletClient: BlockingLightWalletClient,
|
||||
compactBlockRepository: 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.
|
||||
*
|
||||
* @param heightRange the inclusive range of heights to request. For example 10..20 would
|
||||
* 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) {
|
||||
val result = lightWalletClient.getBlockRange(
|
||||
|
@ -62,7 +62,7 @@ open class CompactBlockDownloader private constructor(val compactBlockRepository
|
|||
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.
|
||||
*/
|
||||
|
@ -83,7 +83,7 @@ open class CompactBlockDownloader private constructor(val compactBlockRepository
|
|||
is Response.Success -> return@withContext response.result
|
||||
else -> {
|
||||
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})")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue