Skip to content

Commit

Permalink
NODE-2652 Lazy GRPC API response (#3934)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrtm000 authored Oct 17, 2024
1 parent 9713818 commit b3c8746
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class TransactionsApiGrpcImpl(blockchain: Blockchain, commonApi: CommonTransacti

// By ids
case None =>
Observable.fromIterable(transactionIds.flatMap(commonApi.transactionById))
for {
id <- Observable.fromIterable(transactionIds)
tx <- Observable.fromIterable(commonApi.transactionById(id))
} yield tx
}

val transactionIdSet = transactionIds.toSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ object CommonBlocksApi {
.flatMap(Observable.fromIterable(_))

def blocksRange(fromHeight: Int, toHeight: Int, generatorAddress: Address): Observable[(BlockMeta, Seq[(TxMeta, Transaction)])] =
Observable.fromIterable(
(fixHeight(fromHeight) to fixHeight(toHeight))
.flatMap(h => metaAt(h))
.collect { case m if m.header.generator.toAddress == generatorAddress => m.height }
.flatMap(h => blockInfoAt(h))
)
for {
height <- Observable.fromIterable(fixHeight(fromHeight) to fixHeight(toHeight))
meta <- Observable.fromIterable(metaAt(height)) if meta.header.generator.toAddress == generatorAddress
block <- Observable.fromIterable(blockInfoAt(meta.height))
} yield block

def blockDelay(blockId: BlockId, blockNum: Int): Option[Long] =
blockchain
Expand All @@ -75,7 +74,10 @@ object CommonBlocksApi {
def meta(id: ByteStr): Option[BlockMeta] = blockchain.heightOf(id).flatMap(metaAt)

def metaRange(fromHeight: Int, toHeight: Int): Observable[BlockMeta] =
Observable.fromIterable((fixHeight(fromHeight) to fixHeight(toHeight)).flatMap(h => metaAt(h)))
for {
height <- Observable.fromIterable(fixHeight(fromHeight) to fixHeight(toHeight))
meta <- Observable.fromIterable(metaAt(height))
} yield meta

def block(blockId: BlockId): Option[(BlockMeta, Seq[(TxMeta, Transaction)])] = blockchain.heightOf(blockId).flatMap(h => blockInfoAt(h))
}
Expand Down

0 comments on commit b3c8746

Please sign in to comment.