Skip to content

Commit

Permalink
add missing token management methods
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Nov 20, 2024
1 parent a1bd656 commit b6fe456
Show file tree
Hide file tree
Showing 6 changed files with 433 additions and 5 deletions.
5 changes: 3 additions & 2 deletions multiversx_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
DelegationTransactionsOutcomeParser)
from multiversx_sdk.entrypoints import (DevnetEntrypoint, MainnetEntrypoint,
NetworkEntrypoint, TestnetEntrypoint)
from multiversx_sdk.network_providers import (AccountOnNetwork, AccountStorage,
from multiversx_sdk.network_providers import (AccountAwaiter, AccountOnNetwork,
AccountStorage,
AccountStorageEntry,
ApiNetworkProvider,
AwaitingOptions,
Expand Down Expand Up @@ -79,5 +80,5 @@
"BurnQuantityOutcome", "TransactionOnNetwork", "TransactionStatus", "ParsedSmartContractCallOutcome",
"AccountOnNetwork", "AccountStorage", "AccountStorageEntry", "AwaitingOptions", "BlockCoordinates",
"BlockOnNetwork", "FungibleTokenMetadata", "GetBlockArguments", "NetworkConfig", "NetworkStatus",
"TokenAmountOnNetwork", "TokensCollectionMetadata", "TransactionCostResponse"
"TokenAmountOnNetwork", "TokensCollectionMetadata", "TransactionCostResponse", "AccountAwaiter"
]
8 changes: 8 additions & 0 deletions multiversx_sdk/core/transactions_factory_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class TransactionsFactoryConfig:
gas_limit_update_token_id: int = 60_000_000
gas_limit_register_dynamic: int = 60_000_000
issue_cost: int = 50_000_000_000_000_000
gas_limit_transfer_ownership: int = 60_000_000
gas_limit_freeze_single_nft: int = 60_000_000
gas_limit_unfreeze_single_nft: int = 60_000_000
gas_limit_change_sft_to_meta_esdt: int = 60_000_000
gas_limit_transfer_nft_create_role: int = 60_000_000
gas_limit_stop_nft_create: int = 60_000_000
gas_limit_wipe_single_nft: int = 60_000_000
gas_limit_esdt_nft_add_uri: int = 10_000_000
esdt_contract_address: Address = field(default_factory=lambda: Address.new_from_bech32(
"erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"))

Expand Down
3 changes: 2 additions & 1 deletion multiversx_sdk/network_providers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from multiversx_sdk.network_providers.account_awaiter import AccountAwaiter
from multiversx_sdk.network_providers.api_network_provider import \
ApiNetworkProvider
from multiversx_sdk.network_providers.config import NetworkProviderConfig
Expand All @@ -21,5 +22,5 @@
"AccountOnNetwork", "AccountStorage", "AccountStorageEntry", "AwaitingOptions",
"BlockCoordinates", "BlockOnNetwork", "FungibleTokenMetadata",
"GetBlockArguments", "NetworkConfig", "NetworkStatus", "TokenAmountOnNetwork",
"TokensCollectionMetadata", "TransactionCostResponse"
"TokensCollectionMetadata", "TransactionCostResponse", "AccountAwaiter"
]
132 changes: 132 additions & 0 deletions multiversx_sdk/token_management/token_management_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,135 @@ def parse_burn_quantity(self, transaction_on_network: TransactionOnNetwork) -> l
def await_completed_burn_quantity(self, transaction_hash: Union[str, bytes]) -> list[BurnQuantityOutcome]:
transaction = self.network_provider.await_transaction_completed(transaction_hash)
return self.parse_burn_quantity(transaction)

def create_transaction_for_transferring_ownership(self,
sender: IAccount,
nonce: int,
token_identifier: str,
new_owner: Address) -> Transaction:
transaction = self.factory.create_transaction_for_transferring_ownership(
sender=sender.address,
token_identifier=token_identifier,
new_owner=new_owner
)

transaction.nonce = nonce
transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction))

return transaction

def create_transaction_for_freezing_single_nft(self,
sender: IAccount,
nonce: int,
token_identifier: str,
token_nonce: int,
user: Address) -> Transaction:
transaction = self.factory.create_transaction_for_freezing_single_nft(
sender=sender.address,
token_identifier=token_identifier,
token_nonce=token_nonce,
user=user
)

