-
Notifications
You must be signed in to change notification settings - Fork 0
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
Send Native token in MultiESDTNFTTransfer #73
Changes from all commits
a94637d
40af8de
de3eb53
42a8656
b0ad9d6
38e6194
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
from multiversx_sdk.core.errors import BadUsageError | ||
from multiversx_sdk.core.interfaces import IAddress, ITokenTransfer | ||
from multiversx_sdk.core.tokens import TokenComputer | ||
from multiversx_sdk.core.tokens import TokenComputer, TokenTransfer | ||
from multiversx_sdk.core.transaction import Transaction | ||
from multiversx_sdk.core.transactions_factories.token_transfers_data_builder import \ | ||
TokenTransfersDataBuilder | ||
|
@@ -76,3 +76,34 @@ def create_transaction_for_esdt_token_transfer(self, | |
gas_limit=extra_gas_for_transfer, | ||
add_data_movement_gas=True | ||
).build() | ||
|
||
def create_transaction_for_transfer(self, | ||
sender: IAddress, | ||
receiver: IAddress, | ||
native_amount: Optional[int] = None, | ||
token_transfers: Optional[Sequence[ITokenTransfer]] = None, | ||
data: Optional[bytes] = None) -> Transaction: | ||
if not native_amount and not token_transfers: | ||
raise BadUsageError("No native token amount or token transfers provided") | ||
|
||
if token_transfers and data: | ||
raise BadUsageError("Can't set data field when sending esdt tokens") | ||
|
||
if native_amount and not token_transfers: | ||
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, we handle this as a simple move balance. |
||
return self.create_transaction_for_native_token_transfer( | ||
sender=sender, | ||
receiver=receiver, | ||
native_amount=native_amount, | ||
data=data.decode() if data else None | ||
) | ||
|
||
token_transfers = list(token_transfers) if token_transfers 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. The optional refactoring idea from above, if applicable. 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. I can do it, but I am not sure it's what we want. |
||
|
||
native_transfer = TokenTransfer.new_from_native_amount(native_amount) if native_amount else None | ||
token_transfers.append(native_transfer) if native_transfer else None | ||
|
||
return self.create_transaction_for_esdt_token_transfer( | ||
sender=sender, | ||
receiver=receiver, | ||
token_transfers=token_transfers | ||
) |
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.
If we move
number_of_tokens = len(transfers)
above this line, then maybe we don't neednumber_of_tokens += 1
anymore.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, but I was using it in the above
if
statement, as well.