Run scalafmt, i forgot to run on #783 (#788)

This commit is contained in:
Chris Stewart 2019-10-07 08:16:28 -05:00 committed by GitHub
parent c27e1136e2
commit 780ac75bf0
4 changed files with 14 additions and 9 deletions

View File

@ -10,8 +10,11 @@ import scodec.bits.ByteVector
* Represents a P2P network message
*/
sealed abstract class NetworkMessage extends NetworkElement {
require(header.payloadSize.toInt == payload.bytes.length, s"Payload size is not what header says it is, " +
s"header.payloadSize=${header.payloadSize.toInt} actual=${payload.bytes.length}")
require(
header.payloadSize.toInt == payload.bytes.length,
s"Payload size is not what header says it is, " +
s"header.payloadSize=${header.payloadSize.toInt} actual=${payload.bytes.length}"
)
def header: NetworkHeader
def payload: NetworkPayload
override def bytes: ByteVector = RawNetworkMessageSerializer.write(this)

View File

@ -8,13 +8,14 @@ trait RawNetworkMessageSerializer extends RawBitcoinSerializer[NetworkMessage] {
def read(bytes: ByteVector): NetworkMessage = {
//first 24 bytes are the header
val (headerBytes,payloadBytes) = bytes.splitAt(24)
val (headerBytes, payloadBytes) = bytes.splitAt(24)
val header = NetworkHeader.fromBytes(headerBytes)
if (header.payloadSize.toInt > payloadBytes.length) {
throw new RuntimeException(s"We do not have enough bytes for payload! Expected=${header.payloadSize.toInt} got=${payloadBytes.length}")
throw new RuntimeException(
s"We do not have enough bytes for payload! Expected=${header.payloadSize.toInt} got=${payloadBytes.length}")
} else {
val payload = NetworkPayload(header, payloadBytes)
val n = NetworkMessage(header, payload)
val n = NetworkMessage(header, payload)
n
}
}

View File

@ -21,7 +21,9 @@ trait RawNetworkHeaderSerializer
* @return the native object for the MessageHeader
*/
def read(bytes: ByteVector): NetworkHeader = {
require(bytes.length == 24, s"Got bytes.length=${bytes.length} when NetworkHeader expects 24 bytes")
require(
bytes.length == 24,
s"Got bytes.length=${bytes.length} when NetworkHeader expects 24 bytes")
val network = Networks.magicToNetwork(bytes.take(4))
//.trim removes the null characters appended to the command name
val commandName = bytes.slice(4, 16).toArray.map(_.toChar).mkString.trim

View File

@ -377,9 +377,8 @@ object P2PClient extends P2PLogger {
val messageTry = Try(NetworkMessage(remainingBytes))
messageTry match {
case Success(message) =>
val newRemainingBytes = remainingBytes.slice(
message.bytes.length,
remainingBytes.length)
val newRemainingBytes =
remainingBytes.slice(message.bytes.length, remainingBytes.length)
logger.trace(
s"Parsed a message=${message.header.commandName} from bytes, continuing with remainingBytes=${newRemainingBytes.length}")
loop(newRemainingBytes, message :: accum)