diff --git a/docs/ref-01-api-commands.adoc b/docs/ref-01-api-commands.adoc index fec9f1f..0c65718 100644 --- a/docs/ref-01-api-commands.adoc +++ b/docs/ref-01-api-commands.adoc @@ -5,6 +5,7 @@ * Chain - <> +- <> - <> - <> - <> @@ -35,6 +36,16 @@ Command:: `chain_getBlock` Parameters:: hash of the requested block Java Object:: `BlockResponseJson` +[#chainGetBlockHash] +=== Get Block Hash (`chain_getBlockHash`) + +Get the block hash for a specific block + +Shortcut:: `{shortcut-base}.getBlockHash(at)` +Command:: `chain_getBlockHash` +Parameters:: `at` - (optional) block height +Java Object:: `Hash256` + .BlockResponseJson Properties - `BlockJson getBlock()` block details - `Object getJustification()` diff --git a/polkaj-api-base/src/main/java/io/emeraldpay/polkaj/api/StandardCommands.java b/polkaj-api-base/src/main/java/io/emeraldpay/polkaj/api/StandardCommands.java index 2ed06fe..b8c8698 100644 --- a/polkaj-api-base/src/main/java/io/emeraldpay/polkaj/api/StandardCommands.java +++ b/polkaj-api-base/src/main/java/io/emeraldpay/polkaj/api/StandardCommands.java @@ -27,6 +27,14 @@ public RpcCall getBlock(Hash256 hash) { return RpcCall.create(BlockResponseJson.class, "chain_getBlock", hash); } + public RpcCall getBlockHash() { + return RpcCall.create(Hash256.class, "chain_getBlockHash"); + } + + public RpcCall getBlockHash(long at) { + return RpcCall.create(Hash256.class, "chain_getBlockHash", at); + } + /** * Request for the hash of the current finalized head * @return command diff --git a/polkaj-api-base/src/test/groovy/io/emeraldpay/polkaj/api/StandardCommandsSpec.groovy b/polkaj-api-base/src/test/groovy/io/emeraldpay/polkaj/api/StandardCommandsSpec.groovy index 6b6ed61..ab3d124 100644 --- a/polkaj-api-base/src/test/groovy/io/emeraldpay/polkaj/api/StandardCommandsSpec.groovy +++ b/polkaj-api-base/src/test/groovy/io/emeraldpay/polkaj/api/StandardCommandsSpec.groovy @@ -31,6 +31,22 @@ class StandardCommandsSpec extends Specification { act.getResultType(typeFactory).getRawClass() == BlockResponseJson.class } + def "Chain get block hash"() { + when: + def act = StandardCommands.getInstance().getBlockHash() + then: + act.method == "chain_getBlockHash" + act.params.toList() == [] + act.getResultType(typeFactory).getRawClass() == Hash256.class + + when: + act = StandardCommands.getInstance().getBlockHash(101) + then: + act.method == "chain_getBlockHash" + act.params.toList() == [101] + act.getResultType(typeFactory).getRawClass() == Hash256.class + } + def "Chain get finalized head"() { when: def act = StandardCommands.getInstance().getFinalizedHead()