From c227f80dcc00e20575a70d67770549d92829766c Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 19 Mar 2024 15:08:31 -0500 Subject: [PATCH] Add DB wrapper for `HexString` --- src/Zenith/Types.hs | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/Zenith/Types.hs b/src/Zenith/Types.hs index 715e338..33a946b 100644 --- a/src/Zenith/Types.hs +++ b/src/Zenith/Types.hs @@ -14,6 +14,7 @@ import Data.Aeson.Types (prependFailure, typeMismatch) import qualified Data.ByteString as BS import qualified Data.ByteString.Base64 as B64 import qualified Data.ByteString.Char8 as C +import Data.HexString import Data.Maybe (fromMaybe) import qualified Data.Text as T import qualified Data.Text.Encoding as E @@ -29,6 +30,13 @@ import ZcashHaskell.Types , ZcashNet(..) ) +-- * Database field type wrappers +newtype HexStringDB = HexStringDB + { getHex :: HexString + } deriving newtype (Eq, Show, Read) + +derivePersistField "HexStringDB" + newtype ZcashNetDB = ZcashNetDB { getNet :: ZcashNet } deriving newtype (Eq, Show, Read) @@ -71,15 +79,8 @@ newtype TransparentSpendingKeyDB = TransparentSpendingKeyDB derivePersistField "TransparentSpendingKeyDB" --- | A type to model Zcash RPC calls -data RpcCall = RpcCall - { jsonrpc :: T.Text - , id :: T.Text - , method :: T.Text - , params :: [Value] - } deriving (Show, Generic, ToJSON, FromJSON) - --- | Type for modelling the different address sources for Zcash 5.0.0 +-- * RPC +-- | Type for modelling the different address sources for `zcashd` 5.0.0 data AddressSource = LegacyRandom | Imported @@ -128,24 +129,6 @@ instance Show ZcashAddress where T.unpack (T.take 8 a) ++ "..." ++ T.unpack (T.takeEnd 8 a) ++ " Pools: " ++ show p --- | A type to model the response of the Zcash RPC -data RpcResponse r = RpcResponse - { err :: Maybe T.Text - , respId :: T.Text - , result :: r - } deriving (Show, Generic, ToJSON) - -instance (FromJSON r) => FromJSON (RpcResponse r) where - parseJSON (Object obj) = do - e <- obj .: "error" - rId <- obj .: "id" - r <- obj .: "result" - pure $ RpcResponse e rId r - parseJSON invalid = - prependFailure - "parsing RpcResponse failed, " - (typeMismatch "Object" invalid) - newtype NodeVersion = NodeVersion Integer deriving (Eq, Show)