diff --git a/examples/Cookbook.ipynb b/examples/Cookbook.ipynb index 6dfa8ae5..264230b5 100644 --- a/examples/Cookbook.ipynb +++ b/examples/Cookbook.ipynb @@ -789,70 +789,6 @@ "print(transaction_converter.transaction_to_dictionary(relayed_tx))" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Relayed V3\n", - "\n", - "This is the latest iteration of relayed transactions and we highly recommend using this version over the previous ones as soon as it becomes available on the network." - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'nonce': 0, 'value': '0', 'receiver': 'erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th', 'sender': 'erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th', 'senderUsername': '', 'receiverUsername': '', 'gasPrice': 1000000000, 'gasLimit': 110000, 'data': '', 'chainID': 'D', 'version': 2, 'options': 0, 'guardian': '', 'signature': '', 'guardianSignature': '', 'relayer': '', 'innerTransactions': [{'nonce': 15, 'value': '0', 'receiver': 'erd1qqqqqqqqqqqqqpgqqczn0ccd2gh8eqdswln7w9vzctv0dwq7d8ssm4y34z', 'sender': 'erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx', 'senderUsername': '', 'receiverUsername': '', 'gasPrice': 1000000000, 'gasLimit': 60000, 'data': 'aGVsbG8=', 'chainID': 'D', 'version': 2, 'options': 0, 'guardian': '', 'signature': '730ae25bda39d5aaa25cc6f8e27c1cc5fa67869464559187dcdd02e22b88e561bf4660718791200a37290d2ff8c73449c1ef6ef38ddce7b36c89931d8fa2f10b', 'guardianSignature': '', 'relayer': 'erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th', 'innerTransactions': []}]}\n" - ] - } - ], - "source": [ - "from pathlib import Path\n", - "\n", - "from multiversx_sdk import (Address, RelayedTransactionsFactory, Transaction,\n", - " TransactionComputer, TransactionsFactoryConfig,\n", - " UserSigner)\n", - "\n", - "bob = UserSigner.from_pem_file(Path(\"../multiversx_sdk/testutils/testwallets/bob.pem\"))\n", - "relayer = Address.new_from_bech32(\"erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th\")\n", - "\n", - "inner_tx = Transaction(\n", - " chain_id=network_config.chain_id,\n", - " sender=\"erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx\",\n", - " receiver=\"erd1qqqqqqqqqqqqqpgqqczn0ccd2gh8eqdswln7w9vzctv0dwq7d8ssm4y34z\",\n", - " gas_limit=60000,\n", - " nonce=15,\n", - " data=b\"hello\",\n", - " relayer=relayer.to_bech32()\n", - " )\n", - "transaction_computer = TransactionComputer()\n", - "inner_tx.signature = bob.sign(transaction_computer.compute_bytes_for_signing(inner_tx))\n", - "\n", - "config = TransactionsFactoryConfig(chain_id=\"D\")\n", - "factory = RelayedTransactionsFactory(config=config)\n", - "\n", - "relayed_tx = factory.create_relayed_v3_transaction(\n", - " relayer_address=relayer,\n", - " inner_transactions=[inner_tx]\n", - ")\n", - "\n", - "print(transaction_converter.transaction_to_dictionary(relayed_tx))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A few things worth mentioning before moving further, the `data` field of the relayer's transaction **should not** be set and the relayer should be in the same shard as the sender of the inner transaction.\n", - "\n", - "Don't forget, after the Relayed V3 transaction is created, the `nonce` needs to be set and the transaction should be signed before broadcasting it." - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/multiversx_sdk/converters/transactions_converter.py b/multiversx_sdk/converters/transactions_converter.py index a074992c..dd0b1481 100644 --- a/multiversx_sdk/converters/transactions_converter.py +++ b/multiversx_sdk/converters/transactions_converter.py @@ -33,9 +33,7 @@ def transaction_to_dictionary(self, transaction: ITransaction) -> Dict[str, Any] "options": transaction.options, "guardian": transaction.guardian, "signature": self._value_to_hex_or_empty(transaction.signature), - "guardianSignature": self._value_to_hex_or_empty(transaction.guardian_signature), - "relayer": transaction.relayer, - "innerTransactions": [self.transaction_to_dictionary(inner_tx) for inner_tx in transaction.inner_transactions] + "guardianSignature": self._value_to_hex_or_empty(transaction.guardian_signature) } def dictionary_to_transaction(self, dictionary: Dict[str, Any]) -> Transaction: @@ -57,8 +55,6 @@ def dictionary_to_transaction(self, dictionary: Dict[str, Any]) -> Transaction: options=dictionary.get("options", None), signature=self._bytes_from_hex(dictionary.get("signature", "")), guardian_signature=self._bytes_from_hex(dictionary.get("guardianSignature", "")), - relayer=dictionary.get("relayer", None), - inner_transactions=[self.dictionary_to_transaction(inner_tx) for inner_tx in dictionary.get("innerTransactions", [])], ) def transaction_on_network_to_outcome(self, transaction_on_network: TransactionOnNetwork) -> TransactionOutcome: diff --git a/multiversx_sdk/converters/transactions_converter_test.py b/multiversx_sdk/converters/transactions_converter_test.py index 54be7994..3f78a1bf 100644 --- a/multiversx_sdk/converters/transactions_converter_test.py +++ b/multiversx_sdk/converters/transactions_converter_test.py @@ -43,37 +43,6 @@ def test_transaction_converter(): assert transaction == restored_tx -def test_transaction_from_dictionary_with_inner_transaction(): - converter = TransactionsConverter() - - inner_transaction = Transaction( - nonce=90, - value=123456789000000000000000000000, - sender="erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - receiver="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", - sender_username="alice", - receiver_username="bob", - gas_limit=80000, - data=b"hello", - chain_id="localnet", - relayer="erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" - ) - - relayed_transaction = Transaction( - nonce=77, - sender="erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8", - receiver="erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8", - gas_limit=180000, - chain_id="localnet", - inner_transactions=[inner_transaction] - ) - - tx_as_dict = converter.transaction_to_dictionary(relayed_transaction) - restored_tx = converter.dictionary_to_transaction(tx_as_dict) - - assert relayed_transaction == restored_tx - - def test_convert_tx_on_network_to_outcome(): converter = TransactionsConverter() diff --git a/multiversx_sdk/core/interfaces.py b/multiversx_sdk/core/interfaces.py index aeb0065d..47aeb20e 100644 --- a/multiversx_sdk/core/interfaces.py +++ b/multiversx_sdk/core/interfaces.py @@ -1,4 +1,4 @@ -from typing import Optional, Protocol, Sequence +from typing import Optional, Protocol class IAddress(Protocol): @@ -25,11 +25,6 @@ class ITransaction(Protocol): guardian: str signature: bytes guardian_signature: bytes - relayer: str - - @property - def inner_transactions(self) -> Sequence["ITransaction"]: - ... class IMessage(Protocol): diff --git a/multiversx_sdk/core/proto/transaction.proto b/multiversx_sdk/core/proto/transaction.proto index c72428c4..6e38de1f 100644 --- a/multiversx_sdk/core/proto/transaction.proto +++ b/multiversx_sdk/core/proto/transaction.proto @@ -21,6 +21,4 @@ message Transaction { uint32 Options = 13; bytes GuardAddr = 14; bytes GuardSignature = 15; - bytes Relayer = 16; - repeated Transaction InnerTransactions = 17; } diff --git a/multiversx_sdk/core/proto/transaction_pb2.py b/multiversx_sdk/core/proto/transaction_pb2.py index cc245c33..3e3b677a 100644 --- a/multiversx_sdk/core/proto/transaction_pb2.py +++ b/multiversx_sdk/core/proto/transaction_pb2.py @@ -2,23 +2,24 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: transaction.proto """Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder - # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x11transaction.proto\x12\x05proto\"\xda\x02\n\x0bTransaction\x12\r\n\x05Nonce\x18\x01 \x01(\x04\x12\r\n\x05Value\x18\x02 \x01(\x0c\x12\x0f\n\x07RcvAddr\x18\x03 \x01(\x0c\x12\x13\n\x0bRcvUserName\x18\x04 \x01(\x0c\x12\x0f\n\x07SndAddr\x18\x05 \x01(\x0c\x12\x13\n\x0bSndUserName\x18\x06 \x01(\x0c\x12\x10\n\x08GasPrice\x18\x07 \x01(\x04\x12\x10\n\x08GasLimit\x18\x08 \x01(\x04\x12\x0c\n\x04\x44\x61ta\x18\t \x01(\x0c\x12\x0f\n\x07\x43hainID\x18\n \x01(\x0c\x12\x0f\n\x07Version\x18\x0b \x01(\r\x12\x11\n\tSignature\x18\x0c \x01(\x0c\x12\x0f\n\x07Options\x18\r \x01(\r\x12\x11\n\tGuardAddr\x18\x0e \x01(\x0c\x12\x16\n\x0eGuardSignature\x18\x0f \x01(\x0c\x12\x0f\n\x07Relayer\x18\x10 \x01(\x0c\x12-\n\x11InnerTransactions\x18\x11 \x03(\x0b\x32\x12.proto.Transactionb\x06proto3') + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x11transaction.proto\x12\x05proto\"\x9a\x02\n\x0bTransaction\x12\r\n\x05Nonce\x18\x01 \x01(\x04\x12\r\n\x05Value\x18\x02 \x01(\x0c\x12\x0f\n\x07RcvAddr\x18\x03 \x01(\x0c\x12\x13\n\x0bRcvUserName\x18\x04 \x01(\x0c\x12\x0f\n\x07SndAddr\x18\x05 \x01(\x0c\x12\x13\n\x0bSndUserName\x18\x06 \x01(\x0c\x12\x10\n\x08GasPrice\x18\x07 \x01(\x04\x12\x10\n\x08GasLimit\x18\x08 \x01(\x04\x12\x0c\n\x04\x44\x61ta\x18\t \x01(\x0c\x12\x0f\n\x07\x43hainID\x18\n \x01(\x0c\x12\x0f\n\x07Version\x18\x0b \x01(\r\x12\x11\n\tSignature\x18\x0c \x01(\x0c\x12\x0f\n\x07Options\x18\r \x01(\r\x12\x11\n\tGuardAddr\x18\x0e \x01(\x0c\x12\x16\n\x0eGuardSignature\x18\x0f \x01(\x0c\x62\x06proto3') _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'transaction_pb2', globals()) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _TRANSACTION._serialized_start = 29 # pyright: ignore[reportUndefinedVariable] - _TRANSACTION._serialized_end = 375 # pyright: ignore[reportUndefinedVariable] + DESCRIPTOR._options = None + _TRANSACTION._serialized_start=29 # pyright: ignore[reportUndefinedVariable] + _TRANSACTION._serialized_end=311 # pyright: ignore[reportUndefinedVariable] # @@protoc_insertion_point(module_scope) diff --git a/multiversx_sdk/core/proto/transaction_pb2.pyi b/multiversx_sdk/core/proto/transaction_pb2.pyi index ce06fad9..047a4fc8 100644 --- a/multiversx_sdk/core/proto/transaction_pb2.pyi +++ b/multiversx_sdk/core/proto/transaction_pb2.pyi @@ -1,12 +1,11 @@ -from google.protobuf.internal import containers as _containers from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message -from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union +from typing import ClassVar as _ClassVar, Optional as _Optional DESCRIPTOR: _descriptor.FileDescriptor class Transaction(_message.Message): - __slots__ = ["ChainID", "Data", "GasLimit", "GasPrice", "GuardAddr", "GuardSignature", "InnerTransactions", "Nonce", "Options", "RcvAddr", "RcvUserName", "Relayer", "Signature", "SndAddr", "SndUserName", "Value", "Version"] + __slots__ = ["ChainID", "Data", "GasLimit", "GasPrice", "GuardAddr", "GuardSignature", "Nonce", "Options", "RcvAddr", "RcvUserName", "Signature", "SndAddr", "SndUserName", "Value", "Version"] CHAINID_FIELD_NUMBER: _ClassVar[int] ChainID: bytes DATA_FIELD_NUMBER: _ClassVar[int] @@ -19,18 +18,14 @@ class Transaction(_message.Message): GasPrice: int GuardAddr: bytes GuardSignature: bytes - INNERTRANSACTIONS_FIELD_NUMBER: _ClassVar[int] - InnerTransactions: _containers.RepeatedCompositeFieldContainer[Transaction] NONCE_FIELD_NUMBER: _ClassVar[int] Nonce: int OPTIONS_FIELD_NUMBER: _ClassVar[int] Options: int RCVADDR_FIELD_NUMBER: _ClassVar[int] RCVUSERNAME_FIELD_NUMBER: _ClassVar[int] - RELAYER_FIELD_NUMBER: _ClassVar[int] RcvAddr: bytes RcvUserName: bytes - Relayer: bytes SIGNATURE_FIELD_NUMBER: _ClassVar[int] SNDADDR_FIELD_NUMBER: _ClassVar[int] SNDUSERNAME_FIELD_NUMBER: _ClassVar[int] @@ -41,4 +36,4 @@ class Transaction(_message.Message): VERSION_FIELD_NUMBER: _ClassVar[int] Value: bytes Version: int - def __init__(self, Nonce: _Optional[int] = ..., Value: _Optional[bytes] = ..., RcvAddr: _Optional[bytes] = ..., RcvUserName: _Optional[bytes] = ..., SndAddr: _Optional[bytes] = ..., SndUserName: _Optional[bytes] = ..., GasPrice: _Optional[int] = ..., GasLimit: _Optional[int] = ..., Data: _Optional[bytes] = ..., ChainID: _Optional[bytes] = ..., Version: _Optional[int] = ..., Signature: _Optional[bytes] = ..., Options: _Optional[int] = ..., GuardAddr: _Optional[bytes] = ..., GuardSignature: _Optional[bytes] = ..., Relayer: _Optional[bytes] = ..., InnerTransactions: _Optional[_Iterable[_Union[Transaction, _Mapping]]] = ...) -> None: ... # pyright: ignore + def __init__(self, Nonce: _Optional[int] = ..., Value: _Optional[bytes] = ..., RcvAddr: _Optional[bytes] = ..., RcvUserName: _Optional[bytes] = ..., SndAddr: _Optional[bytes] = ..., SndUserName: _Optional[bytes] = ..., GasPrice: _Optional[int] = ..., GasLimit: _Optional[int] = ..., Data: _Optional[bytes] = ..., ChainID: _Optional[bytes] = ..., Version: _Optional[int] = ..., Signature: _Optional[bytes] = ..., Options: _Optional[int] = ..., GuardAddr: _Optional[bytes] = ..., GuardSignature: _Optional[bytes] = ...) -> None: ... diff --git a/multiversx_sdk/core/proto/transaction_serializer.py b/multiversx_sdk/core/proto/transaction_serializer.py index 070bad1e..b0176a0e 100644 --- a/multiversx_sdk/core/proto/transaction_serializer.py +++ b/multiversx_sdk/core/proto/transaction_serializer.py @@ -1,4 +1,4 @@ -from typing import Protocol, Sequence +from typing import Protocol import multiversx_sdk.core.proto.transaction_pb2 as ProtoTransaction from multiversx_sdk.core.address import Address @@ -21,11 +21,6 @@ class ITransaction(Protocol): guardian: str signature: bytes guardian_signature: bytes - relayer: str - - @property - def inner_transactions(self) -> Sequence["ITransaction"]: - ... class ProtoSerializer: @@ -71,10 +66,4 @@ def convert_to_proto_message(self, transaction: ITransaction) -> ProtoTransactio proto_transaction.GuardAddr = Address.new_from_bech32(guardian_address).get_public_key() proto_transaction.GuardSignature = transaction.guardian_signature - if transaction.relayer != "": - proto_transaction.Relayer = Address.new_from_bech32(transaction.relayer).get_public_key() - - proto_transaction.InnerTransactions.extend( - [self.convert_to_proto_message(inner_tx) for inner_tx in transaction.inner_transactions]) - return proto_transaction diff --git a/multiversx_sdk/core/proto/transaction_serializer_test.py b/multiversx_sdk/core/proto/transaction_serializer_test.py index b6ec0386..1ec470a9 100644 --- a/multiversx_sdk/core/proto/transaction_serializer_test.py +++ b/multiversx_sdk/core/proto/transaction_serializer_test.py @@ -86,34 +86,3 @@ def test_serialized_tx_with_usernames(self): serialized_transaction = self.proto_serializer.serialize_transaction(transaction) assert serialized_transaction.hex() == "08cc011209000de0b6b3a76400001a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e12205616c6963652a20b2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba32056361726f6c388094ebdc0340d086035201545802624051e6cd78fb3ab4b53ff7ad6864df27cb4a56d70603332869d47a5cf6ea977c30e696103e41e8dddf2582996ad335229fdf4acb726564dbc1a0bc9e705b511f06" - - def test_serialized_tx_with_inner_txs(self): - inner_transaction = Transaction( - sender=self.carol.label, - receiver=self.alice.label, - gas_limit=50000, - chain_id="T", - nonce=204, - value=1000000000000000000, - sender_username="carol", - receiver_username="alice" - ) - inner_transaction.signature = self.carol.secret_key.sign(self.transaction_computer.compute_bytes_for_signing(inner_transaction)) - - relayed_transaction = Transaction( - sender=self.carol.label, - receiver=self.alice.label, - gas_limit=50000, - chain_id="T", - nonce=204, - value=1000000000000000000, - sender_username="carol", - receiver_username="alice", - relayer=self.carol.label, - inner_transactions=[inner_transaction] - ) - - relayed_transaction.signature = self.carol.secret_key.sign(self.transaction_computer.compute_bytes_for_signing( - relayed_transaction)) - serialized_transaction = self.proto_serializer.serialize_transaction(relayed_transaction) - assert serialized_transaction.hex() == "08cc011209000de0b6b3a76400001a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e12205616c6963652a20b2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba32056361726f6c388094ebdc0340d0860352015458026240901a6a974d6ab36546e7881c6e0364ec4c61a891aa70e5eb60f818d6c92a39cfa0beac6fab73f503853cfe8fe6149b4be207ddb93788f8450d75a07fa8759d06820120b2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba8a01b10108cc011209000de0b6b3a76400001a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e12205616c6963652a20b2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba32056361726f6c388094ebdc0340d086035201545802624051e6cd78fb3ab4b53ff7ad6864df27cb4a56d70603332869d47a5cf6ea977c30e696103e41e8dddf2582996ad335229fdf4acb726564dbc1a0bc9e705b511f06" diff --git a/multiversx_sdk/core/transaction.py b/multiversx_sdk/core/transaction.py index 103fe65a..0f87e289 100644 --- a/multiversx_sdk/core/transaction.py +++ b/multiversx_sdk/core/transaction.py @@ -1,9 +1,8 @@ -from typing import Optional, Sequence +from typing import Optional from multiversx_sdk.core.constants import (TRANSACTION_MIN_GAS_PRICE, TRANSACTION_OPTIONS_DEFAULT, TRANSACTION_VERSION_DEFAULT) -from multiversx_sdk.core.interfaces import ITransaction class Transaction: @@ -22,9 +21,7 @@ def __init__(self, options: Optional[int] = None, guardian: Optional[str] = None, signature: Optional[bytes] = None, - guardian_signature: Optional[bytes] = None, - relayer: Optional[str] = None, - inner_transactions: Optional[Sequence[ITransaction]] = None) -> None: + guardian_signature: Optional[bytes] = None) -> None: self.chain_id = chain_id self.sender = sender self.receiver = receiver @@ -44,8 +41,6 @@ def __init__(self, self.guardian = guardian or "" self.guardian_signature = guardian_signature or bytes() - self.relayer = relayer or "" - self.inner_transactions = inner_transactions or [] def __eq__(self, other: object) -> bool: if not isinstance(other, Transaction): diff --git a/multiversx_sdk/core/transaction_computer.py b/multiversx_sdk/core/transaction_computer.py index c34ac590..647c1b99 100644 --- a/multiversx_sdk/core/transaction_computer.py +++ b/multiversx_sdk/core/transaction_computer.py @@ -126,14 +126,6 @@ def _to_dictionary(self, transaction: ITransaction, with_signature: bool = False if transaction.guardian: dictionary["guardian"] = transaction.guardian - if transaction.relayer: - dictionary["relayer"] = transaction.relayer - - if len(transaction.inner_transactions): - dictionary["innerTransactions"] = [ - self._to_dictionary(transaction=tx, with_signature=True) for tx in transaction.inner_transactions - ] - 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 e7f56503..f6813fc5 100644 --- a/multiversx_sdk/core/transaction_test.py +++ b/multiversx_sdk/core/transaction_test.py @@ -317,8 +317,8 @@ def test_compute_bytes_for_verifying_signature(self): signature=tx.signature ) - assert is_signed_by_alice == True - assert is_signed_by_bob == False + assert is_signed_by_alice + assert is_signed_by_bob is False def test_compute_bytes_for_verifying_transaction_signed_by_hash(self): tx = Transaction( @@ -343,5 +343,5 @@ def test_compute_bytes_for_verifying_transaction_signed_by_hash(self): signature=tx.signature ) - assert is_signed_by_alice == True - assert is_signed_by_bob == False + assert is_signed_by_alice + assert is_signed_by_bob is False diff --git a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py index 3ad93e10..0bb840f7 100644 --- a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py +++ b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory.py @@ -1,6 +1,6 @@ import base64 import json -from typing import Any, Dict, List, Protocol, Sequence +from typing import Any, Dict, List, Protocol from multiversx_sdk.core.address import Address from multiversx_sdk.core.errors import InvalidInnerTransactionError @@ -72,34 +72,6 @@ def create_relayed_v2_transaction(self, options=inner_transaction.options ) - def create_relayed_v3_transaction(self, - relayer_address: IAddress, - inner_transactions: Sequence[ITransaction]) -> Transaction: - if len(inner_transactions) == 0: - raise InvalidInnerTransactionError("The are no inner transactions") - - inner_txs_gas_limit = 0 - for inner_transaction in inner_transactions: - if not inner_transaction.signature: - raise InvalidInnerTransactionError("The inner transaction is not signed") - - if inner_transaction.relayer != relayer_address.to_bech32(): - raise InvalidInnerTransactionError("The inner transaction has an incorrect relayer address") - - inner_txs_gas_limit += inner_transaction.gas_limit - - move_balances_gas = self._config.min_gas_limit * len(inner_transactions) - gas_limit = move_balances_gas + inner_txs_gas_limit - - return Transaction( - sender=relayer_address.to_bech32(), - receiver=relayer_address.to_bech32(), - value=0, - gas_limit=gas_limit, - chain_id=self._config.chain_id, - inner_transactions=inner_transactions, - ) - 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 e12fdb54..056cf1e9 100644 --- a/multiversx_sdk/core/transactions_factories/relayed_transactions_factory_test.py +++ b/multiversx_sdk/core/transactions_factories/relayed_transactions_factory_test.py @@ -1,5 +1,3 @@ -from typing import List - import pytest from multiversx_sdk.core.address import Address @@ -233,75 +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_compute_relayed_v3_transaction(self): - alice = self.wallets["alice"] - bob = self.wallets["bob"] - - inner_transaction = Transaction( - sender=bob.label, - receiver=bob.label, - gas_limit=50000, - chain_id="T", - nonce=0, - version=2, - relayer=alice.label - ) - - inner_transactions = [inner_transaction] - serialized_inner_transaction = self.transaction_computer.compute_bytes_for_signing(inner_transaction) - inner_transaction.signature = bob.secret_key.sign(serialized_inner_transaction) - - relayed_transaction = self.factory.create_relayed_v3_transaction( - relayer_address=Address.from_bech32(alice.label), - inner_transactions=inner_transactions - ) - serialized_relayed_transaction = self.transaction_computer.compute_bytes_for_signing(relayed_transaction) - relayed_transaction.signature = alice.secret_key.sign(serialized_relayed_transaction) - assert relayed_transaction.signature.hex() == "88b9bce6fe62a641fca593f95c12ad09032a44b34c9e5cf16d070f0563b1695bf9d452a9df52bce3373fd5e10ed96c3d65cd189f5873e3a3184a89f4980c9e0c" - assert relayed_transaction.gas_limit == 100000 - - def test_create_relayed_v3_with_invalid_inner_tx(self): - alice = self.wallets["alice"] - bob = self.wallets["bob"] - - inner_transaction = Transaction( - sender=bob.label, - receiver="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", - gas_limit=2500, - chain_id="local-testnet", - nonce=0, - version=2, - relayer="erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" - ) - - serialized_inner_transaction = self.transaction_computer.compute_bytes_for_signing(inner_transaction) - inner_transaction.signature = bob.secret_key.sign(serialized_inner_transaction) - - inner_transactions = [inner_transaction] - - """ - In the inner tx, the relayer address is acutally bob's. The creation should fail - """ - with pytest.raises(InvalidInnerTransactionError) as err: - self.factory.create_relayed_v3_transaction( - relayer_address=Address.from_bech32(alice.label), - inner_transactions=inner_transactions - ) - assert str(err.value) == "The inner transaction has an incorrect relayer address" - - inner_transaction.signature = b"" - with pytest.raises(InvalidInnerTransactionError) as err: - self.factory.create_relayed_v3_transaction( - relayer_address=Address.from_bech32(alice.label), - inner_transactions=inner_transactions - ) - assert str(err.value) == "The inner transaction is not signed" - - inner_transactions: List[Transaction] = [] - with pytest.raises(InvalidInnerTransactionError) as err: - self.factory.create_relayed_v3_transaction( - relayer_address=Address.from_bech32(alice.label), - inner_transactions=inner_transactions - ) - assert str(err.value) == "The are no inner transactions" diff --git a/multiversx_sdk/network_providers/transactions.py b/multiversx_sdk/network_providers/transactions.py index 661be9f8..a03264d9 100644 --- a/multiversx_sdk/network_providers/transactions.py +++ b/multiversx_sdk/network_providers/transactions.py @@ -1,5 +1,5 @@ import base64 -from typing import Any, Dict, Optional, Protocol, Sequence +from typing import Any, Dict, Optional, Protocol from multiversx_sdk.core.address import Address from multiversx_sdk.network_providers.contract_results import ContractResults @@ -28,11 +28,6 @@ class ITransaction(Protocol): guardian: str signature: bytes guardian_signature: bytes - relayer: str - - @property - def inner_transactions(self) -> Sequence["ITransaction"]: - ... class TransactionOnNetwork: diff --git a/pyproject.toml b/pyproject.toml index d66bad14..8da78b39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ allow-direct-references = true [project] name = "multiversx-sdk" -version = "0.14.0" +version = "0.15.0" authors = [ { name="MultiversX" }, ]