fetchUtxos returns flow

- Switched fetchUtxos() to return Flow of Service.GetAddressUtxosReply
- Internally it calls getAddressUtxosStream() instead of getAddressUtxos() from GRPC layer
This commit is contained in:
Honza 2023-01-24 13:33:28 +01:00
parent 0f1663f02c
commit 2b834013cb
2 changed files with 12 additions and 9 deletions

View File

@ -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<Service.GetAddressUtxosReply>
): Flow<Service.GetAddressUtxosReply>
/**
* @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<BlockHeightUnsafe>): Flow<CompactFormats.CompactBlock>
@ -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,

View File

@ -126,20 +126,23 @@ internal class CoroutineLightWalletClientImpl private constructor(
override suspend fun fetchUtxos(
tAddress: String,
startHeight: BlockHeightUnsafe
): List<Service.GetAddressUtxosReply> {
val result = requireChannel().createStub().getAddressUtxos(
): Flow<Service.GetAddressUtxosReply> {
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<BlockHeightUnsafe>
): Flow<Service.RawTransaction> {
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()