Skip to content

Commit 25bcbcb

Browse files
Merge branch 'development'
2 parents 2b9bc95 + bbfc49d commit 25bcbcb

File tree

7 files changed

+199
-111
lines changed

7 files changed

+199
-111
lines changed

.github/dependabot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ updates:
1010
schedule:
1111
interval: "monthly"
1212
versioning-strategy: increase-if-necessary
13+
groups:
14+
production-dependencies:
15+
dependency-type: "production"
16+
dev-dependencies:
17+
dependency-type: "development"

poetry.lock

Lines changed: 100 additions & 99 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "starknet-py"
3-
version = "0.18.0"
3+
version = "0.18.1"
44
description = "A python SDK for Starknet"
55
authors = ["Tomasz Rejowski <tomasz.rejowski@swmansion.com>", "Jakub Ptak <jakub.ptak@swmansion.com>"]
66
include = ["starknet_py", "starknet_py/utils/crypto/libcrypto_c_exports.*"]

starknet_py/net/account/account.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ async def _prepare_invoke(
137137
nonce: Optional[int] = None,
138138
max_fee: Optional[int] = None,
139139
auto_estimate: bool = False,
140+
cairo_version: int = 0,
140141
) -> Invoke:
141142
"""
142143
Takes calls and creates Invoke from them.
@@ -149,10 +150,16 @@ async def _prepare_invoke(
149150
if nonce is None:
150151
nonce = await self.get_nonce()
151152

152-
call_descriptions, calldata = _merge_calls(ensure_iterable(calls))
153-
wrapped_calldata = _execute_payload_serializer.serialize(
154-
{"call_array": call_descriptions, "calldata": calldata}
155-
)
153+
if cairo_version == 1:
154+
parsed_calls = _parse_calls_v2(ensure_iterable(calls))
155+
wrapped_calldata = _execute_payload_serializer_v2.serialize(
156+
{"calls": parsed_calls}
157+
)
158+
else:
159+
call_descriptions, calldata = _merge_calls(ensure_iterable(calls))
160+
wrapped_calldata = _execute_payload_serializer.serialize(
161+
{"call_array": call_descriptions, "calldata": calldata}
162+
)
156163

157164
transaction = Invoke(
158165
calldata=wrapped_calldata,
@@ -246,9 +253,14 @@ async def sign_invoke_transaction(
246253
nonce: Optional[int] = None,
247254
max_fee: Optional[int] = None,
248255
auto_estimate: bool = False,
256+
cairo_version: int = 0,
249257
) -> Invoke:
250258
execute_tx = await self._prepare_invoke(
251-
calls, nonce=nonce, max_fee=max_fee, auto_estimate=auto_estimate
259+
calls,
260+
nonce=nonce,
261+
max_fee=max_fee,
262+
auto_estimate=auto_estimate,
263+
cairo_version=cairo_version,
252264
)
253265
signature = self.signer.sign_transaction(execute_tx)
254266
return _add_signature_to_transaction(execute_tx, signature)
@@ -375,9 +387,14 @@ async def execute(
375387
nonce: Optional[int] = None,
376388
max_fee: Optional[int] = None,
377389
auto_estimate: bool = False,
390+
cairo_version: int = 0,
378391
) -> SentTransactionResponse:
379392
execute_transaction = await self.sign_invoke_transaction(
380-
calls, nonce=nonce, max_fee=max_fee, auto_estimate=auto_estimate
393+
calls,
394+
nonce=nonce,
395+
max_fee=max_fee,
396+
auto_estimate=auto_estimate,
397+
cairo_version=cairo_version,
381398
)
382399
return await self._client.send_transaction(execute_transaction)
383400

@@ -529,6 +546,19 @@ def _merge_calls(calls: Iterable[Call]) -> Tuple[List[Dict], List[int]]:
529546
return call_descriptions, entire_calldata
530547

531548

549+
def _parse_calls_v2(calls: Iterable[Call]) -> List[Dict]:
550+
calls_parsed = []
551+
for call in calls:
552+
_data = {
553+
"to": call.to_addr,
554+
"selector": call.selector,
555+
"calldata": call.calldata,
556+
}
557+
calls_parsed.append(_data)
558+
559+
return calls_parsed
560+
561+
532562
_felt_serializer = FeltSerializer()
533563
_call_description = StructSerializer(
534564
OrderedDict(
@@ -538,9 +568,22 @@ def _merge_calls(calls: Iterable[Call]) -> Tuple[List[Dict], List[int]]:
538568
data_len=_felt_serializer,
539569
)
540570
)
571+
_call_description_v2 = StructSerializer(
572+
OrderedDict(
573+
to=_felt_serializer,
574+
selector=_felt_serializer,
575+
calldata=ArraySerializer(_felt_serializer),
576+
)
577+
)
578+
541579
_execute_payload_serializer = PayloadSerializer(
542580
OrderedDict(
543581
call_array=ArraySerializer(_call_description),
544582
calldata=ArraySerializer(_felt_serializer),
545583
)
546584
)
585+
_execute_payload_serializer_v2 = PayloadSerializer(
586+
OrderedDict(
587+
calls=ArraySerializer(_call_description_v2),
588+
)
589+
)

starknet_py/net/gateway_client.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ async def get_state_update(
147147
self,
148148
block_hash: Optional[Union[Hash, Tag]] = None,
149149
block_number: Optional[Union[int, Tag]] = None,
150-
include_block: bool = False,
150+
# TODO (#1166): revert to `bool = False`
151+
include_block: Optional[bool] = None,
151152
) -> Union[BlockStateUpdate, StateUpdateWithBlock]:
152153
"""
153154
Get the information about the result of executing the requested block.
@@ -157,14 +158,25 @@ async def get_state_update(
157158
:param include_block: Flag deciding whether to include the queried block. Defaults to false.
158159
:return: BlockStateUpdate object representing changes in the requested block.
159160
"""
161+
# TODO (#1166): remove that
162+
if include_block is not None and self._net in [
163+
"https://alpha-mainnet.starknet.io",
164+
"mainnet",
165+
]:
166+
raise ValueError(
167+
"Argument 'include_block' does not work on mainnet yet and will be working after v0.12.2 release."
168+
)
169+
160170
block_identifier = get_block_identifier(
161171
block_hash=block_hash, block_number=block_number
162172
)
163173

164174
params = {
165-
"includeBlock": str(include_block).lower(),
166175
**block_identifier,
167176
}
177+
# TODO (#1166): bring back into params
178+
if include_block is not None:
179+
params["includeBlock"] = str(include_block).lower()
168180

169181
res = await self._feeder_gateway_client.call(
170182
method_name="get_state_update", params=params

starknet_py/net/schemas/gateway.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ class StarknetBlockSchema(Schema):
261261
parent_block_hash = Felt(data_key="parent_block_hash", required=True)
262262
block_number = fields.Integer(data_key="block_number")
263263
status = BlockStatusField(data_key="status", required=True)
264-
root = Felt(data_key="state_root")
264+
# TODO (#1166): change nonprefixedhex to felt in line below
265+
root = NonPrefixedHex(data_key="state_root")
265266
transactions = fields.List(
266267
fields.Nested(TypesOfTransactionsSchema(unknown=EXCLUDE)),
267268
data_key="transactions",
@@ -423,8 +424,10 @@ def make_dataclass(self, data, **kwargs) -> GatewayStateDiff:
423424

424425
class BlockStateUpdateSchema(Schema):
425426
block_hash = Felt(data_key="block_hash", required=True)
426-
new_root = Felt(data_key="new_root", required=True)
427-
old_root = Felt(data_key="old_root", required=True)
427+
# TODO (#1166): change nonprefixedhex to felt in line below
428+
new_root = NonPrefixedHex(data_key="new_root", required=True)
429+
# TODO (#1166): change nonprefixedhex to felt in line below
430+
old_root = NonPrefixedHex(data_key="old_root", required=True)
428431
state_diff = fields.Nested(StateDiffSchema(), data_key="state_diff", required=True)
429432

430433
@post_load

starknet_py/tests/e2e/integration_tests/client_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,27 @@ async def test_get_state_update_with_block(gateway_client_integration):
450450

451451
assert res.block == block
452452
assert res.state_update is not None
453+
454+
455+
# TODO (#1166): remove tests below after mainnet release
456+
@pytest.mark.asyncio
457+
async def test_get_block_different_starknet_versions():
458+
mainnet = GatewayClient(net="mainnet")
459+
testnet = GatewayClient(net="testnet")
460+
461+
_ = await mainnet.get_block(block_number=100000)
462+
_ = await testnet.get_block(block_number=100000)
463+
464+
465+
@pytest.mark.asyncio
466+
async def test_get_state_update_different_starknet_versions():
467+
mainnet = GatewayClient(net="mainnet")
468+
testnet = GatewayClient(net="testnet")
469+
470+
_ = await mainnet.get_state_update(block_number=100000)
471+
472+
with pytest.raises(ValueError):
473+
_ = await mainnet.get_state_update(block_number=100000, include_block=False)
474+
_ = await mainnet.get_state_update(block_number=100000, include_block=True)
475+
476+
_ = await testnet.get_state_update(block_number=100000, include_block=True)

0 commit comments

Comments
 (0)