Skip to content

Commit 8754ba0

Browse files
authored
Fix parsing ABIs with multiple l1_handler entries (#1302)
* Parse multiple L1 handlers function in Abi parser V2 * Update migration guide * Update docs before release
1 parent 167e873 commit 8754ba0

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

docs/guide/account_and_client.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ For V3 transactions, ``max_amount`` and ``max_price_per_unit`` are scaled by ``1
3636
by changing ``ESTIMATED_FEE_MULTIPLIER`` for V1 and V2 transactions in :class:`~starknet_py.net.account.account.Account`.
3737
The same applies to ``ESTIMATED_AMOUNT_MULTIPLIER`` and ``ESTIMATED_UNIT_PRICE_MULTIPLIER`` for V3 transactions.
3838

39+
The fee for a specific transaction or list of transactions can be also estimated using the :meth:`~starknet_py.net.account.account.Account.estimate_fee` of the :ref:`Account` class.
40+
3941
Creating transactions without executing them
4042
--------------------------------------------
4143

docs/migration_guide.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ Migration guide
55
0.20.0 Migration guide
66
**********************
77

8-
0.20.0 Breaking Changes
8+
Version 0.20.0 of **starknet.py** comes with support for Python 3.12!
9+
10+
0.20.0 Targeted versions
11+
------------------------
12+
13+
- Starknet - `0.13.0 <https://docs.starknet.io/documentation/starknet_versions/version_notes/#version0.13.0>`_
14+
- RPC - `0.6.0 <https://github.com/starkware-libs/starknet-specs/releases/tag/v0.6.0>`_
15+
16+
0.20.0 Breaking changes
917
-----------------------
1018

11-
1. :class:`StarknetEthProxyCheck` has been removed from the Proxy checks
19+
1. Type of ``l1_handler`` in :class:`~starknet_py.abi.v2.model.Abi` model class for Cairo 2 has been changed from ``Function`` to ``Dict[str, Function]``
1220
2. In :ref:`Abi` module the code related to Cairo 0 has been moved from ``starknet_py.abi`` to ``starknet_py.abi.v0``
21+
3. :class:`StarknetEthProxyCheck` has been removed from the Proxy checks
1322

1423
**********************
1524
0.19.0 Migration guide

starknet_py/abi/v2/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Impl:
8383
Constructor
8484
] #: Contract's constructor. It is None if class doesn't define one.
8585
l1_handler: Optional[
86-
Function
87-
] #: Handler of L1 messages. It is None if class doesn't define one.
86+
Dict[str, Function]
87+
] #: Handlers of L1 messages. It is None if class doesn't define one.
8888
interfaces: Dict[str, Interface]
8989
implementations: Dict[str, Impl]

starknet_py/abi/v2/parser.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,17 @@ def parse(self) -> Abi:
100100
Dict[str, ImplDict],
101101
AbiParser._group_by_entry_name(self._grouped[IMPL_ENTRY], "defined impls"),
102102
)
103+
l1_handlers_dict = cast(
104+
Dict[str, FunctionDict],
105+
AbiParser._group_by_entry_name(
106+
self._grouped[L1_HANDLER_ENTRY], "defined L1 handlers"
107+
),
108+
)
103109
constructors = self._grouped[CONSTRUCTOR_ENTRY]
104-
l1_handlers = self._grouped[L1_HANDLER_ENTRY]
105110

106111
if len(constructors) > 1:
107112
raise AbiParsingError("Constructor in ABI must be defined at most once.")
108113

109-
if len(l1_handlers) > 1:
110-
raise AbiParsingError("L1 handler in ABI must be defined at most once.")
111-
112114
return Abi(
113115
defined_structures=structures,
114116
defined_enums=enums,
@@ -117,11 +119,10 @@ def parse(self) -> Abi:
117119
if constructors
118120
else None
119121
),
120-
l1_handler=(
121-
self._parse_function(cast(FunctionDict, l1_handlers[0]))
122-
if l1_handlers
123-
else None
124-
),
122+
l1_handler={
123+
name: self._parse_function(entry)
124+
for name, entry in l1_handlers_dict.items()
125+
},
125126
functions={
126127
name: self._parse_function(entry)
127128
for name, entry in functions_dict.items()

starknet_py/contract.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,12 @@ def __init__(
538538

539539
if abi["type"] == L1_HANDLER_ENTRY:
540540
assert not isinstance(contract_data.parsed_abi, AbiV1)
541-
function = contract_data.parsed_abi.l1_handler
541+
function = (
542+
contract_data.parsed_abi.l1_handler
543+
if contract_data.parsed_abi.l1_handler is None
544+
or isinstance(contract_data.parsed_abi.l1_handler, AbiV0.Function)
545+
else contract_data.parsed_abi.l1_handler.get(name)
546+
)
542547
elif interface_name is None:
543548
function = contract_data.parsed_abi.functions.get(name)
544549
else:

0 commit comments

Comments
 (0)