refactored RPC parsing

This commit is contained in:
timlucmiptev 2020-12-13 19:00:52 +02:00 committed by ixv
parent 676e70a260
commit 9eeaa31f4f
3 changed files with 23 additions and 17 deletions

View File

@ -192,10 +192,11 @@
++ handle-rpc-error
|= [=wire e=error:rpc-types]
^- (quip card _state)
:: TODO: broadcast this error to subscribers
:: use the wire to get req-id
:: (get-req-id wire)
`state
?+ e [~[(send-update [%.n [%rpc-error ~]])] state]
%tx-inputs-missing-or-spent
:_ state
~[(send-update [%.y (get-req-id wire) %broadcast-tx %.n %tx-inputs-missing-or-spent])]
==
::
++ handle-rpc-result
|= [=wire r=result:rpc-types]
@ -220,6 +221,11 @@
?> ?=([%get-raw-tx *] r)
:_ state
~[(send-update [%.y (get-req-id wire) %raw-tx +.r])]
::
[%broadcast-raw-tx @ *]
?> ?=([%broadcast-tx *] r)
:_ state
~[(send-update [%.y (get-req-id wire) %broadcast-tx %.y +.r])]
::
[%ping @ *]
?> ?=([%get-block-and-fee *] r)

View File

@ -128,25 +128,20 @@
::
++ parse-error
|= res=response:json-rpc
|^ ^- error:rpc-types
^- error:rpc-types
?> ?=(%error -.res)
%tx-inputs-missing-or-spent
:: if code = -25, then return
:: -28 is blocks not ready
:: ?+ code:(error res.res)
++ error
%- ot:dejs:format
:~ [%code ni:dejs:format]
[%message so:dejs:format]
==
--
?: =('-25' code.res)
%tx-inputs-missing-or-spent
?: =('28' code.res)
%blocks-not-ready
%connection-error
::
++ parse-result
|= res=response:json-rpc
|^ ^- result:rpc-types
~| -.res
?> ?=(%result -.res)
?+ id.res ~|([%unsupported-response id.res] !!)
?+ id.res ~|([%unsupported-result id.res] !!)
%get-address-info
[id.res (address-info res.res)]
::
@ -158,6 +153,9 @@
::
%create-raw-tx
[%get-raw-tx (raw-tx res.res)]
::
%broadcast-tx
[%broadcast-tx ((cu:dejs:format to-hash256 so:dejs:format) res.res)]
::
%get-block-count
[id.res (ni:dejs:format res.res)]

View File

@ -22,6 +22,7 @@
$% [%address-info utxos=(set utxo) used=? block=@ud]
[%tx-info =info:tx]
[%raw-tx =txid =rawtx]
[%broadcast-tx (each txid %tx-inputs-missing-or-spent)]
==
+$ error
$% [%not-connected status=@ud]
@ -53,7 +54,7 @@
[%unhandled-response ~]
==
+$ error
$? %tx-inputs-missing-or-spent
$? %tx-inputs-missing-or-spent
%blocks-not-ready
%connection-error
==
@ -62,6 +63,7 @@
[%get-tx-vals =info:tx]
[%get-raw-tx =txid =rawtx]
[%create-raw-tx =rawtx]
[%broadcast-tx =txid]
[%get-block-count block=@ud]
[%get-block-and-fee block=@ud fee=sats]