Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoeldner committed Nov 16, 2023
1 parent 2c39519 commit a288587
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
12 changes: 6 additions & 6 deletions pact-core/Pact/Core/Guards.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ instance (Pretty name, Pretty term) => Pretty (Guard name term) where
GModuleGuard g -> pretty g


data Namespace name term
= Namespace
{ _nsName :: !NamespaceName
, _nsUser :: !(Guard name term)
, _nsAdmin :: !(Guard name term)
} deriving (Eq, Show)
-- data Namespace name term
-- = Namespace
-- { _nsName :: !NamespaceName
-- , _nsUser :: !(Guard name term)
-- , _nsAdmin :: !(Guard name term)
-- } deriving (Eq, Show)

instance (Pretty name, Pretty term) => Pretty (CapabilityGuard name term) where
pretty (CapabilityGuard cg args pid) = "CapabilityGuard" <+> commaBraces
Expand Down
50 changes: 43 additions & 7 deletions pact-core/Pact/Core/Serialise/LegacyPact.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- |

{-# OPTIONS_GHC -fno-warn-orphans #-}
module Pact.Core.Serialise.LegacyPact
( decodeModuleData
, decodeKeySet
Expand All @@ -16,21 +16,57 @@ import Pact.Core.DefPacts.Types
import Pact.Core.Namespace
import Pact.Core.PactValue
import Data.ByteString (ByteString)
import Control.Applicative ((<|>))
import Data.Maybe (fromMaybe)

import qualified Pact.JSON.Decode as JD

decodeModuleData :: ByteString -> Maybe (ModuleData RawBuiltin ())
decodeModuleData = undefined

decodeModuleData = JD.decodeStrict'

decodeKeySet :: ByteString -> Maybe (KeySet FullyQualifiedName)
decodeKeySet = undefined
decodeKeySet = JD.decodeStrict'

decodeDefPactExec :: ByteString -> Maybe (Maybe DefPactExec)
decodeDefPactExec = undefined
decodeDefPactExec = JD.decodeStrict'

decodeNamespace :: ByteString -> Maybe Namespace
decodeNamespace = undefined
decodeNamespace = JD.decodeStrict'

decodeRowData :: ByteString -> Maybe RowData
decodeRowData = undefined
decodeRowData = JD.decodeStrict'

instance JD.FromJSON NamespaceName where
parseJSON = JD.withText "NamespaceName" (pure . NamespaceName)


instance JD.FromJSON (KeySet FullyQualifiedName) where
parseJSON v = JD.withObject "KeySet" keyListPred v <|> keyListOnly
where
defPred = KeysAll

keyListPred o = KeySet
<$> o JD..: "keys"
<*> (fromMaybe defPred <$> o JD..:? "pred")

keyListOnly = KeySet <$> JD.parseJSON v <*> pure defPred

instance JD.FromJSON (KSPredicate FullyQualifiedName) where
parseJSON = JD.withText "KSPredicate" $ \case
"keys-all" -> pure KeysAll
"keys2" -> pure Keys2
"KeysAny" -> pure KeysAny
_ -> fail "unexpected parsing"

instance JD.FromJSON PublicKeyText where
parseJSON = JD.withText "PublicKeyText" (pure . PublicKeyText)


instance JD.FromJSON Namespace where
parseJSON = JD.withObject "Namespace" $ \v -> Namespace
<$> v JD..: "name"
<*> v JD..: "user"
<*> v JD..: "admin"

instance JD.FromJSON (Guard FullyQualifiedName PactValue) where
parseJSON = undefined

0 comments on commit a288587

Please sign in to comment.