Skip to content

Commit

Permalink
Merge pull request #423 from multiversx/main
Browse files Browse the repository at this point in the history
Main into feat/next
  • Loading branch information
andreibancioiu authored Apr 22, 2024
2 parents 106bde2 + 6783cd1 commit 4329ab3
Show file tree
Hide file tree
Showing 34 changed files with 1,029 additions and 175 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/install-macos.yml

This file was deleted.

31 changes: 0 additions & 31 deletions .github/workflows/install-ubuntu.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/install-windows.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/test-localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ jobs:
python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml
python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml --stop-after-seconds=120
if grep -r --include=\*.log "started committing block" ./localnet; then
echo "The localnet processed blocks successfully."
else
echo "The localnet failed to process blocks."
exit 1
fi
- name: Smoke test (with resolution == local)
run: |
mkdir -p ~/multiversx-sdk/sandbox
Expand All @@ -65,3 +72,10 @@ jobs:
python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_local.toml
python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_local.toml
python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_local.toml --stop-after-seconds=120
if grep -r --include=\*.log "started committing block" ./localnet; then
echo "The localnet processed blocks successfully."
else
echo "The localnet failed to process blocks."
exit 1
fi
625 changes: 625 additions & 0 deletions CLI.md

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions CLI.md.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ generate() {
command "Validator.ChangeRewardAddress" "validator change-reward-address"
command "Validator.Claim" "validator claim"

group "StakingProvider" "staking-provider"
command "StakingProvider.CreateNewDelegationContract" "staking-provider create-new-delegation-contract"
command "StakingProvider.GetContractAddress" "staking-provider get-contract-address"
command "StakingProvider.AddNodes" "staking-provider add-nodes"
command "StakingProvider.RemoveNodes" "staking-provider remove-nodes"
command "StakingProvider.StakeNodes" "staking-provider stake-nodes"
command "StakingProvider.UnbondNodes" "staking-provider unbond-nodes"
command "StakingProvider.UnstakeNodes" "staking-provider unstake-nodes"
command "StakingProvider.UnjailNodes" "staking-provider unjail-nodes"
command "StakingProvider.ChangeServiceFee" "staking-provider change-service-fee"
command "StakingProvider.ModifyDelegationCap" "staking-provider modify-delegation-cap"
command "StakingProvider.AutomaticActivation" "staking-provider automatic-activation"
command "StakingProvider.RedelegateCap" "staking-provider redelegate-cap"
command "StakingProvider.SetMetadata" "staking-provider set-metadata"

group "Account" "account"
command "Account.Get" "account get"

Expand Down
5 changes: 4 additions & 1 deletion multiversx_sdk_cli/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def sign_transaction(self, transaction: ITransaction) -> str:
assert self.signer is not None

transaction_computer = TransactionComputer()
if transaction.options & TX_HASH_SIGN_OPTIONS == TX_HASH_SIGN_OPTIONS:
return self.signer.sign(transaction_computer.compute_hash_for_signing(transaction)).hex()

return self.signer.sign(transaction_computer.compute_bytes_for_signing(transaction)).hex()

def sign_message(self, data: bytes) -> str:
Expand All @@ -96,7 +99,7 @@ def sign_transaction(self, transaction: ITransaction) -> str:
should_use_hash_signing = compare_versions(ledger_version, SIGN_USING_HASH_VERSION) >= 0
if should_use_hash_signing:
transaction.version = TX_HASH_SIGN_VERSION
transaction.options = TX_HASH_SIGN_OPTIONS
transaction.options = transaction.options | TX_HASH_SIGN_OPTIONS

transaction_computer = TransactionComputer()

Expand Down
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def query(args: Any):

proxy = ProxyNetworkProvider(args.proxy)
function = args.function
arguments = args.arguments or []
arguments: List[Any] = args.arguments or []

result = query_contract(contract_address, proxy, function, arguments)
utils.dump_out_json(result)
Expand Down
28 changes: 23 additions & 5 deletions multiversx_sdk_cli/cli_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,44 @@ def setup_parser(args: List[str], subparsers: Any) -> Any:
# remove nodes
sub = cli_shared.add_command_subparser(subparsers, "staking-provider", "remove-nodes",
"Remove nodes must be called by the contract owner")
sub.add_argument("--bls-keys", required=True, help="a list with the bls keys of the nodes")
sub.add_argument("--bls-keys", help="a list with the bls keys of the nodes")
sub.add_argument("--validators-file", help="a JSON file describing the Nodes")
sub.add_argument("--delegation-contract", required=True, help="address of the delegation contract")
_add_common_arguments(args, sub)
sub.set_defaults(func=remove_nodes)

# stake nodes
sub = cli_shared.add_command_subparser(subparsers, "staking-provider", "stake-nodes",
"Stake nodes must be called by the contract owner")
sub.add_argument("--bls-keys", required=True, help="a list with the bls keys of the nodes")
sub.add_argument("--bls-keys", help="a list with the bls keys of the nodes")
sub.add_argument("--validators-file", help="a JSON file describing the Nodes")
sub.add_argument("--delegation-contract", required=True, help="address of the delegation contract")
_add_common_arguments(args, sub)
sub.set_defaults(func=stake_nodes)

# unbond nodes
sub = cli_shared.add_command_subparser(subparsers, "staking-provider", "unbond-nodes",
"Unbond nodes must be called by the contract owner")
sub.add_argument("--bls-keys", required=True, help="a list with the bls keys of the nodes")
sub.add_argument("--bls-keys", help="a list with the bls keys of the nodes")
sub.add_argument("--validators-file", help="a JSON file describing the Nodes")
sub.add_argument("--delegation-contract", required=True, help="address of the delegation contract")
_add_common_arguments(args, sub)
sub.set_defaults(func=unbond_nodes)

# unstake nodes
sub = cli_shared.add_command_subparser(subparsers, "staking-provider", "unstake-nodes",
"Unstake nodes must be called by the contract owner")
sub.add_argument("--bls-keys", required=True, help="a list with the bls keys of the nodes")
sub.add_argument("--bls-keys", help="a list with the bls keys of the nodes")
sub.add_argument("--validators-file", help="a JSON file describing the Nodes")
sub.add_argument("--delegation-contract", required=True, help="address of the delegation contract")
_add_common_arguments(args, sub)
sub.set_defaults(func=unstake_nodes)

# unjail nodes
sub = cli_shared.add_command_subparser(subparsers, "staking-provider", "unjail-nodes",
"Unjail nodes must be called by the contract owner")
sub.add_argument("--bls-keys", required=True, help="a list with the bls keys of the nodes")
sub.add_argument("--bls-keys", help="a list with the bls keys of the nodes")
sub.add_argument("--validators-file", help="a JSON file describing the Nodes")
sub.add_argument("--delegation-contract", required=True, help="address of the delegation contract")
_add_common_arguments(args, sub)
sub.set_defaults(func=unjail_nodes)
Expand Down Expand Up @@ -182,6 +187,7 @@ def add_new_nodes(args: Any):


def remove_nodes(args: Any):
_check_if_either_bls_keys_or_validators_file_are_provided(args)
cli_shared.check_guardian_and_options_args(args)
cli_shared.check_broadcast_args(args)
cli_shared.prepare_chain_id_in_args(args)
Expand All @@ -196,6 +202,7 @@ def remove_nodes(args: Any):


def stake_nodes(args: Any):
_check_if_either_bls_keys_or_validators_file_are_provided(args)
cli_shared.check_guardian_and_options_args(args)
cli_shared.check_broadcast_args(args)
cli_shared.prepare_chain_id_in_args(args)
Expand All @@ -209,7 +216,16 @@ def stake_nodes(args: Any):
cli_shared.send_or_simulate(tx, args)


def _check_if_either_bls_keys_or_validators_file_are_provided(args: Any):
bls_keys = args.bls_keys
validators_file = args.validators_file

if not bls_keys and not validators_file:
raise errors.BadUsage("No bls keys or validators file provided. Use either `--bls-keys` or `--validators-file`")


def unbond_nodes(args: Any):
_check_if_either_bls_keys_or_validators_file_are_provided(args)
cli_shared.check_guardian_and_options_args(args)
cli_shared.check_broadcast_args(args)
cli_shared.prepare_chain_id_in_args(args)
Expand All @@ -224,6 +240,7 @@ def unbond_nodes(args: Any):


def unstake_nodes(args: Any):
_check_if_either_bls_keys_or_validators_file_are_provided(args)
cli_shared.check_guardian_and_options_args(args)
cli_shared.check_broadcast_args(args)
cli_shared.prepare_chain_id_in_args(args)
Expand All @@ -238,6 +255,7 @@ def unstake_nodes(args: Any):


def unjail_nodes(args: Any):
_check_if_either_bls_keys_or_validators_file_are_provided(args)
cli_shared.check_guardian_and_options_args(args)
cli_shared.check_broadcast_args(args)
cli_shared.prepare_chain_id_in_args(args)
Expand Down
5 changes: 3 additions & 2 deletions multiversx_sdk_cli/cli_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
load_password)
from multiversx_sdk_cli.constants import (DEFAULT_TX_VERSION,
TRANSACTION_OPTIONS_TX_GUARDED)
from multiversx_sdk_cli.custom_network_provider import CustomNetworkProvider
from multiversx_sdk_cli.errors import ArgumentsNotProvidedError
from multiversx_sdk_cli.interfaces import ITransaction
from multiversx_sdk_cli.ledger.ledger_functions import do_get_ledger_address
Expand Down Expand Up @@ -245,11 +246,11 @@ def should_sign_with_guardian_key(args: Any) -> bool:

