-
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
Implemented token management transactions parser #8
Conversation
nonce: str | ||
initial_quantity: str |
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.
in specs nonce, balance, supply quantity are set as uint64, should we set here to int? and in all other places
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.
Indeed. Very good catch, thanks! Fixed!
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 "" |
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.
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?
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.
done
outcome = self.parser.parse_issue_fungible(tx_results_and_logs) | ||
assert outcome.identifier == "ZZZ-9ee87d" |
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.
update the tests so it is more clear where this identifier comes from, like decode from expected topic
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.
same for the other tests
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.
Done.
|
||
outcome = self.parser.parse_issue_fungible(tx_results_and_logs) | ||
assert outcome.identifier == "ZZZ-9ee87d" | ||
assert outcome.identifier == base64.b64decode(event.topics[0]).decode() |
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.
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
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.
replaced the identifier as described above
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.
Very nice 🚀
Just one renaming, plus making some functions private (optionally).
address: str = "", | ||
identifier: str = "", | ||
topics: List[str] = [], | ||
data: str = "") -> None: |
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.
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 = "", |
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.
I think hash is not needed (yet!) in the context of the outcome parsers. Perhaps remove it (can also stay for now)?
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.
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) |
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.
burned_quantity
. Or burnt
?
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.
renamed to burnt
|
||
return BurnQuantityOutcome(token_identifier, nonce, added_quantity) | ||
|
||
def ensure_no_error(self, transaction_events: List[TransactionEvent]) -> None: |
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.
The functions from this point can be made private.
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.
made the methods private
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 frombase64
.