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 *