ethio: handles a result member in an error response

When using a Ganache for running a local Ethereum node, an error RPC 
response can contain a 'result' member with the hash of the transaction, 
 even though that goes against the JSON-RPC spec
This commit is contained in:
yosoyubik 2021-05-21 12:11:56 +02:00
parent 9e7cb91398
commit 31ae6c2227

View File

@ -108,16 +108,25 @@
++ parse-one-response
|= =json
^- (unit response:rpc)
=/ res=(unit [@t ^json])
?. &(?=([%o *] json) (~(has by p.json) 'error'))
=/ res=(unit [@t ^json])
%. json
=, dejs-soft:format
(ot id+so result+some ~)
?~ res ~
`[%result u.res]
~| parse-one-response=json
=/ error=(unit [id=@t ^json code=@ta mssg=@t])
%. json
=, dejs-soft:format
(ot id+so result+some ~)
?^ res `[%result u.res]
~| parse-one-response=json
:+ ~ %error %- need
%. json
=, dejs-soft:format
(ot id+so error+(ot code+no message+so ~) ~)
:: A 'result' member is present in the error
:: response when using ganache, even though
:: that goes against the JSON-RPC spec
::
(ot id+so result+some error+(ot code+no message+so ~) ~)
?~ error ~
=* err u.error
`[%error id.err code.err mssg.err]
--
::
:: +read-contract: calls a read function on a contract, produces result hex