diff --git a/CHANGELOG.md b/CHANGELOG.md index 02b499b178..cb965bfb10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Add configuration of Consolidation Request Contract Address via genesis configuration [#7647](https://github.com/hyperledger/besu/pull/7647) - Interrupt pending transaction processing on block creation timeout [#7673](https://github.com/hyperledger/besu/pull/7673) - Align gas cap calculation for transaction simulation to Geth approach [#7703](https://github.com/hyperledger/besu/pull/7703) +- Expose chainId in the `BlockchainService` [7702](https://github.com/hyperledger/besu/pull/7702) ### Bug fixes - Fix mounted data path directory permissions for besu user [#7575](https://github.com/hyperledger/besu/pull/7575) 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 1f014ee061..e981a3e78d 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java @@ -30,6 +30,7 @@ import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.data.TransactionReceipt; import org.hyperledger.besu.plugin.services.BlockchainService; +import java.math.BigInteger; import java.util.List; import java.util.Optional; import java.util.function.Supplier; @@ -182,4 +183,12 @@ public class BlockchainServiceImpl implements BlockchainService { } }; } + + @Override + public Optional getChainId() { + if (protocolSchedule == null) { + return Optional.empty(); + } + return protocolSchedule.getChainId(); + } } diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 6d3a1f93a9..dd2da0a15e 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 = '5H+3gUzCwZtLByfnk11kf+kAPwykQ+WR+n3xWgyfsyY=' + knownHash = '4jVaj9yW88nHbX0KmTR3dPQRvj9x8Pvh5E9Ry7KRT6w=' } 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 84a573aadc..a89d1144af 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 @@ -22,6 +22,7 @@ import org.hyperledger.besu.plugin.data.BlockContext; import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.data.TransactionReceipt; +import java.math.BigInteger; import java.util.List; import java.util.Optional; @@ -106,5 +107,11 @@ public interface BlockchainService extends BesuService { * @throws UnsupportedOperationException if the network is a PoS network */ void setSafeBlock(Hash blockHash) throws IllegalArgumentException, UnsupportedOperationException; - ; + + /** + * Get the chain id + * + * @return the chain id + */ + Optional getChainId(); }