diff --git a/docs/api.rst b/docs/api.rst index 246380c0e..6ef7ecff3 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -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 diff --git a/docs/api/client_models.rst b/docs/api/client_models.rst new file mode 100644 index 000000000..5ae32855a --- /dev/null +++ b/docs/api/client_models.rst @@ -0,0 +1,6 @@ +Client responses +================ + +.. automodule:: starknet_py.net.client_models + :members: + :member-order: groupwise diff --git a/docs/api/hash.rst b/docs/api/hash.rst new file mode 100644 index 000000000..2f83eef28 --- /dev/null +++ b/docs/api/hash.rst @@ -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 diff --git a/starknet_py/hash/transaction.py b/starknet_py/hash/transaction.py index de023de41..e6f260a71 100644 --- a/starknet_py/hash/transaction.py +++ b/starknet_py/hash/transaction.py @@ -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") @@ -32,6 +36,7 @@ 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. @@ -39,6 +44,7 @@ def compute_transaction_hash( 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). diff --git a/starknet_py/net/client_models.py b/starknet_py/net/client_models.py index f3b57ef5f..379a38d15 100644 --- a/starknet_py/net/client_models.py +++ b/starknet_py/net/client_models.py @@ -18,6 +18,10 @@ @dataclass class Call: + """ + Dataclass representing a call to Starknet contract. + """ + to_addr: int selector: int calldata: List[int] @@ -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 @@ -256,23 +264,39 @@ 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 @@ -280,30 +304,50 @@ class EstimatedFee: @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. + """ + 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] @@ -458,5 +502,9 @@ class CasmClass: @dataclass class TransactionStatusResponse: + """ + Dataclass representing transaction status. + """ + block_hash: Optional[int] transaction_status: TransactionStatus