def check_options_for_guarded_tx(options: int):
if not options & TRANSACTION_OPTIONS_TX_GUARDED == TRANSACTION_OPTIONS_TX_GUARDED:
raise errors.BadUsage("Invalid guarded transaction's options. The second least significant bit must be set.")
raise errors.BadUsage("Invalid guarded transaction's options. The second least significant bit must be set")


def send_or_simulate(tx: ITransaction, args: Any, dump_output: bool = True) -> CLIOutputBuilder:
proxy = ProxyNetworkProvider(args.proxy)
proxy = CustomNetworkProvider(args.proxy)

is_set_wait_result = hasattr(args, "wait_result") and args.wait_result
is_set_send = hasattr(args, "send") and args.send
Expand Down
8 changes: 3 additions & 5 deletions multiversx_sdk_cli/cli_transactions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from pathlib import Path
from typing import Any, List

from multiversx_sdk_network_providers.proxy_network_provider import \
ProxyNetworkProvider

from multiversx_sdk_cli import cli_shared, utils
from multiversx_sdk_cli.cli_output import CLIOutputBuilder
from multiversx_sdk_cli.cosign_transaction import cosign_transaction
from multiversx_sdk_cli.custom_network_provider import CustomNetworkProvider
from multiversx_sdk_cli.errors import NoWalletProvided
from multiversx_sdk_cli.transactions import (compute_relayed_v1_data,
do_prepare_transaction,
Expand Down Expand Up @@ -88,9 +86,9 @@ def send_transaction(args: Any):

tx = load_transaction_from_file(args.infile)
output = CLIOutputBuilder()
proxy = CustomNetworkProvider(args.proxy)

try:
proxy = ProxyNetworkProvider(args.proxy)
tx_hash = proxy.send_transaction(tx)
output.set_emitted_transaction_hash(tx_hash)
finally:
Expand All @@ -101,7 +99,7 @@ def send_transaction(args: Any):
def get_transaction(args: Any):
args = utils.as_object(args)
omit_fields = cli_shared.parse_omit_fields_arg(args)
proxy = ProxyNetworkProvider(args.proxy)
proxy = CustomNetworkProvider(args.proxy)

transaction = proxy.get_transaction(args.hash, True)
output = CLIOutputBuilder().set_transaction_on_network(transaction, omit_fields).build()
Expand Down
1 change: 1 addition & 0 deletions multiversx_sdk_cli/cli_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def wallet_new(args: Any):

mnemonic = Mnemonic.generate()
print(f"Mnemonic: {mnemonic.get_text()}")
print(f"Wallet address: {mnemonic.derive_key().generate_public_key().to_address(address_hrp).to_bech32()}")

if format is None:
return
Expand Down
2 changes: 2 additions & 0 deletions multiversx_sdk_cli/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ def prepare_args_for_factory(arguments: List[str]) -> List[Any]:
args.append(True)
elif arg.startswith(STR_PREFIX):
args.append(arg[len(STR_PREFIX):])
else:
raise errors.BadUserInput(f"Unknown argument type for argument: `{arg}`. Use `mxpy contract <sub-command> --help` to check all supported arguments")

return args

Expand Down
36 changes: 36 additions & 0 deletions multiversx_sdk_cli/custom_network_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from typing import Any, Dict, Optional, Protocol

from multiversx_sdk_network_providers import GenericError, ProxyNetworkProvider

from multiversx_sdk_cli.errors import ProxyError
from multiversx_sdk_cli.interfaces import ISimulateResponse, ITransaction


class ITransactionOnNetwork(Protocol):
hash: str
is_completed: Optional[bool]

def to_dictionary(self) -> Dict[str, Any]:
...


class CustomNetworkProvider:
def __init__(self, url: str) -> None:
self._provider = ProxyNetworkProvider(url)

def send_transaction(self, transaction: ITransaction) -> str:
try:
hash = self._provider.send_transaction(transaction)
return hash
except GenericError as ge:
url = ge.url
message = ge.data.get("error", "")
data = ge.data.get("data", "")
code = ge.data.get("code", "")
raise ProxyError(message, url, data, code)

def get_transaction(self, tx_hash: str, with_process_status: Optional[bool] = False) -> ITransactionOnNetwork:
return self._provider.get_transaction(tx_hash, with_process_status)

def simulate_transaction(self, transaction: ITransaction) -> ISimulateResponse:
return self._provider.simulate_transaction(transaction)
Loading

0 comments on commit 4329ab3

Please sign in to comment.