[BUG] The CairoSerializer cannot handle names starting with a underscore
See original GitHub issueI’ve a Cairo contract using names starting with a underscore. And using the FunctionCallSerializer
for get back data from Cairo to Python (to decode transactions return data) will raise:
ValueError: Field names cannot start with an underscore: '_name`
It’s a namedtuple limitation, from here: https://github.com/software-mansion/starknet.py/blob/36acd9f75e189b94a75ac413f99e72984d1e3121/starknet_py/utils/data_transformer/data_transformer.py#L207-L209
Python version
All.
Expected Behavior
Names starting with a underscore should not be a problem.
Current Behavior
ValueError: Field names cannot start with an underscore: '_name`
Possible Solution
- We could use the
rename
kwargs from the namedtuple, but will would loose the real name then. - An idea using dataclasses, but we would then loose the tuple comparison (which is mandatory to keep):
from dataclasses import make_dataclass
# instead of the namedtuple:
result = make_dataclass("Result", [(k, v) for k, v in ...], order=True, frozen=True, slots=True)
Steps to Reproduce
- Use a name starting with a underscore, in any Cairo method.
- Use
FunctionCallSerializer.to_python()
. - See the exception.
Context (Environment)
The issue is quite big, because we’re using the FunctionCallSerializer
in the Ape StarkNet plugin to decode transactions return data. The goal is to leverage all the fantastic work you’ve already done to decode all kind of data types (like arrays, and custom complex structs).
Detailed Description
Possible Implementation
I like the 3rd idea. If you think it’s something you would like to implement, I could give a try.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
Oh OK 😃 I know that
FunctionCallSerializer
callsCairoSerializer
under the wood, and asFunctionCallSerializer
is the newDataTransformer
name, I used it. But yes, both have the same issue at the end.Or me if he’s too busy 😉