Skip to content

Commit

Permalink
Added debug mode for GethDevNodeGuard
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaven committed Jul 8, 2024
1 parent 667a0d9 commit 48d3be9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
30 changes: 25 additions & 5 deletions PyEthHelper/GethNodeGuard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@

class GethNodeGuard(object):

def __init__(self, cmd: List[str], termTimeout: int = 10):
def __init__(
self,
cmd: List[str],
termTimeout: int = 10,
showOutput: bool = False
):
super(GethNodeGuard, self).__init__()

self.cmd = cmd
self.termTimeout = termTimeout
self.showOutput = showOutput

self.proc = None

Expand All @@ -34,9 +40,9 @@ def Start(self) -> None:
self.logger.info(f'Starting Geth node with command: {cmdStr}')
self.proc = subprocess.Popen(
[ str(x) for x in self.cmd ],
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdin =subprocess.DEVNULL,
stdout=subprocess.DEVNULL if not self.showOutput else None,
stderr=subprocess.DEVNULL if not self.showOutput else None,
)

def Stop(self) -> None:
Expand Down Expand Up @@ -85,6 +91,7 @@ def __init__(
httpApis: List[str] = DEFAULT_HTTP_APIS,
connTimeout: int = 5,
termTimeout: int = 10,
debug: bool = False
):
httpApisStr = ','.join(httpApis)
cmd = [
Expand All @@ -97,14 +104,27 @@ def __init__(
'--http.api', httpApisStr,
'--http.port', httpPort,
]
super(GethDevNodeGuard, self).__init__(cmd=cmd, termTimeout=termTimeout)
if debug:
cmd += [
'--log.debug',
'--verbosity', 5, # verbosity level set to 5 - detail
]
super(GethDevNodeGuard, self).__init__(
cmd=cmd,
termTimeout=termTimeout,
showOutput=debug
)

self.httpPort = httpPort
self.connTimeout = connTimeout

self.w3 = None
self.devAccount = None

self.logger.info(
'Debug mode is {}'.format('enabled' if debug else 'disabled')
)

def Start(self) -> None:
super(GethDevNodeGuard, self).Start()

Expand Down
2 changes: 1 addition & 1 deletion PyEthHelper/_Meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@



__version__ = '0.1.4'
__version__ = '0.1.5'

PKG_AUTHOR = 'Languages, Systems, and Data Lab at UC Santa Cruz'
PKG_NAME = 'PyEthHelper'
Expand Down

0 comments on commit 48d3be9

Please sign in to comment.