Skip to content

Commit

Permalink
Merge pull request #459 from multiversx/fix-hardcoded-validators-address
Browse files Browse the repository at this point in the history
Fix hardcoded address to use config hrp
  • Loading branch information
popenta authored Dec 3, 2024
2 parents e467c0e + 3260310 commit 7aa66a1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion multiversx_sdk_cli/delegation/staking_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Transaction, ValidatorPublicKey)
from multiversx_sdk.core.serializer import args_to_string

from multiversx_sdk_cli.config import get_address_hrp
from multiversx_sdk_cli.errors import BadUsage
from multiversx_sdk_cli.interfaces import IAddress, ITransaction
from multiversx_sdk_cli.validators.validators_file import ValidatorsFile
Expand Down Expand Up @@ -408,7 +409,7 @@ def prepare_transaction_for_setting_metadata(self, owner: IAccount, args: Any) -
return tx

def prepare_transaction_for_creating_delegation_contract_from_validator(self, owner: IAccount, args: Any) -> ITransaction:
receiver = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"
receiver = Address.new_from_hex("000000000000000000010000000000000000000000000000000000000004ffff", get_address_hrp()).to_bech32()
max_cap = int(args.max_cap)
fee = int(args.fee)
data = "makeNewContractFromValidatorData@" + args_to_string([max_cap, fee])
Expand Down
30 changes: 15 additions & 15 deletions multiversx_sdk_cli/validators/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from multiversx_sdk_cli.accounts import Account
from multiversx_sdk_cli.cli_password import load_password
from multiversx_sdk_cli.config import (GAS_PER_DATA_BYTE, MIN_GAS_LIMIT,
MetaChainSystemSCsCost)
MetaChainSystemSCsCost, get_address_hrp)
from multiversx_sdk_cli.contracts import prepare_execute_transaction_data
from multiversx_sdk_cli.errors import BadUsage
from multiversx_sdk_cli.validators.validators_file import ValidatorsFile

logger = logging.getLogger("validators")

VALIDATORS_SMART_CONTRACT_ADDRESS = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqplllst77y4l"
VALIDATORS_SMART_CONTRACT_ADDRESS_HEX = "000000000000000000010000000000000000000000000000000000000001ffff"


def prepare_args_for_stake(args: Any):
Expand All @@ -36,7 +36,7 @@ def prepare_args_for_stake(args: Any):

data, gas_limit = prepare_transaction_data_for_stake(node_operator.address, validators_file_path, reward_address)
args.data = data
args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()

if args.estimate_gas:
args.gas_limit = gas_limit
Expand Down Expand Up @@ -74,7 +74,7 @@ def prepare_transaction_data_for_stake(node_operator_address: Address, validator

def prepare_args_for_top_up(args: Any):
args.data = 'stake'
args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()

if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.STAKE, 1)
Expand All @@ -83,7 +83,7 @@ def prepare_args_for_top_up(args: Any):
def prepare_args_for_unstake(args: Any):
parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys)
args.data = 'unStake' + parsed_keys
args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()

if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNSTAKE, num_keys)
Expand All @@ -92,7 +92,7 @@ def prepare_args_for_unstake(args: Any):
def prepare_args_for_unbond(args: Any):
parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys)
args.data = 'unBond' + parsed_keys
args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()

if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNBOND, num_keys)
Expand All @@ -101,7 +101,7 @@ def prepare_args_for_unbond(args: Any):
def prepare_args_for_unjail(args: Any):
parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys)
args.data = 'unJail' + parsed_keys
args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()

if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNJAIL, num_keys)
Expand All @@ -110,15 +110,15 @@ def prepare_args_for_unjail(args: Any):
def prepare_args_for_change_reward_address(args: Any):
reward_address = Address.new_from_bech32(args.reward_address)
args.data = 'changeRewardAddress@' + reward_address.hex()
args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()

if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.CHANGE_REWARD_ADDRESS)


def prepare_args_for_claim(args: Any):
args.data = 'claim'
args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()

if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.CLAIM)
Expand All @@ -128,7 +128,7 @@ def prepare_args_for_unstake_nodes(args: Any):
parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys)
args.data = 'unStakeNodes' + parsed_keys

args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()
if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNSTAKE, num_keys)

Expand All @@ -137,7 +137,7 @@ def prepare_args_for_unstake_tokens(args: Any):
args.data = 'unStakeTokens'
args.data += '@' + utils.str_int_to_hex_str(str(args.unstake_value))

args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()
if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNSTAKE_TOKENS)

Expand All @@ -146,7 +146,7 @@ def prepare_args_for_unbond_nodes(args: Any):
parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys)
args.data = 'unBondNodes' + parsed_keys

args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()
if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNBOND, num_keys)

Expand All @@ -155,15 +155,15 @@ def prepare_args_for_unbond_tokens(args: Any):
args.data = 'unBondTokens'
args.data += '@' + utils.str_int_to_hex_str(str(args.unbond_value))

args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()
if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNBOND_TOKENS)


def prepare_args_for_clean_registered_data(args: Any):
args.data = 'cleanRegisteredData'

args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()
if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.STAKE)

Expand All @@ -172,7 +172,7 @@ def prepare_args_for_restake_unstaked_nodes(args: Any):
parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys)
args.data = 'reStakeUnStakedNodes' + parsed_keys

args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS
args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32()
if args.estimate_gas:
args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.STAKE, num_keys)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "multiversx-sdk-cli"
version = "9.9.0"
version = "9.9.1"
authors = [
{ name="MultiversX" },
]
Expand Down

0 comments on commit 7aa66a1

Please sign in to comment.