Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion starknet_py/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class OutsideExecutionInterfaceID(IntEnum):
V2 = 0x1D1144BB2138366FF28D8E9AB57456B1D332AC42196230C3A602003C89872


EXPECTED_RPC_VERSION = "0.10.0"
EXPECTED_RPC_VERSION = "0.10.1-rc.2"

ARGENT_V040_CLASS_HASH = (
0x036078334509B514626504EDC9FB252328D1A240E4E948BEF8D0C08DFF45927F
Expand Down
12 changes: 12 additions & 0 deletions starknet_py/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ async def invoke(
nonce: Optional[int] = None,
tip: Optional[int] = None,
auto_estimate_tip: bool = False,
proof_facts: Optional[List[int]] = None,
proof: Optional[List[int]] = None,
) -> InvokeResult:
"""
Send an Invoke transaction version 3 for the prepared data.
Expand All @@ -399,6 +401,8 @@ async def invoke(
:param nonce: Nonce of the transaction.
:param tip: The tip amount to be added to the transaction fee.
:param auto_estimate_tip: Use automatic tip estimation. Using this option may lead to higher costs.
:param proof_facts: Optional proof facts for the transaction.
:param proof: Optional proof for the transaction.
:return: InvokeResult.
"""

Expand All @@ -409,6 +413,8 @@ async def invoke(
auto_estimate=auto_estimate,
tip=tip or self.tip,
auto_estimate_tip=auto_estimate_tip,
proof_facts=proof_facts,
proof=proof,
)

return await self._invoke(transaction)
Expand Down Expand Up @@ -563,6 +569,8 @@ async def invoke_v3(
tip: Optional[int] = None,
auto_estimate_tip: bool = False,
nonce: Optional[int] = None,
proof_facts: Optional[List[int]] = None,
proof: Optional[List[int]] = None,
**kwargs,
) -> InvokeResult:
"""
Expand All @@ -574,6 +582,8 @@ async def invoke_v3(
:param tip: The tip amount to be added to the transaction fee.
:param auto_estimate_tip: Use automatic tip estimation. Using this option may lead to higher costs.
:param nonce: Nonce of the transaction.
:param proof_facts: Optional proof facts for the transaction.
:param proof: Optional proof for the transaction.
:return: InvokeResult.
"""
prepared_invoke = self.prepare_invoke_v3(*args, **kwargs)
Expand All @@ -583,6 +593,8 @@ async def invoke_v3(
auto_estimate=auto_estimate,
tip=tip,
auto_estimate_tip=auto_estimate_tip,
proof_facts=proof_facts,
proof=proof,
)

@staticmethod
Expand Down
18 changes: 11 additions & 7 deletions starknet_py/hash/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def compute_invoke_v3_transaction_hash(
account_deployment_data: List[int],
calldata: List[int],
common_fields: CommonTransactionV3Fields,
proof_facts: Optional[List[int]] = None,
) -> int:
"""
Computes hash of an Invoke transaction version 3.
Expand All @@ -190,15 +191,18 @@ def compute_invoke_v3_transaction_hash(
Currently, this value is always empty.
:param calldata: Calldata of the function.
:param common_fields: Common fields for V3 transactions.
:param proof_facts: Optional proof facts for the transaction.
:return: Hash of the transaction.
"""
return poseidon_hash_many(
[
*common_fields.compute_common_tx_fields(),
poseidon_hash_many(account_deployment_data),
poseidon_hash_many(calldata),
]
)
elements = [
*common_fields.compute_common_tx_fields(),
poseidon_hash_many(account_deployment_data),
poseidon_hash_many(calldata),
]
if proof_facts:
elements.append(poseidon_hash_many(proof_facts))

return poseidon_hash_many(elements)


def compute_deploy_account_transaction_hash(
Expand Down
12 changes: 12 additions & 0 deletions starknet_py/net/account/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ async def _prepare_invoke_v3(
auto_estimate: bool = False,
tip: Optional[int] = None,
auto_estimate_tip: bool = False,
proof_facts: Optional[List[int]] = None,
proof: Optional[List[int]] = None,
) -> InvokeV3:
# pylint: disable=too-many-arguments
"""
Expand All @@ -210,6 +212,8 @@ async def _prepare_invoke_v3(
sender_address=self.address,
version=3,
tip=tip,
proof_facts=proof_facts or [],
proof=proof or [],
)

resource_bounds = await self._get_resource_bounds(
Expand Down Expand Up @@ -399,6 +403,8 @@ async def sign_invoke_v3(
auto_estimate: bool = False,
tip: Optional[int] = None,
auto_estimate_tip: bool = False,
proof_facts: Optional[List[int]] = None,
proof: Optional[List[int]] = None,
) -> InvokeV3:
# pylint: disable=too-many-arguments
invoke_tx = await self._prepare_invoke_v3(
Expand All @@ -408,6 +414,8 @@ async def sign_invoke_v3(
auto_estimate=auto_estimate,
tip=tip,
auto_estimate_tip=auto_estimate_tip,
proof_facts=proof_facts,
proof=proof,
)
signature = self.signer.sign_transaction(invoke_tx)
return _add_signature_to_transaction(invoke_tx, signature)
Expand Down Expand Up @@ -513,6 +521,8 @@ async def execute_v3(
auto_estimate: bool = False,
tip: Optional[int] = None,
auto_estimate_tip: bool = False,
proof_facts: Optional[List[int]] = None,
proof: Optional[List[int]] = None,
) -> SentTransactionResponse:
# pylint: disable=too-many-arguments
execute_transaction = await self.sign_invoke_v3(
Expand All @@ -522,6 +532,8 @@ async def execute_v3(
auto_estimate=auto_estimate,
tip=tip,
auto_estimate_tip=auto_estimate_tip,
proof_facts=proof_facts,
proof=proof,
)
return await self._client.send_transaction(execute_transaction)

Expand Down
8 changes: 8 additions & 0 deletions starknet_py/net/account/base_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ async def sign_invoke_v3(
auto_estimate: bool = False,
tip: Optional[int] = None,
auto_estimate_tip: bool = False,
proof_facts: Optional[List[int]] = None,
proof: Optional[List[int]] = None,
) -> InvokeV3:
# pylint: disable=too-many-arguments
"""
Expand All @@ -178,6 +180,8 @@ async def sign_invoke_v3(
:param auto_estimate: Use automatic fee estimation, not recommend as it may lead to high costs.
:param tip: The tip amount to be added to the transaction fee.
:param auto_estimate_tip: Use automatic tip estimation. Using this option may lead to higher costs.
:param proof_facts: Optional proof facts for the transaction.
:param proof: Optional proof for the transaction.
:return: Invoke created from the calls.
"""

Expand Down Expand Up @@ -249,6 +253,8 @@ async def execute_v3(
auto_estimate: bool = False,
tip: Optional[int] = None,
auto_estimate_tip: bool = False,
proof_facts: Optional[List[int]] = None,
proof: Optional[List[int]] = None,
) -> SentTransactionResponse:
# pylint: disable=too-many-arguments
"""
Expand All @@ -260,6 +266,8 @@ async def execute_v3(
:param auto_estimate: Use automatic fee estimation, not recommend as it may lead to high costs.
:param tip: The tip amount to be added to the transaction fee.
:param auto_estimate_tip: Use automatic tip estimation. Using this option may lead to higher costs.
:param proof_facts: Optional proof facts for the transaction.
:param proof: Optional proof for the transaction.
:return: SentTransactionResponse.
"""

Expand Down
11 changes: 11 additions & 0 deletions starknet_py/net/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
StarknetBlockWithTxHashes,
StorageProofResponse,
Tag,
TraceFlag,
Transaction,
TransactionExecutionStatus,
TransactionReceiptWithBlockInfo,
TransactionResponseFlag,
TransactionStatus,
TransactionStatusResponse,
)
Expand Down Expand Up @@ -72,12 +74,14 @@ async def get_block_with_txs(
self,
block_hash: Optional[Union[Hash, Tag]] = None,
block_number: Optional[Union[int, Tag]] = None,
response_flags: Optional[List[TransactionResponseFlag]] = None,
) -> Union[StarknetBlock, PreConfirmedStarknetBlock]:
"""
Retrieve the block's data by its number or hash.

:param block_hash: Block's hash or literals `"l1_accepted"`, `"pre_confirmed"` or `"latest"`
:param block_number: Block's number or literals `"l1_accepted"`, `"pre_confirmed"` or `"latest"`
:param response_flags: Flags that control what additional fields are included in transaction responses
:return: StarknetBlock object representing retrieved block with transactions.
"""

Expand All @@ -86,12 +90,14 @@ async def get_block_with_tx_hashes(
self,
block_hash: Optional[Union[Hash, Tag]] = None,
block_number: Optional[Union[int, Tag]] = None,
response_flags: Optional[List[TransactionResponseFlag]] = None,
) -> Union[StarknetBlockWithTxHashes, PreConfirmedStarknetBlockWithTxHashes]:
"""
Retrieve the block's data with a list of contained transaction hashes.

:param block_hash: Block's hash or literals `"l1_accepted"`, `"pre_confirmed"` or `"latest"`
:param block_number: Block's number or literals `"l1_accepted"`, `"pre_confirmed"` or `"latest"`
:param response_flags: Flags that control what additional fields are included in transaction responses
:return: StarknetBlockWithTxHashes object representing retrieved block with transactions.
"""

Expand All @@ -100,12 +106,14 @@ async def get_block_with_receipts(
self,
block_hash: Optional[Union[Hash, Tag]] = None,
block_number: Optional[Union[int, Tag]] = None,
response_flags: Optional[List[TransactionResponseFlag]] = None,
) -> Union[StarknetBlockWithReceipts, PreConfirmedStarknetBlockWithReceipts]:
"""
Retrieve the block's data with a list of receipts for contained transactions.

:param block_hash: Block's hash or literals `"l1_accepted"`, `"pre_confirmed"` or `"latest"`
:param block_number: Block's number or literals `"l1_accepted"`, `"pre_confirmed"` or `"latest"`
:param response_flags: Flags that control what additional fields are included in transaction responses
:return: StarknetBlockWithReceipts object representing retrieved block with transactions.
"""

Expand All @@ -114,12 +122,14 @@ async def trace_block_transactions(
self,
block_hash: Optional[Union[Hash, LatestTag]] = None,
block_number: Optional[Union[int, LatestTag]] = None,
trace_flags: Optional[List[TraceFlag]] = None,
) -> List[BlockTransactionTrace]:
"""
Receive the traces of all the transactions within specified block

:param block_hash: Block's hash
:param block_number: Block's number or "pre_confirmed" for pre_confirmed block
:param trace_flags: Flags that indicate when additional information should be included in the trace
:return: BlockTransactionTraces object representing received traces
"""

Expand Down Expand Up @@ -178,6 +188,7 @@ async def get_storage_proof(
async def get_transaction(
self,
tx_hash: Hash,
response_flags: Optional[List[TransactionResponseFlag]] = None,
) -> Transaction:
"""
Get the details and status of a submitted transaction
Expand Down
76 changes: 76 additions & 0 deletions starknet_py/net/client_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ class InvokeTransactionV3(TransactionV3):
sender_address: int
nonce: int
account_deployment_data: List[int]
proof: Optional[List[int]] = None
proof_facts: Optional[List[int]] = None


@dataclass
Expand Down Expand Up @@ -638,6 +640,10 @@ class StarknetBlockWithTxHashes(BlockHeader):
transactions: List[int]


class TransactionResponseFlag(str, Enum):
INCLUDE_PROOF_FACTS = "INCLUDE_PROOF_FACTS"


@dataclass
class StarknetBlockWithReceipts(BlockHeader):
"""
Expand Down Expand Up @@ -1052,6 +1058,53 @@ class SimulationFlag(str, Enum):

SKIP_VALIDATE = "SKIP_VALIDATE"
SKIP_FEE_CHARGE = "SKIP_FEE_CHARGE"
RETURN_INITIAL_READS = "RETURN_INITIAL_READS"


class TraceFlag(str, Enum):
"""
Enum class representing flags that indicate what additional information should be included in the trace.
"""

RETURN_INITIAL_READS = "RETURN_INITIAL_READS"


@dataclass
class StorageInitialRead:
contract_address: int
key: str
value: int


@dataclass
class NonceInitialRead:
contract_address: int
nonce: int


@dataclass
class ClassHashInitialRead:
contract_address: int
class_hash: int


@dataclass
class DeclaredContractInitialRead:
class_hash: int
is_declared: bool


@dataclass
class InitialReads:
"""
Dataclass representing the set of state values fetched from
the underlying state reader during execution.
"""

storage: Optional[List[StorageInitialRead]] = None
nonces: Optional[List[NonceInitialRead]] = None
class_hashes: Optional[List[ClassHashInitialRead]] = None
declared_contracts: Optional[List[DeclaredContractInitialRead]] = None


class EntryPointType(Enum):
Expand Down Expand Up @@ -1172,6 +1225,18 @@ class SimulatedTransaction:
fee_estimation: EstimatedFee


@dataclass
class SimulatedTransactionsWithInitialReads:
"""
Dataclass representing the execution trace and consumed resources
of the required transactions, along with initial reads when
RETURN_INITIAL_READS is present in simulation_flags.
"""

simulated_transactions: List[SimulatedTransaction]
initial_reads: InitialReads


@dataclass
class BlockTransactionTrace:
"""
Expand All @@ -1182,6 +1247,17 @@ class BlockTransactionTrace:
trace_root: TransactionTrace


@dataclass
class BlockTransactionTracesWithInitialReads:
"""
Dataclass representing the traces of all transactions in the block, along with the initial reads
when RETURN_INITIAL_READS is present in trace_flags.
"""

transaction_traces: List[BlockTransactionTrace]
initial_reads: InitialReads


@dataclass
class BinaryNode:
"""
Expand Down
Loading
Loading