Skip to content

Commit 5b2ce03

Browse files
author
Nicolás Tallar
authored
[Chore] Single line for message logging (#779)
1 parent cd1f83c commit 5b2ce03

File tree

12 files changed

+93
-122
lines changed

12 files changed

+93
-122
lines changed

src/main/scala/io/iohk/ethereum/blockchain/data/GenesisDataLoader.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class GenesisDataLoader(blockchain: Blockchain, blockchainConfig: BlockchainConf
102102

103103
val header: BlockHeader = prepareHeader(genesisData, stateMptRootHash)
104104

105-
log.debug(s"prepared genesis header: $header, with hash ${header.hashAsHexString}")
105+
log.debug(s"Prepared genesis header: $header")
106106

107107
blockchain.getBlockHeaderByNumber(0) match {
108108
case Some(existingGenesisHeader) if existingGenesisHeader.hash == header.hash =>

src/main/scala/io/iohk/ethereum/blockchain/sync/regular/ImportMessages.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ class NewBlockImportMessages(block: Block, peerId: PeerId) extends ImportMessage
8585
val lastHeader = newBranch.last.header
8686
(
8787
DebugLevel,
88-
s"""Imported block $number ($hash) from $peerId
89-
|resulting in chain reorganisation: new branch of length ${newBranch.size} with head at block
90-
|${lastHeader.number} (${hash2string(lastHeader.hash)})""".stripMargin
88+
s"Imported block $number ($hash) from $peerId " +
89+
s"resulting in chain reorganisation: new branch of length ${newBranch.size} with head at block " +
90+
s"${lastHeader.number} (${hash2string(lastHeader.hash)})"
9191
)
9292
}
9393
override def importFailed(error: String): LogEntry =

src/main/scala/io/iohk/ethereum/domain/Block.scala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ import io.iohk.ethereum.rlp.{RLPEncodeable, RLPList, RLPSerializable, rawDecode}
1111
* @param body Block body
1212
*/
1313
case class Block(header: BlockHeader, body: BlockBody) {
14-
override def toString: String = {
15-
s"""BlockHeader {
16-
| header: $header
17-
| body: $body
18-
""".stripMargin
19-
}
14+
override def toString: String =
15+
s"Block { header: $header, body: $body }"
2016

2117
def idTag: String =
2218
header.idTag

src/main/scala/io/iohk/ethereum/domain/BlockBody.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import io.iohk.ethereum.rlp.{RLPEncodeable, RLPList, RLPSerializable, rawDecode}
55

66
case class BlockBody(transactionList: Seq[SignedTransaction], uncleNodesList: Seq[BlockHeader]) {
77
override def toString: String =
8-
s"""BlockBody{
9-
|transactionList: $transactionList
10-
|uncleNodesList: $uncleNodesList
11-
|}
12-
""".stripMargin
8+
s"BlockBody{ transactionList: $transactionList, uncleNodesList: $uncleNodesList }"
139

1410
lazy val numberOfTxs: Int = transactionList.size
1511

src/main/scala/io/iohk/ethereum/domain/BlockHeader.scala

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,26 @@ case class BlockHeader(
5959
("Pre-ECIP1098 block", "Pre-ECIP1097 block")
6060
}
6161

62-
s"""BlockHeader {
63-
|hash: $hashAsHexString
64-
|parentHash: ${ByteStringUtils.hash2string(parentHash)}
65-
|ommersHash: ${ByteStringUtils.hash2string(ommersHash)}
66-
|beneficiary: ${ByteStringUtils.hash2string(beneficiary)}
67-
|stateRoot: ${ByteStringUtils.hash2string(stateRoot)}
68-
|transactionsRoot: ${ByteStringUtils.hash2string(transactionsRoot)}
69-
|receiptsRoot: ${ByteStringUtils.hash2string(receiptsRoot)}
70-
|logsBloom: ${ByteStringUtils.hash2string(logsBloom)}
71-
|difficulty: $difficulty,
72-
|number: $number,
73-
|gasLimit: $gasLimit,
74-
|gasUsed: $gasUsed,
75-
|unixTimestamp: $unixTimestamp,
76-
|extraData: ${ByteStringUtils.hash2string(extraData)}
77-
|mixHash: ${ByteStringUtils.hash2string(mixHash)}
78-
|nonce: ${ByteStringUtils.hash2string(nonce)},
79-
|treasuryOptOut: $treasuryOptOutString
80-
|isCheckpointing: $checkpointString
81-
|}""".stripMargin
62+
s"BlockHeader { " +
63+
s"hash: $hashAsHexString, " +
64+
s"parentHash: ${ByteStringUtils.hash2string(parentHash)}, " +
65+
s"ommersHash: ${ByteStringUtils.hash2string(ommersHash)}, " +
66+
s"beneficiary: ${ByteStringUtils.hash2string(beneficiary)} " +
67+
s"stateRoot: ${ByteStringUtils.hash2string(stateRoot)} " +
68+
s"transactionsRoot: ${ByteStringUtils.hash2string(transactionsRoot)} " +
69+
s"receiptsRoot: ${ByteStringUtils.hash2string(receiptsRoot)} " +
70+
s"logsBloom: ${ByteStringUtils.hash2string(logsBloom)} " +
71+
s"difficulty: $difficulty, " +
72+
s"number: $number, " +
73+
s"gasLimit: $gasLimit, " +
74+
s"gasUsed: $gasUsed, " +
75+
s"unixTimestamp: $unixTimestamp, " +
76+
s"extraData: ${ByteStringUtils.hash2string(extraData)} " +
77+
s"mixHash: ${ByteStringUtils.hash2string(mixHash)} " +
78+
s"nonce: ${ByteStringUtils.hash2string(nonce)}, " +
79+
s"treasuryOptOut: $treasuryOptOutString " +
80+
s"isCheckpointing: $checkpointString" +
81+
s"}"
8282
}
8383

8484
/**

src/main/scala/io/iohk/ethereum/domain/Receipt.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,11 @@ case class Receipt(
4848
case _ => Array(0.toByte)
4949
}
5050

51-
s"""
52-
|Receipt{
53-
| postTransactionStateHash: ${Hex.toHexString(stateHash)}
54-
| cumulativeGasUsed: $cumulativeGasUsed
55-
| logsBloomFilter: ${Hex.toHexString(logsBloomFilter.toArray[Byte])}
56-
| logs: $logs
57-
|}
58-
""".stripMargin
51+
s"Receipt{ " +
52+
s"postTransactionStateHash: ${Hex.toHexString(stateHash)}, " +
53+
s"cumulativeGasUsed: $cumulativeGasUsed, " +
54+
s"logsBloomFilter: ${Hex.toHexString(logsBloomFilter.toArray[Byte])}, " +
55+
s"logs: $logs" +
56+
s"}"
5957
}
6058
}

src/main/scala/io/iohk/ethereum/domain/SignedTransaction.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,11 @@ case class SignedTransaction(tx: Transaction, signature: ECDSASignature) {
166166
def safeSenderIsEqualTo(address: Address): Boolean =
167167
SignedTransaction.getSender(this).contains(address)
168168

169-
override def toString: String = {
170-
s"""SignedTransaction {
171-
|tx: $tx
172-
|signature: $signature
173-
|}""".stripMargin
174-
}
169+
override def toString: String =
170+
s"SignedTransaction { " +
171+
s"tx: $tx, " +
172+
s"signature: $signature" +
173+
s"}"
175174

176175
def isChainSpecific: Boolean =
177176
signature.v != ECDSASignature.negativePointSign && signature.v != ECDSASignature.positivePointSign

src/main/scala/io/iohk/ethereum/domain/Transaction.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ case class Transaction(
3333
def isContractInit: Boolean = receivingAddress.isEmpty
3434

3535
override def toString: String = {
36-
s"""Transaction {
37-
|nonce: $nonce
38-
|gasPrice: $gasPrice
39-
|gasLimit: $gasLimit
40-
|receivingAddress: ${if (receivingAddress.isDefined) Hex.toHexString(receivingAddress.get.toArray)
41-
else "[Contract creation]"}
42-
|value: $value wei
43-
|payload: ${if (isContractInit) "ContractInit: " else "TransactionData: "}${Hex.toHexString(
44-
payload.toArray[Byte]
45-
)}
46-
|}""".stripMargin
36+
val receivingAddressString =
37+
if (receivingAddress.isDefined) Hex.toHexString(receivingAddress.get.toArray) else "[Contract creation]"
38+
39+
s"Transaction {" +
40+
s"nonce: $nonce " +
41+
s"gasPrice: $gasPrice " +
42+
s"gasLimit: $gasLimit " +
43+
s"receivingAddress: $receivingAddressString " +
44+
s"value: $value wei " +
45+
s"payload: ${if (isContractInit) "ContractInit: " else "TransactionData: "}${Hex.toHexString(payload.toArray[Byte])} " +
46+
s"}"
4747
}
4848
}

src/main/scala/io/iohk/ethereum/network/p2p/messages/CommonMessages.scala

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,15 @@ object CommonMessages {
111111
) extends Message {
112112
require(code == Status.code63 || code == Status.code64, s"Invalid code for Status: $code")
113113

114-
override def toString: String = {
115-
s"""Status {
116-
|code: $code
117-
|protocolVersion: $protocolVersion
118-
|networkId: $networkId
119-
|chainWeight: $chainWeight
120-
|bestHash: ${Hex.toHexString(bestHash.toArray[Byte])}
121-
|genesisHash: ${Hex.toHexString(genesisHash.toArray[Byte])}
122-
|}""".stripMargin
123-
}
114+
override def toString: String =
115+
s"Status { " +
116+
s"code: $code, " +
117+
s"protocolVersion: $protocolVersion, " +
118+
s"networkId: $networkId, " +
119+
s"chainWeight: $chainWeight, " +
120+
s"bestHash: ${Hex.toHexString(bestHash.toArray[Byte])}, " +
121+
s"genesisHash: ${Hex.toHexString(genesisHash.toArray[Byte])}," +
122+
s"}"
124123

125124
def as63: Status =
126125
copy(code = Status.code63)
@@ -293,13 +292,12 @@ object CommonMessages {
293292
case class NewBlock(code: Int, block: Block, chainWeight: ChainWeight) extends Message {
294293
require(code == NewBlock.code63 || code == NewBlock.code64, s"Invalid code for NewBlock: $code")
295294

296-
override def toString: String = {
297-
s"""NewBlock {
298-
|code: $code
299-
|block: $block
300-
|chainWeight: $chainWeight
301-
|}""".stripMargin
302-
}
295+
override def toString: String =
296+
s"NewBlock { " +
297+
s"code: $code, " +
298+
s"block: $block, " +
299+
s"chainWeight: $chainWeight" +
300+
s"}"
303301

304302
def as63: NewBlock =
305303
copy(code = NewBlock.code63)

src/main/scala/io/iohk/ethereum/network/p2p/messages/PV62.scala

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ object PV62 {
3030
}
3131

3232
case class BlockHash(hash: ByteString, number: BigInt) {
33-
override def toString: String = {
34-
s"""BlockHash {
35-
|hash: ${Hex.toHexString(hash.toArray[Byte])}
36-
|number: $number
37-
|}""".stripMargin
38-
}
33+
override def toString: String =
34+
s"BlockHash { " +
35+
s"hash: ${Hex.toHexString(hash.toArray[Byte])} " +
36+
s"number: $number " +
37+
s"}"
3938
}
4039

4140
object NewBlockHashes {
@@ -101,15 +100,13 @@ object PV62 {
101100
extends Message {
102101
override def code: Int = GetBlockHeaders.code
103102

104-
override def toString: String = {
105-
s"""GetBlockHeaders{
106-
|block: ${block.fold(a => a, b => Hex.toHexString(b.toArray[Byte]))}
107-
|maxHeaders: $maxHeaders
108-
|skip: $skip
109-
|reverse: $reverse
110-
|}
111-
""".stripMargin
112-
}
103+
override def toString: String =
104+
s"GetBlockHeaders{ " +
105+
s"block: ${block.fold(a => a, b => Hex.toHexString(b.toArray[Byte]))} " +
106+
s"maxHeaders: $maxHeaders " +
107+
s"skip: $skip " +
108+
s"reverse: $reverse " +
109+
s"}"
113110
}
114111

115112
object BlockBodies {
@@ -189,11 +186,9 @@ object PV62 {
189186
case class GetBlockBodies(hashes: Seq[ByteString]) extends Message {
190187
override def code: Int = GetBlockBodies.code
191188

192-
override def toString: String = {
193-
s"""GetBlockBodies {
194-
|hashes: ${hashes.map(h => Hex.toHexString(h.toArray[Byte]))}
195-
|}
196-
""".stripMargin
197-
}
189+
override def toString: String =
190+
s"GetBlockBodies { " +
191+
s"hashes: ${hashes.map(h => Hex.toHexString(h.toArray[Byte]))} " +
192+
s"}"
198193
}
199194
}

src/main/scala/io/iohk/ethereum/network/p2p/messages/PV63.scala

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ object PV63 {
3434
case class GetNodeData(mptElementsHashes: Seq[ByteString]) extends Message {
3535
override def code: Int = GetNodeData.code
3636

37-
override def toString: String = {
38-
s"""GetNodeData{
39-
|hashes: ${mptElementsHashes.map(e => Hex.toHexString(e.toArray[Byte]))}
40-
|}
41-
""".stripMargin
42-
}
37+
override def toString: String =
38+
s"GetNodeData{ hashes: ${mptElementsHashes.map(e => Hex.toHexString(e.toArray[Byte]))} }"
4339
}
4440

4541
object AccountImplicits {
@@ -111,12 +107,8 @@ object PV63 {
111107

112108
override def code: Int = NodeData.code
113109

114-
override def toString: String = {
115-
s"""NodeData{
116-
|values: ${values.map(b => Hex.toHexString(b.toArray[Byte]))}
117-
|}
118-
""".stripMargin
119-
}
110+
override def toString: String =
111+
s"NodeData{ values: ${values.map(b => Hex.toHexString(b.toArray[Byte]))} }"
120112
}
121113

122114
object GetReceipts {
@@ -142,10 +134,7 @@ object PV63 {
142134
override def code: Int = GetReceipts.code
143135

144136
override def toString: String = {
145-
s"""GetReceipts{
146-
|blockHashes: ${blockHashes.map(e => Hex.toHexString(e.toArray[Byte]))}
147-
|}
148-
""".stripMargin
137+
s"GetReceipts{ blockHashes: ${blockHashes.map(e => Hex.toHexString(e.toArray[Byte]))} } "
149138
}
150139
}
151140

src/main/scala/io/iohk/ethereum/network/p2p/messages/WireProtocol.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ object WireProtocol {
6767
override val code: Int = Hello.code
6868

6969
override def toString: String = {
70-
s"""Hello {
71-
|p2pVersion: $p2pVersion
72-
|clientId: $clientId
73-
|capabilities: $capabilities
74-
|listenPort: $listenPort
75-
|nodeId: ${Hex.toHexString(nodeId.toArray[Byte])}
76-
|}""".stripMargin
70+
s"Hello { " +
71+
s"p2pVersion: $p2pVersion " +
72+
s"clientId: $clientId " +
73+
s"capabilities: $capabilities " +
74+
s"listenPort: $listenPort " +
75+
s"nodeId: ${Hex.toHexString(nodeId.toArray[Byte])} " +
76+
s"}"
7777
}
7878
}
7979

@@ -132,7 +132,7 @@ object WireProtocol {
132132
override val code: Int = Disconnect.code
133133

134134
override def toString: String =
135-
s"Disconnect(${Disconnect.reasonToString(reason)}"
135+
s"Disconnect(${Disconnect.reasonToString(reason)})"
136136

137137
}
138138

0 commit comments

Comments
 (0)