mirror of
https://github.com/urbit/shrub.git
synced 2025-01-05 11:09:30 +03:00
json-rpc: move error response core to lib
This commit is contained in:
parent
c1f071878a
commit
30bd648d7f
@ -132,8 +132,8 @@
|
|||||||
(response-to-json:json-rpc response)
|
(response-to-json:json-rpc response)
|
||||||
=, azimuth-rpc
|
=, azimuth-rpc
|
||||||
?. ?=([%map *] params)
|
?. ?=([%map *] params)
|
||||||
[~ ~(parse error id)]
|
[~ ~(parse error:json-rpc id)]
|
||||||
?+ method [~ ~(method error id)]
|
?+ method [~ ~(method error:json-rpc id)]
|
||||||
%get-point [~ (get-point id +.params point:scry)]
|
%get-point [~ (get-point id +.params point:scry)]
|
||||||
%transfer-point (transfer-point id +.params)
|
%transfer-point (transfer-point id +.params)
|
||||||
%configure-keys (configure-keys id +.params)
|
%configure-keys (configure-keys id +.params)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
:: azimuth-rpc: command parsing and utilities
|
:: azimuth-rpc: command parsing and utilities
|
||||||
::
|
::
|
||||||
/- rpc=json-rpc
|
/- rpc=json-rpc
|
||||||
/+ naive
|
/+ naive, json-rpc
|
||||||
::
|
::
|
||||||
=> :: Utilities
|
=> :: Utilities
|
||||||
::
|
::
|
||||||
@ -287,13 +287,13 @@
|
|||||||
|= [id=@t params=(map @t json) action=spawn-action]
|
|= [id=@t params=(map @t json) action=spawn-action]
|
||||||
^- [(unit cage) response:rpc]
|
^- [(unit cage) response:rpc]
|
||||||
?. (params:validate params)
|
?. (params:validate params)
|
||||||
[~ ~(params error id)]
|
[~ ~(params error:json-rpc id)]
|
||||||
=/ sig=(unit @ux) (sig:from-json params)
|
=/ sig=(unit @ux) (sig:from-json params)
|
||||||
=/ from=(unit [@p proxy:naive]) (from:from-json params)
|
=/ from=(unit [@p proxy:naive]) (from:from-json params)
|
||||||
=/ raw=(unit octs) (raw:from-json params)
|
=/ raw=(unit octs) (raw:from-json params)
|
||||||
=/ data=(unit @p) (ship:data:from-json params)
|
=/ data=(unit @p) (ship:data:from-json params)
|
||||||
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
|
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
|
||||||
[~ ~(parse error id)]
|
[~ ~(parse error:json-rpc id)]
|
||||||
:_ [%result id s+'ok']
|
:_ [%result id s+'ok']
|
||||||
%- some
|
%- some
|
||||||
:- %aggregator-action
|
:- %aggregator-action
|
||||||
@ -312,13 +312,13 @@
|
|||||||
|= [id=@t params=(map @t json) action=proxy-action]
|
|= [id=@t params=(map @t json) action=proxy-action]
|
||||||
^- [(unit cage) response:rpc]
|
^- [(unit cage) response:rpc]
|
||||||
?. (params:validate params)
|
?. (params:validate params)
|
||||||
[~ ~(params error id)]
|
[~ ~(params error:json-rpc id)]
|
||||||
=/ sig=(unit @ux) (sig:from-json params)
|
=/ sig=(unit @ux) (sig:from-json params)
|
||||||
=/ from=(unit [@p proxy:naive]) (from:from-json params)
|
=/ from=(unit [@p proxy:naive]) (from:from-json params)
|
||||||
=/ raw=(unit octs) (raw:from-json params)
|
=/ raw=(unit octs) (raw:from-json params)
|
||||||
=/ data=(unit @ux) (address:data:from-json params)
|
=/ data=(unit @ux) (address:data:from-json params)
|
||||||
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
|
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
|
||||||
[~ ~(parse error id)]
|
[~ ~(parse error:json-rpc id)]
|
||||||
:_ [%result id s+'ok']
|
:_ [%result id s+'ok']
|
||||||
%- some
|
%- some
|
||||||
:- %aggregator-action
|
:- %aggregator-action
|
||||||
@ -332,18 +332,6 @@
|
|||||||
==
|
==
|
||||||
--
|
--
|
||||||
::
|
::
|
||||||
++ error
|
|
||||||
|_ id=@t
|
|
||||||
:: https://www.jsonrpc.org/specification#error_object
|
|
||||||
::
|
|
||||||
++ parse [%error id '-32700' 'Failed to parsed']
|
|
||||||
++ request [%error id '-32600' 'Invalid Request']
|
|
||||||
++ method [%error id '-32601' 'Method not found']
|
|
||||||
++ params [%error id '-32602' 'Invalid params']
|
|
||||||
++ internal [%error id '-32603' 'Internal error']
|
|
||||||
++ not-found [%error id '-32000' 'Resource not found']
|
|
||||||
--
|
|
||||||
::
|
|
||||||
++ validate
|
++ validate
|
||||||
|%
|
|%
|
||||||
++ params
|
++ params
|
||||||
@ -357,26 +345,26 @@
|
|||||||
|= [id=@t params=(map @t json) scry=$-(ship (unit point:naive))]
|
|= [id=@t params=(map @t json) scry=$-(ship (unit point:naive))]
|
||||||
^- response:rpc
|
^- response:rpc
|
||||||
?. =((lent ~(tap by params)) 1)
|
?. =((lent ~(tap by params)) 1)
|
||||||
~(params error id)
|
~(params error:json-rpc id)
|
||||||
?~ ship=(~(get by params) 'ship')
|
?~ ship=(~(get by params) 'ship')
|
||||||
~(params error id)
|
~(params error:json-rpc id)
|
||||||
?~ ship=(rush (so:dejs:format u.ship) ;~(pfix sig fed:ag))
|
?~ ship=(rush (so:dejs:format u.ship) ;~(pfix sig fed:ag))
|
||||||
~(params error id)
|
~(params error:json-rpc id)
|
||||||
?~ point=(scry u.ship)
|
?~ point=(scry u.ship)
|
||||||
~(params error id)
|
~(params error:json-rpc id)
|
||||||
[%result id (point:to-json u.point)]
|
[%result id (point:to-json u.point)]
|
||||||
::
|
::
|
||||||
++ transfer-point
|
++ transfer-point
|
||||||
|= [id=@t params=(map @t json)]
|
|= [id=@t params=(map @t json)]
|
||||||
^- [(unit cage) response:rpc]
|
^- [(unit cage) response:rpc]
|
||||||
?. (params:validate params)
|
?. (params:validate params)
|
||||||
[~ ~(params error id)]
|
[~ ~(params error:json-rpc id)]
|
||||||
=/ sig=(unit @ux) (sig:from-json params)
|
=/ sig=(unit @ux) (sig:from-json params)
|
||||||
=/ from=(unit [ship @t]) (from:from-json params)
|
=/ from=(unit [ship @t]) (from:from-json params)
|
||||||
=/ raw=(unit octs) (raw:from-json params)
|
=/ raw=(unit octs) (raw:from-json params)
|
||||||
=/ data=(unit [@ux ?]) (address-transfer:data:from-json params)
|
=/ data=(unit [@ux ?]) (address-transfer:data:from-json params)
|
||||||
?: |(?=(~ sig) ?=(~ from) ?=(~ raw) ?=(~ data))
|
?: |(?=(~ sig) ?=(~ from) ?=(~ raw) ?=(~ data))
|
||||||
[~ ~(parse error id)]
|
[~ ~(parse error:json-rpc id)]
|
||||||
:_ [%result id s+'ok']
|
:_ [%result id s+'ok']
|
||||||
%- some
|
%- some
|
||||||
noun+!>([u.sig u.from u.data])
|
noun+!>([u.sig u.from u.data])
|
||||||
@ -385,14 +373,14 @@
|
|||||||
|= [id=@t params=(map @t json)]
|
|= [id=@t params=(map @t json)]
|
||||||
^- [(unit cage) response:rpc]
|
^- [(unit cage) response:rpc]
|
||||||
?. (params:validate params)
|
?. (params:validate params)
|
||||||
[~ ~(params error id)]
|
[~ ~(params error:json-rpc id)]
|
||||||
=/ sig=(unit @ux) (sig:from-json params)
|
=/ sig=(unit @ux) (sig:from-json params)
|
||||||
=/ from=(unit [ship @t]) (from:from-json params)
|
=/ from=(unit [ship @t]) (from:from-json params)
|
||||||
=/ raw=(unit octs) (raw:from-json params)
|
=/ raw=(unit octs) (raw:from-json params)
|
||||||
=/ data=(unit [encrypt=@ auth=@ crypto-suite=@ breach=?])
|
=/ data=(unit [encrypt=@ auth=@ crypto-suite=@ breach=?])
|
||||||
(keys:data:from-json params)
|
(keys:data:from-json params)
|
||||||
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
|
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
|
||||||
[~ ~(parse error id)]
|
[~ ~(parse error:json-rpc id)]
|
||||||
:_ [%result id s+'ok']
|
:_ [%result id s+'ok']
|
||||||
%- some
|
%- some
|
||||||
noun+!>([u.sig u.from u.data])
|
noun+!>([u.sig u.from u.data])
|
||||||
@ -401,13 +389,13 @@
|
|||||||
|= [id=@t params=(map @t json)]
|
|= [id=@t params=(map @t json)]
|
||||||
^- [(unit cage) response:rpc]
|
^- [(unit cage) response:rpc]
|
||||||
?. (params:validate params)
|
?. (params:validate params)
|
||||||
[~ ~(params error id)]
|
[~ ~(params error:json-rpc id)]
|
||||||
=/ sig=(unit @ux) (sig:from-json params)
|
=/ sig=(unit @ux) (sig:from-json params)
|
||||||
=/ from=(unit [@p proxy:naive]) (from:from-json params)
|
=/ from=(unit [@p proxy:naive]) (from:from-json params)
|
||||||
=/ raw=(unit octs) (raw:from-json params)
|
=/ raw=(unit octs) (raw:from-json params)
|
||||||
=/ data=(unit [@p @ux]) (address-ship:data:from-json params)
|
=/ data=(unit [@p @ux]) (address-ship:data:from-json params)
|
||||||
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
|
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
|
||||||
[~ ~(parse error id)]
|
[~ ~(parse error:json-rpc id)]
|
||||||
:_ [%result id s+'ok']
|
:_ [%result id s+'ok']
|
||||||
%- some
|
%- some
|
||||||
aggregator-action+!>([%submit | u.sig %ful u.raw u.from %spawn u.data])
|
aggregator-action+!>([%submit | u.sig %ful u.raw u.from %spawn u.data])
|
||||||
@ -426,11 +414,11 @@
|
|||||||
|= [id=@t params=(map @t json) scry=$-([ship proxy:naive] (unit @))]
|
|= [id=@t params=(map @t json) scry=$-([ship proxy:naive] (unit @))]
|
||||||
^- response:rpc
|
^- response:rpc
|
||||||
?. =((lent ~(tap by params)) 3)
|
?. =((lent ~(tap by params)) 3)
|
||||||
~(params error id)
|
~(params error:json-rpc id)
|
||||||
?~ from=(from:from-json params)
|
?~ from=(from:from-json params)
|
||||||
~(parse error id)
|
~(parse error:json-rpc id)
|
||||||
?~ nonce=(scry u.from)
|
?~ nonce=(scry u.from)
|
||||||
~(params error id)
|
~(params error:json-rpc id)
|
||||||
[%result id (numb:enjs:format u.nonce)]
|
[%result id (numb:enjs:format u.nonce)]
|
||||||
::
|
::
|
||||||
++ pending
|
++ pending
|
||||||
@ -443,7 +431,7 @@
|
|||||||
|= [id=@t params=(map @t json) pending=(list pend-tx)]
|
|= [id=@t params=(map @t json) pending=(list pend-tx)]
|
||||||
^- response:rpc
|
^- response:rpc
|
||||||
?. =((lent ~(tap by params)) 0)
|
?. =((lent ~(tap by params)) 0)
|
||||||
~(params error id)
|
~(params error:json-rpc id)
|
||||||
[%result id (pending:to-json pending)]
|
[%result id (pending:to-json pending)]
|
||||||
:: - readPendingByShip(ship) -> (list pend-tx)
|
:: - readPendingByShip(ship) -> (list pend-tx)
|
||||||
::
|
::
|
||||||
@ -451,9 +439,9 @@
|
|||||||
|= [id=@t params=(map @t json) scry=$-(@p (list pend-tx))]
|
|= [id=@t params=(map @t json) scry=$-(@p (list pend-tx))]
|
||||||
^- response:rpc
|
^- response:rpc
|
||||||
?. =((lent ~(tap by params)) 1)
|
?. =((lent ~(tap by params)) 1)
|
||||||
~(params error id)
|
~(params error:json-rpc id)
|
||||||
?~ ship=(ship:from-json params)
|
?~ ship=(ship:from-json params)
|
||||||
~(parse error id)
|
~(parse error:json-rpc id)
|
||||||
[%result id (pending:to-json (scry u.ship))]
|
[%result id (pending:to-json (scry u.ship))]
|
||||||
:: - readPendingByAddress(address) -> (list pend-tx)
|
:: - readPendingByAddress(address) -> (list pend-tx)
|
||||||
::
|
::
|
||||||
@ -461,9 +449,9 @@
|
|||||||
|= [id=@t params=(map @t json) scry=$-(@ux (list pend-tx))]
|
|= [id=@t params=(map @t json) scry=$-(@ux (list pend-tx))]
|
||||||
^- response:rpc
|
^- response:rpc
|
||||||
?. =((lent ~(tap by params)) 1)
|
?. =((lent ~(tap by params)) 1)
|
||||||
~(params error id)
|
~(params error:json-rpc id)
|
||||||
?~ address=(address:from-json params)
|
?~ address=(address:from-json params)
|
||||||
~(parse error id)
|
~(parse error:json-rpc id)
|
||||||
[%result id (pending:to-json (scry u.address))]
|
[%result id (pending:to-json (scry u.address))]
|
||||||
--
|
--
|
||||||
::
|
::
|
||||||
@ -471,9 +459,9 @@
|
|||||||
|= [id=@t params=(map @t json) scry=$-(@ tx-status)]
|
|= [id=@t params=(map @t json) scry=$-(@ tx-status)]
|
||||||
^- response:rpc
|
^- response:rpc
|
||||||
?. =((lent ~(tap by params)) 1)
|
?. =((lent ~(tap by params)) 1)
|
||||||
~(params error id)
|
~(params error:json-rpc id)
|
||||||
?~ keccak=(keccak:from-json params)
|
?~ keccak=(keccak:from-json params)
|
||||||
~(parse error id)
|
~(parse error:json-rpc id)
|
||||||
[%result id (tx-status:to-json (scry u.keccak))]
|
[%result id (tx-status:to-json (scry u.keccak))]
|
||||||
::
|
::
|
||||||
:: ++ history
|
:: ++ history
|
||||||
@ -485,8 +473,8 @@
|
|||||||
:: ==
|
:: ==
|
||||||
:: ^- response:rpc
|
:: ^- response:rpc
|
||||||
:: ?. =((lent ~(tap by params)) 1)
|
:: ?. =((lent ~(tap by params)) 1)
|
||||||
:: ~(params error id)
|
:: ~(params error:json-rpc id)
|
||||||
:: ?~ from=(from:from-json params)
|
:: ?~ from=(from:from-json params)
|
||||||
:: ~(parse error id)
|
:: ~(parse error:json-rpc id)
|
||||||
:: [%result id (txs:to-json (scry u.from))]
|
:: [%result id (txs:to-json (scry u.from))]
|
||||||
--
|
--
|
||||||
|
@ -25,7 +25,9 @@
|
|||||||
^- json
|
^- json
|
||||||
?- -.params
|
?- -.params
|
||||||
%list [%a +.params]
|
%list [%a +.params]
|
||||||
%map [%o +.params]
|
:: FIXME: support either %map or %object (also in /sur/json/rpc)
|
||||||
|
::
|
||||||
|
%map [%o +.params]
|
||||||
%object [%o (~(gas by *(map @t json)) +.params)]
|
%object [%o (~(gas by *(map @t json)) +.params)]
|
||||||
== ==
|
== ==
|
||||||
::
|
::
|
||||||
@ -40,9 +42,9 @@
|
|||||||
%- molt
|
%- molt
|
||||||
^- (list [@t json])
|
^- (list [@t json])
|
||||||
:: FIXME: return 'id' as string, number or NULL
|
:: FIXME: return 'id' as string, number or NULL
|
||||||
::
|
::
|
||||||
:~ ['jsonrpc' s+'2.0']
|
:~ ['jsonrpc' s+'2.0']
|
||||||
['id' s+id.response]
|
['id' s+id.response]
|
||||||
['result' res.response]
|
['result' res.response]
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
@ -50,8 +52,8 @@
|
|||||||
:- %o
|
:- %o
|
||||||
%- molt
|
%- molt
|
||||||
^- (list [@t json])
|
^- (list [@t json])
|
||||||
:~ ['jsonrpc' s+'2.0']
|
:~ ['jsonrpc' s+'2.0']
|
||||||
['id' ?~(id.response ~ s+id.response)]
|
['id' ?~(id.response ~ s+id.response)]
|
||||||
['code' n+code.response]
|
['code' n+code.response]
|
||||||
['message' s+message.response]
|
['message' s+message.response]
|
||||||
==
|
==
|
||||||
@ -83,6 +85,18 @@
|
|||||||
^- request-params
|
^- request-params
|
||||||
?+ -.json !!
|
?+ -.json !!
|
||||||
%a [%list ((ar same) json)]
|
%a [%list ((ar same) json)]
|
||||||
%o [%map ((om same) json)]
|
%o [%map ((om same) json)]
|
||||||
== ==
|
== ==
|
||||||
|
::
|
||||||
|
++ error
|
||||||
|
|_ id=@t
|
||||||
|
:: https://www.jsonrpc.org/specification#error_object
|
||||||
|
::
|
||||||
|
++ parse [%error id '-32700' 'Failed to parsed']
|
||||||
|
++ request [%error id '-32600' 'Invalid Request']
|
||||||
|
++ method [%error id '-32601' 'Method not found']
|
||||||
|
++ params [%error id '-32602' 'Invalid params']
|
||||||
|
++ internal [%error id '-32603' 'Internal error']
|
||||||
|
++ not-found [%error id '-32000' 'Resource not found']
|
||||||
|
--
|
||||||
--
|
--
|
||||||
|
Loading…
Reference in New Issue
Block a user