transaction.nonce = nonce
transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction))

return transaction

def create_transaction_for_unfreezing_single_nft(self,
sender: IAccount,
nonce: int,
token_identifier: str,
token_nonce: int,
user: Address) -> Transaction:
transaction = self.factory.create_transaction_for_unfreezing_single_nft(
sender=sender.address,
token_identifier=token_identifier,
token_nonce=token_nonce,
user=user
)

transaction.nonce = nonce
transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction))

return transaction

def create_transaction_for_changing_sft_to_meta_esdt(self,
sender: IAccount,
nonce: int,
collection: str,
num_decimals: int) -> Transaction:
transaction = self.factory.create_transaction_for_changing_sft_to_meta_esdt(
sender=sender.address,
collection=collection,
num_decimals=num_decimals
)

transaction.nonce = nonce
transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction))

return transaction

def create_transaction_for_transferring_nft_create_role(self,
sender: IAccount,
nonce: int,
token_identifier: str,
user: Address) -> Transaction:
transaction = self.factory.create_transaction_for_transferring_nft_create_role(
sender=sender.address,
token_identifier=token_identifier,
user=user
)

transaction.nonce = nonce
transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction))

return transaction

def create_transaction_for_stopping_nft_creation(self,
sender: IAccount,
nonce: int,
token_identifier: str) -> Transaction:
transaction = self.factory.create_transaction_for_stopping_nft_creation(
sender=sender.address,
token_identifier=token_identifier
)

transaction.nonce = nonce
transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction))

return transaction

def create_transaction_for_wiping_single_nft(self,
sender: IAccount,
nonce: int,
token_identifier: str,
token_nonce: int,
user: Address) -> Transaction:
transaction = self.factory.create_transaction_for_wiping_single_nft(
sender=sender.address,
token_identifier=token_identifier,
token_nonce=token_nonce,
user=user
)

transaction.nonce = nonce
transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction))

return transaction

def create_transction_for_adding_uris(self,
sender: IAccount,
nonce: int,
token_identifier: str,
uris: list[str]) -> Transaction:
transaction = self.factory.create_transction_for_adding_uris(
sender=sender.address,
token_identifier=token_identifier,
uris=uris
)

transaction.nonce = nonce
transaction.signature = sender.sign(self.tx_computer.compute_bytes_for_signing(transaction))

