Skip to content

Commit 83b2781

Browse files
committed
dev: Cleanup comments
1 parent fbc0608 commit 83b2781

File tree

6 files changed

+29
-40
lines changed

6 files changed

+29
-40
lines changed

starknet_py/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
EC_ORDER = 0x800000000000010FFFFFFFFFFFFFFFFB781126DCAE7B2321E66A241ADC64D2F
3636

3737
# From cairo-lang
38-
# int_from_bytes(b"STARKNET_CONTRACT_ADDRESS")
3938
CONTRACT_ADDRESS_PREFIX = 523065374597054866729014270389667305596563390979550329787219
4039
L2_ADDRESS_UPPER_BOUND = 2**251 - 256
4140

starknet_py/hash/address.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
from starknet_py.constants import CONTRACT_ADDRESS_PREFIX, L2_ADDRESS_UPPER_BOUND
44
from starknet_py.hash.utils import (
5-
# HEX_PREFIX,
65
_starknet_keccak,
76
compute_hash_on_elements,
87
encode_uint,
98
get_bytes_length,
109
)
1110

11+
HEX_PREFIX = "0x"
12+
1213

1314
def compute_address(
1415
*,
@@ -51,7 +52,7 @@ def get_checksum_address(address: str) -> str:
5152
:param address: Address to encode
5253
:return: Checksum address
5354
"""
54-
if not address.lower().startswith("0x"):
55+
if not address.lower().startswith(HEX_PREFIX):
5556
raise ValueError(f"{address} is not a valid hexadecimal address.")
5657

5758
int_address = int(address, 16)
@@ -69,7 +70,7 @@ def get_checksum_address(address: str) -> str:
6970
for i, char in enumerate(string_address)
7071
)
7172

72-
return f"0x{result}"
73+
return f"{HEX_PREFIX}{result}"
7374

7475

7576
def is_checksum_address(address: str) -> bool:

starknet_py/hash/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
cpp_verify,
1111
)
1212

13-
# from starknet_py.common import int_from_bytes
1413
from starknet_py.constants import EC_ORDER
1514

1615
MASK_250 = 2**250 - 1
17-
HEX_PREFIX = "0x"
1816

1917

2018
def _starknet_keccak(data: bytes) -> int:

starknet_py/net/models/typed_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
TypedDict structures for TypedData
33
"""
44

5-
from enum import Enum
65
import sys
6+
from enum import Enum
77
from typing import Any, Dict, List, Optional, TypedDict
88

99
# from starknet_py.net.schemas.common import Revision
@@ -24,7 +24,7 @@ class ParameterDict(TypedDict):
2424
contains: NotRequired[str]
2525

2626

27-
class Revisionx(Enum):
27+
class Revision(Enum):
2828
"""
2929
Enum representing the revision of the specification to be used.
3030
"""
@@ -41,7 +41,7 @@ class DomainDict(TypedDict):
4141
name: str
4242
version: str
4343
chainId: str
44-
revision: Optional[Revisionx]
44+
revision: Optional[Revision]
4545

4646

4747
class TypedDataDict(TypedDict):

starknet_py/net/schemas/common.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
import sys
3-
from enum import Enum
3+
44
from typing import Any, Mapping, Optional, Union
55

66
from marshmallow import Schema, ValidationError, fields, post_load
@@ -19,7 +19,7 @@
1919
TransactionStatusWithoutL1,
2020
TransactionType,
2121
)
22-
from starknet_py.net.models.typed_data import Revisionx
22+
from starknet_py.net.models.typed_data import Revision
2323

2424
# pylint: disable=unused-argument
2525

@@ -380,33 +380,24 @@ def make_dataclass(self, data, **kwargs):
380380
return StorageEntry(**data)
381381

382382

383-
class Revision(Enum):
384-
"""
385-
Enum representing the revision of the specification to be used.
386-
"""
387-
388-
V0 = 0
389-
V1 = 1
390-
391-
392383
class RevisionField(fields.Field):
393384
def _serialize(self, value: Any, attr: Optional[str], obj: Any, **kwargs):
394-
if value is None or value == Revisionx.V0:
395-
return str(Revisionx.V0.value)
385+
if value is None or value == Revision.V0:
386+
return str(Revision.V0.value)
396387
return value.value
397388

398-
def _deserialize(self, value, attr, data, **kwargs) -> Revisionx:
389+
def _deserialize(self, value, attr, data, **kwargs) -> Revision:
399390
if isinstance(value, str):
400391
value = int(value)
401392

402-
if isinstance(value, Revisionx):
393+
if isinstance(value, Revision):
403394
value = value.value
404395

405-
revisions = [revision.value for revision in Revisionx]
396+
revisions = [revision.value for revision in Revision]
406397
if value not in revisions:
407398
allowed_revisions_str = "".join(list(map(str, revisions)))
408399
raise ValidationError(
409400
f"Invalid value provided for Revision: {value}. Allowed values are {allowed_revisions_str}."
410401
)
411402

