Add getBlockByHash to plugins API (#8413)

* Add getBlockByHash to plugins API

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>

* Plugin hash

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>

---------

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matt Whitehead <matthew.whitehead@kaleido.io>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
This commit is contained in:
Matt Whitehead
2025-03-17 01:08:11 +00:00
committed by GitHub
parent 9fc0e40eb2
commit 47f455887a
3 changed files with 22 additions and 1 deletions

View File

@@ -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<BlockContext> getBlockByHash(final Hash hash) {
return blockchain
.getBlockByHash(hash)
.map(block -> blockContext(block::getHeader, block::getBody));
}
@Override
public Hash getChainHeadHash() {
return blockchain.getChainHeadHash();

View File

@@ -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')

View File

@@ -37,6 +37,14 @@ public interface BlockchainService extends BesuService {
*/
Optional<BlockContext> getBlockByNumber(final long number);
/**
* Gets block by hash
*
* @param hash the block hash
* @return the BlockContext
*/
Optional<BlockContext> getBlockByHash(final Hash hash);
/**
* Get the hash of the chain head
*