Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Feb 19, 2024
1 parent 303411e commit 26e5848
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 46 deletions.
17 changes: 5 additions & 12 deletions multiversx_sdk_cli/cli_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Any, Dict, List, Text, cast

from multiversx_sdk_core import Address
from multiversx_sdk_network_providers import GenericError
from multiversx_sdk_network_providers.proxy_network_provider import \
ProxyNetworkProvider

Expand All @@ -17,7 +16,8 @@
load_password)
from multiversx_sdk_cli.constants import (DEFAULT_TX_VERSION,
TRANSACTION_OPTIONS_TX_GUARDED)
from multiversx_sdk_cli.errors import ArgumentsNotProvidedError, ProxyError
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
from multiversx_sdk_cli.simulation import Simulator
Expand Down Expand Up @@ -250,7 +250,7 @@ def check_options_for_guarded_tx(options: int):


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 All @@ -269,15 +269,8 @@ def send_or_simulate(tx: ITransaction, args: Any, dump_output: bool = True) -> C
transaction_on_network = send_and_wait_for_result(tx, proxy, args.timeout)
output_builder.set_awaited_transaction(transaction_on_network)
elif send_only:
try:
hash = proxy.send_transaction(tx)
output_builder.set_emitted_transaction_hash(hash)
except GenericError as ge:
url = ge.url
message = ge.data["error"]
data = ge.data["data"]
code = ge.data["code"]
raise ProxyError(message, url, data, code)
hash = proxy.send_transaction(tx)
output_builder.set_emitted_transaction_hash(hash)
elif simulate:
simulation = Simulator(proxy).run(tx)
output_builder.set_simulation_results(simulation)
Expand Down
28 changes: 9 additions & 19 deletions multiversx_sdk_cli/cli_transactions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from pathlib import Path
from typing import Any, List

from multiversx_sdk_network_providers import GenericError
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.errors import NoWalletProvided, ProxyError
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,
load_transaction_from_file)
Expand Down Expand Up @@ -89,26 +86,19 @@ def send_transaction(args: Any):

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

try:
tx_hash = proxy.send_transaction(tx)
output.set_emitted_transaction_hash(tx_hash)
except GenericError as ge:
url = ge.url
message = ge.data["error"]
data = ge.data["data"]
code = ge.data["code"]
raise ProxyError(message, url, data, code)
finally:
output = output.set_emitted_transaction(tx).build()
utils.dump_out_json(output, outfile=args.outfile)
tx_hash = proxy.send_transaction(tx)
output.set_emitted_transaction_hash(tx_hash)

output = output.set_emitted_transaction(tx).build()
utils.dump_out_json(output, outfile=args.outfile)


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
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

Check failure on line 3 in multiversx_sdk_cli/custom_network_provider.py

View workflow job for this annotation

GitHub Actions / runner / mypy

[mypy] reported by reviewdog 🐶 Skipping analyzing "multiversx_sdk_network_providers": module is installed, but missing library stubs or py.typed marker [import-untyped] Raw Output: /home/runner/work/mx-sdk-py-cli/mx-sdk-py-cli/multiversx_sdk_cli/custom_network_provider.py:3:1: error: Skipping analyzing "multiversx_sdk_network_providers": module is installed, but missing library stubs or py.typed marker [import-untyped]

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

Check failure on line 24 in multiversx_sdk_cli/custom_network_provider.py

View workflow job for this annotation

GitHub Actions / runner / mypy

[mypy] reported by reviewdog 🐶 Returning Any from function declared to return "str" [no-any-return] Raw Output: /home/runner/work/mx-sdk-py-cli/mx-sdk-py-cli/multiversx_sdk_cli/custom_network_provider.py:24:13: error: Returning Any from function declared to return "str" [no-any-return]
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)

Check failure on line 33 in multiversx_sdk_cli/custom_network_provider.py

View workflow job for this annotation

GitHub Actions / runner / mypy

[mypy] reported by reviewdog 🐶 Returning Any from function declared to return "ITransactionOnNetwork" [no-any-return] Raw Output: /home/runner/work/mx-sdk-py-cli/mx-sdk-py-cli/multiversx_sdk_cli/custom_network_provider.py:33:9: error: Returning Any from function declared to return "ITransactionOnNetwork" [no-any-return]

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

Check failure on line 36 in multiversx_sdk_cli/custom_network_provider.py

View workflow job for this annotation

GitHub Actions / runner / mypy

[mypy] reported by reviewdog 🐶 Returning Any from function declared to return "ISimulateResponse" [no-any-return] Raw Output: /home/runner/work/mx-sdk-py-cli/mx-sdk-py-cli/multiversx_sdk_cli/custom_network_provider.py:36:9: error: Returning Any from function declared to return "ISimulateResponse" [no-any-return]
18 changes: 3 additions & 15 deletions multiversx_sdk_cli/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
import json
import logging
import time
from typing import Any, Dict, Optional, Protocol, Sequence, TextIO, Tuple
from typing import Any, Dict, Optional, Protocol, TextIO

from multiversx_sdk_core import Address, Transaction, TransactionPayload
from multiversx_sdk_network_providers import GenericError

from multiversx_sdk_cli import errors
from multiversx_sdk_cli.accounts import Account, LedgerAccount
from multiversx_sdk_cli.cli_password import (load_guardian_password,
load_password)
from multiversx_sdk_cli.cosign_transaction import cosign_transaction
from multiversx_sdk_cli.errors import NoWalletProvided, ProxyError
from multiversx_sdk_cli.errors import NoWalletProvided
from multiversx_sdk_cli.interfaces import ITransaction
from multiversx_sdk_cli.ledger.ledger_functions import do_get_ledger_address

Expand All @@ -31,9 +30,6 @@ class INetworkProvider(Protocol):
def send_transaction(self, transaction: ITransaction) -> str:
...

def send_transactions(self, transactions: Sequence[ITransaction]) -> Tuple[int, Dict[str, str]]:
...

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

Expand Down Expand Up @@ -133,15 +129,7 @@ def send_and_wait_for_result(transaction: ITransaction, proxy: INetworkProvider,
def _send_transaction_and_wait_for_result(proxy: INetworkProvider, payload: ITransaction, num_seconds_timeout: int = 100) -> ITransactionOnNetwork:
AWAIT_TRANSACTION_PERIOD = 5

try:
tx_hash = proxy.send_transaction(payload)
except GenericError as ge:
url = ge.url
message = ge.data["error"]
data = ge.data["data"]
code = ge.data["code"]
raise ProxyError(message, url, data, code)

tx_hash = proxy.send_transaction(payload)
num_periods_to_wait = int(num_seconds_timeout / AWAIT_TRANSACTION_PERIOD)

for _ in range(0, num_periods_to_wait):
Expand Down

0 comments on commit 26e5848

Please sign in to comment.