-
Notifications
You must be signed in to change notification settings - Fork 1
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
Smart Contract deploy transactions parser #22
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from multiversx_sdk.core.address import Address | ||
from multiversx_sdk.core.transactions_outcome_parsers.resources import ( | ||
TransactionEvent, TransactionOutcome, find_events_by_identifier) | ||
from multiversx_sdk.core.transactions_outcome_parsers.smart_contract_transactions_outcome_parser_types import ( | ||
DeployedSmartContract, SmartContractDeployOutcome) | ||
from multiversx_sdk.network_providers.constants import DEFAULT_ADDRESS_HRP | ||
|
||
|
||
class SmartContractTransactionsOutcomeParser: | ||
def __init__(self) -> None: | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in specs there is alo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we'll implement that in the future. We need the |
||
pass | ||
|
||
def parse_deploy(self, transaction_outcome: TransactionOutcome) -> SmartContractDeployOutcome: | ||
direct_call_outcome = transaction_outcome.direct_smart_contract_call | ||
events = find_events_by_identifier(transaction_outcome, "SCDeploy") | ||
contracts = [self._parse_sc_deploy_event(event) for event in events] | ||
|
||
return SmartContractDeployOutcome(direct_call_outcome.return_code, direct_call_outcome.return_message, contracts) | ||
|
||
def _parse_sc_deploy_event(self, event: TransactionEvent) -> DeployedSmartContract: | ||
contract_address_topic = event.topics[0] if event.topics[0] else b'' | ||
owner_address_topic = event.topics[1] if event.topics[1] else b'' | ||
code_hash_topic = event.topics[2] if event.topics[2] else b'' | ||
|
||
contract_address = Address(contract_address_topic, DEFAULT_ADDRESS_HRP).to_bech32() if len(contract_address_topic) else "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the future, we have to parametrize such outcome parsers to receive the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, I was thinking the same. |
||
owner_address = Address(owner_address_topic, DEFAULT_ADDRESS_HRP).to_bech32() if len(owner_address_topic) else "" | ||
code_hash = code_hash_topic | ||
|
||
return DeployedSmartContract(contract_address, owner_address, code_hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No way to do a shorter assert? Deep equality etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No "native" way as far as I know. Will think about doing a custom
deep_equal()
method to use in some tests.