mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 06:31:57 +00:00
rpc: add BlockByHash to Client (#4923)
Ethermint currently has to maintain a map height-> block hash on the store (see here) as it needs to expose the eth_getBlockByHash JSON-RPC query for Web3 compatibility. This query is currently not supported by the tendermint RPC client.
This commit is contained in:
@@ -367,6 +367,18 @@ func (c *baseRPCClient) Block(height *int64) (*ctypes.ResultBlock, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *baseRPCClient) BlockByHash(hash []byte) (*ctypes.ResultBlock, error) {
|
||||
result := new(ctypes.ResultBlock)
|
||||
params := map[string]interface{}{
|
||||
"hash": hash,
|
||||
}
|
||||
_, err := c.caller.Call("block_by_hash", params, result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *baseRPCClient) BlockResults(height *int64) (*ctypes.ResultBlockResults, error) {
|
||||
result := new(ctypes.ResultBlockResults)
|
||||
params := make(map[string]interface{})
|
||||
|
||||
@@ -65,6 +65,7 @@ type ABCIClient interface {
|
||||
// and prove anything about the chain.
|
||||
type SignClient interface {
|
||||
Block(height *int64) (*ctypes.ResultBlock, error)
|
||||
BlockByHash(hash []byte) (*ctypes.ResultBlock, error)
|
||||
BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
|
||||
Commit(height *int64) (*ctypes.ResultCommit, error)
|
||||
Validators(height *int64, page, perPage int) (*ctypes.ResultValidators, error)
|
||||
|
||||
@@ -144,6 +144,10 @@ func (c *Local) Block(height *int64) (*ctypes.ResultBlock, error) {
|
||||
return core.Block(c.ctx, height)
|
||||
}
|
||||
|
||||
func (c *Local) BlockByHash(hash []byte) (*ctypes.ResultBlock, error) {
|
||||
return core.BlockByHash(c.ctx, hash)
|
||||
}
|
||||
|
||||
func (c *Local) BlockResults(height *int64) (*ctypes.ResultBlockResults, error) {
|
||||
return core.BlockResults(c.ctx, height)
|
||||
}
|
||||
|
||||
@@ -150,6 +150,10 @@ func (c Client) Block(height *int64) (*ctypes.ResultBlock, error) {
|
||||
return core.Block(&rpctypes.Context{}, height)
|
||||
}
|
||||
|
||||
func (c Client) BlockByHash(hash []byte) (*ctypes.ResultBlock, error) {
|
||||
return core.BlockByHash(&rpctypes.Context{}, hash)
|
||||
}
|
||||
|
||||
func (c Client) Commit(height *int64) (*ctypes.ResultCommit, error) {
|
||||
return core.Commit(&rpctypes.Context{}, height)
|
||||
}
|
||||
|
||||
@@ -249,6 +249,10 @@ func TestAppCalls(t *testing.T) {
|
||||
assert.True(len(appHash) > 0)
|
||||
assert.EqualValues(apph, block.Block.Header.Height)
|
||||
|
||||
blockByHash, err := c.BlockByHash(block.BlockID.Hash)
|
||||
require.NoError(err)
|
||||
require.Equal(block, blockByHash)
|
||||
|
||||
// now check the results
|
||||
blockResults, err := c.BlockResults(&txh)
|
||||
require.Nil(err, "%d: %+v", i, err)
|
||||
|
||||
Reference in New Issue
Block a user