Skip to content

Commit

Permalink
feat(rpc): fix sonar complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk committed Dec 27, 2024
1 parent 632fe0e commit d76664c
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions rskj-core/src/main/java/org/ethereum/rpc/dto/BlockResultDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -144,7 +140,7 @@ public static BlockResultDTO fromBlock(Block b, boolean fullTx, BlockStore block
List<Object> transactions = IntStream.range(0, blockTransactions.size())
.mapToObj(txIndex -> toTransactionResult(txIndex, b, fullTx, skipRemasc, zeroSignatureIfRemasc, signatureCache))
.filter(Objects::nonNull)
.collect(Collectors.toList());
.toList();

List<String> uncles = new ArrayList<>();

Expand Down Expand Up @@ -216,6 +212,10 @@ public String getParentHash() {
return parentHash;
}

public String getMixHash() {
return mixHash;
}

public String getSha3Uncles() {
return sha3Uncles;
}
Expand Down Expand Up @@ -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;
}
}

0 comments on commit d76664c

Please sign in to comment.