From 47f455887a784a0e00847b06dd0b1debd17393a9 Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Mon, 17 Mar 2025 01:08:11 +0000 Subject: [PATCH] Add getBlockByHash to plugins API (#8413) * Add getBlockByHash to plugins API Signed-off-by: Matthew Whitehead * Plugin hash Signed-off-by: Matthew Whitehead --------- Signed-off-by: Matthew Whitehead Signed-off-by: Matt Whitehead Co-authored-by: Sally MacFarlane --- .../besu/services/BlockchainServiceImpl.java | 13 +++++++++++++ plugin-api/build.gradle | 2 +- .../besu/plugin/services/BlockchainService.java | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java index b1893ef37..a8d8c3620 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java @@ -69,6 +69,19 @@ public class BlockchainServiceImpl implements BlockchainService { .map(block -> blockContext(block::getHeader, block::getBody)); } + /** + * Gets block by hash + * + * @param hash the block hash + * @return the BlockContext if block exists otherwise empty + */ + @Override + public Optional getBlockByHash(final Hash hash) { + return blockchain + .getBlockByHash(hash) + .map(block -> blockContext(block::getHeader, block::getBody)); + } + @Override public Hash getChainHeadHash() { return blockchain.getChainHeadHash(); diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index aaf1f6f44..10b8ed428 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'Qq6tGiNFfAs1JVr7xXx07h/ANxPWcFKe3cBHER43FFQ=' + knownHash = 'xK3KgzBrgVBUosaqd/je+70Ku24Vj4nm2w94E8yHuGE=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BlockchainService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BlockchainService.java index 12d21d789..da6f24c7d 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BlockchainService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BlockchainService.java @@ -37,6 +37,14 @@ public interface BlockchainService extends BesuService { */ Optional getBlockByNumber(final long number); + /** + * Gets block by hash + * + * @param hash the block hash + * @return the BlockContext + */ + Optional getBlockByHash(final Hash hash); + /** * Get the hash of the chain head *