You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuweni.apache.org by to...@apache.org on 2020/04/26 06:00:30 UTC

[incubator-tuweni] branch master updated: simplify code as result

This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git


The following commit(s) were added to refs/heads/master by this push:
     new c05aaa9  simplify code as result
c05aaa9 is described below

commit c05aaa9724c9edf500c92b6220391afaaf0f9ac5
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Sat Apr 25 23:00:07 2020 -0700

    simplify code as result
---
 .../tuweni/devp2p/v5/NodeDiscoveryService.kt       |  8 +--
 .../tuweni/eth/reference/TransactionTestSuite.java |  2 +-
 .../tuweni/eth/repository/BlockchainIndex.kt       | 22 ++----
 .../tuweni/eth/repository/BlockchainRepository.kt  | 84 +++++-----------------
 .../tuweni/eth/repository/BlockchainIndexTest.kt   |  4 +-
 .../eth/repository/BlockchainRepositoryTest.kt     |  2 +-
 .../java/org/apache/tuweni/eth/BlockHeader.java    | 14 ++--
 eth/src/main/java/org/apache/tuweni/eth/Log.java   |  2 +-
 .../org/apache/tuweni/eth/LogsBloomFilter.java     |  2 +-
 .../java/org/apache/tuweni/eth/Transaction.java    |  4 +-
 .../org/apache/tuweni/les/GetBlockBodiesMessage.kt |  2 +-
 .../org/apache/tuweni/les/GetReceiptsMessage.kt    |  2 +-
 .../org/apache/tuweni/les/LESSubProtocolHandler.kt |  4 +-
 .../apache/tuweni/les/LESSubProtocolHandlerTest.kt |  2 +-
 14 files changed, 48 insertions(+), 106 deletions(-)

diff --git a/devp2p/src/main/kotlin/org/apache/tuweni/devp2p/v5/NodeDiscoveryService.kt b/devp2p/src/main/kotlin/org/apache/tuweni/devp2p/v5/NodeDiscoveryService.kt
index ffed109..2862ac1 100644
--- a/devp2p/src/main/kotlin/org/apache/tuweni/devp2p/v5/NodeDiscoveryService.kt
+++ b/devp2p/src/main/kotlin/org/apache/tuweni/devp2p/v5/NodeDiscoveryService.kt
@@ -18,6 +18,7 @@ package org.apache.tuweni.devp2p.v5
 
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.Dispatchers
+import org.apache.tuweni.bytes.Bytes
 import org.apache.tuweni.concurrent.coroutines.asyncCompletion
 import org.apache.tuweni.crypto.Hash
 import org.apache.tuweni.crypto.SECP256K1
@@ -125,7 +126,8 @@ class DefaultNodeDiscoveryService(
     connector.terminate()
   }
 