412-
return Revisionx(value)
403+
return Revision(value)

starknet_py/utils/typed_data.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from starknet_py.hash.hash_method import HashMethod
1212
from starknet_py.hash.selector import get_selector_from_name
1313
from starknet_py.net.client_utils import _to_rpc_felt
14-
from starknet_py.net.models.typed_data import DomainDict, Revisionx, TypedDataDict
14+
from starknet_py.net.models.typed_data import DomainDict, Revision, TypedDataDict
1515
from starknet_py.net.schemas.common import RevisionField
1616
from starknet_py.serialization.data_serializers import ByteArraySerializer
1717
from starknet_py.utils.merkle_tree import MerkleTree
@@ -49,16 +49,16 @@ class Domain:
4949
name: str
5050
version: str
5151
chain_id: Union[str, int]
52-
revision: Optional[Revisionx] = None
52+
revision: Optional[Revision] = None
5353

5454
def __post_init__(self):
5555
self.resolved_revision = (
56-
Revisionx(self.revision) if self.revision else Revisionx.V0
56+
Revision(self.revision) if self.revision else Revision.V0
5757
)
5858
self.separator_name = self._resolve_separator_name()
5959

6060
def _resolve_separator_name(self):
61-
if self.resolved_revision == Revisionx.V0:
61+
if self.resolved_revision == Revision.V0:
6262
return "StarkNetDomain"
6363
return "StarknetDomain"
6464

@@ -136,7 +136,7 @@ def _all_types(self):
136136

137137
@property
138138
def _hash_method(self) -> HashMethod:
139-
if self.domain.resolved_revision == Revisionx.V0:
139+
if self.domain.resolved_revision == Revision.V0:
140140
return HashMethod.PEDERSEN
141141
return HashMethod.POSEIDON
142142

@@ -230,11 +230,11 @@ def _encode_value(
230230
basic_type = BasicType(type_name)
231231

232232
encoded_value = None
233-
if self.domain.resolved_revision == Revisionx.V0 and isinstance(
233+
if self.domain.resolved_revision == Revision.V0 and isinstance(
234234
value, (str, int)
235235
):
236236
encoded_value = self._encode_value_v0(basic_type, value)
237-
elif self.domain.resolved_revision == Revisionx.V1 and isinstance(
237+
elif self.domain.resolved_revision == Revision.V1 and isinstance(
238238
value, (str, int, dict)
239239
):
240240
encoded_value = self._encode_value_v1(basic_type, value, type_name, context)
@@ -328,7 +328,7 @@ def _verify_types(self):
328328
self._validate_enum_type()
329329

330330
def _validate_enum_type(self):
331-
if self.domain.resolved_revision != Revisionx.V1:
331+
if self.domain.resolved_revision != Revision.V1:
332332
raise ValueError(
333333
f"'{BasicType.ENUM.name}' basic type is not supported in revision "
334334
f"{self.domain.resolved_revision.value}."
@@ -369,7 +369,7 @@ def _encode_type(self, type_name: str) -> str:
369369

370370
def encode_dependency(dependency: str) -> str:
371371
def escape(s: str) -> str:
372-
if self.domain.resolved_revision == Revisionx.V0:
372+
if self.domain.resolved_revision == Revision.V0:
373373
return s
374374
return f'"{s}"'
375375

@@ -381,7 +381,7 @@ def escape(s: str) -> str:
381381
target_type = (
382382
param.contains
383383
if isinstance(param, EnumParameter)
384-
and self.domain.resolved_revision == Revisionx.V1
384+
and self.domain.resolved_revision == Revision.V1
385385
else param.type
386386
)
387387

@@ -617,7 +617,7 @@ def is_in_range(n: int):
617617
raise ValueError(f"Value [{value}] is out of range for '{BasicType.I128}'.")
618618

619619

620-
def _get_basic_type_names(revision: Revisionx) -> List[str]:
620+
def _get_basic_type_names(revision: Revision) -> List[str]:
621621
basic_types_v0 = [
622622
BasicType.FELT,
623623
BasicType.SELECTOR,
@@ -628,14 +628,14 @@ def _get_basic_type_names(revision: Revisionx) -> List[str]:
628628

629629
basic_types_v1 = list(BasicType)
630630

631-
basic_types = basic_types_v0 if revision == Revisionx.V0 else basic_types_v1
631+
basic_types = basic_types_v0 if revision == Revision.V0 else basic_types_v1
632632
return [basic_type.value for basic_type in basic_types]
633633

634634

635635
def _get_preset_types(
636-
revision: Revisionx,
636+
revision: Revision,
637637
) -> Dict[str, List[StandardParameter]]:
638-
if revision == Revisionx.V0:
638+
if revision == Revision.V0:
639639
return {}
640640

641641
return {

0 commit comments

Comments
 (0)