Skip to content
Merged
Changes from 5 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
31 changes: 21 additions & 10 deletions proxy/environment.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import sys
from decimal import Decimal
import json
import os
import subprocess
from logged_groups import logged_group, LogMng
from solana.publickey import PublicKey
from solana.account import Account as SolanaAccount
from typing import Optional
from typing import Optional, List

SOLANA_URL = os.environ.get("SOLANA_URL", "http://localhost:8899")
PP_SOLANA_URL = os.environ.get("PP_SOLANA_URL", SOLANA_URL)
Expand Down Expand Up @@ -45,15 +46,27 @@
GET_WHITE_LIST_BALANCE_MAX_RETRIES = int(os.environ.get("GET_WHITE_LIST_BALANCE_MAX_RETRIES", 3))
GET_WHITE_LIST_BALANCE_RETRY_INTERVAL_S = int(os.environ.get("GET_WHITE_LIST_BALANCE_RETRY_INTERVAL_S", 1))


class CliBase:

def run_cli(self, cmd: List[str]) -> str:
self.debug("Calling: " + " ".join(cmd))
proc_result = subprocess.run(cmd, timeout=neon_cli_timeout, universal_newlines=True, stdout=subprocess.PIPE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neon_cli_timeout should only be used for neon-cli

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Vasilii!
Fixed here and in the other place

stderr=subprocess.PIPE)
if proc_result.stderr is not None:
print(proc_result.stderr, file=sys.stderr)
return proc_result.stdout


@logged_group("neon.Proxy")
class solana_cli:
class solana_cli(CliBase):
def call(self, *args):
try:
cmd = ["solana",
"--url", SOLANA_URL,
] + list(args)
self.debug("Calling: " + " ".join(cmd))
return subprocess.check_output(cmd, universal_newlines=True)
return self.run_cli(cmd)
except subprocess.CalledProcessError as err:
self.error("ERR: solana error {}".format(err))
raise
Expand Down Expand Up @@ -101,7 +114,8 @@ def read_sol_account(name) -> Optional[SolanaAccount]:


@logged_group("neon.Proxy")
class neon_cli:
class neon_cli(CliBase):

def call(self, *args):
try:
ctx = json.dumps(LogMng.get_logging_context())
Expand All @@ -113,18 +127,15 @@ def call(self, *args):
]\
+ (["-vvv"] if LOG_NEON_CLI_DEBUG else [])\
+ list(args)
self.debug("Calling: " + " ".join(cmd))
return subprocess.check_output(cmd, timeout=neon_cli_timeout, universal_newlines=True)
return self.run_cli(cmd)
except subprocess.CalledProcessError as err:
self.error("ERR: neon-cli error {}".format(err))
raise

def version(self):
try:
cmd = ["neon-cli",
"--version"]
self.debug("Calling: " + " ".join(cmd))
return subprocess.check_output(cmd, timeout=neon_cli_timeout, universal_newlines=True).split()[1]
cmd = ["neon-cli", "--version"]
return self.run_cli(cmd).split()[1]
except subprocess.CalledProcessError as err:
self.error("ERR: neon-cli error {}".format(err))
raise
Expand Down