-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
279 additions
and
151 deletions.
There are no files selected for viewing
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,122 @@ | ||
{-# LANGUAGE TypeSynonymInstances #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE DerivingVia #-} | ||
{-# LANGUAGE ImplicitParams #-} | ||
{-# LANGUAGE ConstraintKinds #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE FunctionalDependencies #-} | ||
{-# LANGUAGE PatternSynonyms #-} | ||
{-# LANGUAGE InstanceSigs #-} | ||
|
||
module Pact.Core.ChainData | ||
( TxCreationTime(..) | ||
, PublicData(..) | ||
, pdPublicMeta, pdBlockHeight | ||
, pdBlockTime, pdPrevBlockHash | ||
, PublicMeta(..) | ||
, pmChainId, pmSender, pmGasLimit | ||
, pmGasPrice, pmTTL, pmCreationTime | ||
, TTLSeconds(..) | ||
, ChainId(..) | ||
, cdChainId, cdBlockHeight | ||
, cdBlockTime, cdPrevBlockHash | ||
, cdSender, cdGasLimit, cdGasPrice | ||
) where | ||
|
||
import Data.Int(Int64) | ||
import Data.Word(Word64) | ||
import Control.Lens | ||
import Data.Text(Text) | ||
import Data.Default | ||
|
||
|
||
import Pact.Core.Gas | ||
import Pact.Core.Names | ||
|
||
-- | Wrapper for 'PublicMeta' ttl field in seconds since offset | ||
-- | ||
newtype TTLSeconds | ||
= TTLSeconds Integer | ||
deriving (Eq, Show) | ||
|
||
-- | Wrapper for 'PublicMeta' creation time field in seconds since POSIX epoch | ||
-- | ||
newtype TxCreationTime | ||
= TxCreationTime Integer | ||
deriving (Eq, Show) | ||
|
||
newtype ChainId | ||
= ChainId { _chainId :: Text } | ||
deriving (Eq, Show) | ||
|
||
-- | Allows user to specify execution parameters specific to public-chain | ||
-- execution, namely gas parameters, TTL, creation time, chain identifier. | ||
data PublicMeta | ||
= PublicMeta | ||
{ _pmChainId :: !ChainId | ||
-- ^ platform-specific chain identifier, e.g. "0" | ||
, _pmSender :: !Text | ||
-- ^ sender gas account key | ||
, _pmGasLimit :: !GasLimit | ||
-- ^ gas limit (maximum acceptable gas units for tx) | ||
, _pmGasPrice :: !GasPrice | ||
-- ^ per-unit gas price | ||
, _pmTTL :: !TTLSeconds | ||
-- ^ TTL in seconds | ||
, _pmCreationTime :: !TxCreationTime | ||
-- ^ Creation time in seconds since UNIX epoch | ||
} deriving (Eq, Show) | ||
makeLenses ''PublicMeta | ||
|
||
instance Default PublicMeta where | ||
def = | ||
PublicMeta | ||
{ _pmChainId = ChainId "" | ||
, _pmSender = "" | ||
, _pmGasLimit = Gas 0 | ||
, _pmGasPrice = 0 | ||
, _pmTTL = TTLSeconds 0 | ||
, _pmCreationTime = TxCreationTime 0 | ||
} | ||
|
||
-- | "Public chain" data with immutable block data | ||
-- height, hash, creation time | ||
data PublicData = PublicData | ||
{ _pdPublicMeta :: !PublicMeta | ||
-- ^ 'PublicMeta' data from request | ||
, _pdBlockHeight :: !Word64 | ||
-- ^ block height as specified by platform. | ||
, _pdBlockTime :: !Int64 | ||
-- ^ block creation time, micros since UNIX epoch | ||
, _pdPrevBlockHash :: !Text | ||
-- ^ block hash of preceding block | ||
} | ||
deriving (Show) | ||
makeLenses ''PublicData | ||
|
||
instance Default PublicData where | ||
def = | ||
PublicData | ||
{ _pdPublicMeta = def | ||
, _pdBlockHeight = 0 | ||
, _pdBlockTime = 0 | ||
, _pdPrevBlockHash = ""} | ||
|
||
cdChainId :: Field | ||
cdChainId = Field "chain-id" | ||
cdBlockHeight :: Field | ||
cdBlockHeight = Field "block-height" | ||
cdBlockTime :: Field | ||
cdBlockTime = Field "block-time" | ||
cdPrevBlockHash :: Field | ||
cdPrevBlockHash = Field "prev-block-hash" | ||
cdSender :: Field | ||
cdSender = Field "sender" | ||
cdGasLimit :: Field | ||
cdGasLimit = Field "gas-limit" | ||
cdGasPrice :: Field | ||
cdGasPrice = Field "gas-price" |
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
Oops, something went wrong.