Skip to content
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

Implemented token management transactions parser #8

Merged
merged 5 commits into from
Feb 12, 2024

Conversation

popenta
Copy link
Collaborator

@popenta popenta commented Feb 5, 2024

Implemented the parser based on the sdk-specs.

The events and logs should be provided to the TransactionOutcome as they come from the api, because the parser converts them from base64.

@popenta popenta self-assigned this Feb 5, 2024
@ssd04 ssd04 self-requested a review February 5, 2024 13:27
Comment on lines 41 to 42
nonce: str
initial_quantity: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in specs nonce, balance, supply quantity are set as uint64, should we set here to int? and in all other places

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Very good catch, thanks! Fixed!

Comment on lines 234 to 238
def extract_token_identifier(self, event: TransactionEvent) -> str:
if event.topics[0]:
hex_ticker = base64.b64decode(event.topics[0]).hex()
return bytes.fromhex(hex_ticker).decode()
return ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def extract_token_identifier(self, event: TransactionEvent) -> str:
if event.topics[0]:
hex_ticker = base64.b64decode(event.topics[0]).hex()
return bytes.fromhex(hex_ticker).decode()
return ""
def extract_token_identifier(self, event: TransactionEvent) -> str:
if !event.topics[0]:
return ""
hex_ticker = base64.b64decode(event.topics[0]).hex()
return bytes.fromhex(hex_ticker).decode()

maybe like this would be cleaner on these functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 51 to 52
outcome = self.parser.parse_issue_fungible(tx_results_and_logs)
assert outcome.identifier == "ZZZ-9ee87d"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the tests so it is more clear where this identifier comes from, like decode from expected topic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for the other tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 54 to 56

outcome = self.parser.parse_issue_fungible(tx_results_and_logs)
assert outcome.identifier == "ZZZ-9ee87d"
assert outcome.identifier == base64.b64decode(event.topics[0]).decode()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's more visible to have the identifier in plain form and then as encoded, something like this

        identifier = "ZZZ-9ee87d"
        identifier_base64 = base64.b64encode(identifier.encode()).decode()

        event = TransactionEvent(
            address="erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2",
            identifier="issue",
            topics=[
                identifier_base64,
                "U0VDT05E",
                "Wlpa",
                "RnVuZ2libGVFU0RU",
                "Ag=="
            ]
        )
        empty_result = SmartContractResult()
        tx_log = TransactionLogs("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2", [event])
        tx_results_and_logs = TransactionOutcome([empty_result], tx_log)

        outcome = self.parser.parse_issue_fungible(tx_results_and_logs)
        assert outcome.identifier == identifier

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced the identifier as described above

@andreibancioiu andreibancioiu self-requested a review February 8, 2024 13:58
Copy link
Contributor

@andreibancioiu andreibancioiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice 🚀

Just one renaming, plus making some functions private (optionally).

address: str = "",
identifier: str = "",
topics: List[str] = [],
data: str = "") -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Sirius, there's also additionalData, but it's not necessary here (though, we should keep that in mind, for the specs etc.).


class SmartContractResult:
def __init__(self,
hash: str = "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think hash is not needed (yet!) in the context of the outcome parsers. Perhaps remove it (can also stay for now)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hash is indeed not needed. On the other hand, timestamp is not needed, as well. Will remove them both.

event = self.find_single_event_by_identifier(transaction_outcome, "ESDTNFTBurn")
token_identifier = self.extract_token_identifier(event)
nonce = self.extract_nonce(event)
added_quantity = self.extract_amount(event)
Copy link
Contributor

@andreibancioiu andreibancioiu Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

burned_quantity. Or burnt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to burnt


return BurnQuantityOutcome(token_identifier, nonce, added_quantity)

def ensure_no_error(self, transaction_events: List[TransactionEvent]) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functions from this point can be made private.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the methods private

@popenta popenta merged commit f03476b into main Feb 12, 2024
3 checks passed
@popenta popenta deleted the token-management-txs-outcome-parser branch February 12, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants