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

Removed validator pubkey interface #170

Merged
merged 2 commits into from
Dec 12, 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: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
},
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"python.languageServer": "Pylance"
"python.languageServer": "Pylance",
"black-formatter.args": ["--line-length=100"]
}
5 changes: 0 additions & 5 deletions multiversx_sdk/core/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ class INetworkConfig(Protocol):
gas_price_modifier: float


class IValidatorPublicKey(Protocol):
def hex(self) -> str:
...


class IAccount(Protocol):
@property
def address(self) -> Address:
Expand Down
1 change: 1 addition & 0 deletions multiversx_sdk/core/transaction_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self) -> None:
pass

def compute_transaction_fee(self, transaction: Transaction, network_config: INetworkConfig) -> int:
"""`TransactionsFactoryConfig` can be used here as the `network_config`."""
move_balance_gas = network_config.min_gas_limit + len(transaction.data) * network_config.gas_per_data_byte
if move_balance_gas > transaction.gas_limit:
raise NotEnoughGasError(transaction.gas_limit)
Expand Down
15 changes: 8 additions & 7 deletions multiversx_sdk/delegation/delegation_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from multiversx_sdk.core import (Address, Transaction, TransactionComputer,
TransactionOnNetwork,
TransactionsFactoryConfig)
from multiversx_sdk.core.interfaces import IAccount, IValidatorPublicKey
from multiversx_sdk.core.interfaces import IAccount
from multiversx_sdk.delegation.delegation_transactions_factory import \
DelegationTransactionsFactory
from multiversx_sdk.delegation.delegation_transactions_outcome_parser import \
DelegationTransactionsOutcomeParser
from multiversx_sdk.delegation.delegation_transactions_outcome_parser_types import \
CreateNewDelegationContractOutcome
from multiversx_sdk.network_providers.resources import AwaitingOptions
from multiversx_sdk.wallet.validator_keys import ValidatorPublicKey


class INetworkProvider(Protocol):
Expand Down Expand Up @@ -60,7 +61,7 @@ def create_transaction_for_adding_nodes(self,
sender: IAccount,
nonce: int,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey],
public_keys: Sequence[ValidatorPublicKey],
signed_messages: Sequence[bytes],
guardian: Optional[Address] = None,
relayer: Optional[Address] = None) -> Transaction:
Expand All @@ -82,7 +83,7 @@ def create_transaction_for_removing_nodes(self,
sender: IAccount,
nonce: int,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey],
public_keys: Sequence[ValidatorPublicKey],
guardian: Optional[Address] = None,
relayer: Optional[Address] = None) -> Transaction:
transaction = self.factory.create_transaction_for_removing_nodes(
Expand All @@ -102,7 +103,7 @@ def create_transaction_for_staking_nodes(self,
sender: IAccount,
nonce: int,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey],
public_keys: Sequence[ValidatorPublicKey],
guardian: Optional[Address] = None,
relayer: Optional[Address] = None) -> Transaction:
transaction = self.factory.create_transaction_for_staking_nodes(
Expand All @@ -122,7 +123,7 @@ def create_transaction_for_unbonding_nodes(self,
sender: IAccount,
nonce: int,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey],
public_keys: Sequence[ValidatorPublicKey],
guardian: Optional[Address] = None,
relayer: Optional[Address] = None) -> Transaction:
transaction = self.factory.create_transaction_for_unbonding_nodes(
Expand All @@ -142,7 +143,7 @@ def create_transaction_for_unstaking_nodes(self,
sender: IAccount,
nonce: int,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey],
public_keys: Sequence[ValidatorPublicKey],
guardian: Optional[Address] = None,
relayer: Optional[Address] = None) -> Transaction:
transaction = self.factory.create_transaction_for_unstaking_nodes(
Expand All @@ -162,7 +163,7 @@ def create_transaction_for_unjailing_nodes(self,
sender: IAccount,
nonce: int,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey],
public_keys: Sequence[ValidatorPublicKey],
amount: int,
guardian: Optional[Address] = None,
relayer: Optional[Address] = None) -> Transaction:
Expand Down
14 changes: 7 additions & 7 deletions multiversx_sdk/delegation/delegation_transactions_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from multiversx_sdk.builders.transaction_builder import TransactionBuilder
from multiversx_sdk.core import Address, Transaction
from multiversx_sdk.core.constants import DELEGATION_MANAGER_SC_ADDRESS_HEX
from multiversx_sdk.core.interfaces import IValidatorPublicKey
from multiversx_sdk.core.transactions_factory_config import \
TransactionsFactoryConfig
from multiversx_sdk.delegation.errors import ListsLengthMismatchError
from multiversx_sdk.wallet.validator_keys import ValidatorPublicKey


class DelegationTransactionsFactory:
Expand Down Expand Up @@ -46,7 +46,7 @@ def create_transaction_for_new_delegation_contract(self,
def create_transaction_for_adding_nodes(self,
sender: Address,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey],
public_keys: Sequence[ValidatorPublicKey],
signed_messages: Sequence[bytes]) -> Transaction:
if len(public_keys) != len(signed_messages):
raise ListsLengthMismatchError("The number of public keys should match the number of signed messages")
Expand Down Expand Up @@ -75,7 +75,7 @@ def _compute_execution_gas_limit_for_nodes_management(self, num_nodes: int) -> i
def create_transaction_for_removing_nodes(self,
sender: Address,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey]) -> Transaction:
public_keys: Sequence[ValidatorPublicKey]) -> Transaction:
num_nodes = len(public_keys)

