Add new fields to Owner for payment confirmation

This commit is contained in:
Rene Vergara 2022-07-18 15:22:44 -05:00
parent ebf3d2ce25
commit 00f2f2003a
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
2 changed files with 18 additions and 5 deletions

View file

@ -9,9 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- New `Config` type to house the configuration parameters - 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 ### Changed
- Added alphabetic sorting to list of items
- Refactored code to use new `Config` type - Refactored code to use new `Config` type
- Enhance `decodeHexText` to support Unicode - Enhance `decodeHexText` to support Unicode
- Enhance `encodeHexText` to support Unicode - Enhance `encodeHexText` to support Unicode

View file

@ -6,6 +6,7 @@ module Owner where
import Data.Aeson import Data.Aeson
import qualified Data.Bson as B import qualified Data.Bson as B
import Data.Maybe
import qualified Data.Text as T import qualified Data.Text as T
import Data.Time.Clock import Data.Time.Clock
import Data.Typeable import Data.Typeable
@ -37,12 +38,13 @@ data Owner =
, ozats :: Bool , ozats :: Bool
, oinvoices :: Bool , oinvoices :: Bool
, oexpiration :: UTCTime , oexpiration :: UTCTime
, opayconf :: Bool
, oviewkey :: T.Text , oviewkey :: T.Text
} }
deriving (Eq, Show, Generic, Typeable) deriving (Eq, Show, Generic, Typeable)
instance ToJSON Owner where 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 case i of
Just oid -> Just oid ->
object object
@ -68,6 +70,7 @@ instance ToJSON Owner where
, "zats" .= zats , "zats" .= zats
, "invoices" .= inv , "invoices" .= inv
, "expiration" .= eTs , "expiration" .= eTs
, "payconf" .= pc
, "viewKey" .= vk , "viewKey" .= vk
] ]
Nothing -> Nothing ->
@ -94,6 +97,7 @@ instance ToJSON Owner where
, "zats" .= zats , "zats" .= zats
, "invoices" .= inv , "invoices" .= inv
, "expiration" .= eTs , "expiration" .= eTs
, "payconf" .= pc
, "viewKey" .= vk , "viewKey" .= vk
] ]
@ -122,7 +126,8 @@ instance FromJSON Owner where
zats <- obj .: "zats" zats <- obj .: "zats"
inv <- obj .: "invoices" inv <- obj .: "invoices"
ets <- obj .: "expiration" ets <- obj .: "expiration"
vk <- obj .: "viewKey" pc <- obj .:? "payconf"
vk <- obj .:? "viewKey"
pure $ pure $
Owner Owner
(if not (null i) (if not (null i)
@ -149,7 +154,8 @@ instance FromJSON Owner where
zats zats
inv inv
ets ets
vk (fromMaybe False pc)
(fromMaybe "" vk)
instance Val Owner where instance Val Owner where
cast' (Doc d) = do cast' (Doc d) = do
@ -175,10 +181,12 @@ instance Val Owner where
zats <- B.lookup "zats" d zats <- B.lookup "zats" d
inv <- B.lookup "invoices" d inv <- B.lookup "invoices" d
ets <- B.lookup "expiration" d ets <- B.lookup "expiration" d
pc <- B.lookup "payconf" d
vk <- B.lookup "viewKey" 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 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 case i of
Just oid -> Just oid ->
Doc Doc
@ -204,6 +212,7 @@ instance Val Owner where
, "zats" =: zats , "zats" =: zats
, "invoices" =: inv , "invoices" =: inv
, "expiration" =: ets , "expiration" =: ets
, "payconf" =: pc
, "viewKey" =: vk , "viewKey" =: vk
] ]
Nothing -> Nothing ->
@ -229,6 +238,7 @@ instance Val Owner where
, "zats" =: zats , "zats" =: zats
, "invoices" =: inv , "invoices" =: inv
, "expiration" =: ets , "expiration" =: ets
, "payconf" =: pc
, "viewKey" =: vk , "viewKey" =: vk
] ]