-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[data transformer::01] Adapt transformer and use it in `deploy_contra…
…ct` (#353) * add starknet_py * add data transformer facade * connect data transformer without testing * use data transformer in deploy contract * lint * update docs * fix test
- Loading branch information
1 parent
aeb0a86
commit e9f701d
Showing
10 changed files
with
211 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pathlib import Path | ||
from typing import List | ||
|
||
from starknet_py.utils.data_transformer.data_transformer import ( | ||
ABIFunctionEntry, | ||
DataTransformer, | ||
) | ||
from starkware.starknet.public.abi import AbiType | ||
from starkware.starknet.public.abi_structs import identifier_manager_from_abi | ||
|
||
from protostar.utils.starknet_compilation import StarknetCompiler | ||
|
||
|
||
class FunctionNotFoundException(BaseException): | ||
pass | ||
|
||
|
||
class DataTransformerFacade: | ||
@classmethod | ||
def from_contract_path( | ||
cls, path: Path, starknet_compiler: StarknetCompiler | ||
) -> "DataTransformerFacade": | ||
preprocessed = starknet_compiler.preprocess_contract(path) | ||
return cls(preprocessed.abi) | ||
|
||
def __init__(self, contract_abi: AbiType) -> None: | ||
self._contract_abi = contract_abi | ||
self._identifier_manager = identifier_manager_from_abi(contract_abi) | ||
|
||
def _get_function_abi(self, fn_name: str) -> ABIFunctionEntry: | ||
for item in self._contract_abi: | ||
if (item["type"] == "function" or item["type"] == "constructor") and item[ | ||
"name" | ||
] == fn_name: | ||
return item | ||
raise FunctionNotFoundException(f"Couldn't find a function '{fn_name}'") | ||
|
||
def from_python(self, fn_name: str, *args, **kwargs) -> List[int]: | ||
data_transformer = DataTransformer( | ||
self._get_function_abi(fn_name), | ||
identifier_manager_from_abi(self._contract_abi), | ||
) | ||
return data_transformer.from_python(*args, **kwargs)[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.