parts = ["removeNodes"]
Expand All @@ -96,7 +96,7 @@ def create_transaction_for_removing_nodes(self,
def create_transaction_for_staking_nodes(self,
sender: Address,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey]) -> Transaction:
public_keys: Sequence[ValidatorPublicKey]) -> Transaction:
num_nodes = len(public_keys)

parts = ["stakeNodes"]
Expand All @@ -118,7 +118,7 @@ def create_transaction_for_staking_nodes(self,
def create_transaction_for_unbonding_nodes(self,
sender: Address,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey]) -> Transaction:
public_keys: Sequence[ValidatorPublicKey]) -> Transaction:
num_nodes = len(public_keys)

parts = ["unBondNodes"]
Expand All @@ -140,7 +140,7 @@ def create_transaction_for_unbonding_nodes(self,
def create_transaction_for_unstaking_nodes(self,
sender: Address,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey]) -> Transaction:
public_keys: Sequence[ValidatorPublicKey]) -> Transaction:
num_nodes = len(public_keys)

parts = ["unStakeNodes"]
Expand All @@ -162,7 +162,7 @@ def create_transaction_for_unstaking_nodes(self,
def create_transaction_for_unjailing_nodes(self,
sender: Address,
delegation_contract: Address,
public_keys: Sequence[IValidatorPublicKey],
public_keys: Sequence[ValidatorPublicKey],
amount: int) -> Transaction:
num_nodes = len(public_keys)

Expand Down
22 changes: 12 additions & 10 deletions multiversx_sdk/delegation/delegation_transactions_factory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from multiversx_sdk.delegation import DelegationTransactionsFactory
from multiversx_sdk.wallet import ValidatorSecretKey, ValidatorSigner

from multiversx_sdk.wallet.validator_keys import ValidatorPublicKey


class TestDelegationTransactionsFactory:
config = TransactionsFactoryConfig("D")
Expand Down Expand Up @@ -54,7 +56,7 @@ def test_create_transaction_for_removing_nodes(self):
sender = Address.new_from_bech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2")
delegation_contract = Address.new_from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc")

public_keys = ["notavalidblskeyhexencoded".encode()]
public_keys = [ValidatorPublicKey(bytes([0] * 96))]

transaction = self.factory.create_transaction_for_removing_nodes(
sender=sender,
Expand All @@ -65,14 +67,14 @@ def test_create_transaction_for_removing_nodes(self):
assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"
assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"
assert transaction.data
assert transaction.data.decode() == "removeNodes@6e6f746176616c6964626c736b6579686578656e636f646564"
assert transaction.data.decode() == "removeNodes@000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
assert transaction.value == 0

def test_create_transaction_for_staking_nodes(self):
sender = Address.new_from_bech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2")
delegation_contract = Address.new_from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc")

public_keys = ["notavalidblskeyhexencoded".encode()]
public_keys = [ValidatorPublicKey(bytes([0] * 96))]

transaction = self.factory.create_transaction_for_staking_nodes(
sender=sender,
Expand All @@ -83,14 +85,14 @@ def test_create_transaction_for_staking_nodes(self):
assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"
assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"
assert transaction.data
assert transaction.data.decode() == "stakeNodes@6e6f746176616c6964626c736b6579686578656e636f646564"
assert transaction.data.decode() == "stakeNodes@000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
assert transaction.value == 0

def test_create_transaction_for_unbonding_nodes(self):
sender = Address.new_from_bech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2")
delegation_contract = Address.new_from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc")

public_keys = ["notavalidblskeyhexencoded".encode()]
public_keys = [ValidatorPublicKey(bytes([0] * 96))]

transaction = self.factory.create_transaction_for_unbonding_nodes(
sender=sender,
Expand All @@ -101,14 +103,14 @@ def test_create_transaction_for_unbonding_nodes(self):
assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"
assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"
assert transaction.data
assert transaction.data.decode() == "unBondNodes@6e6f746176616c6964626c736b6579686578656e636f646564"
assert transaction.data.decode() == "unBondNodes@000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
assert transaction.value == 0

def test_create_transaction_for_unstaking_nodes(self):
sender = Address.new_from_bech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2")
delegation_contract = Address.new_from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc")

public_keys = ["notavalidblskeyhexencoded".encode()]
public_keys = [ValidatorPublicKey(bytes([0] * 96))]

transaction = self.factory.create_transaction_for_unstaking_nodes(
sender=sender,
Expand All @@ -119,14 +121,14 @@ def test_create_transaction_for_unstaking_nodes(self):
assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"
assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"
assert transaction.data
assert transaction.data.decode() == "unStakeNodes@6e6f746176616c6964626c736b6579686578656e636f646564"
assert transaction.data.decode() == "unStakeNodes@000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
assert transaction.value == 0

def test_create_transaction_for_unjailing_nodes(self):
sender = Address.new_from_bech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2")
delegation_contract = Address.new_from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc")

public_keys = ["notavalidblskeyhexencoded".encode()]
public_keys = [ValidatorPublicKey(bytes([0] * 96))]

transaction = self.factory.create_transaction_for_unjailing_nodes(
sender=sender,
Expand All @@ -138,7 +140,7 @@ def test_create_transaction_for_unjailing_nodes(self):
assert transaction.sender.to_bech32() == "erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"
assert transaction.receiver.to_bech32() == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"
assert transaction.data
assert transaction.data.decode() == "unJailNodes@6e6f746176616c6964626c736b6579686578656e636f646564"
assert transaction.data.decode() == "unJailNodes@000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
assert transaction.value == 25000000000000000000

def test_create_transaction_for_changing_service_fee(self):
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pytest
pytest-cov
flake8
autopep8
black
pre-commit
ipykernel
sphinx
Expand Down
Loading