From 1d18dcbe796820b30e0c8c1db241da95ee7566cb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 18 Apr 2017 13:04:16 -0400 Subject: improve types Including adding a timestamp to logs --- Types.hs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'Types.hs') diff --git a/Types.hs b/Types.hs index fdd10a5..0e918ea 100644 --- a/Types.hs +++ b/Types.hs @@ -15,6 +15,7 @@ import Val import GHC.Generics (Generic) import Data.Aeson +import Data.Time.Clock.POSIX -- | Things that the developer sees. data Seen = Seen @@ -66,24 +67,31 @@ instance FromJSON (Activity Seen) instance ToJSON (Activity Entered) instance FromJSON (Activity Entered) +data SomeActivity + = ActivitySeen (Activity Seen) + | ActivityEntered (Activity Entered) + deriving (Show, Generic) + +instance ToJSON (SomeActivity) +instance FromJSON (SomeActivity) + -- | A log of Activity both Entered and Seen, which can be recorded to -- prove what happened in a debug-me session. -data ActivityLog - = ActivitySeen - { activitySeen :: (Activity Seen, Hash) - } - | ActivityEntered - { activityEntered :: (Activity Entered, Hash) - } +-- +-- Note that the time stamp is included to allow replaying logs, but +-- it's not part of the provable session. +data ActivityLog = ActivityLog + { loggedActivity :: SomeActivity + , loggedHash :: Hash + , loggedTimestamp :: Timestamp + } deriving (Show, Generic) -activityLogHash :: ActivityLog -> Hash -activityLogHash (ActivitySeen (_, h)) = h -activityLogHash (ActivityEntered (_, h)) = h - instance ToJSON (ActivityLog) instance FromJSON (ActivityLog) +type Timestamp = POSIXTime + newtype Signature = Signature Val deriving (Show, Generic) -- cgit v1.2.3