From f0995441628381fee14ae1c655c3c4f8d96162e5 Mon Sep 17 00:00:00 2001 From: pitmutt Date: Fri, 22 Mar 2024 18:04:04 +0000 Subject: [PATCH] Account for missing response fields in Zebra response (#43) This PR adds code to account for the missing `time` field in the Zebra response for blocks and raw transactions. Reviewed-on: https://git.vergara.tech/Vergara_Tech/zcash-haskell/pulls/43 Co-authored-by: pitmutt Co-committed-by: pitmutt --- src/ZcashHaskell/Types.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ZcashHaskell/Types.hs b/src/ZcashHaskell/Types.hs index e7f68b3..612410e 100644 --- a/src/ZcashHaskell/Types.hs +++ b/src/ZcashHaskell/Types.hs @@ -7,7 +7,7 @@ -- Copyright : 2022-2024 Vergara Technologies -- License : MIT -- --- Maintainer : pitmut@vergara.tech +-- Maintainer : pitmutt@vergara.tech -- Stability : experimental -- Portability : unknown -- @@ -31,6 +31,7 @@ import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as C import Data.HexString import Data.Int +import Data.Maybe (fromMaybe) import Data.Structured import qualified Data.Text as T import qualified Data.Text.Encoding as E @@ -199,9 +200,9 @@ instance FromJSON BlockResponse where withObject "BlockResponse" $ \obj -> do c <- obj .: "confirmations" h <- obj .: "height" - t <- obj .: "time" + t <- obj .:? "time" txs <- obj .: "tx" - pure $ BlockResponse c h t txs + pure $ BlockResponse c h (fromMaybe 0 t) txs -- | Type to represent response from the `zcashd` RPC `getrawtransaction` data RawTxResponse = RawTxResponse