From 632fe0efcacf4b2ceb2fd1139c76c1a18521c638 Mon Sep 17 00:00:00 2001 From: Volodymyr Kravets Date: Fri, 27 Dec 2024 12:02:09 +0200 Subject: [PATCH 1/2] feat(rpc): add mixHash field to block dto with zero value --- .../main/java/org/ethereum/rpc/dto/BlockResultDTO.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rskj-core/src/main/java/org/ethereum/rpc/dto/BlockResultDTO.java b/rskj-core/src/main/java/org/ethereum/rpc/dto/BlockResultDTO.java index d529bee160c..355c3183bb2 100644 --- a/rskj-core/src/main/java/org/ethereum/rpc/dto/BlockResultDTO.java +++ b/rskj-core/src/main/java/org/ethereum/rpc/dto/BlockResultDTO.java @@ -65,11 +65,13 @@ public class BlockResultDTO { private final String paidFees; private final String cumulativeDifficulty; private final short[] rskPteEdges; + private final String mixHash; private BlockResultDTO( Long number, Keccak256 hash, Keccak256 parentHash, + Keccak256 mixHash, byte[] sha3Uncles, byte[] logsBloom, byte[] transactionsRoot, @@ -96,6 +98,7 @@ private BlockResultDTO( this.number = number != null ? HexUtils.toQuantityJsonHex(number) : null; this.hash = hash != null ? hash.toJsonString() : null; this.parentHash = parentHash.toJsonString(); + this.mixHash = mixHash != null ? mixHash.toJsonString() : null; this.sha3Uncles = HexUtils.toUnformattedJsonHex(sha3Uncles); this.logsBloom = logsBloom != null ? HexUtils.toUnformattedJsonHex(logsBloom) : null; this.transactionsRoot = HexUtils.toUnformattedJsonHex(transactionsRoot); @@ -160,6 +163,7 @@ public static BlockResultDTO fromBlock(Block b, boolean fullTx, BlockStore block isPending ? null : b.getNumber(), isPending ? null : b.getHash(), b.getParentHash(), + Keccak256.ZERO_HASH, b.getUnclesHash(), isPending ? null : b.getLogBloom(), transactionsRoot, @@ -299,4 +303,8 @@ public String getPaidFees() { public short[] getRskPteEdges() { return rskPteEdges; } -} \ No newline at end of file + + public String getMixHash() { + return mixHash; + } +} From d76664cb44d91cd27a2cf95940de62dda33fc89b Mon Sep 17 00:00:00 2001 From: Volodymyr Kravets Date: Fri, 27 Dec 2024 12:41:29 +0200 Subject: [PATCH 2/2] feat(rpc): fix sonar complaints --- .../org/ethereum/rpc/dto/BlockResultDTO.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/rskj-core/src/main/java/org/ethereum/rpc/dto/BlockResultDTO.java b/rskj-core/src/main/java/org/ethereum/rpc/dto/BlockResultDTO.java index 355c3183bb2..fc595f7ed12 100644 --- a/rskj-core/src/main/java/org/ethereum/rpc/dto/BlockResultDTO.java +++ b/rskj-core/src/main/java/org/ethereum/rpc/dto/BlockResultDTO.java @@ -17,31 +17,28 @@ */ package org.ethereum.rpc.dto; -import static org.ethereum.crypto.HashUtil.EMPTY_TRIE_HASH; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - +import co.rsk.core.BlockDifficulty; +import co.rsk.core.Coin; +import co.rsk.core.RskAddress; +import co.rsk.crypto.Keccak256; +import co.rsk.util.HexUtils; import org.ethereum.core.Block; import org.ethereum.core.BlockHeader; import org.ethereum.core.SignatureCache; import org.ethereum.core.Transaction; import org.ethereum.db.BlockStore; -import co.rsk.core.BlockDifficulty; -import co.rsk.core.Coin; -import co.rsk.core.RskAddress; -import co.rsk.crypto.Keccak256; -import co.rsk.util.HexUtils; +import javax.annotation.Nullable; +import java.util.*; +import java.util.stream.IntStream; + +import static org.ethereum.crypto.HashUtil.EMPTY_TRIE_HASH; public class BlockResultDTO { private final String number; // QUANTITY - the block number. null when its pending block. private final String hash; // DATA, 32 Bytes - hash of the block. null when its pending block. private final String parentHash; // DATA, 32 Bytes - hash of the parent block. + private final String mixHash; // DATA, 32 Bytes - mix hash field used for compatibility reasons. private final String sha3Uncles; // DATA, 32 Bytes - SHA3 of the uncles data in the block. private final String logsBloom; // DATA, 256 Bytes - the bloom filter for the logs of the block. null when its pending block. private final String transactionsRoot; // DATA, 32 Bytes - the root of the transaction trie of the block. @@ -65,7 +62,6 @@ public class BlockResultDTO { private final String paidFees; private final String cumulativeDifficulty; private final short[] rskPteEdges; - private final String mixHash; private BlockResultDTO( Long number, @@ -126,7 +122,7 @@ private BlockResultDTO( this.hashForMergedMining = HexUtils.toUnformattedJsonHex(hashForMergedMining); this.paidFees = paidFees != null ? HexUtils.toQuantityJsonHex(paidFees.getBytes()) : null; - this.rskPteEdges = rskPteEdges; + this.rskPteEdges = copyOfArrayOrNull(rskPteEdges); } public static BlockResultDTO fromBlock(Block b, boolean fullTx, BlockStore blockStore, boolean skipRemasc, boolean zeroSignatureIfRemasc, SignatureCache signatureCache) { @@ -144,7 +140,7 @@ public static BlockResultDTO fromBlock(Block b, boolean fullTx, BlockStore block List transactions = IntStream.range(0, blockTransactions.size()) .mapToObj(txIndex -> toTransactionResult(txIndex, b, fullTx, skipRemasc, zeroSignatureIfRemasc, signatureCache)) .filter(Objects::nonNull) - .collect(Collectors.toList()); + .toList(); List uncles = new ArrayList<>(); @@ -216,6 +212,10 @@ public String getParentHash() { return parentHash; } + public String getMixHash() { + return mixHash; + } + public String getSha3Uncles() { return sha3Uncles; } @@ -301,10 +301,11 @@ public String getPaidFees() { } public short[] getRskPteEdges() { - return rskPteEdges; + return copyOfArrayOrNull(rskPteEdges); } - public String getMixHash() { - return mixHash; + @Nullable + private static short[] copyOfArrayOrNull(short[] array) { + return array != null ? Arrays.copyOf(array, array.length) : null; } }