use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugStorageRangeAtResult in project besu by hyperledger.
the class DebugStorageRangeAt method extractStorageAt.
private JsonRpcSuccessResponse extractStorageAt(final JsonRpcRequestContext requestContext, final Address accountAddress, final Hash startKey, final int limit, final WorldState worldState) {
final Account account = worldState.get(accountAddress);
final NavigableMap<Bytes32, AccountStorageEntry> entries = account.storageEntriesFrom(startKey, limit + 1);
Bytes32 nextKey = null;
if (entries.size() == limit + 1) {
nextKey = entries.lastKey();
entries.remove(nextKey);
}
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), new DebugStorageRangeAtResult(entries, nextKey, shortValues));
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugStorageRangeAtResult in project besu by hyperledger.
the class DebugStorageRangeAtTest method shouldRetrieveStorageRange_fullValues.
@Test
public void shouldRetrieveStorageRange_fullValues() {
final TransactionWithMetadata transactionWithMetadata = new TransactionWithMetadata(transaction, 12L, Optional.empty(), blockHash, TRANSACTION_INDEX);
final BlockWithMetadata<TransactionWithMetadata, Hash> blockWithMetadata = new BlockWithMetadata<>(blockHeader, Collections.singletonList(transactionWithMetadata), Collections.emptyList(), Difficulty.ONE, 1);
final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_storageRangeAt", new Object[] { blockHash.toString(), TRANSACTION_INDEX, accountAddress, START_KEY_HASH.toString(), 10 }));
when(blockchainQueries.blockByHash(blockHash)).thenReturn(Optional.of(blockWithMetadata));
when(blockchainQueries.transactionByBlockHashAndIndex(blockHash, TRANSACTION_INDEX)).thenReturn(Optional.of(transactionWithMetadata));
when(worldState.get(accountAddress)).thenReturn(account);
when(blockReplay.afterTransactionInBlock(eq(blockHash), eq(transactionHash), any())).thenAnswer(this::callAction);
final List<AccountStorageEntry> entries = new ArrayList<>();
entries.add(AccountStorageEntry.forKeyAndValue(UInt256.fromHexString("0x33"), UInt256.valueOf(6)));
entries.add(AccountStorageEntry.forKeyAndValue(UInt256.fromHexString("0x44"), UInt256.valueOf(7)));
entries.add(AccountStorageEntry.create(UInt256.valueOf(7), Hash.hash(Bytes32.fromHexString("0x45")), Optional.empty()));
final NavigableMap<Bytes32, AccountStorageEntry> rawEntries = new TreeMap<>();
entries.forEach(e -> rawEntries.put(e.getKeyHash(), e));
when(account.storageEntriesFrom(START_KEY_HASH, 11)).thenReturn(rawEntries);
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) debugStorageRangeAt.response(request);
final DebugStorageRangeAtResult result = (DebugStorageRangeAtResult) response.getResult();
assertThat(result).isNotNull();
assertThat(result.getNextKey()).isNull();
entries.sort(Comparator.comparing(AccountStorageEntry::getKeyHash));
assertThat(result.getStorage()).containsExactly(entry(entries.get(0).getKeyHash().toString(), new DebugStorageRangeAtResult.StorageEntry(entries.get(0), false)), entry(entries.get(1).getKeyHash().toString(), new DebugStorageRangeAtResult.StorageEntry(entries.get(1), false)), entry(entries.get(2).getKeyHash().toString(), new DebugStorageRangeAtResult.StorageEntry(entries.get(2), false)));
}
Aggregations