change(rpc): handle 'version' and 'type' arguments in constructor

Additionally, added RPC.error, which produces an RPC-compatible
error based on the version passed during construction.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-10-21 10:13:25 -07:00
parent a06f4ec19c
commit 6662975005
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 35 additions and 23 deletions

View file

@ -61,6 +61,10 @@ async def rpc(request: Request,
arg: Optional[str] = Query(None),
args: Optional[List[str]] = Query(None, alias="arg[]")):
# Prepare output list of arguments.
# Create a handle to our RPC class.
rpc = RPC(version=v, type=type)
# Prepare list of arguments for input. If 'arg' was given, it'll
# be a list with one element.
arguments = parse_args(request)
return JSONResponse(RPC().handle(v=v, type=type, args=arguments))
return JSONResponse(rpc.handle(arguments))