Skip to content

Commit 13c81d5

Browse files
authored
Merge pull request #3135 from rsksmart/vovchyk/rc710/nonce-fix
fix(rpc): extend BlockResultDTO with nonce field
2 parents f9f3856 + 6a1db70 commit 13c81d5

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

rskj-core/src/main/java/org/ethereum/rpc/dto/BlockResultDTO.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class BlockResultDTO {
3939
private final String hash; // DATA, 32 Bytes - hash of the block. null when its pending block.
4040
private final String parentHash; // DATA, 32 Bytes - hash of the parent block.
4141
private final String mixHash; // DATA, 32 Bytes - mix hash field used for compatibility reasons.
42+
private final String nonce; // QUANTITY - nonce field used for compatibility reasons.
4243
private final String sha3Uncles; // DATA, 32 Bytes - SHA3 of the uncles data in the block.
4344
private final String logsBloom; // DATA, 256 Bytes - the bloom filter for the logs of the block. null when its pending block.
4445
private final String transactionsRoot; // DATA, 32 Bytes - the root of the transaction trie of the block.
@@ -95,6 +96,7 @@ private BlockResultDTO(
9596
this.hash = hash != null ? hash.toJsonString() : null;
9697
this.parentHash = parentHash.toJsonString();
9798
this.mixHash = mixHash != null ? mixHash.toJsonString() : null;
99+
this.nonce = "0x0000000000000000"; // hardcoded for compatibility with Ethereum
98100
this.sha3Uncles = HexUtils.toUnformattedJsonHex(sha3Uncles);
99101
this.logsBloom = logsBloom != null ? HexUtils.toUnformattedJsonHex(logsBloom) : null;
100102
this.transactionsRoot = HexUtils.toUnformattedJsonHex(transactionsRoot);
@@ -216,6 +218,10 @@ public String getMixHash() {
216218
return mixHash;
217219
}
218220

221+
public String getNonce() {
222+
return nonce;
223+
}
224+
219225
public String getSha3Uncles() {
220226
return sha3Uncles;
221227
}

rskj-core/src/test/java/org/ethereum/rpc/dto/BlockResultDTOTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.math.BigInteger;
3636
import java.nio.file.Path;
3737
import java.util.Arrays;
38+
import java.util.Collections;
3839
import java.util.List;
3940
import java.util.Objects;
4041
import java.util.stream.Collectors;
@@ -98,6 +99,14 @@ void getBlockResultDTOWithoutRemasc_emptyTransactions() {
9899
Assertions.assertTrue(blockResultDTO.getTransactions().isEmpty());
99100
}
100101

102+
@Test
103+
void getBlockResultDTO_containsObsoleteFields() {
104+
Block block = buildBlockWithTransactions(Collections.emptyList());
105+
BlockResultDTO blockResultDTO = BlockResultDTO.fromBlock(block, false, blockStore, true, false, new BlockTxSignatureCache(new ReceivedTxSignatureCache()));
106+
107+
Assertions.assertEquals("0x0000000000000000000000000000000000000000000000000000000000000000", blockResultDTO.getMixHash());
108+
Assertions.assertEquals("0x0000000000000000", blockResultDTO.getNonce());
109+
}
101110

102111
@Test
103112
void getBlockResultDTOWithNullSignatureRemascAndFullTransactions() {

0 commit comments

Comments
 (0)