From 13bf0cc559f18852e012d161f2b3be82b537cb5f Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 21 Nov 2024 17:47:11 +0200 Subject: [PATCH 1/2] remove factory method and fixes --- multiversx_sdk/core/transaction_computer.py | 3 +++ multiversx_sdk/core/transaction_test.py | 17 ++++++++++++ .../relayed_transactions_factory.py | 23 ---------------- .../relayed_transactions_factory_test.py | 26 ------------------- pyproject.toml | 2 +- 5 files changed, 21 insertions(+), 50 deletions(-) diff --git a/multiversx_sdk/core/transaction_computer.py b/multiversx_sdk/core/transaction_computer.py index 647c1b99..e6b5bc7e 100644 --- a/multiversx_sdk/core/transaction_computer.py +++ b/multiversx_sdk/core/transaction_computer.py @@ -126,6 +126,9 @@ def _to_dictionary(self, transaction: ITransaction, with_signature: bool = False if transaction.guardian: dictionary["guardian"] = transaction.guardian + if transaction.relayer: + dictionary["relayer"] = transaction.relayer + return dictionary def _dict_to_json(self, dictionary: Dict[str, Any]) -> bytes: diff --git a/multiversx_sdk/core/transaction_test.py b/multiversx_sdk/core/transaction_test.py index f6813fc5..8d59d697 100644 --- a/multiversx_sdk/core/transaction_test.py +++ b/multiversx_sdk/core/transaction_test.py @@ -345,3 +345,20 @@ def test_compute_bytes_for_verifying_transaction_signed_by_hash(self): assert is_signed_by_alice assert is_signed_by_bob is False + + def test_serialize_tx_with_relayed_v3(self): + sender = "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + relayer = "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + + transaction = Transaction( + nonce=89, + sender=sender, + receiver=sender, + value=0, + gas_limit=50000, + gas_price=1000000000, + chain_id="D", + relayer=relayer + ) + serialized_tx = self.transaction_computer.compute_bytes_for_signing(transaction) + assert serialized_tx.decode() == r"""{"nonce":89,"value":"0","receiver":"erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th","sender":"erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th","gasPrice":1000000000,"gasLimit":50000,"chainID":"D","version":2,"relayer":"erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"}""" diff --git a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py index 8dfe2fb4..72031c25 100644 --- a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py +++ b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py @@ -73,29 +73,6 @@ def create_relayed_v2_transaction(self, options=inner_transaction.options ) - def create_relayed_v3_transaction(self, - transaction: ITransaction, - relayer_address: IAddress) -> Transaction: - """Relayer address must be in the same shard with sender address.""" - gas_limit = transaction.gas_limit + self._config.extra_gas_limit_for_relayed_v3 - - return Transaction( - sender=transaction.sender, - receiver=transaction.receiver, - gas_limit=gas_limit, - chain_id=transaction.chain_id, - nonce=transaction.nonce, - value=transaction.value, - sender_username=transaction.sender_username, - receiver_username=transaction.receiver_username, - gas_price=transaction.gas_price, - data=transaction.data, - version=transaction.version, - options=transaction.options, - guardian=transaction.guardian, - relayer=relayer_address.to_bech32() - ) - def _prepare_inner_transaction_for_relayed_v1(self, inner_transaction: ITransaction) -> str: sender = Address.new_from_bech32(inner_transaction.sender).to_hex() receiver = Address.new_from_bech32(inner_transaction.receiver).to_hex() diff --git a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory_test.py b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory_test.py index 0faa03a8..056cf1e9 100644 --- a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory_test.py +++ b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory_test.py @@ -231,29 +231,3 @@ def test_compute_relayed_v2_transaction(self): assert relayed_transaction.options == 0 assert relayed_transaction.gas_limit == 60414500 assert relayed_transaction.data.decode() == "relayedTxV2@000000000000000000010000000000000000000000000000000000000002ffff@0f@676574436f6e7472616374436f6e666967@fc3ed87a51ee659f937c1a1ed11c1ae677e99629fae9cc289461f033e6514d1a8cfad1144ae9c1b70f28554d196bd6ba1604240c1c1dc19c959e96c1c3b62d0c" - - def test_relayed_v3(self): - alice = self.wallets["alice"] - alice_address = Address.new_from_bech32(alice.label) - bob = self.wallets["bob"] - - tx = Transaction( - sender=bob.label, - receiver="erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", - gas_limit=1_000_000, - chain_id=self.config.chain_id, - data=b"add@07", - nonce=15, - version=2, - options=0 - ) - - relayed_tx = self.factory.create_relayed_v3_transaction( - transaction=tx, - relayer_address=alice_address - ) - - assert relayed_tx.sender == bob.label - assert relayed_tx.receiver == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" - assert relayed_tx.relayer == alice.label - assert relayed_tx.gas_limit == 1_050_000 diff --git a/pyproject.toml b/pyproject.toml index dae7cf51..2eae3b17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ allow-direct-references = true [project] name = "multiversx-sdk" -version = "0.16.3" +version = "0.17.0" authors = [ { name="MultiversX" }, ] From 53ad3f3b972cfa4d943125fe8106872175310224 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Fri, 22 Nov 2024 09:22:26 +0200 Subject: [PATCH 2/2] remove config value for extra gas --- .../core/transactions_factories/relayed_transactions_factory.py | 1 - .../core/transactions_factories/transactions_factory_config.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py index 72031c25..0bb840f7 100644 --- a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py +++ b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py @@ -13,7 +13,6 @@ class IConfig(Protocol): chain_id: str min_gas_limit: int gas_limit_per_byte: int - extra_gas_limit_for_relayed_v3: int class RelayedTransactionsFactory: diff --git a/multiversx_sdk/core/transactions_factories/transactions_factory_config.py b/multiversx_sdk/core/transactions_factories/transactions_factory_config.py index dd311030..966681ac 100644 --- a/multiversx_sdk/core/transactions_factories/transactions_factory_config.py +++ b/multiversx_sdk/core/transactions_factories/transactions_factory_config.py @@ -60,5 +60,3 @@ def __init__(self, chain_id: str) -> None: # Configuration for smart contract operations self.gas_limit_claim_developer_rewards = 6_000_000 self.gas_limit_change_owner_address = 6_000_000 - - self.extra_gas_limit_for_relayed_v3 = 50_000