From 2b834013cb751c3b6c0294ae7483f79578ec9336 Mon Sep 17 00:00:00 2001 From: Honza Date: Tue, 24 Jan 2023 13:33:28 +0100 Subject: [PATCH] fetchUtxos returns flow - Switched fetchUtxos() to return Flow of Service.GetAddressUtxosReply - Internally it calls getAddressUtxosStream() instead of getAddressUtxos() from GRPC layer --- .../client/CoroutineLightWalletClient.kt | 8 ++++---- .../internal/CoroutineLightWalletClientImpl.kt | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/CoroutineLightWalletClient.kt b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/CoroutineLightWalletClient.kt index 99ca9b0f..186e947d 100644 --- a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/CoroutineLightWalletClient.kt +++ b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/CoroutineLightWalletClient.kt @@ -27,18 +27,18 @@ interface CoroutineLightWalletClient { * @param tAddress the transparent address to use. * @param startHeight the starting height to use. * - * @return the UTXOs for the given address from the [startHeight]. + * @return a flow of UTXOs for the given address from the [startHeight]. */ suspend fun fetchUtxos( tAddress: String, startHeight: BlockHeightUnsafe - ): List + ): Flow /** * @param heightRange the inclusive range to fetch. For instance if 1..5 is given, then every * block in that range will be fetched, including 1 and 5. * - * @return a list of compact blocks for the given range + * @return a flow of compact blocks for the given range * */ fun getBlockRange(heightRange: ClosedRange): Flow @@ -58,7 +58,7 @@ interface CoroutineLightWalletClient { * effectively the same as an RPC call to a node that's running an insight server. The data is * indexed and responses are fairly quick. * - * @return a list of transactions that correspond to the given address for the given range. + * @return a flow of transactions that correspond to the given address for the given range. */ fun getTAddressTransactions( tAddress: String, 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 6fc4f915..42c64fb2 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 @@ -126,20 +126,23 @@ internal class CoroutineLightWalletClientImpl private constructor( override suspend fun fetchUtxos( tAddress: String, startHeight: BlockHeightUnsafe - ): List { - val result = requireChannel().createStub().getAddressUtxos( + ): Flow { + if (tAddress.isBlank()) { + return emptyFlow() + } + return requireChannel().createStub().getAddressUtxosStream( Service.GetAddressUtxosArg.newBuilder().setAddress(tAddress) .setStartHeight(startHeight.value).build() ) - return result.addressUtxosList } override fun getTAddressTransactions( tAddress: String, blockHeightRange: ClosedRange ): Flow { - if (blockHeightRange.isEmpty() || tAddress.isBlank()) return emptyFlow() - + if (blockHeightRange.isEmpty() || tAddress.isBlank()) { + return emptyFlow() + } return requireChannel().createStub().getTaddressTxids( Service.TransparentAddressBlockFilter.newBuilder().setAddress(tAddress) .setRange(blockHeightRange.toBlockRange()).build()