Skip to content

Commit

Permalink
Correct confirmations counting for transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskin1 committed Jul 25, 2020
1 parent 2d5e498 commit 043e0db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object TransactionsService {
assets <- boxIdsNel.toList.flatTraverse(assetRepo.getAllByBoxIds)
bestHeight <- headerRepo.getBestHeight
txInfo = txOpt.map(tx =>
TransactionSummary(tx, bestHeight - tx.inclusionHeight, ins, outs, assets)
TransactionSummary(tx, tx.numConfirmations(bestHeight), ins, outs, assets)
)
} yield txInfo) ||> trans.xa

Expand Down Expand Up @@ -112,7 +112,7 @@ object TransactionsService {
boxIdsNel <- OptionT.fromOption[D](outs.map(_.output.boxId).toNel)
assets <- OptionT.liftF(assetRepo.getAllByBoxIds(boxIdsNel))
bestHeight <- OptionT.liftF(headerRepo.getBestHeight)
txsWithHeights = txChunk.map(tx => tx -> (bestHeight - tx.inclusionHeight))
txsWithHeights = txChunk.map(tx => tx -> tx.numConfirmations(bestHeight))
txInfo = TransactionInfo.batch(txsWithHeights, ins, outs, assets)
} yield txInfo).value.map(_.toList.flatten)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ final case class Transaction(
size: Int, // transaction size in bytes
index: Int, // index of transaction inside a block
mainChain: Boolean
)
) {

def numConfirmations(bestHeight: Int): Int = bestHeight - inclusionHeight + 1
}

0 comments on commit 043e0db

Please sign in to comment.