From 00f2f2003a56d8fe16d4aecf67cc01a55043a0aa Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 18 Jul 2022 15:22:44 -0500 Subject: [PATCH] Add new fields to Owner for payment confirmation --- CHANGELOG.md | 3 +++ src/Owner.hs | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 509ba24..5c0a091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - New `Config` type to house the configuration parameters +- New field in `Owner` type to store toggle for payment confirmation +- New field in `Owner` type to store viewing key ### Changed +- Added alphabetic sorting to list of items - Refactored code to use new `Config` type - Enhance `decodeHexText` to support Unicode - Enhance `encodeHexText` to support Unicode diff --git a/src/Owner.hs b/src/Owner.hs index ab4ae3c..0621bc4 100644 --- a/src/Owner.hs +++ b/src/Owner.hs @@ -6,6 +6,7 @@ module Owner where import Data.Aeson import qualified Data.Bson as B +import Data.Maybe import qualified Data.Text as T import Data.Time.Clock import Data.Typeable @@ -37,12 +38,13 @@ data Owner = , ozats :: Bool , oinvoices :: Bool , oexpiration :: UTCTime + , opayconf :: Bool , oviewkey :: T.Text } deriving (Eq, Show, Generic, Typeable) instance ToJSON Owner where - toJSON (Owner i a n c t tV v vV f l e s ct st p ph w co paid zats inv eTs vk) = + toJSON (Owner i a n c t tV v vV f l e s ct st p ph w co paid zats inv eTs pc vk) = case i of Just oid -> object @@ -68,6 +70,7 @@ instance ToJSON Owner where , "zats" .= zats , "invoices" .= inv , "expiration" .= eTs + , "payconf" .= pc , "viewKey" .= vk ] Nothing -> @@ -94,6 +97,7 @@ instance ToJSON Owner where , "zats" .= zats , "invoices" .= inv , "expiration" .= eTs + , "payconf" .= pc , "viewKey" .= vk ] @@ -122,7 +126,8 @@ instance FromJSON Owner where zats <- obj .: "zats" inv <- obj .: "invoices" ets <- obj .: "expiration" - vk <- obj .: "viewKey" + pc <- obj .:? "payconf" + vk <- obj .:? "viewKey" pure $ Owner (if not (null i) @@ -149,7 +154,8 @@ instance FromJSON Owner where zats inv ets - vk + (fromMaybe False pc) + (fromMaybe "" vk) instance Val Owner where cast' (Doc d) = do @@ -175,10 +181,12 @@ instance Val Owner where zats <- B.lookup "zats" d inv <- B.lookup "invoices" d ets <- B.lookup "expiration" d + pc <- B.lookup "payconf" d vk <- B.lookup "viewKey" d - Just (Owner i a n c t tV v vV f l e s ct st p ph w co paid zats inv ets vk) + Just + (Owner i a n c t tV v vV f l e s ct st p ph w co paid zats inv ets pc vk) cast' _ = Nothing - val (Owner i a n c t tV v vV f l e s ct st p ph w co paid zats inv ets vk) = + val (Owner i a n c t tV v vV f l e s ct st p ph w co paid zats inv ets pc vk) = case i of Just oid -> Doc @@ -204,6 +212,7 @@ instance Val Owner where , "zats" =: zats , "invoices" =: inv , "expiration" =: ets + , "payconf" =: pc , "viewKey" =: vk ] Nothing -> @@ -229,6 +238,7 @@ instance Val Owner where , "zats" =: zats , "invoices" =: inv , "expiration" =: ets + , "payconf" =: pc , "viewKey" =: vk ]