Skip to content

Commit f3e3d3f

Browse files
authored
Fix missing event context fields (#1308)
1 parent 67049e0 commit f3e3d3f

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

docs/migration_guide.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Migration guide
22
===============
33

4+
**********************
5+
0.21.0 Migration guide
6+
**********************
7+
8+
0.21.0 Minor changes
9+
-----------------------
10+
11+
.. currentmodule:: starknet_py.net.client_models
12+
13+
1. :class:`EventsChunk` field ``events`` is now a list of :class:`EmittedEvent` instead of :class:`Event`
14+
415
**********************
516
0.20.0 Migration guide
617
**********************

starknet_py/net/client_models.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,32 @@ class Call:
3333
@dataclass
3434
class Event:
3535
"""
36-
Dataclass representing an event emitted by transaction.
36+
Dataclass representing a Starknet event.
3737
"""
3838

3939
from_address: int
4040
keys: List[int]
4141
data: List[int]
4242

4343

44+
@dataclass
45+
class EmittedEvent(Event):
46+
"""
47+
Dataclass representing an event emitted by transaction.
48+
"""
49+
50+
transaction_hash: int
51+
block_hash: Optional[int] = None
52+
block_number: Optional[int] = None
53+
54+
4455
@dataclass
4556
class EventsChunk:
4657
"""
4758
Dataclass representing events returned by FullNodeClient.get_events method.
4859
"""
4960

50-
events: List[Event]
61+
events: List[EmittedEvent]
5162
continuation_token: Optional[str] = None
5263

5364

starknet_py/net/schemas/rpc.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
DeployAccountTransactionV3,
2323
DeployedContract,
2424
DeployTransaction,
25+
EmittedEvent,
2526
EntryPoint,
2627
EntryPointsByType,
2728
EstimatedFee,
@@ -92,9 +93,19 @@ def make_dataclass(self, data, **kwargs) -> Event:
9293
return Event(**data)
9394

9495

96+
class EmittedEventSchema(EventSchema):
97+
transaction_hash = Felt(data_key="transaction_hash", required=True)
98+
block_hash = Felt(data_key="block_hash", load_default=None)
99+
block_number = fields.Integer(data_key="block_number", load_default=None)
100+
101+
@post_load
102+
def make_dataclass(self, data, **kwargs) -> EmittedEvent:
103+
return EmittedEvent(**data)
104+
105+
95106
class EventsChunkSchema(Schema):
96107
events = fields.List(
97-
fields.Nested(EventSchema(unknown=EXCLUDE)),
108+
fields.Nested(EmittedEventSchema()),
98109
data_key="events",
99110
required=True,
100111
)

starknet_py/tests/e2e/tests_on_networks/client_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
DAMode,
1111
DeclareTransactionV3,
1212
DeployAccountTransactionV3,
13+
EmittedEvent,
1314
EstimatedFee,
1415
EventsChunk,
1516
InvokeTransactionV3,
@@ -425,6 +426,12 @@ async def test_get_events_sepolia_testnet(client_sepolia_testnet):
425426
assert isinstance(events_chunk, EventsChunk)
426427
assert len(events_chunk.events) == 10
427428
assert events_chunk.continuation_token is not None
429+
assert isinstance(events_chunk.events[0], EmittedEvent)
430+
assert events_chunk.events[0].block_number == 1000
431+
assert events_chunk.events[0].block_hash is not None
432+
assert events_chunk.events[0].from_address is not None
433+
assert events_chunk.events[0].data is not None
434+
assert events_chunk.events[0].keys is not None
428435

429436

430437
@pytest.mark.asyncio

0 commit comments

Comments
 (0)