-  suspend fun addPeer(enr: Bytes) {
+  suspend fun addPeer(rlpENR: Bytes) {
+    val enr: EthereumNodeRecord = EthereumNodeRecord.fromRLP(rlpENR)
     val randomMessage = RandomMessage()
     val address = InetSocketAddress(enr.ip(), enr.udp())
 
@@ -140,9 +142,7 @@ class DefaultNodeDiscoveryService(
       if (it.startsWith("enr:")) {
         val encodedEnr = it.substringAfter("enr:")
         val rlpENR = Base64URLSafe.decode(encodedEnr)
-        val enr = EthereumNodeRecord.fromRLP(rlpENR)
-
-        addPeer(enr)
+        addPeer(rlpENR)
       }
     }
   }
diff --git a/eth-reference-tests/src/test/java/org/apache/tuweni/eth/reference/TransactionTestSuite.java b/eth-reference-tests/src/test/java/org/apache/tuweni/eth/reference/TransactionTestSuite.java
index f013437..e453bb3 100644
--- a/eth-reference-tests/src/test/java/org/apache/tuweni/eth/reference/TransactionTestSuite.java
+++ b/eth-reference-tests/src/test/java/org/apache/tuweni/eth/reference/TransactionTestSuite.java
@@ -60,7 +60,7 @@ class TransactionTestSuite {
     Transaction tx = Transaction.fromBytes(rlpBytes);
     assertEquals(Address.fromBytes(Bytes.fromHexString(sender)), tx.getSender());
     assertEquals(rlpBytes, tx.toBytes());
-    assertEquals(Bytes.fromHexString(hash), tx.getHash().toBytes());
+    assertEquals(Bytes.fromHexString(hash), tx.getHash());
   }
 
   private void testInvalidTransaction(String rlp, String milestone) {
diff --git a/eth-repository/src/main/kotlin/org/apache/tuweni/eth/repository/BlockchainIndex.kt b/eth-repository/src/main/kotlin/org/apache/tuweni/eth/repository/BlockchainIndex.kt
index aaa1a87..ce7cf6a 100644
--- a/eth-repository/src/main/kotlin/org/apache/tuweni/eth/repository/BlockchainIndex.kt
+++ b/eth-repository/src/main/kotlin/org/apache/tuweni/eth/repository/BlockchainIndex.kt
@@ -233,7 +233,7 @@ interface BlockchainIndexReader {
    * @param index the index of the transaction in the block
    * @return the matching hash of the transaction if found
    */
-  fun findByBlockHashAndIndex(blockHash: Hash, index: Int): Hash?
+  fun findByBlockHashAndIndex(blockHash: Bytes, index: Int): Hash?
 
   /**
    * Retrieves the total difficulty of the block header, if it has been computed.
@@ -241,7 +241,7 @@ interface BlockchainIndexReader {
    * @param hash the hash of the header
    * @return the total difficulty of the header if it could be computed.
    */
-  fun totalDifficulty(hash: Hash): UInt256?
+  fun totalDifficulty(hash: Bytes): UInt256?
 }
 
 /**
@@ -264,7 +264,7 @@ interface BlockchainIndexWriter {
    * @param txHash the hash of the transaction
    * @param blockHash the hash of the block
    */
-  fun indexTransactionReceipt(txReceipt: TransactionReceipt, txIndex: Int, txHash: Hash, blockHash: Hash)
+  fun indexTransactionReceipt(txReceipt: TransactionReceipt, txIndex: Int, txHash: Bytes, blockHash: Bytes)
 }
 
 /**
@@ -362,7 +362,7 @@ class BlockchainIndex(private val indexWriter: IndexWriter) : BlockchainIndexWri
     }
   }
 
-  override fun indexTransactionReceipt(txReceipt: TransactionReceipt, txIndex: Int, txHash: Hash, blockHash: Hash) {
+  override fun indexTransactionReceipt(txReceipt: TransactionReceipt, txIndex: Int, txHash: Bytes, blockHash: Bytes) {
     val document = mutableListOf<IndexableField>()
     val id = toBytesRef(txHash)
     document += StringField("_id", id, Field.Store.YES)
@@ -370,7 +370,7 @@ class BlockchainIndex(private val indexWriter: IndexWriter) : BlockchainIndexWri
 
     document += NumericDocValuesField(TransactionReceiptFields.INDEX.fieldName, txIndex.toLong())
     document += StringField(TransactionReceiptFields.TRANSACTION_HASH.fieldName, id, Field.Store.NO)
-    document += StringField(TransactionReceiptFields.BLOCK_HASH.fieldName, toBytesRef(blockHash.toBytes()),
+    document += StringField(TransactionReceiptFields.BLOCK_HASH.fieldName, toBytesRef(blockHash),
       Field.Store.NO)
     for (log in txReceipt.getLogs()) {
       document += StringField(TransactionReceiptFields.LOGGER.fieldName, toBytesRef(log.getLogger()), Field.Store.NO)
@@ -570,7 +570,7 @@ class BlockchainIndex(private val indexWriter: IndexWriter) : BlockchainIndexWri
     return findByOneTerm(field, toBytesRef(value))
   }
 
-  override fun findByBlockHashAndIndex(blockHash: Hash, index: Int): Hash? {
+  override fun findByBlockHashAndIndex(blockHash: Bytes, index: Int): Hash? {
     return queryTxReceipts(
       BooleanQuery.Builder()
         .add(
@@ -596,7 +596,7 @@ class BlockchainIndex(private val indexWriter: IndexWriter) : BlockchainIndexWri
     return queryBlocks(query)
   }
 
-  override fun totalDifficulty(hash: Hash): UInt256? =
+  override fun totalDifficulty(hash: Bytes): UInt256? =
     queryBlockDocs(TermQuery(Term("_id", toBytesRef(hash))), listOf(TOTAL_DIFFICULTY)).firstOrNull()?.let {
       it.getField(TOTAL_DIFFICULTY.fieldName)?.binaryValue()?.bytes?.let { bytes ->
         UInt256.fromBytes(Bytes.wrap(bytes))
@@ -623,14 +623,6 @@ class BlockchainIndex(private val indexWriter: IndexWriter) : BlockchainIndexWri
     return toBytesRef(uint.toBytes())
   }
 
-  private fun toBytesRef(address: Address): BytesRef {
-    return toBytesRef(address.toBytes())
-  }
-
-  private fun toBytesRef(hash: Hash): BytesRef {
-    return toBytesRef(hash.toBytes())
-  }
-
   companion object {
 
     private val HITS = 10
diff --git a/eth-repository/src/main/kotlin/org/apache/tuweni/eth/repository/BlockchainRepository.kt b/eth-repository/src/main/kotlin/org/apache/tuweni/eth/repository/BlockchainRepository.kt
index 9c4e30a..cb2f43d 100644
--- a/eth-repository/src/main/kotlin/org/apache/tuweni/eth/repository/BlockchainRepository.kt
+++ b/eth-repository/src/main/kotlin/org/apache/tuweni/eth/repository/BlockchainRepository.kt
@@ -83,7 +83,7 @@ class BlockchainRepository
    * @return a handle to the storage operation completion
    */
   suspend fun storeBlockBody(blockHash: Hash, blockBody: BlockBody) {
-    blockBodyStore.put(blockHash.toBytes(), blockBody.toBytes())
+    blockBodyStore.put(blockHash, blockBody.toBytes())
   }
 
   /**
@@ -94,7 +94,7 @@ class BlockchainRepository
    */
   suspend fun storeBlock(block: Block) {
     storeBlockBody(block.getHeader().getHash(), block.getBody())
-    blockHeaderStore.put(block.getHeader().getHash().toBytes(), block.getHeader().toBytes())
+    blockHeaderStore.put(block.getHeader().getHash(), block.getHeader().toBytes())
     indexBlockHeader(block.getHeader())
   }
 
@@ -107,7 +107,7 @@ class BlockchainRepository
    * @param txHash the hash of the transaction
    * @param blockHash the hash of the block that this transaction belongs to
    */
-  suspend fun storeTransactionReceipts(vararg transactionReceipts: TransactionReceipt, txHash: Hash, blockHash: Hash) {
+  suspend fun storeTransactionReceipts(vararg transactionReceipts: TransactionReceipt, txHash: Bytes, blockHash: Bytes) {
     for (i in 0 until transactionReceipts.size) {
       storeTransactionReceipt(transactionReceipts[i], i, txHash, blockHash)
     }
@@ -124,10 +124,10 @@ class BlockchainRepository
   suspend fun storeTransactionReceipt(
     transactionReceipt: TransactionReceipt,
     txIndex: Int,
-    txHash: Hash,
-    blockHash: Hash
+    txHash: Bytes,
+    blockHash: Bytes
   ) {
-    transactionReceiptsStore.put(txHash.toBytes(), transactionReceipt.toBytes())
+    transactionReceiptsStore.put(txHash, transactionReceipt.toBytes())
     indexTransactionReceipt(transactionReceipt, txIndex, txHash, blockHash)
   }
 
@@ -138,14 +138,14 @@ class BlockchainRepository
    * @return handle to the storage operation completion
    */
   suspend fun storeBlockHeader(header: BlockHeader) {
-    blockHeaderStore.put(header.getHash().toBytes(), header.toBytes())
+    blockHeaderStore.put(header.getHash(), header.toBytes())
     indexBlockHeader(header)
   }
 
   private suspend fun indexBlockHeader(header: BlockHeader) {
     blockchainIndex.index { writer -> writer.indexBlockHeader(header) }
     for (hash in findBlocksByParentHash(header.getHash())) {
-      blockHeaderStore.get(hash.toBytes())?.let { bytes ->
+      blockHeaderStore.get(hash)?.let { bytes ->
         indexBlockHeader(BlockHeader.fromBytes(bytes))
       }
     }
@@ -154,8 +154,8 @@ class BlockchainRepository
   private suspend fun indexTransactionReceipt(
     txReceipt: TransactionReceipt,
     txIndex: Int,
-    txHash: Hash,
-    blockHash: Hash
+    txHash: Bytes,
+    blockHash: Bytes
   ) {
     blockchainIndex.index {
       it.indexTransactionReceipt(txReceipt, txIndex, txHash, blockHash)
@@ -163,16 +163,6 @@ class BlockchainRepository
   }
 
   /**
-   * Retrieves a block into the repository as its serialized RLP bytes representation.
-   *
-   * @param blockHash the hash of the block stored
-   * @return a future with the bytes if found
-   */
-  suspend fun retrieveBlockBodyBytes(blockHash: Hash): Bytes? {
-    return retrieveBlockBodyBytes(blockHash.toBytes())
-  }
-
-  /**
    * Retrieves a block body into the repository as its serialized RLP bytes representation.
    *
    * @param blockHash the hash of the block stored
@@ -188,16 +178,6 @@ class BlockchainRepository
    * @param blockHash the hash of the block stored
    * @return a future with the block if found
    */
-  suspend fun retrieveBlockBody(blockHash: Hash): BlockBody? {
-    return retrieveBlockBody(blockHash.toBytes())
-  }
-
-  /**
-   * Retrieves a block body into the repository.
-   *
-   * @param blockHash the hash of the block stored
-   * @return a future with the block if found
-   */
   suspend fun retrieveBlockBody(blockHash: Bytes): BlockBody? {
     return retrieveBlockBodyBytes(blockHash)?.let { BlockBody.fromBytes(it) }
   }
@@ -208,16 +188,6 @@ class BlockchainRepository
    * @param blockHash the hash of the block stored
    * @return a future with the block if found
    */
-  suspend fun retrieveBlock(blockHash: Hash): Block? {
-    return retrieveBlock(blockHash.toBytes())
-  }
-
-  /**
-   * Retrieves a block into the repository.
-   *
-   * @param blockHash the hash of the block stored
-   * @return a future with the block if found
-   */
   suspend fun retrieveBlock(blockHash: Bytes): Block? {
     return retrieveBlockBody(blockHash)?.let {
         body -> this.retrieveBlockHeader(blockHash)?.let { Block(it, body) }
@@ -230,16 +200,6 @@ class BlockchainRepository
    * @param blockHash the hash of the block stored
    * @return a future with the block header bytes if found
    */
-  suspend fun retrieveBlockHeaderBytes(blockHash: Hash): Bytes? {
-    return retrieveBlockBodyBytes(blockHash.toBytes())
-  }
-
-  /**
-   * Retrieves a block header into the repository as its serialized RLP bytes representation.
-   *
-   * @param blockHash the hash of the block stored
-   * @return a future with the block header bytes if found
-   */
   suspend fun retrieveBlockHeaderBytes(blockHash: Bytes): Bytes? {
     return blockHeaderStore.get(blockHash)
   }
@@ -250,16 +210,6 @@ class BlockchainRepository
    * @param blockHash the hash of the block stored
    * @return a future with the block header if found
    */
-  suspend fun retrieveBlockHeader(blockHash: Hash): BlockHeader? {
-    return retrieveBlockHeaderBytes(blockHash.toBytes())?.let { BlockHeader.fromBytes(it) } ?: return null
-  }
-
-  /**
-   * Retrieves a block header into the repository.
-   *
-   * @param blockHash the hash of the block stored
-   * @return a future with the block header if found
-   */
   suspend fun retrieveBlockHeader(blockHash: Bytes): BlockHeader? {
     val bytes = retrieveBlockHeaderBytes(blockHash) ?: return null
     return BlockHeader.fromBytes(bytes)
@@ -300,9 +250,9 @@ class BlockchainRepository
    * @param blockHash the hash of the block
    * @return all transaction receipts associated with a block, in the correct order
    */
-  suspend fun retrieveTransactionReceipts(blockHash: Hash): List<TransactionReceipt?> {
+  suspend fun retrieveTransactionReceipts(blockHash: Bytes): List<TransactionReceipt?> {
     return blockchainIndex.findBy(TransactionReceiptFields.BLOCK_HASH, blockHash).map {
-      transactionReceiptsStore.get(it.toBytes())?.let { TransactionReceipt.fromBytes(it) }
+      transactionReceiptsStore.get(it)?.let { TransactionReceipt.fromBytes(it) }
     }
   }
 
@@ -311,9 +261,9 @@ class BlockchainRepository
    * @param blockHash the hash of the block
    * @param index the index of the transaction in the block
    */
-  suspend fun retrieveTransactionReceipt(blockHash: Hash, index: Int): TransactionReceipt? {
+  suspend fun retrieveTransactionReceipt(blockHash: Bytes, index: Int): TransactionReceipt? {
     return blockchainIndex.findByBlockHashAndIndex(blockHash, index)?.let {
-      transactionReceiptsStore.get(it.toBytes())?.let { TransactionReceipt.fromBytes(it) }
+      transactionReceiptsStore.get(it)?.let { TransactionReceipt.fromBytes(it) }
     }
   }
 
@@ -322,7 +272,7 @@ class BlockchainRepository
    * @param txHash the hash of the transaction
    */
   suspend fun retrieveTransactionReceipt(txHash: Hash): TransactionReceipt? {
-    return transactionReceiptsStore.get(txHash.toBytes())?.let { TransactionReceipt.fromBytes(it) }
+    return transactionReceiptsStore.get(txHash)?.let { TransactionReceipt.fromBytes(it) }
   }
 
   /**
@@ -341,12 +291,12 @@ class BlockchainRepository
    * @param parentHash the parent hash
    * @return the matching blocks
    */
-  fun findBlocksByParentHash(parentHash: Hash): List<Hash> {
+  fun findBlocksByParentHash(parentHash: Bytes): List<Hash> {
     return blockchainIndex.findBy(BlockHeaderFields.PARENT_HASH, parentHash)
   }
 
   private suspend fun setGenesisBlock(block: Block) {
     return chainMetadata
-      .put(GENESIS_BLOCK, block.getHeader().getHash().toBytes())
+      .put(GENESIS_BLOCK, block.getHeader().getHash())
   }
 }
diff --git a/eth-repository/src/test/kotlin/org/apache/tuweni/eth/repository/BlockchainIndexTest.kt b/eth-repository/src/test/kotlin/org/apache/tuweni/eth/repository/BlockchainIndexTest.kt
index 2c245a6..92c6ce4 100644
--- a/eth-repository/src/test/kotlin/org/apache/tuweni/eth/repository/BlockchainIndexTest.kt
+++ b/eth-repository/src/test/kotlin/org/apache/tuweni/eth/repository/BlockchainIndexTest.kt
@@ -76,7 +76,7 @@ internal class BlockchainIndexTest {
     val reader = DirectoryReader.open(writer)
     val searcher = IndexSearcher(reader)
     val collector = TopScoreDocCollector.create(10, ScoreDoc(1, 1.0f))
-    searcher.search(TermQuery(Term("_id", BytesRef(header.hash.toBytes().toArrayUnsafe()))), collector)
+    searcher.search(TermQuery(Term("_id", BytesRef(header.hash.toArrayUnsafe()))), collector)
     val hits = collector.topDocs().scoreDocs
     assertEquals(1, hits.size)
   }
@@ -108,7 +108,7 @@ internal class BlockchainIndexTest {
     val reader = DirectoryReader.open(index)
     val searcher = IndexSearcher(reader)
     val collector = TopScoreDocCollector.create(10, ScoreDoc(1, 1.0f))
-    searcher.search(TermQuery(Term("_id", BytesRef(header.hash.toBytes().toArrayUnsafe()))), collector)
+    searcher.search(TermQuery(Term("_id", BytesRef(header.hash.toArrayUnsafe()))), collector)
     val hits = collector.topDocs().scoreDocs
     assertEquals(1, hits.size)
   }
diff --git a/eth-repository/src/test/kotlin/org/apache/tuweni/eth/repository/BlockchainRepositoryTest.kt b/eth-repository/src/test/kotlin/org/apache/tuweni/eth/repository/BlockchainRepositoryTest.kt
index 08644eb..98ada59 100644
--- a/eth-repository/src/test/kotlin/org/apache/tuweni/eth/repository/BlockchainRepositoryTest.kt
+++ b/eth-repository/src/test/kotlin/org/apache/tuweni/eth/repository/BlockchainRepositoryTest.kt
@@ -109,7 +109,7 @@ internal class BlockchainRepositoryTest {
     )
     val block = Block(header, body)
     repo.storeBlock(block)
-    val read = repo.retrieveBlock(block.getHeader().getHash().toBytes())
+    val read = repo.retrieveBlock(block.getHeader().getHash())
     assertEquals(block, read)
     assertEquals(block.getHeader(), repo.retrieveBlockHeader(block.getHeader().getHash()))
   }
diff --git a/eth/src/main/java/org/apache/tuweni/eth/BlockHeader.java b/eth/src/main/java/org/apache/tuweni/eth/BlockHeader.java
index e430a2f..73f406b 100644
--- a/eth/src/main/java/org/apache/tuweni/eth/BlockHeader.java
+++ b/eth/src/main/java/org/apache/tuweni/eth/BlockHeader.java
@@ -381,12 +381,12 @@ public final class BlockHeader {
    * @param writer The RLP writer.
    */
   void writeTo(RLPWriter writer) {
-    writer.writeValue((parentHash != null) ? parentHash.toBytes() : Bytes.EMPTY);
-    writer.writeValue(ommersHash.toBytes());
-    writer.writeValue(coinbase.toBytes());
-    writer.writeValue(stateRoot.toBytes());
-    writer.writeValue(transactionsRoot.toBytes());
-    writer.writeValue(receiptsRoot.toBytes());
+    writer.writeValue((parentHash != null) ? parentHash : Bytes.EMPTY);
+    writer.writeValue(ommersHash);
+    writer.writeValue(coinbase);
+    writer.writeValue(stateRoot);
+    writer.writeValue(transactionsRoot);
+    writer.writeValue(receiptsRoot);
     writer.writeValue(logsBloom);
     writer.writeValue(difficulty.toMinimalBytes());
     writer.writeValue(number.toMinimalBytes());
@@ -394,7 +394,7 @@ public final class BlockHeader {
     writer.writeValue(gasUsed.toMinimalBytes());
     writer.writeLong(timestamp.getEpochSecond());
     writer.writeValue(extraData);
-    writer.writeValue(mixHash.toBytes());
+    writer.writeValue(mixHash);
     writer.writeValue(nonce);
   }
 }
diff --git a/eth/src/main/java/org/apache/tuweni/eth/Log.java b/eth/src/main/java/org/apache/tuweni/eth/Log.java
index 185053f..7eedad0 100644
--- a/eth/src/main/java/org/apache/tuweni/eth/Log.java
+++ b/eth/src/main/java/org/apache/tuweni/eth/Log.java
@@ -63,7 +63,7 @@ public final class Log {
    */
   public void writeTo(final RLPWriter writer) {
     writer.writeList(out -> {
-      out.writeValue(logger.toBytes());
+      out.writeValue(logger);
       out.writeList(topicsWriter -> {
         for (Bytes32 topic : topics) {
           topicsWriter.writeValue(topic);
diff --git a/eth/src/main/java/org/apache/tuweni/eth/LogsBloomFilter.java b/eth/src/main/java/org/apache/tuweni/eth/LogsBloomFilter.java
index 8805e31..b015236 100644
--- a/eth/src/main/java/org/apache/tuweni/eth/LogsBloomFilter.java
+++ b/eth/src/main/java/org/apache/tuweni/eth/LogsBloomFilter.java
@@ -75,7 +75,7 @@ public final class LogsBloomFilter {
   }
 
   public void insertLog(final Log log) {
-    setBits(keccak256(log.getLogger().toBytes()));
+    setBits(keccak256(log.getLogger()));
 
     for (final Bytes32 topic : log.getTopics()) {
       setBits(keccak256(topic));
diff --git a/eth/src/main/java/org/apache/tuweni/eth/Transaction.java b/eth/src/main/java/org/apache/tuweni/eth/Transaction.java
index 8bb3e5b..63da4ba 100644
--- a/eth/src/main/java/org/apache/tuweni/eth/Transaction.java
+++ b/eth/src/main/java/org/apache/tuweni/eth/Transaction.java
@@ -390,7 +390,7 @@ public final class Transaction {
     writer.writeUInt256(nonce);
     writer.writeUInt256(gasPrice.toUInt256());
     writer.writeLong(gasLimit.toLong());
-    writer.writeValue((to != null) ? to.toBytes() : Bytes.EMPTY);
+    writer.writeValue((to != null) ? to : Bytes.EMPTY);
     writer.writeUInt256(value.toUInt256());
     writer.writeValue(payload);
     if (chainId != null) {
@@ -427,7 +427,7 @@ public final class Transaction {
       writer.writeUInt256(nonce);
       writer.writeValue(gasPrice.toMinimalBytes());
       writer.writeValue(gasLimit.toMinimalBytes());
-      writer.writeValue((to != null) ? to.toBytes() : Bytes.EMPTY);
+      writer.writeValue((to != null) ? to : Bytes.EMPTY);
       writer.writeValue(value.toMinimalBytes());
       writer.writeValue(payload);
       if (chainId != null) {
diff --git a/les/src/main/kotlin/org/apache/tuweni/les/GetBlockBodiesMessage.kt b/les/src/main/kotlin/org/apache/tuweni/les/GetBlockBodiesMessage.kt
index 0ae3d73..30fc402 100644
--- a/les/src/main/kotlin/org/apache/tuweni/les/GetBlockBodiesMessage.kt
+++ b/les/src/main/kotlin/org/apache/tuweni/les/GetBlockBodiesMessage.kt
@@ -25,7 +25,7 @@ internal data class GetBlockBodiesMessage(val reqID: Long, val blockHashes: List
   fun toBytes(): Bytes {
     return RLP.encodeList { writer ->
       writer.writeLong(reqID)
-      writer.writeList(blockHashes) { eltWriter, hash -> eltWriter.writeValue(hash.toBytes()) }
+      writer.writeList(blockHashes) { eltWriter, hash -> eltWriter.writeValue(hash) }
     }
   }
 
diff --git a/les/src/main/kotlin/org/apache/tuweni/les/GetReceiptsMessage.kt b/les/src/main/kotlin/org/apache/tuweni/les/GetReceiptsMessage.kt
index d6a9b5f..7d384c5 100644
--- a/les/src/main/kotlin/org/apache/tuweni/les/GetReceiptsMessage.kt
+++ b/les/src/main/kotlin/org/apache/tuweni/les/GetReceiptsMessage.kt
@@ -25,7 +25,7 @@ internal data class GetReceiptsMessage(val reqID: Long, val blockHashes: List<Ha
   fun toBytes(): Bytes {
     return RLP.encodeList { writer ->
       writer.writeLong(reqID)
-      writer.writeList(blockHashes) { eltWriter, hash -> eltWriter.writeValue(hash.toBytes()) }
+      writer.writeList(blockHashes) { eltWriter, hash -> eltWriter.writeValue(hash) }
     }
   }
 
diff --git a/les/src/main/kotlin/org/apache/tuweni/les/LESSubProtocolHandler.kt b/les/src/main/kotlin/org/apache/tuweni/les/LESSubProtocolHandler.kt
index 5da47cb..7734bd2 100644
--- a/les/src/main/kotlin/org/apache/tuweni/les/LESSubProtocolHandler.kt
+++ b/les/src/main/kotlin/org/apache/tuweni/les/LESSubProtocolHandler.kt
@@ -174,9 +174,9 @@ internal class LESSubProtocolHandler(
           subProtocolIdentifier.version(),
           networkId,
           headTd,
-          headHash.toBytes(),
+          headHash,
           head.getHeader().getNumber(),
-          genesis.getHeader().getHash().toBytes(),
+          genesis.getHeader().getHash(),
           serveHeaders,
           serveChainSince,
           serveStateSince,
diff --git a/les/src/test/kotlin/org/apache/tuweni/les/LESSubProtocolHandlerTest.kt b/les/src/test/kotlin/org/apache/tuweni/les/LESSubProtocolHandlerTest.kt
index 5b8fbab..3619b12 100644
--- a/les/src/test/kotlin/org/apache/tuweni/les/LESSubProtocolHandlerTest.kt
+++ b/les/src/test/kotlin/org/apache/tuweni/les/LESSubProtocolHandlerTest.kt
@@ -163,7 +163,7 @@ constructor() {
       assertNotNull(message)
       assertEquals(2, message.protocolVersion)
       assertEquals(UInt256.ZERO, message.flowControlBufferLimit)
-      assertEquals(block.getHeader().getHash().toBytes(), message.genesisHash)
+      assertEquals(block.getHeader().getHash(), message.genesisHash)
     }
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org