From cbbbaa0fd0af4c7fc430e1d98c843cd519faa0c5 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Thu, 28 Sep 2023 13:56:31 -0500 Subject: [PATCH] Correct JSON parser for raw Tx --- src/ZcashHaskell/Sapling.hs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ZcashHaskell/Sapling.hs b/src/ZcashHaskell/Sapling.hs index ffec5f8..f5a7c43 100644 --- a/src/ZcashHaskell/Sapling.hs +++ b/src/ZcashHaskell/Sapling.hs @@ -48,12 +48,21 @@ instance FromJSON RawTxResponse where parseJSON = withObject "RawTxResponse" $ \obj -> do i <- obj .: "txid" - o <- obj .: "orchard" + o <- obj .:? "orchard" h <- obj .: "hex" - a <- o .: "actions" - pure $ - RawTxResponse - i - (decodeHexText h) - (getShieldedOutputs (decodeHexText h)) - a + case o of + Nothing -> + pure $ + RawTxResponse + i + (decodeHexText h) + (getShieldedOutputs (decodeHexText h)) + [] + Just o' -> do + a <- o' .: "actions" + pure $ + RawTxResponse + i + (decodeHexText h) + (getShieldedOutputs (decodeHexText h)) + a