Skip to content

Commit 8b00dab

Browse files
chfastaxic
authored andcommitted
jsonrpcproxy: Separate argument parsing
1 parent 43b10d5 commit 8b00dab

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

scripts/jsonrpcproxy.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,29 +221,37 @@ def process(self, request):
221221
return response
222222

223223

224-
def run():
224+
if sys.platform == 'win32':
225+
DEFAULT_BACKEND_PATH = r'\\.\pipe\geth.ipc'
226+
BACKEND_PATH_HELP = "Named Pipe of a backend RPC server"
227+
else:
228+
DEFAULT_BACKEND_PATH = '~/.ethereum/geth.ipc'
229+
BACKEND_PATH_HELP = "Unix Socket of a backend RPC server"
230+
231+
DEFAULT_PROXY_URL = 'http://127.0.0.1:8545'
232+
PROXY_URL_HELP = "URL for this proxy server"
233+
234+
235+
def parse_args():
225236
parser = ArgumentParser(
226237
description='HTTP Proxy for JSON-RPC servers',
227238
formatter_class=ArgumentDefaultsHelpFormatter
228239
)
229240

230-
if sys.platform == 'win32':
231-
default_backend_path = r'\\.\pipe\geth.ipc'
232-
backend_path_help = "Named Pipe of a backend RPC server"
233-
else:
234-
default_backend_path = '~/.ethereum/geth.ipc'
235-
backend_path_help = "Unix Socket of a backend RPC server"
236-
237241
parser.add_argument('backend_path', nargs='?',
238-
default=default_backend_path,
239-
help=backend_path_help)
242+
default=DEFAULT_BACKEND_PATH,
243+
help=BACKEND_PATH_HELP)
240244
parser.add_argument('proxy_url', nargs='?',
241-
default='http://127.0.0.1:8545',
242-
help="URL for this proxy server")
243-
args = parser.parse_args()
244-
proxy = Proxy(args.proxy_url, args.backend_path)
245+
default=DEFAULT_PROXY_URL,
246+
help=PROXY_URL_HELP)
247+
return parser.parse_args()
248+
249+
250+
def run(proxy_url=DEFAULT_PROXY_URL, backend_path=DEFAULT_BACKEND_PATH):
251+
proxy = Proxy(proxy_url, backend_path)
245252
proxy.serve_forever()
246253

247254

248255
if __name__ == '__main__':
249-
run()
256+
args = parse_args()
257+
run(args.proxy_url, args.backend_path)

0 commit comments

Comments
 (0)