json-rpc: add response-to-json

This commit is contained in:
yosoyubik 2021-04-29 10:56:29 +02:00
parent afd3c9b85e
commit 0c704bb145
2 changed files with 24 additions and 25 deletions

View File

@ -1,7 +1,7 @@
:: Azimuth RPC API
::
/- rpc=json-rpc
/+ naive, *server, default-agent, verb, dbug, version
/+ naive, json-rpc, *server, default-agent, verb, dbug, version
|%
+$ card card:agent:gall
::
@ -141,7 +141,7 @@
++ get-point
|= [id=@t params=request-params:rpc]
%- json-response:gen
%- rpc-response-to-json
%- response-to-json:json-rpc
?. ?=([%object *] params)
[%error id 'X' 'RPC params must be an object']
?> ?=(^ +.params)
@ -204,29 +204,6 @@
['nonce' (numb:enjs:format nonce)]
==
--
:: TODO: move to rpc library
::
++ rpc-response-to-json
|= =response:rpc
^- json
:: TODO: consider all cases
::
?+ -.response ~|([%unsupported-rpc-response response] !!)
%result
:- %o
%- molt
^- (list [@t json])
~[['id' s+id.response] ['res' res.response]]
::
%error
:- %o
%- molt
^- (list [@t json])
:~ ['id' s+id.response]
['code' s+code.response]
['message' s+message.response]
==
==
--
::
++ scry-point

View File

@ -28,4 +28,26 @@
%object [%o (~(gas by *(map @t json)) +.params)]
==
==
::
++ response-to-json
|= =response
^- json
:: TODO: consider all cases
::
?+ -.response ~|([%unsupported-rpc-response response] !!)
%result
:- %o
%- molt
^- (list [@t json])
~[['id' s+id.response] ['res' res.response]]
::
%error
:- %o
%- molt
^- (list [@t json])
:~ ['id' s+id.response]
['code' s+code.response]
['message' s+message.response]
==
==
--