Skip to content

Commit

Permalink
yield with provenance
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Oct 18, 2023
1 parent 66520e1 commit edc107f
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 151 deletions.
1 change: 1 addition & 0 deletions pact-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ library
Pact.Core.Capabilities
Pact.Core.ModRefs
Pact.Core.Interpreter
Pact.Core.ChainData
Pact.Core.Environment

-- Syntax modules
Expand Down
20 changes: 1 addition & 19 deletions pact-core/Pact/Core/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -559,22 +559,6 @@ data ReplBuiltins
| RSigKeyset
| RTestCapability
| REnvExecConfig
-- | RLoad
-- | RLoadWithEnv
-- | RExpect
-- | RExpectFailure
-- | RExpectThat
-- | RPactState
-- | RRollbackTx
-- | RSigKeyset
-- | RTestCapability
-- | RVerify
-- | RWithAppliedEnv
-- | REnvEnableReplNatives
-- | RBeginTx
-- | RBench
-- | RCommitTx
-- | REnvExecConfig
-- | REnvGas
-- | REnvGasLimit
-- | REnvGasLog
Expand All @@ -599,7 +583,7 @@ instance IsBuiltin ReplBuiltins where
RExpectFailureMatch -> 3
RExpectThat -> 3
RPrint -> 1
RPactState -> 1
RPactState -> 0
RResetPactState -> 1
REnvStackFrame -> 0
REnvChainData -> 1
Expand Down Expand Up @@ -685,8 +669,6 @@ replBuiltinsToText = \case
RContinuePactRollback -> "continue-pact-with-rollback"
RContinuePactRollbackYield -> "continue-pact-rollback-yield"
REnvExecConfig -> "env-exec-config"
-- RLoad -> "load"
-- RLoadWithEnv -> "load-with-env"

replBuiltinToText :: (t -> Text) -> ReplBuiltin t -> Text
replBuiltinToText f = \case
Expand Down
122 changes: 122 additions & 0 deletions pact-core/Pact/Core/ChainData.hs
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"
170 changes: 84 additions & 86 deletions pact-core/Pact/Core/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ module Pact.Core.Environment
, ExecutionFlag(..)
) where

import Data.Int(Int64)
import Data.Word(Word64)
import Control.Lens
import Data.Set(Set)
import Data.Text(Text)
Expand All @@ -53,83 +51,83 @@ import Data.Default
import qualified Data.Text as T
import qualified Data.Map.Strict as M

import Pact.Core.Gas
import Pact.Core.Persistence
import Pact.Core.Capabilities
import Pact.Core.Guards
import Pact.Core.PactValue ( PactValue, EnvData )
import Pact.Core.Hash
import Pact.Core.Names
import Pact.Core.Pacts.Types

-- | 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 = ""}
import Pact.Core.ChainData

-- -- | 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 = ""}

-- | Execution flags specify behavior of the runtime environment,
-- with an orientation towards some alteration of a default behavior.
Expand Down Expand Up @@ -211,17 +209,17 @@ makeClassy ''EvalState
instance HasLoaded (EvalState b i) b i where
loaded = esLoaded

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"
-- 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"
Loading

0 comments on commit edc107f

Please sign in to comment.