Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document missing API (hash and client_models) #914

Merged
merged 3 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ API
api/gateway_client
api/full_node_client
api/account
api/client_models
api/client_errors
api/contract
api/udc_deployer
api/hash
api/compiler
api/signer
api/models
Expand Down
6 changes: 6 additions & 0 deletions docs/api/client_models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Client responses
================

.. automodule:: starknet_py.net.client_models
:members:
:member-order: groupwise
58 changes: 58 additions & 0 deletions docs/api/hash.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Hash
====

------------------
Transaction hashes
------------------

.. automodule:: starknet_py.hash.transaction
:members:
:member-order: bysource

----------
Class hash
----------

.. automodule:: starknet_py.hash.class_hash
:members:
:member-order: bysource

-----------------
Sierra class hash
-----------------

.. automodule:: starknet_py.hash.sierra_class_hash
:members:
:member-order: bysource

---------------
Casm class hash
---------------

.. automodule:: starknet_py.hash.casm_class_hash
:members:
:member-order: bysource

-------
Address
-------

.. automodule:: starknet_py.hash.address
:members:
:member-order: bysource

--------
Selector
--------

.. automodule:: starknet_py.hash.selector
:members:
:member-order: bysource

-------
Storage
-------

.. automodule:: starknet_py.hash.storage
:members:
:member-order: bysource
6 changes: 6 additions & 0 deletions starknet_py/hash/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@


class TransactionHashPrefix(Enum):
"""
Enum representing possible transaction prefixes.
"""

DECLARE = int_from_bytes(b"declare")
DEPLOY = int_from_bytes(b"deploy")
DEPLOY_ACCOUNT = int_from_bytes(b"deploy_account")
Expand All @@ -32,13 +36,15 @@ def compute_transaction_hash(
Calculates the transaction hash in the StarkNet network - a unique identifier of the
transaction.
The transaction hash is a hash chain of the following information:

1. A prefix that depends on the transaction type.
2. The transaction's version.
3. Contract address.
4. Entry point selector.
5. A hash chain of the calldata.
6. The transaction's maximum fee.
7. The network's chain ID.

Each hash chain computation begins with 0 as initialization and ends with its length appended.
The length is appended in order to avoid collisions of the following kind:
H([x,y,z]) = h(h(x,y),z) = H([w, z]) where w = h(x,y).
Expand Down
48 changes: 48 additions & 0 deletions starknet_py/net/client_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

@dataclass
class Call:
"""
Dataclass representing a call to Starknet contract.
"""

to_addr: int
selector: int
calldata: List[int]
Expand Down Expand Up @@ -247,6 +251,10 @@ class GatewayBlock(StarknetBlock):

@dataclass
class BlockSingleTransactionTrace:
"""
Dataclass representing a trace of transaction execution.
"""

signature: List[int]
transaction_hash: int
function_invocation: Optional[dict] = None
Expand All @@ -256,54 +264,90 @@ class BlockSingleTransactionTrace:

@dataclass
class BlockTransactionTraces:
"""
Dataclass representing traces of all transactions in block.
"""

traces: List[BlockSingleTransactionTrace]


@dataclass
class StorageEntry:
"""
Dataclass representing single change in the storage.
"""

key: int
value: int


@dataclass
class StorageDiffItem:
"""
Dataclass representing all storage changes for the contract.
"""

address: int
storage_entries: List[StorageEntry]


@dataclass
class EstimatedFee:
"""
Dataclass representing estimated fee.
"""

overall_fee: int
gas_price: int
gas_usage: int


@dataclass
class DeployedContract:
"""
Dataclass representing basic data of the deployed contract.
"""

address: int
class_hash: int


@dataclass
class ContractsNonce:
"""
Dataclass representing nonce of the contract.
"""

contract_address: int
nonce: int


@dataclass
class DeclaredContractHash:
"""
Dataclass containing hashes of the declared contract.
"""

class_hash: int
compiled_class_hash: int


@dataclass
class ReplacedClass:
"""
Dataclass representing new class_hash of the contract.
war-in marked this conversation as resolved.
Show resolved Hide resolved
"""

contract_address: int
class_hash: int


@dataclass
class StateDiff:
"""
Dataclass representing state changes in the block.
"""

deployed_contracts: List[DeployedContract]
declared_contract_hashes: List[DeclaredContractHash]
storage_diffs: List[StorageDiffItem]
Expand Down Expand Up @@ -458,5 +502,9 @@ class CasmClass:

@dataclass
class TransactionStatusResponse:
"""
Dataclass representing transaction status.
"""

block_hash: Optional[int]
transaction_status: TransactionStatus