Skip to content

Commit

Permalink
chore: implement BlockQueryClient#Block
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Dec 21, 2024
1 parent 9868d2b commit 4812a43
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/poktroll_clients/block_client.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions src/poktroll_clients/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion tests/test_block_client.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down

0 comments on commit 4812a43

Please sign in to comment.