Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): add mixHash field to block dto with zero value #2909

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 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 Down Expand Up @@ -70,6 +67,7 @@ private BlockResultDTO(
Long number,
Keccak256 hash,
Keccak256 parentHash,
Keccak256 mixHash,
byte[] sha3Uncles,
byte[] logsBloom,
byte[] transactionsRoot,
Expand All @@ -96,6 +94,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);
Expand Down Expand Up @@ -123,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 @@ -141,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 All @@ -160,6 +159,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,
Expand Down Expand Up @@ -212,6 +212,10 @@ public String getParentHash() {
return parentHash;
}

public String getMixHash() {
return mixHash;
}

public String getSha3Uncles() {
return sha3Uncles;
}
Expand Down Expand Up @@ -297,6 +301,11 @@ public String getPaidFees() {
}

public short[] getRskPteEdges() {
return rskPteEdges;
return copyOfArrayOrNull(rskPteEdges);
}

@Nullable
private static short[] copyOfArrayOrNull(short[] array) {
return array != null ? Arrays.copyOf(array, array.length) : null;
}
}
}
Loading