-- | Run an asynchronous `ETH` action
runWeb3 :: forall a. Provider -> Web3 a -> Aff (Either Web3Error a)
runWeb3 p (Web3 action) =
attempt (runReaderT action p)
>>= case _ of
Left err -> maybe (throwError err) (pure <<< Left) $ parseMsg $ message err
Right x -> pure $ Right x
where
-- NOTE: it's a bit hacky
-- for this to work, errors of type `Web3Error` should be converted to json
-- using `genericEncodeJSON defaultOptions` and then Error
-- should be created with json string as a message.
-- see Network.Ethereum.Web3.JsonRPC#asError
parseMsg :: String -> Maybe Web3Error
parseMsg msg = hush $ runExcept $ genericDecodeJSON defaultOptions msg
which is used to catch errors sent from
instance remoteBase :: (Decode a) => Remote (Web3 a) where
Web3 a = Provider -> Aff (Either Web3 a)
will resolve
which is used to catch errors sent from