From e2d1d93ac2794a4613c636b604d21917b9bac59f Mon Sep 17 00:00:00 2001 From: Honza Date: Sun, 29 Jan 2023 18:37:44 +0100 Subject: [PATCH] Unify new clients instances name --- .../sdk/darkside/reorgs/ReorgLargeTest.kt | 2 +- .../wallet/sdk/sample/demoapp/SampleCodeTest.kt | 8 ++++---- .../ecc/android/sdk/demoapp/BaseDemoFragment.kt | 4 ++-- .../demoapp/demos/getblock/GetBlockFragment.kt | 4 ++-- .../demos/getblockrange/GetBlockRangeFragment.kt | 4 ++-- .../getlatestheight/GetLatestHeightFragment.kt | 2 +- .../demoapp/demos/listutxos/ListUtxosFragment.kt | 2 +- docs/Architecture.md | 16 ++++++++-------- .../internal/BlockingLightWalletClientImpl.kt | 2 +- .../internal/CoroutineLightWalletClientImpl.kt | 4 +--- .../sdk/internal/block/CompactBlockDownloader.kt | 16 ++++++++-------- 11 files changed, 31 insertions(+), 33 deletions(-) diff --git a/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/reorgs/ReorgLargeTest.kt b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/reorgs/ReorgLargeTest.kt index 043dcf63..7eaf6dd4 100644 --- a/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/reorgs/ReorgLargeTest.kt +++ b/darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/reorgs/ReorgLargeTest.kt @@ -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 diff --git a/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt b/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt index a198d72c..3cb47044 100644 --- a/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt +++ b/demo-app/src/androidTest/java/cash/z/wallet/sdk/sample/demoapp/SampleCodeTest.kt @@ -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 -> diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/BaseDemoFragment.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/BaseDemoFragment.kt index 8ff0b850..3e94c09b 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/BaseDemoFragment.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/BaseDemoFragment.kt @@ -23,11 +23,11 @@ import kotlinx.coroutines.launch abstract class BaseDemoFragment : 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() diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getblock/GetBlockFragment.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getblock/GetBlockFragment.kt index a797658d..9693960e 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getblock/GetBlockFragment.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getblock/GetBlockFragment.kt @@ -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() { private fun setBlockHeight(blockHeight: BlockHeight) { val blocks = - lightWalletService?.getBlockRange( + lightWalletClient?.getBlockRange( BlockHeightUnsafe(blockHeight.value)..BlockHeightUnsafe( blockHeight.value ) diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getblockrange/GetBlockRangeFragment.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getblockrange/GetBlockRangeFragment.kt index 02c36688..736c2494 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getblockrange/GetBlockRangeFragment.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getblockrange/GetBlockRangeFragment.kt @@ -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() { private fun setBlockRange(blockRange: ClosedRange) { val start = System.currentTimeMillis() val blocks = - lightWalletService?.getBlockRange( + lightWalletClient?.getBlockRange( BlockHeightUnsafe(blockRange.start.value)..BlockHeightUnsafe( blockRange.endInclusive.value ) diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getlatestheight/GetLatestHeightFragment.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getlatestheight/GetLatestHeightFragment.kt index cfbd7e55..9d53b90e 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getlatestheight/GetLatestHeightFragment.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/getlatestheight/GetLatestHeightFragment.kt @@ -15,7 +15,7 @@ class GetLatestHeightFragment : BaseDemoFragment 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() } // diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/listutxos/ListUtxosFragment.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/listutxos/ListUtxosFragment.kt index 304de357..405e8127 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/listutxos/ListUtxosFragment.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/demos/listutxos/ListUtxosFragment.kt @@ -85,7 +85,7 @@ class ListUtxosFragment : BaseDemoFragment() { ?: 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) ) diff --git a/docs/Architecture.md b/docs/Architecture.md index 68bef90c..54eab9e1 100644 --- a/docs/Architecture.md +++ b/docs/Architecture.md @@ -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. diff --git a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/BlockingLightWalletClientImpl.kt b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/BlockingLightWalletClientImpl.kt index 6666225b..97959b4e 100644 --- a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/BlockingLightWalletClientImpl.kt +++ b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/BlockingLightWalletClientImpl.kt @@ -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 diff --git a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/CoroutineLightWalletClientImpl.kt b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/CoroutineLightWalletClientImpl.kt index 8d7970fa..8c385bb5 100644 --- a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/CoroutineLightWalletClientImpl.kt +++ b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/CoroutineLightWalletClientImpl.kt @@ -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): Flow { require(!heightRange.isEmpty()) { "${Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE} range: $heightRange." // NON-NLS diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/block/CompactBlockDownloader.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/block/CompactBlockDownloader.kt index 01c172ec..454d960c 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/block/CompactBlockDownloader.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/block/CompactBlockDownloader.kt @@ -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): 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})") } } }