Skip to content

Commit

Permalink
namespacing starknet_abi pacakge
Browse files Browse the repository at this point in the history
  • Loading branch information
elicbarbieri committed Jun 10, 2024
1 parent 273ff93 commit b6ea31f
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 82 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
repos:
- repo: https://github.com/ambv/black
rev: 23.12.1
rev: 24.4.2
hooks:
- id: black
language_version: python3.12
- repo: local
hooks:
- id: isort
name: isort
entry: poetry run isort starknet_abi/
entry: poetry run isort nethermind/starknet_abi/
language: system
types: [ python ]
require_serial: true
- repo: local
hooks:
- id: pylint
name: pylint
entry: poetry run pylint starknet_abi/
entry: poetry run pylint nethermind/starknet_abi/
args: [
'-rn',
'-sn',
Expand All @@ -27,6 +27,6 @@ repos:
types: [ python ]
require_serial: true
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.10.0
hooks:
- id: 'mypy'
4 changes: 2 additions & 2 deletions benchmarks/starknet_abi_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

from starknet_abi.core import StarknetAbi
from starknet_abi.decode import decode_from_params
from nethermind.starknet_abi.core import StarknetAbi
from nethermind.starknet_abi.decode import decode_from_params

from .abi import STARKNET_ETH_ABI_JSON

Expand Down
2 changes: 1 addition & 1 deletion docs/source/Quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Setup
.. code-block:: python
import json
from starknet_abi import StarknetABI
from nethermind.starknet_abi import StarknetABI
with open('abi.json') as f:
raw_abi = json.load(f)
Expand Down
21 changes: 21 additions & 0 deletions nethermind/starknet_abi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from nethermind.starknet_abi.abi_types import (
StarknetArray,
StarknetCoreType,
StarknetEnum,
StarknetOption,
StarknetStruct,
StarknetTuple,
)
from nethermind.starknet_abi.core import (
AbiEvent,
AbiFunction,
AbiInterface,
AbiParameter,
StarknetAbi,
)
from nethermind.starknet_abi.decode import (
decode_core_type,
decode_from_params,
decode_from_types,
)
from nethermind.starknet_abi.decoding_types import DecodedEvent, DecodedFunction
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def int_from_string(cls, type_str):
parses a core::integer::<type_str> into a Starknet Core type
.. doctest::
>>> from starknet_abi.abi_types import StarknetCoreType
>>> from nethermind.starknet_abi.abi_types import StarknetCoreType
>>> StarknetCoreType.int_from_string('u16')
StarknetCoreType.U16
>>> StarknetCoreType.int_from_string('u256')
Expand Down Expand Up @@ -92,7 +92,7 @@ def id_str(self):
.. doctest::
>>> from starknet_abi.abi_types import StarknetCoreType
>>> from nethermind.starknet_abi.abi_types import StarknetCoreType
>>> StarknetCoreType.U128.id_str()
'U128'
>>> StarknetCoreType.Bool.id_str()
Expand All @@ -114,7 +114,7 @@ def max_value(self):
.. doctest::
>>> from starknet_abi.abi_types import StarknetCoreType
>>> from nethermind.starknet_abi.abi_types import StarknetCoreType
>>> StarknetCoreType.U256.max_value()
115792089237316195423570985008687907853269984665640564039457584007913129639935
Expand Down Expand Up @@ -150,7 +150,7 @@ def id_str(self):
.. doctest::
>>> from starknet_abi.abi_types import StarknetArray, StarknetCoreType
>>> from nethermind.starknet_abi.abi_types import StarknetArray, StarknetCoreType
>>> felt_array = StarknetArray(StarknetCoreType.Felt)
>>> felt_array.id_str()
'[Felt]'
Expand All @@ -174,7 +174,7 @@ def id_str(self):
.. doctest::
>>> from starknet_abi.abi_types import StarknetOption, StarknetCoreType
>>> from nethermind.starknet_abi.abi_types import StarknetOption, StarknetCoreType
>>> uint_option = StarknetOption(StarknetCoreType.U128)
>>> uint_option.id_str()
'Option[U128]'
Expand All @@ -199,7 +199,7 @@ def id_str(self):
.. doctest::
>>> from starknet_abi.abi_types import StarknetEnum, StarknetCoreType
>>> from nethermind.starknet_abi.abi_types import StarknetEnum, StarknetCoreType
>>> status_enum = StarknetEnum(
... name="Status",
... variants=[
Expand Down Expand Up @@ -247,7 +247,7 @@ def id_str(self):
Returns the string representation of a tuple of types
.. doctest::
>>> from starknet_abi.abi_types import StarknetTuple, StarknetCoreType
>>> from nethermind.starknet_abi.abi_types import StarknetTuple, StarknetCoreType
>>> uint_tuple = StarknetTuple([StarknetCoreType.U32, StarknetCoreType.U32])
>>> uint_tuple.id_str()
'(U32,U32)'
Expand Down Expand Up @@ -277,7 +277,7 @@ def id_str(self):
"""
.. doctest::
>>> from starknet_abi.abi_types import StarknetStruct, StarknetCoreType, StarknetArray, AbiParameter
>>> from nethermind.starknet_abi.abi_types import StarknetStruct, StarknetCoreType, StarknetArray, AbiParameter
>>> struct_def = StarknetStruct(
... name="PackageVersion",
... members=[
Expand Down Expand Up @@ -321,7 +321,7 @@ def id_str(self):
.. doctest::
>>> from starknet_abi.abi_types import StarknetCoreType, AbiParameter
>>> from nethermind.starknet_abi.abi_types import StarknetCoreType, AbiParameter
>>> from_param = AbiParameter('from', StarknetCoreType.ContractAddress)
>>> from_param.id_str()
'from:ContractAddress'
Expand Down
8 changes: 4 additions & 4 deletions starknet_abi/core.py → nethermind/starknet_abi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from dataclasses import dataclass
from typing import Any, Sequence

from starknet_abi.abi_types import AbiParameter
from starknet_abi.decoding_types import AbiEvent, AbiFunction, AbiInterface
from starknet_abi.exceptions import InvalidAbiError
from starknet_abi.parse import (
from nethermind.starknet_abi.abi_types import AbiParameter
from nethermind.starknet_abi.decoding_types import AbiEvent, AbiFunction, AbiInterface
from nethermind.starknet_abi.exceptions import InvalidAbiError
from nethermind.starknet_abi.parse import (
_parse_type,
group_abi_by_type,
parse_abi_event,
Expand Down
10 changes: 5 additions & 5 deletions starknet_abi/decode.py → nethermind/starknet_abi/decode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Sequence

from starknet_abi.abi_types import (
from nethermind.starknet_abi.abi_types import (
AbiParameter,
StarknetArray,
StarknetCoreType,
Expand All @@ -10,7 +10,7 @@
StarknetTuple,
StarknetType,
)
from starknet_abi.exceptions import InvalidCalldataError, TypeDecodeError
from nethermind.starknet_abi.exceptions import InvalidCalldataError, TypeDecodeError

# Disable linter line breaks to make assert statements more readable
# fmt: off
Expand All @@ -25,7 +25,7 @@ def decode_core_type( # pylint: disable=too-many-return-statements
calldata array is recursively passed between type decoders, so this array is modified during decoding
.. doctest::
>>> from starknet_abi.decode import decode_core_type, StarknetCoreType
>>> from nethermind.starknet_abi.decode import decode_core_type, StarknetCoreType
>>> decode_core_type(StarknetCoreType.Bool, [0])
False
>>> decode_core_type(StarknetCoreType.U256, [12345, 0])
Expand Down Expand Up @@ -120,7 +120,7 @@ def decode_from_types(
popped off the stack as decoding occurs
.. doctest::
>>> from starknet_abi.decode import decode_from_types, StarknetCoreType, StarknetArray
>>> from nethermind.starknet_abi.decode import decode_from_types, StarknetCoreType, StarknetArray
>>> decode_from_types([StarknetArray(StarknetCoreType.U8), StarknetCoreType.Bool], [3, 123, 244, 210, 0])
[[123, 244, 210], False]
>>> decode_from_types(
Expand Down Expand Up @@ -219,7 +219,7 @@ def decode_from_params(
.. doctest::
>>> from starknet_abi.decode import AbiParameter, decode_from_params, StarknetCoreType
>>> from nethermind.starknet_abi.decode import AbiParameter, decode_from_params, StarknetCoreType
>>> decode_from_params(
... [AbiParameter("a", StarknetCoreType.U32), AbiParameter("b", StarknetCoreType.U32)],
... [123456, 654321]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from dataclasses import dataclass
from typing import Any, Sequence

from starknet_abi.abi_types import AbiParameter, StarknetType
from starknet_abi.decode import decode_from_params, decode_from_types
from starknet_abi.encode import encode_from_params
from starknet_abi.exceptions import InvalidCalldataError
from starknet_abi.utils import starknet_keccak
from nethermind.starknet_abi.abi_types import AbiParameter, StarknetType
from nethermind.starknet_abi.decode import decode_from_params, decode_from_types
from nethermind.starknet_abi.encode import encode_from_params
from nethermind.starknet_abi.exceptions import InvalidCalldataError
from nethermind.starknet_abi.utils import starknet_keccak


@dataclass(slots=True)
Expand Down Expand Up @@ -61,8 +61,8 @@ def id_str(self):
.. doctest::
>>> from starknet_abi.decoding_types import AbiFunction
>>> from starknet_abi.abi_types import StarknetCoreType
>>> from nethermind.starknet_abi.decoding_types import AbiFunction
>>> from nethermind.starknet_abi.abi_types import StarknetCoreType
>>> add_function = AbiFunction(
... name="add",
... inputs=[AbiParameter("a", StarknetCoreType.U32), AbiParameter("b", StarknetCoreType.U32)],
Expand All @@ -87,8 +87,8 @@ def decode( # pylint: disable=line-too-long
.. doctest::
>>> from starknet_abi.decoding_types import AbiFunction
>>> from starknet_abi.abi_types import StarknetCoreType
>>> from nethermind.starknet_abi.decoding_types import AbiFunction
>>> from nethermind.starknet_abi.abi_types import StarknetCoreType
>>> add_function = AbiFunction(
... name="add",
... inputs=[AbiParameter("a", StarknetCoreType.U32), AbiParameter("b", StarknetCoreType.U32)],
Expand Down Expand Up @@ -126,8 +126,8 @@ def encode(
.. doctest::
>>> from starknet_abi.decoding_types import AbiFunction
>>> from starknet_abi.abi_types import StarknetCoreType, StarknetArray
>>> from nethermind.starknet_abi.decoding_types import AbiFunction
>>> from nethermind.starknet_abi.abi_types import StarknetCoreType, StarknetArray
>>> add_function = AbiFunction(
... name="add",
... inputs=[AbiParameter("add_vals", StarknetArray(StarknetCoreType.U8))],
Expand Down Expand Up @@ -173,8 +173,8 @@ def id_str(self):
.. doctest::
>>> from starknet_abi.decoding_types import AbiEvent
>>> from starknet_abi.abi_types import StarknetCoreType
>>> from nethermind.starknet_abi.decoding_types import AbiEvent
>>> from nethermind.starknet_abi.abi_types import StarknetCoreType
>>> add_event = AbiEvent(
... name="Create",
... data=[AbiParameter("address", StarknetCoreType.ContractAddress)],
Expand Down
10 changes: 5 additions & 5 deletions starknet_abi/dispatch.py → nethermind/starknet_abi/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from dataclasses import dataclass
from typing import Sequence

from starknet_abi.abi_types import AbiParameter, StarknetType
from starknet_abi.core import StarknetAbi
from starknet_abi.decode import decode_from_params, decode_from_types
from starknet_abi.decoding_types import DecodedEvent, DecodedFunction
from starknet_abi.exceptions import InvalidCalldataError
from nethermind.starknet_abi.abi_types import AbiParameter, StarknetType
from nethermind.starknet_abi.core import StarknetAbi
from nethermind.starknet_abi.decode import decode_from_params, decode_from_types
from nethermind.starknet_abi.decoding_types import DecodedEvent, DecodedFunction
from nethermind.starknet_abi.exceptions import InvalidCalldataError


def _id_hash(id_str: str) -> bytes:
Expand Down
4 changes: 2 additions & 2 deletions starknet_abi/encode.py → nethermind/starknet_abi/encode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Sequence

from starknet_abi.abi_types import (
from nethermind.starknet_abi.abi_types import (
AbiParameter,
StarknetArray,
StarknetCoreType,
Expand All @@ -10,7 +10,7 @@
StarknetTuple,
StarknetType,
)
from starknet_abi.exceptions import TypeEncodeError
from nethermind.starknet_abi.exceptions import TypeEncodeError

# Disables Assert statements from being formatted into multi-line messes
# fmt: off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class InvalidCalldataError(Exception):
.. doctest::
>>> from starknet_abi.decode import decode_from_types, StarknetCoreType
>>> from nethermind.starknet_abi.decode import decode_from_types, StarknetCoreType
>>> decode_from_types([StarknetCoreType.U256], [12345])
Traceback (most recent call last):
...
starknet_abi.exceptions.InvalidCalldataError: Not Enough Calldata to decode StarknetCoreType.U256
nethermind.starknet_abi.exceptions.InvalidCalldataError: Not Enough Calldata to decode StarknetCoreType.U256
"""

Expand All @@ -28,12 +28,12 @@ class TypeDecodeError(Exception):
.. doctest::
>>> from starknet_abi.decode import decode_from_types, StarknetCoreType
>>> from nethermind.starknet_abi.decode import decode_from_types, StarknetCoreType
>>> decode_from_types([StarknetCoreType.Bool], [3])
Traceback (most recent call last):
...
starknet_abi.exceptions.TypeDecodeError: Could not decode StarknetCoreType.Bool: Bool Value must be 0 or 1
nethermind.starknet_abi.exceptions.TypeDecodeError: Could not decode StarknetCoreType.Bool: Bool Value must be 0 or 1
"""

Expand All @@ -44,17 +44,17 @@ class TypeEncodeError(Exception):
.. doctest::
>>> from starknet_abi.encode import encode_from_types, StarknetCoreType
>>> from nethermind.starknet_abi.encode import encode_from_types, StarknetCoreType
>>> encode_from_types([StarknetCoreType.Bool], [{'a': 123}])
Traceback (most recent call last):
...
starknet_abi.exceptions.TypeEncodeError: Cannot Encode Non-Boolean Value '{'a': 123}' to StarknetCoreType.Bool
nethermind.starknet_abi.exceptions.TypeEncodeError: Cannot Encode Non-Boolean Value '{'a': 123}' to StarknetCoreType.Bool
>>> encode_from_types([StarknetCoreType.U16], [2**17])
Traceback (most recent call last):
...
starknet_abi.exceptions.TypeEncodeError: Integer 131072 is out of range for StarknetCoreType.U16
nethermind.starknet_abi.exceptions.TypeEncodeError: Integer 131072 is out of range for StarknetCoreType.U16
"""

Expand Down
8 changes: 4 additions & 4 deletions starknet_abi/parse.py → nethermind/starknet_abi/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from graphlib import TopologicalSorter
from typing import Any

from starknet_abi.abi_types import (
from nethermind.starknet_abi.abi_types import (
AbiMemberType,
AbiParameter,
StarknetArray,
Expand All @@ -14,8 +14,8 @@
StarknetTuple,
StarknetType,
)
from starknet_abi.decoding_types import AbiEvent, AbiFunction
from starknet_abi.exceptions import InvalidAbiError
from nethermind.starknet_abi.decoding_types import AbiEvent, AbiFunction
from nethermind.starknet_abi.exceptions import InvalidAbiError


def group_abi_by_type(abi_json: list[dict]) -> defaultdict[AbiMemberType, list[dict]]:
Expand Down Expand Up @@ -227,7 +227,7 @@ def extract_inner_type(abi_type: str) -> str:
Extracts the inner type from a type string
.. doctest::
>>> from starknet_abi.parse import extract_inner_type
>>> from nethermind.starknet_abi.parse import extract_inner_type
>>> extract_inner_type("core::array::Array::<core::integer::u256>")
'core::integer::u256'
Expand Down
Loading

0 comments on commit b6ea31f

Please sign in to comment.