Skip to content

Commit

Permalink
solution: rpc for get block hash
Browse files Browse the repository at this point in the history
  • Loading branch information
splix committed Jun 29, 2020
1 parent 1005e67 commit d710c64
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/ref-01-api-commands.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

* Chain
- <<getBlock>>
- <<chainGetBlockHash>>
- <<getFinalizedHead>>
- <<getHead>>
- <<getRuntimeVersion>>
Expand Down Expand Up @@ -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()`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public RpcCall<BlockResponseJson> getBlock(Hash256 hash) {
return RpcCall.create(BlockResponseJson.class, "chain_getBlock", hash);
}

public RpcCall<Hash256> getBlockHash() {
return RpcCall.create(Hash256.class, "chain_getBlockHash");
}

public RpcCall<Hash256> getBlockHash(long at) {
return RpcCall.create(Hash256.class, "chain_getBlockHash", at);
}

/**
* Request for the hash of the current finalized head
* @return command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d710c64

Please sign in to comment.