-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3197 from input-output-hk/scp-2214-switch-slot-to…
…-time SCP-2214 Switch to POSIXTime instead of Slot in TxInfo
- Loading branch information
Showing
30 changed files
with
1,599 additions
and
991 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
nix/pkgs/haskell/materialized-unix/.plan.nix/plutus-ledger-api.nix
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE MonoLocalBinds #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE UndecidableInstances #-} | ||
-- Otherwise we get a complaint about the 'fromIntegral' call in the generated instance of 'Integral' for 'Ada' | ||
{-# OPTIONS_GHC -Wno-identities #-} | ||
{-# OPTIONS_GHC -fno-ignore-interface-pragmas #-} | ||
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-} | ||
|
||
-- | UTCTime and UTCTime ranges. | ||
module Plutus.V1.Ledger.Time( | ||
POSIXTime(..) | ||
, POSIXTimeRange | ||
) where | ||
|
||
import Codec.Serialise.Class (Serialise) | ||
import Control.DeepSeq (NFData) | ||
import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey) | ||
import Data.Hashable (Hashable) | ||
import Data.Text.Prettyprint.Doc (Pretty (pretty), comma, (<+>)) | ||
import GHC.Generics (Generic) | ||
import qualified Prelude as Haskell | ||
|
||
import qualified PlutusTx | ||
import PlutusTx.Lift (makeLift) | ||
import PlutusTx.Prelude | ||
|
||
import Plutus.V1.Ledger.Interval | ||
|
||
-- | POSIX time is measured as the number of seconds since 1970-01-01 00:00 UTC | ||
newtype POSIXTime = POSIXTime { getPOSIXTime :: Integer } | ||
deriving stock (Haskell.Eq, Haskell.Ord, Show, Generic) | ||
deriving anyclass (FromJSON, FromJSONKey, ToJSON, ToJSONKey, NFData) | ||
deriving newtype (Haskell.Num, AdditiveSemigroup, AdditiveMonoid, AdditiveGroup, Enum, Eq, Ord, Real, Integral, Serialise, Hashable, PlutusTx.IsData) | ||
|
||
makeLift ''POSIXTime | ||
|
||
instance Pretty POSIXTime where | ||
pretty (POSIXTime i) = "POSIXTime" <+> pretty i | ||
|
||
instance Pretty (Interval POSIXTime) where | ||
pretty (Interval l h) = pretty l <+> comma <+> pretty h | ||
|
||
-- | An 'Interval' of 'POSIXTime's. | ||
type POSIXTimeRange = Interval POSIXTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
-- This GHC option prevents the error: | ||
-- "GHC Core to PLC plugin: E042:Error: Unsupported feature: Kind: *" | ||
-- Because Plutus can't handle unboxed tuples which come from worker/wrapper | ||
{-# OPTIONS_GHC -fno-worker-wrapper #-} | ||
|
||
module Ledger.TimeSlot( | ||
slotRangeToPOSIXTimeRange | ||
, slotToPOSIXTime | ||
, posixTimeRangeToSlotRange | ||
, posixTimeToSlot | ||
) where | ||
|
||
import Plutus.V1.Ledger.Slot (Slot (Slot), SlotRange) | ||
import Plutus.V1.Ledger.Time (POSIXTime (POSIXTime), POSIXTimeRange) | ||
import PlutusTx.Prelude | ||
|
||
{-# INLINABLE shelleyLaunchDate #-} | ||
-- | 'shelleyLaunchDatePOSIXTime' corresponds to the time 2020-07-29T21:44:51Z | ||
-- which is 1596059091 in POSIX time. | ||
shelleyLaunchDate :: Integer | ||
shelleyLaunchDate = 1596059091 | ||
|
||
{-# INLINABLE slotRangeToPOSIXTimeRange #-} | ||
-- | Convert a 'SlotRange' to 'POSIXTimeRange' | ||
slotRangeToPOSIXTimeRange :: SlotRange -> POSIXTimeRange | ||
slotRangeToPOSIXTimeRange sr = slotToPOSIXTime <$> sr | ||
|
||
{-# INLINABLE slotToPOSIXTime #-} | ||
-- | Convert a 'Slot to 'POSIXTime | ||
slotToPOSIXTime :: Slot -> POSIXTime | ||
slotToPOSIXTime (Slot n) = POSIXTime (n + shelleyLaunchDate) | ||
|
||
{-# INLINABLE posixTimeRangeToSlotRange #-} | ||
-- | Convert a 'POSIXTimeRange' to 'SlotRange' | ||
posixTimeRangeToSlotRange :: POSIXTimeRange -> SlotRange | ||
posixTimeRangeToSlotRange ptr = posixTimeToSlot <$> ptr | ||
|
||
{-# INLINABLE posixTimeToSlot #-} | ||
-- | Convert a 'POSIXTime' to 'Slot' | ||
posixTimeToSlot :: POSIXTime -> Slot | ||
posixTimeToSlot (POSIXTime t) = Slot (t - shelleyLaunchDate) | ||
|
Oops, something went wrong.