diff --git a/src/poktroll_clients/block_client.py b/src/poktroll_clients/block_client.py index c5c6df4..fb427c7 100644 --- a/src/poktroll_clients/block_client.py +++ b/src/poktroll_clients/block_client.py @@ -1,5 +1,7 @@ from poktroll_clients.ffi import ffi, libpoktroll_clients -from poktroll_clients.go_memory import GoManagedMem, go_ref +from poktroll_clients.go_memory import GoManagedMem, go_ref, check_err +from poktroll_clients.proto.tendermint.types.block_pb2 import Block +from poktroll_clients.protobuf import get_proto_from_go_ref class BlockClient(GoManagedMem): @@ -33,3 +35,18 @@ def __init__(self, query_node_rpc_url: str): self.err_ptr) super().__init__(go_ref) + + def block(self, query_height: int = 0) -> Block: + """ + TODO_IN_THIS_COMMIT: comment + """ + if query_height < 1: + c_query_height = ffi.NULL + else: + c_query_height = ffi.new("int64_t *", query_height) + + + block_ref = libpoktroll_clients.BlockQueryClient_Block(self.go_ref, c_query_height, self.err_ptr) + check_err(self.err_ptr) + + return get_proto_from_go_ref(block_ref) diff --git a/src/poktroll_clients/ffi.py b/src/poktroll_clients/ffi.py index 29e8248..0325373 100644 --- a/src/poktroll_clients/ffi.py +++ b/src/poktroll_clients/ffi.py @@ -85,6 +85,7 @@ go_ref EventsQueryClientEventsBytes(go_ref selfRef, const char* query); go_ref NewBlockQueryClient(char *comet_websocket_url, char **err); + go_ref BlockQueryClient_Block(go_ref self_ref, int64_t* query_height, char **err); go_ref NewTxContext(char *tcp_url, char **err); diff --git a/tests/test_block_client.py b/tests/test_block_client.py index 457448f..a23fd3f 100644 --- a/tests/test_block_client.py +++ b/tests/test_block_client.py @@ -1,14 +1,21 @@ +from typing_extensions import assert_type + from poktroll_clients import ( BlockQueryClient, BlockClient, EventsQueryClient, SupplyMany, ) +from poktroll_clients.proto.tendermint.types.block_pb2 import Block def test_block_query_client(): - events_query_client = EventsQueryClient("ws://127.0.0.1:26657/websocket") block_query_client = BlockQueryClient("http://127.0.0.1:26657") + current_block = block_query_client.block() + + assert_type(current_block, Block) + assert current_block.header.height != 0 + def test_block_client():