From 2b60bbb1c359737f896b4f3957af476a68dd0685 Mon Sep 17 00:00:00 2001 From: Chris Stewart Date: Wed, 6 Jul 2022 18:23:14 -0500 Subject: [PATCH] Remove .map() and use .foreach() with buffer in CryptoBytesUtil.toByteVector() (#4454) --- .../main/scala/org/bitcoins/scripts/ScanBitcoind.scala | 2 +- .../main/scala/org/bitcoins/crypto/CryptoBytesUtil.scala | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/scripts/src/main/scala/org/bitcoins/scripts/ScanBitcoind.scala b/app/scripts/src/main/scala/org/bitcoins/scripts/ScanBitcoind.scala index cc4958b513..109da541fd 100644 --- a/app/scripts/src/main/scala/org/bitcoins/scripts/ScanBitcoind.scala +++ b/app/scripts/src/main/scala/org/bitcoins/scripts/ScanBitcoind.scala @@ -36,7 +36,7 @@ class ScanBitcoind()(implicit bitcoind <- bitcoindF endHeight <- endHeightF //_ <- countWitV1MempoolTxs(bitcoind) - _ <- countTaprootTxsInBlocks(endHeight, 10000, bitcoind) + _ <- countTaprootTxsInBlocks(endHeight, 250000, bitcoind) } yield () f.failed.foreach(err => logger.error(s"Failed to count witness v1 mempool txs", err)) diff --git a/crypto/src/main/scala/org/bitcoins/crypto/CryptoBytesUtil.scala b/crypto/src/main/scala/org/bitcoins/crypto/CryptoBytesUtil.scala index 29ad699704..9d6aa0e9f0 100644 --- a/crypto/src/main/scala/org/bitcoins/crypto/CryptoBytesUtil.scala +++ b/crypto/src/main/scala/org/bitcoins/crypto/CryptoBytesUtil.scala @@ -2,7 +2,7 @@ package org.bitcoins.crypto import scodec.bits.{BitVector, ByteVector} -import scala.math.BigInt +import java.io.ByteArrayOutputStream /** Created by chris on 2/26/16. */ @@ -97,7 +97,11 @@ trait CryptoBytesUtil { @inline final def toByteVector[T <: NetworkElement](h: Seq[T]): ByteVector = { - ByteVector.concat(h.map(_.bytes)) + val outputStream = new ByteArrayOutputStream() + h.foreach { ne => + outputStream.write(ne.bytes.toArray) + } + ByteVector(outputStream.toByteArray) } }