-
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
Fix for sending message with ESDTTransfer for transaction decoder #186
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -15,6 +15,10 @@ def __init__(self) -> None: | |
self.function_name: Optional[str] = None | ||
self.function_args: Optional[list[str]] = None | ||
self.transfers: Optional[list[TokenTransfer]] = None | ||
self.transfer_messages: list[bytes] = [] | ||
""" | ||
This property is set to the extra arguments passed to ESDTTransfer when transferring tokens to non-smart contract accounts. | ||
""" | ||
|
||
def to_dict(self) -> dict[str, Any]: | ||
return { | ||
|
@@ -24,6 +28,7 @@ def to_dict(self) -> dict[str, Any]: | |
"function_name": self.function_name if self.function_name else "", | ||
"function_args": self.function_args if self.function_args else [], | ||
"transfers": self._transfers_to_dict(), | ||
"transfer_messages": [message.decode() for message in self.transfer_messages], | ||
} | ||
|
||
def _transfers_to_dict(self) -> list[dict[str, Any]]: | ||
|
@@ -48,6 +53,8 @@ def _transfers_to_dict(self) -> list[dict[str, Any]]: | |
|
||
|
||
class TransactionDecoder: | ||
"""Can be used for decoding custom token transfers transactions (ESDTTransfer, NFTTransfer, MultiESDTNFTTransfer).""" | ||
|
||
def get_transaction_metadata(self, transaction: TransactionOnNetwork) -> TransactionMetadata: | ||
metadata = self.get_normal_transaction_metadata(transaction) | ||
|
||
|
@@ -82,6 +89,7 @@ def get_normal_transaction_metadata(self, transaction: TransactionOnNetwork) -> | |
if len(args) == 0 and not transaction.receiver.is_smart_contract(): | ||
metadata.function_name = "transfer" | ||
metadata.function_args = [] | ||
metadata.transfer_messages = [bytes.fromhex(data) for data in data_components] | ||
|
||
return metadata | ||
|
||
|
@@ -106,9 +114,15 @@ def get_esdt_transaction_metadata(self, metadata: TransactionMetadata) -> Option | |
result.value = value | ||
result.transfers = [] | ||
|
||
receiver = Address.new_from_bech32(result.receiver) | ||
is_receiver_sc = receiver.is_smart_contract() | ||
|
||
if len(args) > 2: | ||
result.function_name = self.hex_to_string(args[2]) | ||
result.function_args = args[3:] | ||
if is_receiver_sc: | ||
result.function_name = self.hex_to_string(args[2]) | ||
result.function_args = args[3:] | ||
else: | ||
result.transfer_messages = [bytes.fromhex(arg) for arg in args[2:]] | ||
|
||
token = Token(identifier) | ||
transfer = TokenTransfer(token, value) | ||
|
@@ -145,8 +159,11 @@ def get_nft_transfer_metadata(self, metadata: TransactionMetadata) -> Optional[T | |
result.transfers = [] | ||
|
||
if len(args) > 4: | ||
result.function_name = self.hex_to_string(args[4]) | ||
result.function_args = args[5:] | ||
if receiver.is_smart_contract(): | ||
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. Here, 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. yep, the actual receiver |
||
result.function_name = self.hex_to_string(args[4]) | ||
result.function_args = args[5:] | ||
else: | ||
result.transfer_messages = [bytes.fromhex(arg) for arg in args[4:]] | ||
|
||
token = Token(collection_identifier, self.hex_to_number(nonce)) | ||
transfer = TokenTransfer(token, value) | ||
|
@@ -202,10 +219,13 @@ def get_multi_transfer_metadata(self, metadata: TransactionMetadata) -> Optional | |
result.receiver = receiver.to_bech32() | ||
|
||
if len(args) > index: | ||
result.function_name = self.hex_to_string(args[index]) | ||
index += 1 | ||
result.function_args = args[index:] | ||
index += 1 | ||
if receiver.is_smart_contract(): | ||
result.function_name = self.hex_to_string(args[index]) | ||
index += 1 | ||
result.function_args = args[index:] | ||
index += 1 | ||
else: | ||
result.transfer_messages = [bytes.fromhex(arg) for arg in args[index:]] | ||
|
||
return result | ||
|
||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How about the same case for NFT transfers or multi transfers? In that case, I think
receiver.is_smart_contract()
would not be appropriate.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.
did the same for nft and multi transfer.