Skip to content

Commit 9137b40

Browse files
committed
* lint
* test fixes
1 parent 40b01ed commit 9137b40

File tree

17 files changed

+354
-278
lines changed

17 files changed

+354
-278
lines changed

.github/workflows/checks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ jobs:
200200
cd /apps/app-starknet
201201
git checkout ${{ env.LEDGER_APP_SHA }}
202202
cargo clean
203-
cargo ledger build nanox
203+
cargo ledger build nanos
204204
205205
- name: Start Speculos emulator container
206206
uses: addnab/docker-run-action@v3
@@ -213,7 +213,7 @@ jobs:
213213
--apdu-port 9999 \
214214
--api-port 5000 \
215215
--display headless \
216-
/apps/app-starknet/target/nanox/release/starknet
216+
/apps/app-starknet/target/nanos/release/starknet
217217
218218
- name: Wait for Speculos to start
219219
run: sleep 5

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ max-locals=15
561561
max-parents=7
562562

563563
# Maximum number of public methods for a class (see R0904).
564-
max-public-methods=23
564+
max-public-methods=20
565565

566566
# Maximum number of return / yield for function / method body.
567567
max-returns=6

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,4 @@ Contract automatically serializes values to Cairo calldata. This includes adding
212212
See more info in [Serialization](https://starknetpy.readthedocs.io/en/latest/guide/serialization.html#serialization).
213213

214214
Quickstart in docs - click [here](https://starknetpy.rtfd.io/en/latest/quickstart.html).
215+

docs/guide/account_and_client.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Account also provides a way of creating signed transaction without sending them.
4747
:dedent: 4
4848

4949
Creating "Outside transaction" and executing it. `SNIP-9 <https://github.com/starknet-io/SNIPs/blob/main/SNIPS/snip-9.md>`_
50-
--------------------------------------------
50+
---------------------------------------------------------------------------------------------------------------------------
5151

5252
Account also provides a way of creating a call and signing to allow for another account (caller) to execute it later on original account behalf. This will also allow caller to execute calls encoded in that transaction for free (signer will pay the fee).
5353

starknet_py/constants.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@
4848
VERSION_RESPONSE_LENGTH = 3
4949

5050
# SNIP-9 ANY_CALLER
51-
ANY_CALLER = 0x414e595f43414c4c4552
51+
ANY_CALLER = 0x414E595F43414C4C4552
52+
5253

5354
# SNIP-9 INTERFACE_VERSION with ID
5455
class SNIP9InterfaceVersion(IntEnum):
55-
V1 = 0x68cfd18b92d1907b8ba3cc324900277f5a3622099431ea85dd8089255e4181
56-
V2 = 0x1d1144bb2138366ff28d8e9ab57456b1d332ac42196230c3a602003c89872
56+
V1 = 0x68CFD18B92D1907B8BA3CC324900277F5A3622099431EA85DD8089255E4181
57+
V2 = 0x1D1144BB2138366FF28D8E9AB57456B1D332AC42196230C3A602003C89872
Lines changed: 90 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from starknet_py.net.client_models import OutsideExecution
2-
31
from starknet_py.constants import SNIP9InterfaceVersion
4-
2+
from starknet_py.net.client_models import OutsideExecution
53
from starknet_py.net.schemas.common import Revision
64
from starknet_py.utils import typed_data as td
75

@@ -10,10 +8,11 @@
108
SNIP9InterfaceVersion.V2: Revision.V1,
119
}
1210

11+
1312
def outside_execution_to_typed_data(
1413
outside_execution: OutsideExecution,
1514
snip9_version: SNIP9InterfaceVersion,
16-
chain_id: int
15+
chain_id: int,
1716
) -> td.TypedData:
1817
"""
1918
SNIP-12 Typed Data for OutsideExecution implementation. For revision V0 and V1.
@@ -22,92 +21,98 @@ def outside_execution_to_typed_data(
2221
revision = SNIP9_INTERFACE_ID_TO_SNIP12_REVISION[snip9_version]
2322

2423
if revision == Revision.V0:
25-
return td.TypedData.from_dict({
26-
'types': {
27-
'StarkNetDomain': [
28-
{'name': 'name', 'type': 'felt'},
29-
{'name': 'version', 'type': 'felt'},
30-
{'name': 'chainId', 'type': 'felt'},
24+
return td.TypedData.from_dict(
25+
{
26+
"types": {
27+
"StarkNetDomain": [
28+
{"name": "name", "type": "felt"},
29+
{"name": "version", "type": "felt"},
30+
{"name": "chainId", "type": "felt"},
31+
],
32+
"OutsideExecution": [
33+
{"name": "caller", "type": "felt"},
34+
{"name": "nonce", "type": "felt"},
35+
{"name": "execute_after", "type": "felt"},
36+
{"name": "execute_before", "type": "felt"},
37+
{"name": "calls_len", "type": "felt"},
38+
{"name": "calls", "type": "OutsideCall*"},
39+
],
40+
"OutsideCall": [
41+
{"name": "to", "type": "felt"},
42+
{"name": "selector", "type": "felt"},
43+
{"name": "calldata_len", "type": "felt"},
44+
{"name": "calldata", "type": "felt*"},
45+
],
46+
},
47+
"primaryType": "OutsideExecution",
48+
"domain": {
49+
"name": "Account.execute_from_outside",
50+
"version": "1",
51+
"chainId": str(chain_id),
52+
"revision": Revision.V0,
53+
},
54+
"message": {
55+
"caller": outside_execution.caller,
56+
"nonce": outside_execution.nonce,
57+
"execute_after": outside_execution.execute_after,
58+
"execute_before": outside_execution.execute_before,
59+
"calls_len": len(outside_execution.calls),
60+
"calls": [
61+
{
62+
"to": call.to_addr,
63+
"selector": call.selector,
64+
"calldata_len": len(call.calldata),
65+
"calldata": call.calldata,
66+
}
67+
for call in outside_execution.calls
68+
],
69+
},
70+
}
71+
)
72+
73+
# revision == Revision.V1
74+
return td.TypedData.from_dict(
75+
{
76+
"types": {
77+
"StarknetDomain": [
78+
{"name": "name", "type": "shortstring"},
79+
{"name": "version", "type": "shortstring"},
80+
{"name": "chainId", "type": "shortstring"},
81+
{"name": "revision", "type": "shortstring"},
3182
],
32-
'OutsideExecution': [
33-
{'name': 'caller', 'type': 'felt' },
34-
{'name': 'nonce', 'type': 'felt' },
35-
{'name': 'execute_after', 'type': 'felt' },
36-
{'name': 'execute_before', 'type': 'felt' },
37-
{'name': 'calls_len', 'type': 'felt' },
38-
{'name': 'calls', 'type': 'OutsideCall*' },
83+
"OutsideExecution": [
84+
{"name": "Caller", "type": "ContractAddress"},
85+
{"name": "Nonce", "type": "felt"},
86+
{"name": "Execute After", "type": "u128"},
87+
{"name": "Execute Before", "type": "u128"},
88+
{"name": "Calls", "type": "Call*"},
3989
],
40-
'OutsideCall': [
41-
{ 'name': 'to', 'type': 'felt' },
42-
{ 'name': 'selector', 'type': 'felt' },
43-
{ 'name': 'calldata_len', 'type': 'felt' },
44-
{ 'name': 'calldata', 'type': 'felt*' },
90+
"Call": [
91+
{"name": "To", "type": "ContractAddress"},
92+
{"name": "Selector", "type": "selector"},
93+
{"name": "Calldata", "type": "felt*"},
4594
],
4695
},
47-
'primaryType': 'OutsideExecution',
48-
'domain': {
49-
'name': 'Account.execute_from_outside',
50-
'version': '1',
51-
'chainId': str(chain_id),
52-
'revision': Revision.V0,
96+
"primaryType": "OutsideExecution",
97+
"domain": {
98+
"name": "Account.execute_from_outside",
99+
"version": "2",
100+
"chainId": str(chain_id),
101+
"revision": Revision.V1,
53102
},
54-
'message': {
55-
'caller': outside_execution.caller,
56-
'nonce': outside_execution.nonce,
57-
'execute_after': outside_execution.execute_after,
58-
'execute_before': outside_execution.execute_before,
59-
'calls_len': len(outside_execution.calls),
60-
'calls': [
103+
"message": {
104+
"Caller": outside_execution.caller,
105+
"Nonce": outside_execution.nonce,
106+
"Execute After": outside_execution.execute_after,
107+
"Execute Before": outside_execution.execute_before,
108+
"Calls": [
61109
{
62-
'to': call.to_addr,
63-
'selector': call.selector,
64-
'calldata_len': len(call.calldata),
65-
'calldata': call.calldata,
66-
} for call in outside_execution.calls
110+
"To": call.to_addr,
111+
"Selector": call.selector,
112+
"Calldata": call.calldata,
113+
}
114+
for call in outside_execution.calls
67115
],
68116
},
69-
})
70-
71-
# revision == Revision.V1
72-
return td.TypedData.from_dict({
73-
'types': {
74-
'StarknetDomain': [
75-
{'name': 'name', 'type': 'shortstring'},
76-
{'name': 'version', 'type': 'shortstring'},
77-
{'name': 'chainId', 'type': 'shortstring'},
78-
{'name': 'revision', 'type': 'shortstring'},
79-
],
80-
'OutsideExecution': [
81-
{'name': 'Caller', 'type': 'ContractAddress' },
82-
{'name': 'Nonce', 'type': 'felt' },
83-
{'name': 'Execute After', 'type': 'u128' },
84-
{'name': 'Execute Before', 'type': 'u128' },
85-
{'name': 'Calls', 'type': 'Call*' },
86-
],
87-
'Call': [
88-
{ 'name': 'To', 'type': 'ContractAddress' },
89-
{ 'name': 'Selector', 'type': 'selector' },
90-
{ 'name': 'Calldata', 'type': 'felt*' },
91-
],
92-
},
93-
'primaryType': 'OutsideExecution',
94-
'domain': {
95-
'name': 'Account.execute_from_outside',
96-
'version': '2',
97-
'chainId': str(chain_id),
98-
'revision': Revision.V1,
99-
},
100-
'message': {
101-
'Caller': outside_execution.caller,
102-
'Nonce': outside_execution.nonce,
103-
'Execute After': outside_execution.execute_after,
104-
'Execute Before': outside_execution.execute_before,
105-
'Calls': [
106-
{
107-
'To': call.to_addr,
108-
'Selector': call.selector,
109-
'Calldata': call.calldata,
110-
} for call in outside_execution.calls
111-
],
112-
},
113-
})
117+
}
118+
)

starknet_py/net/account/account.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,30 @@
44
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
55

66
from starknet_py.common import create_compiled_contract, create_sierra_compiled_contract
7-
from starknet_py.constants import FEE_CONTRACT_ADDRESS, QUERY_VERSION_BASE, ANY_CALLER
7+
from starknet_py.constants import (
8+
ANY_CALLER,
9+
FEE_CONTRACT_ADDRESS,
10+
QUERY_VERSION_BASE,
11+
SNIP9InterfaceVersion,
12+
)
813
from starknet_py.hash.address import compute_address
14+
from starknet_py.hash.outside_execution import outside_execution_to_typed_data
915
from starknet_py.hash.selector import get_selector_from_name
1016
from starknet_py.hash.utils import verify_message_signature
11-
from starknet_py.hash.outside_execution import outside_execution_to_typed_data
1217
from starknet_py.net.account.account_deployment_result import AccountDeploymentResult
13-
from starknet_py.net.account.base_account import BaseAccount, SNIP9SupportMixin
18+
from starknet_py.net.account.base_account import BaseAccount, SNIP9SupportBaseMixin
1419
from starknet_py.net.client import Client
15-
from starknet_py.constants import SNIP9InterfaceVersion
1620
from starknet_py.net.client_models import (
1721
Call,
1822
Calls,
1923
EstimatedFee,
24+
ExecutionTimeBounds,
2025
Hash,
26+
OutsideExecution,
2127
ResourceBounds,
22-
ExecutionTimeBounds,
2328
ResourceBoundsMapping,
2429
SentTransactionResponse,
2530
SierraContractClass,
26-
OutsideExecution,
2731
Tag,
2832
)
2933
from starknet_py.net.full_node_client import FullNodeClient
@@ -55,8 +59,9 @@
5559
from starknet_py.utils.typed_data import TypedData
5660

5761

62+
# pylint: disable=too-many-public-methods
5863
@add_sync_methods
59-
class Account(BaseAccount, SNIP9SupportMixin):
64+
class Account(BaseAccount, SNIP9SupportBaseMixin):
6065
"""
6166
Default Account implementation.
6267
"""
@@ -216,12 +221,9 @@ async def _prepare_invoke(
216221
nonce=nonce,
217222
sender_address=self.address,
218223
)
219-
220224
max_fee = await self._get_max_fee(transaction, max_fee, auto_estimate)
221-
222225
return _add_max_fee_to_transaction(transaction, max_fee)
223226

224-
225227
async def _prepare_invoke_v3(
226228
self,
227229
calls: Calls,
@@ -301,13 +303,14 @@ async def _check_snip9_nonce(
301303
block_hash: Optional[Union[Hash, Tag]] = None,
302304
block_number: Optional[Union[int, Tag]] = None,
303305
) -> bool:
304-
(is_valid, ) = await self._client.call_contract(
306+
(is_valid,) = await self._client.call_contract(
305307
call=Call(
306308
to_addr=self.address,
307309
selector=get_selector_from_name("is_valid_outside_execution_nonce"),
308310
calldata=[nonce],
309311
),
310-
block_hash=block_hash, block_number=block_number
312+
block_hash=block_hash,
313+
block_number=block_number,
311314
)
312315
return bool(is_valid)
313316

@@ -402,7 +405,9 @@ async def sign_outside_execution_call(
402405
version = await self._get_snip9_version()
403406

404407
if version is None:
405-
raise RuntimeError("Can't initiate outside execution SNIP-9 is unsupported.")
408+
raise RuntimeError(
409+
"Can't initiate outside execution SNIP-9 is unsupported."
410+
)
406411

407412
if nonce is None:
408413
nonce = await self.get_snip9_nonce()
@@ -416,23 +421,23 @@ async def sign_outside_execution_call(
416421
)
417422
chain_id = await self._get_chain_id()
418423
signature = self.signer.sign_message(
419-
outside_execution_to_typed_data(
420-
outside_execution, version, chain_id
421-
),
422-
self.address
424+
outside_execution_to_typed_data(outside_execution, version, chain_id),
425+
self.address,
423426
)
424427
selector_for_version = {
425428
SNIP9InterfaceVersion.V1: "execute_from_outside",
426-
SNIP9InterfaceVersion.V2: "execute_from_outside_v2"
429+
SNIP9InterfaceVersion.V2: "execute_from_outside_v2",
427430
}
428431

429432
return Call(
430433
to_addr=self.address,
431434
selector=get_selector_from_name(selector_for_version[version]),
432-
calldata=_transaction_serialiser.serialize({
433-
"external_execution": outside_execution.to_abi_dict(),
434-
"signature": signature
435-
})
435+
calldata=_transaction_serialiser.serialize(
436+
{
437+
"external_execution": outside_execution.to_abi_dict(),
438+
"signature": signature,
439+
}
440+
),
436441
)
437442

438443
async def sign_invoke_v3(
@@ -968,7 +973,6 @@ def _parse_calls_cairo_v1(calls: Iterable[Call]) -> List[Dict]:
968973
calldata=ArraySerializer(_felt_serializer),
969974
)
970975
)
971-
972976
_execute_payload_serializer_v0 = PayloadSerializer(
973977
OrderedDict(
974978
call_array=ArraySerializer(_call_description_cairo_v0),
@@ -980,7 +984,6 @@ def _parse_calls_cairo_v1(calls: Iterable[Call]) -> List[Dict]:
980984
calls=ArraySerializer(_call_description_cairo_v1),
981985
)
982986
)
983-
984987
_transaction_serialiser = StructSerializer(
985988
OrderedDict(
986989
external_execution=StructSerializer(

0 commit comments

Comments
 (0)