Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
feat: declare
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Apr 17, 2023
1 parent 7097cba commit f7a0f3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 6 additions & 7 deletions ape_starknet/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ethpm_types import ContractType, HexBytes
from ethpm_types.abi import EventABI, MethodABI
from pydantic import Field, validator
from starknet_py.hash.sierra_class_hash import compute_sierra_class_hash
from starknet_py.hash.casm_class_hash import compute_casm_class_hash
from starknet_py.hash.transaction import compute_declare_v2_transaction_hash
from starknet_py.net.client_models import (
Call,
Expand Down Expand Up @@ -122,24 +122,24 @@ def validate_sender(cls, value):
@cached_property
def sierra_contract(self) -> SierraContractClass:
code = (
(self.contract_type.runtime_bytecode.bytecode or 0)
if self.contract_type.runtime_bytecode
(self.contract_type.deployment_bytecode.bytecode or 0)
if self.contract_type.deployment_bytecode
else 0
)
return create_sierra_class(code)

@cached_property
def casm_class(self) -> CasmClass:
code = (
(self.contract_type.deployment_bytecode.bytecode or 0)
if self.contract_type.deployment_bytecode
(self.contract_type.runtime_bytecode.bytecode or 0)
if self.contract_type.runtime_bytecode
else 0
)
return create_casm_class(code)

@cached_property
def compiled_class_hash(self) -> int:
return compute_sierra_class_hash(self.sierra_contract)
return compute_casm_class_hash(self.casm_class)

@property
def txn_hash(self) -> HexBytes:
Expand Down Expand Up @@ -418,7 +418,6 @@ def decode_logs(
self,
abi: Optional[ContractEventABI] = None,
) -> ContractLogContainer:

log_data_items: List[Dict] = []
for log in self.logs:
log_data = {
Expand Down
9 changes: 8 additions & 1 deletion ape_starknet/utils/basemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,14 @@ def create_casm_class(code: Union[str, bytes, int]) -> CasmClass:
constructor=[create_casm_entry_point(v) for v in ep_data["CONSTRUCTOR"]],
l1_handler=[create_casm_entry_point(v) for v in ep_data["L1_HANDLER"]],
)
return CasmClass(program=class_data, entry_points_by_type=entry_points)
return CasmClass(
prime=int(class_data["prime"], 16),
bytecode=[int(x, 16) for x in class_data["bytecode"]],
hints=class_data["hints"],
pythonic_hints=[],
entry_points_by_type=entry_points,
compiler_version=class_data["compiler_version"],
)


def create_sierra_entry_point(data: Dict) -> SierraEntryPoint:
Expand Down

0 comments on commit f7a0f3e

Please sign in to comment.