return transaction
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ def create_transaction_for_freezing(
user: Address,
token_identifier: str
) -> Transaction:
"""Can be used for FungibleESDT"""
parts = [
"freeze",
self.serializer.serialize([StringValue(token_identifier)]),
Expand All @@ -630,6 +631,7 @@ def create_transaction_for_unfreezing(
user: Address,
token_identifier: str
) -> Transaction:
"""Can be used for FungibleESDT"""
parts = [
"unFreeze",
self.serializer.serialize([StringValue(token_identifier)]),
Expand Down Expand Up @@ -850,7 +852,7 @@ def create_transaction_for_modifying_creator(self,
sender: Address,
token_identifier: str,
token_nonce: int) -> Transaction:
parts: list[str] = [
parts = [
"ESDTModifyCreator",
self.serializer.serialize([StringValue(token_identifier)]),
self.serializer.serialize([BigUIntValue(token_nonce)])
Expand Down Expand Up @@ -1033,6 +1035,175 @@ def create_transaction_for_registering_dynamic_and_setting_roles(self,
data_parts=parts
).build()

def create_transaction_for_transferring_ownership(self,
sender: Address,
token_identifier: str,
new_owner: Address) -> Transaction:
parts = [
"transferOwnership",
self.serializer.serialize([StringValue(token_identifier)]),
new_owner.to_hex()
]

return TransactionBuilder(
config=self._config,
sender=sender,
receiver=self._config.esdt_contract_address,
amount=0,
gas_limit=self._config.gas_limit_transfer_ownership,
add_data_movement_gas=True,
data_parts=parts
).build()

def create_transaction_for_freezing_single_nft(self,
sender: Address,
token_identifier: str,
token_nonce: int,
user: Address) -> Transaction:
parts = [
"freezeSingleNFT",
self.serializer.serialize([StringValue(token_identifier)]),
self.serializer.serialize([BigUIntValue(token_nonce)]),
user.to_hex()
]

return TransactionBuilder(
config=self._config,
sender=sender,
receiver=self._config.esdt_contract_address,
amount=0,
gas_limit=self._config.gas_limit_freeze_single_nft,
add_data_movement_gas=True,
data_parts=parts
).build()

def create_transaction_for_unfreezing_single_nft(self,
sender: Address,
token_identifier: str,
token_nonce: int,
user: Address) -> Transaction:
parts = [
"unFreezeSingleNFT",
self.serializer.serialize([StringValue(token_identifier)]),
self.serializer.serialize([BigUIntValue(token_nonce)]),
user.to_hex()
]

return TransactionBuilder(
config=self._config,
sender=sender,
receiver=self._config.esdt_contract_address,
amount=0,
gas_limit=self._config.gas_limit_unfreeze_single_nft,
add_data_movement_gas=True,
data_parts=parts
).build()

def create_transaction_for_changing_sft_to_meta_esdt(self,
sender: Address,
collection: str,
num_decimals: int) -> Transaction:
parts = [
"changeSFTToMetaESDT",
self.serializer.serialize([StringValue(collection)]),
self.serializer.serialize([BigUIntValue(num_decimals)])
]

return TransactionBuilder(
config=self._config,
sender=sender,
receiver=self._config.esdt_contract_address,
amount=0,
gas_limit=self._config.gas_limit_change_sft_to_meta_esdt,
add_data_movement_gas=True,
data_parts=parts
).build()

def create_transaction_for_transferring_nft_create_role(self,
sender: Address,
token_identifier: str,
user: Address) -> Transaction:
"""This role can be transferred only if the `canTransferNFTCreateRole` property of the token is set to `true`."""
parts = [
"transferNFTCreateRole",
self.serializer.serialize([StringValue(token_identifier)]),
sender.to_hex(),
user.to_hex()
]

return TransactionBuilder(
config=self._config,
sender=sender,
receiver=self._config.esdt_contract_address,
amount=0,
gas_limit=self._config.gas_limit_transfer_nft_create_role,
add_data_movement_gas=True,
data_parts=parts
).build()

def create_transaction_for_stopping_nft_creation(self,
sender: Address,
token_identifier: str) -> Transaction:
parts = [
"stopNFTCreate",
self.serializer.serialize([StringValue(token_identifier)])
]

return TransactionBuilder(
config=self._config,
sender=sender,
receiver=self._config.esdt_contract_address,
amount=0,
gas_limit=self._config.gas_limit_stop_nft_create,
add_data_movement_gas=True,
data_parts=parts
).build()

def create_transaction_for_wiping_single_nft(self,
sender: Address,
token_identifier: str,
token_nonce: int,
user: Address) -> Transaction:
parts = [
"wipeSingleNFT",
self.serializer.serialize([StringValue(token_identifier)]),
self.serializer.serialize([BigUIntValue(token_nonce)]),
user.to_hex()
]

return TransactionBuilder(
config=self._config,
sender=sender,
receiver=self._config.esdt_contract_address,
amount=0,
gas_limit=self._config.gas_limit_wipe_single_nft,
add_data_movement_gas=True,
data_parts=parts
).build()

def create_transction_for_adding_uris(self,
sender: Address,
token_identifier: str,
uris: list[str]) -> Transaction:
parts = ["ESDTNFTAddURI"]

serialized_parts = self.serializer.serialize_to_parts([
StringValue(token_identifier),
*map(StringValue, uris)
])

parts.extend([part.hex() for part in serialized_parts])

return TransactionBuilder(
config=self._config,
sender=sender,
receiver=sender,
amount=0,
gas_limit=self._config.gas_limit_esdt_nft_add_uri,
add_data_movement_gas=True,
data_parts=parts
).build()

def _bool_to_typed_string(self, value: bool) -> StringValue:
if value:
return StringValue("true")
Expand Down
Loading

0 comments on commit b6fe456

Please sign in to comment.