Skip to content

Commit

Permalink
Fix serialization of the Hydra.Contract.ContestationPeriod
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Jul 29, 2021
1 parent 58eb201 commit fc767f6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions hydra-plutus/src/Hydra/Contract/ContestationPeriod.hs
Expand Up @@ -5,10 +5,19 @@ module Hydra.Contract.ContestationPeriod where

import Hydra.Prelude

import Data.Time (diffTimeToPicoseconds, picosecondsToDiffTime)
import qualified PlutusTx

newtype ContestationPeriod = UnsafeContestationPeriod {seconds :: Integer}
newtype ContestationPeriod = UnsafeContestationPeriod {picoseconds :: Integer}
deriving stock (Generic, Eq, Ord, Show)
deriving newtype (Num, FromJSON, ToJSON)
deriving newtype (Num)

PlutusTx.unstableMakeIsData ''ContestationPeriod

instance FromJSON ContestationPeriod where
parseJSON =
fmap (UnsafeContestationPeriod . diffTimeToPicoseconds) . parseJSON

instance ToJSON ContestationPeriod where
toJSON =
toJSON . picosecondsToDiffTime . picoseconds

0 comments on commit fc767f6

Please sign in to comment.