Skip to content
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

Remove factory method and fixes #156

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions multiversx_sdk/core/transaction_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions multiversx_sdk/core/transaction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}"""
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -73,29 +72,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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ allow-direct-references = true

[project]
name = "multiversx-sdk"
version = "0.16.3"
version = "0.17.0"
authors = [
{ name="MultiversX" },
]
Expand Down
Loading