From 473192e34b61b914b149f8ec7c201b64b6a86c97 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Thu, 8 Aug 2024 09:24:44 -0500 Subject: [PATCH] Create type for Zcash note --- src/Zenith/Types.hs | 60 +++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/src/Zenith/Types.hs b/src/Zenith/Types.hs index 029be71..ee70177 100644 --- a/src/Zenith/Types.hs +++ b/src/Zenith/Types.hs @@ -16,6 +16,7 @@ import qualified Data.ByteString.Base64 as B64 import qualified Data.ByteString.Char8 as C import Data.Char (toLower) import Data.HexString +import Data.Int (Int64) import Data.Maybe (fromMaybe) import qualified Data.Text as T import qualified Data.Text.Encoding as E @@ -103,6 +104,32 @@ data Config = Config , c_zenithPort :: !Int } deriving (Eq, Prelude.Show) +data ZcashPool + = Transparent + | Sprout + | Sapling + | Orchard + deriving (Show, Read, Eq) + +derivePersistField "ZcashPool" + +instance ToJSON ZcashPool where + toJSON zp = + case zp of + Transparent -> Data.Aeson.String "p2pkh" + Sprout -> Data.Aeson.String "sprout" + Sapling -> Data.Aeson.String "sapling" + Orchard -> Data.Aeson.String "orchard" + +instance FromJSON ZcashPool where + parseJSON = + withText "ZcashPool" $ \case + "p2pkh" -> return Transparent + "sprout" -> return Sprout + "sapling" -> return Sapling + "orchard" -> return Orchard + _ -> fail "Not a known Zcash pool" + -- ** API types data ZcashWalletAPI = ZcashWalletAPI { zw_index :: !Int @@ -133,6 +160,21 @@ data ZcashAddressAPI = ZcashAddressAPI $(deriveJSON defaultOptions {fieldLabelModifier = drop 3} ''ZcashAddressAPI) +data ZcashNoteAPI = ZcashNoteAPI + { zn_txid :: !HexString + , zn_pool :: !ZcashPool + , zn_amount :: !Float + , zn_amountZats :: !Int64 + , zn_memo :: !T.Text + , zn_confirmed :: !Bool + , zn_blockheight :: !Int64 + , zn_blocktime :: !Int64 + , zn_outindex :: !Int + , zn_change :: !Bool + } deriving (Eq, Prelude.Show) + +$(deriveJSON defaultOptions {fieldLabelModifier = drop 3} ''ZcashNoteAPI) + -- ** `zebrad` -- | Type for modeling the tree state response data ZebraTreeInfo = ZebraTreeInfo @@ -177,24 +219,6 @@ instance FromJSON AddressSource where "mnemonic_seed" -> return MnemonicSeed _ -> fail "Not a known address source" -data ZcashPool - = Transparent - | Sprout - | Sapling - | Orchard - deriving (Show, Read, Eq, Generic, ToJSON) - -derivePersistField "ZcashPool" - -instance FromJSON ZcashPool where - parseJSON = - withText "ZcashPool" $ \case - "p2pkh" -> return Transparent - "sprout" -> return Sprout - "sapling" -> return Sapling - "orchard" -> return Orchard - _ -> fail "Not a known Zcash pool" - data ZcashAddress = ZcashAddress { source :: AddressSource , pool :: [ZcashPool]