From 0041f3f45fee4e604c1206f1dd445e01211c5479 Mon Sep 17 00:00:00 2001 From: jmcardon Date: Fri, 15 Dec 2023 13:24:10 -0500 Subject: [PATCH] move pactvalues to qualnames, fix serialise instances --- pact-core-tests/Pact/Core/Gen/Serialise.hs | 45 ++++++----------- .../Pact/Core/Test/PersistenceTests.hs | 12 ++--- .../Pact/Core/Test/SerialiseTests.hs | 2 +- pact-core/Pact/Core/DefPacts/Types.hs | 2 +- pact-core/Pact/Core/Environment/Utils.hs | 2 +- pact-core/Pact/Core/Guards.hs | 11 ++-- pact-core/Pact/Core/IR/Eval/CEK.hs | 46 +++++++++-------- pact-core/Pact/Core/IR/Eval/RawBuiltin.hs | 47 ++++++++--------- pact-core/Pact/Core/IR/Eval/Runtime/Types.hs | 2 +- pact-core/Pact/Core/IR/ModuleHashing.hs | 50 +++++++++---------- pact-core/Pact/Core/Interpreter.hs | 2 +- pact-core/Pact/Core/Names.hs | 3 ++ pact-core/Pact/Core/Namespace.hs | 4 +- pact-core/Pact/Core/PactValue.hs | 4 +- pact-core/Pact/Core/Persistence.hs | 4 +- pact-core/Pact/Core/Serialise.hs | 4 +- pact-core/Pact/Core/Serialise/CBOR_V1.hs | 30 +++++------ pact-core/Pact/Core/Serialise/LegacyPact.hs | 43 +++++++--------- pact-core/Pact/Core/StableEncoding.hs | 31 ++++-------- 19 files changed, 160 insertions(+), 184 deletions(-) diff --git a/pact-core-tests/Pact/Core/Gen/Serialise.hs b/pact-core-tests/Pact/Core/Gen/Serialise.hs index 4100166d1..17d9f1a62 100644 --- a/pact-core-tests/Pact/Core/Gen/Serialise.hs +++ b/pact-core-tests/Pact/Core/Gen/Serialise.hs @@ -17,36 +17,19 @@ import qualified Data.Vector as Vec import Hedgehog hiding (Var) import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Range as Range - -import Pact.Core.Names (BareName(..), DefPactId(..), DynamicName(..), - DynamicRef(..), Field(..), FQNameRef(FQName), - FullyQualifiedName(..), ModuleName(..), Name(..), - NameKind(NBound, NDynRef, NModRef, NTopLevel), - NamespaceName(..), ParsedName(BN,DN,QN), - QualifiedName(..)) -import Pact.Core.Guards (CapGovRef(UnresolvedGov, ResolvedGov), - Governance(CapGov, KeyGov), Guard(GKeyset,GKeySetRef), - KeySet(..), KeySetName(..), - KSPredicate(KeysAll, Keys2, KeysAny), PublicKeyText(..), - UserGuard(..)) +import Pact.Core.Names +import Pact.Core.Guards import Pact.Core.Hash (Hash(..), ModuleHash(..)) -import Pact.Core.Type (Arg(..), PrimType(PrimBool, PrimDecimal, PrimGuard, - PrimInt, PrimString, PrimTime, - PrimUnit), - Schema(Schema, _schema), Type(TyList, TyModRef, TyObject, - TyPrim, TyTable)) +import Pact.Core.Type import Pact.Core.Imports (Import(..)) import Pact.Core.IR.Term import Pact.Core.Info (SpanInfo) -import Pact.Core.Builtin (RawBuiltin, BuiltinForm(CAnd, COr, CIf, CEnforce, - CEnforceOne)) -import Pact.Core.Literal (Literal(LBool, LDecimal, LInteger, LString, LUnit)) -import Pact.Core.Capabilities (DefManagedMeta(DefManagedMeta, AutoManagedMeta), - DefCapMeta(DefEvent, DefManaged, Unmanaged) ) -import Pact.Core.Persistence (ModuleData(ModuleData, InterfaceData)) -import Pact.Core.PactValue (PactValue(PGuard, PList, PLiteral)) -import Pact.Core.DefPacts.Types (DefPactContinuation(..), DefPactExec(..), - Provenance(..), Yield(..)) +import Pact.Core.Builtin +import Pact.Core.Literal +import Pact.Core.Capabilities +import Pact.Core.Persistence +import Pact.Core.PactValue +import Pact.Core.DefPacts.Types import Pact.Core.ChainData (ChainId(..)) import Pact.Core.Namespace (Namespace(..)) import Pact.Core.Test.LexerParserTests (identGen) @@ -57,8 +40,8 @@ namespaceNameGen = NamespaceName <$> identGen namespaceGen :: Gen Namespace namespaceGen = do name <- namespaceNameGen - user <- guardGen 3 fullyQualifiedNameGen - Namespace name user <$> guardGen 3 fullyQualifiedNameGen + user <- guardGen 3 qualifiedNameGen + Namespace name user <$> guardGen 3 qualifiedNameGen moduleNameGen :: Gen ModuleName moduleNameGen = do @@ -437,7 +420,7 @@ pactValueGen' :: Int ->Gen PactValue pactValueGen' depth = Gen.choice [ PLiteral <$> literalGen , PList . Vec.fromList <$> Gen.list (Range.linear 0 depth) (pactValueGen' (depth - 1)) - , PGuard <$> guardGen (depth - 1) fullyQualifiedNameGen + , PGuard <$> guardGen (depth - 1) qualifiedNameGen ] chainIdGen :: Gen ChainId @@ -454,9 +437,9 @@ yieldGen = do p <- Gen.maybe provenanceGen Yield d p <$> Gen.maybe chainIdGen -defPactContinuationGen :: Gen (DefPactContinuation FullyQualifiedName PactValue) +defPactContinuationGen :: Gen (DefPactContinuation QualifiedName PactValue) defPactContinuationGen = do - ident <- fullyQualifiedNameGen + ident <- qualifiedNameGen DefPactContinuation ident <$> Gen.list (Range.linear 0 8) pactValueGen defPactExecGen :: Gen DefPactExec diff --git a/pact-core-tests/Pact/Core/Test/PersistenceTests.hs b/pact-core-tests/Pact/Core/Test/PersistenceTests.hs index 74331ef06..d5ebbe39a 100644 --- a/pact-core-tests/Pact/Core/Test/PersistenceTests.hs +++ b/pact-core-tests/Pact/Core/Test/PersistenceTests.hs @@ -19,7 +19,7 @@ import Pact.Core.Guards (KeySet(KeySet), KeySetName(..), PublicKeyText(..), KSPr import Pact.Core.Gen.Serialise (keySetGen, keySetNameGen, moduleNameGen, moduleDataGen, builtinGen ,defPactIdGen, defPactExecGen, namespaceNameGen, namespaceGen) import Pact.Core.Literal (Literal(LUnit)) -import Pact.Core.Names (Field(..), FullyQualifiedName, RowKey(..), TableName(..), ModuleName(..)) +import Pact.Core.Names import Pact.Core.PactValue import qualified Pact.Core.PactValue as PactValue import Pact.Core.Persistence.SQLite @@ -53,7 +53,7 @@ testsWithSerial serial b i = , testProperty "Namespace" $ namespaceRoundtrip serial ] -keysetPersistRoundtrip :: PactSerialise b i -> Gen (KeySet FullyQualifiedName) -> Property +keysetPersistRoundtrip :: PactSerialise b i -> Gen (KeySet QualifiedName) -> Property keysetPersistRoundtrip serial keysetGen = property $ do keysetName <- forAll keySetNameGen @@ -130,7 +130,7 @@ sqliteRegression = , (Field "fh", PactValue.PInteger 1) ] row2Enc = _encodeRowData serialisePact_repl_spaninfo row2 - + _pdbWrite pdb Update (DUserTables usert) (RowKey "key1") row2 Just row2' <- _pdbRead pdb (DUserTables usert) (RowKey "key1") assertEqual "user update should overwrite with new value" row2 row2' @@ -159,7 +159,7 @@ sqliteRegression = , TxLog "user1" "key1" row2Enc , TxLog "user1" "key1" rowEnc ] - + -- begin tx _ <- _pdbBeginTx pdb Transactional tids <- _pdbTxIds pdb usert t1 @@ -183,7 +183,7 @@ sqliteRegression = rkeys2 <- _pdbKeys pdb (DUserTables usert) assertEqual "keys post-rollback [key1]" [RowKey "key1"] rkeys2 - + where loadModule = do let src = "(module test G (defcap G () true) (defun f (a: integer) 1))" @@ -195,4 +195,4 @@ sqliteRegression = Right _ <- runReplT ref (interpretReplProgram (SourceCode "test" src) (const (pure ()))) Just md <- readModule pdb (ModuleName "test" Nothing) pure md - + diff --git a/pact-core-tests/Pact/Core/Test/SerialiseTests.hs b/pact-core-tests/Pact/Core/Test/SerialiseTests.hs index 68f1dd403..94e5f279b 100644 --- a/pact-core-tests/Pact/Core/Test/SerialiseTests.hs +++ b/pact-core-tests/Pact/Core/Test/SerialiseTests.hs @@ -102,7 +102,7 @@ serialiseModule = property $ do serialiseKeySet :: Property serialiseKeySet = property $ do - ks <- forAll (keySetGen fullyQualifiedNameGen) + ks <- forAll (keySetGen qualifiedNameGen) let encoded = _encodeKeySet serialisePact ks case _decodeKeySet serialisePact encoded of diff --git a/pact-core/Pact/Core/DefPacts/Types.hs b/pact-core/Pact/Core/DefPacts/Types.hs index 1c6da9844..458d697ee 100644 --- a/pact-core/Pact/Core/DefPacts/Types.hs +++ b/pact-core/Pact/Core/DefPacts/Types.hs @@ -56,7 +56,7 @@ data DefPactExec , _peYield :: Maybe Yield , _peStep :: Int , _peDefPactId :: DefPactId - , _peContinuation :: DefPactContinuation FullyQualifiedName PactValue + , _peContinuation :: DefPactContinuation QualifiedName PactValue , _peStepHasRollback :: Bool , _peNestedDefPactExec :: Map DefPactId DefPactExec } deriving (Show, Eq) diff --git a/pact-core/Pact/Core/Environment/Utils.hs b/pact-core/Pact/Core/Environment/Utils.hs index c8ddda159..2cd24297a 100644 --- a/pact-core/Pact/Core/Environment/Utils.hs +++ b/pact-core/Pact/Core/Environment/Utils.hs @@ -182,7 +182,7 @@ mangleNamespace mn@(ModuleName mnraw ns) = isKeysetInSigs :: MonadEval b i m - => KeySet FullyQualifiedName + => KeySet QualifiedName -> m Bool isKeysetInSigs (KeySet kskeys ksPred) = do matchedSigs <- M.filterWithKey matchKey <$> viewEvalEnv eeMsgSigs diff --git a/pact-core/Pact/Core/Guards.hs b/pact-core/Pact/Core/Guards.hs index 9d882d61e..f03693d5b 100644 --- a/pact-core/Pact/Core/Guards.hs +++ b/pact-core/Pact/Core/Guards.hs @@ -23,9 +23,6 @@ module Pact.Core.Guards ) where -import qualified Data.Char as Char -import qualified Data.Set as S -import qualified Data.Text as T import Control.Applicative import Control.Monad import Data.Attoparsec.Text @@ -34,6 +31,10 @@ import Data.String import Data.Text(Text) import Text.Parser.Token as P +import qualified Data.Char as Char +import qualified Data.Set as S +import qualified Data.Text as T + import Pact.Core.Pretty import Pact.Core.Names import Pact.Core.RuntimeParsers @@ -97,7 +98,7 @@ data KSPredicate name | Keys2 | KeysAny -- | CustomPredicate name -- TODO: When this is brought back, fix up `keySetGen`! - deriving (Eq, Show, Ord) + deriving (Eq, Show, Ord, Functor, Foldable, Traversable) predicateToString :: IsString s => KSPredicate name -> s predicateToString = \case @@ -112,7 +113,7 @@ data KeySet name = KeySet { _ksKeys :: !(S.Set PublicKeyText) , _ksPredFun :: KSPredicate name - } deriving (Eq, Show, Ord) + } deriving (Eq, Show, Ord, Functor, Foldable, Traversable) instance Pretty name => Pretty (KeySet name) where pretty (KeySet ks f) = "KeySet" <+> commaBraces diff --git a/pact-core/Pact/Core/IR/Eval/CEK.hs b/pact-core/Pact/Core/IR/Eval/CEK.hs index 14917ae86..07f41ef9a 100644 --- a/pact-core/Pact/Core/IR/Eval/CEK.hs +++ b/pact-core/Pact/Core/IR/Eval/CEK.hs @@ -247,7 +247,7 @@ mkDefPactClosure info fqn dpact env = case _dpArgs dpact of initPact :: MonadEval b i m => i - -> DefPactContinuation FullyQualifiedName PactValue + -> DefPactContinuation QualifiedName PactValue -> Cont b i m -> CEKErrorHandler b i m -> CEKEnv b i m @@ -272,7 +272,7 @@ initPact i pc cont handler cenv = do applyPact :: MonadEval b i m => i - -> DefPactContinuation FullyQualifiedName PactValue + -> DefPactContinuation QualifiedName PactValue -> DefPactStep -> Cont b i m -> CEKErrorHandler b i m @@ -281,8 +281,8 @@ applyPact -> m (EvalResult b i m) applyPact i pc ps cont handler cenv nested = useEvalState esDefPactExec >>= \case Just pe -> throwExecutionError i (MultipleOrNestedDefPactExecFound pe) - Nothing -> lookupFqName (pc ^. pcName) >>= \case - Just (DPact defPact) -> do + Nothing -> getModuleMember i (_cePactDb cenv) (pc ^. pcName) >>= \case + DPact defPact -> do let nSteps = NE.length (_dpSteps defPact) -- Check we try to apply the correct pact Step @@ -311,14 +311,14 @@ applyPact i pc ps cont handler cenv nested = useEvalState esDefPactExec >>= \cas (True, StepWithRollback _ rollbackExpr) -> evalWithStackFrame i cont' handler cenv sf Nothing rollbackExpr (True, Step{}) -> throwExecutionError i (DefPactStepHasNoRollback ps) - _otherwise -> failInvariant i "DefPact not found" + _otherwise -> failInvariant i "defpact continuation does not point to defun" where - sf = StackFrame (view (pcName . fqName) pc) (view (pcName . fqModule) pc) SFDefPact + sf = StackFrame (view (pcName . qnName) pc) (view (pcName . qnModName) pc) SFDefPact applyNestedPact :: MonadEval b i m => i - -> DefPactContinuation FullyQualifiedName PactValue + -> DefPactContinuation QualifiedName PactValue -> DefPactStep -> Cont b i m -> CEKErrorHandler b i m @@ -328,8 +328,8 @@ applyNestedPact i pc ps cont handler cenv = useEvalState esDefPactExec >>= \case Nothing -> failInvariant i $ "applyNestedPact: Nested DefPact attempted but no pactExec found" <> T.pack (show pc) - Just pe -> lookupFqName (pc ^. pcName) >>= \case - Just (DPact defPact) -> do + Just pe -> getModuleMember i (_cePactDb cenv) (pc ^. pcName) >>= \case + DPact defPact -> do step <- maybe (failInvariant i "Step not found") pure $ _dpSteps defPact ^? ix (ps ^. psStep) @@ -377,7 +377,7 @@ applyNestedPact i pc ps cont handler cenv = useEvalState esDefPactExec >>= \case (True, Step{}) -> throwExecutionError i (DefPactStepHasNoRollback ps) _otherwise -> failInvariant i "applyNestedPact: Expected a DefPact bot got something else" where - sf = StackFrame (view (pcName . fqName) pc) (view (pcName . fqModule) pc) SFDefPact + sf = StackFrame (view (pcName . qnName) pc) (view (pcName . qnModName) pc) SFDefPact resumePact :: MonadEval b i m @@ -538,7 +538,7 @@ evalCap -> (CEKEnv b i m -> Maybe (CapToken QualifiedName PactValue) -> Maybe (PactEvent PactValue) -> EvalTerm b i -> Cont b i m -> Cont b i m) -> EvalTerm b i -> m (EvalResult b i m) -evalCap info currCont handler env origToken@(CapToken fqn args) modCont contbody = isCapInStack origToken >>= \case +evalCap info currCont handler env origToken@(CapToken fqn args) modCont contbody = isCapInStack' origToken >>= \case False -> do lookupFqName fqn >>= \case Just (DCap d) -> do @@ -715,20 +715,26 @@ requireCap -> CEKErrorHandler b i m -> FQCapToken -> m (EvalResult b i m) -requireCap info cont handler ct@(CapToken fqn _) = do - capInStack <- isCapInStack ct +requireCap info cont handler (CapToken fqn args) = do + capInStack <- isCapInStack (CapToken (fqnToQualName fqn) args) if capInStack then returnCEKValue cont handler (VBool True) else returnCEK cont handler $ VError ("cap not in scope " <> renderQualName (fqnToQualName fqn)) info isCapInStack :: (MonadEval b i m) - => FQCapToken + => CapToken QualifiedName PactValue -> m Bool -isCapInStack (CapToken fqn args) = do - let ct = CapToken (fqnToQualName fqn) args +isCapInStack ct = do capSet <- getAllStackCaps pure $ S.member ct capSet +isCapInStack' + :: (MonadEval b i m) + => CapToken FullyQualifiedName PactValue + -> m Bool +isCapInStack' (CapToken fqn args) = + isCapInStack (CapToken (fqnToQualName fqn) args) + composeCap :: (MonadEval b i m) => i @@ -738,7 +744,7 @@ composeCap -> FQCapToken -> m (EvalResult b i m) composeCap info cont handler env origToken = - isCapInStack origToken >>= \case + isCapInStack' origToken >>= \case False -> evalCap info cont handler env origToken (CapBodyC PopCapComposed) (Constant (LBool True) info) -- let ct = CapToken (fqnToQualName fqn) args @@ -814,7 +820,7 @@ createUserGuard createUserGuard info cont handler fqn args = lookupFqName fqn >>= \case Just (Dfun _) -> - returnCEKValue cont handler (VGuard (GUserGuard (UserGuard fqn args))) + returnCEKValue cont handler (VGuard (GUserGuard (UserGuard (fqnToQualName fqn) args))) Just _ -> returnCEK cont handler (VError "create-user-guard pointing to non-guard" info) Nothing -> @@ -1166,11 +1172,11 @@ applyLam (DPC (DefPactClosure fqn argtys arity env i)) args cont handler ArgClosure cloargs -> do args' <- traverse (enforcePactValue i) args tcArgs <- zipWithM (\arg ty -> maybeTCType i arg ty) args' (NE.toList cloargs) - let pc = DefPactContinuation fqn tcArgs + let pc = DefPactContinuation (fqnToQualName fqn) tcArgs env' = set ceLocal (RAList.fromList (reverse (VPactValue <$> tcArgs))) env initPact i pc cont handler env' NullaryClosure -> do - let pc = DefPactContinuation fqn [] + let pc = DefPactContinuation (fqnToQualName fqn) [] env' = set ceLocal mempty env initPact i pc cont handler env' | otherwise = throwExecutionError i ClosureAppliedToTooManyArgs diff --git a/pact-core/Pact/Core/IR/Eval/RawBuiltin.hs b/pact-core/Pact/Core/IR/Eval/RawBuiltin.hs index 330caae71..91e74f79d 100644 --- a/pact-core/Pact/Core/IR/Eval/RawBuiltin.hs +++ b/pact-core/Pact/Core/IR/Eval/RawBuiltin.hs @@ -660,7 +660,7 @@ enforceGuard -> Cont b i m -> CEKErrorHandler b i m -> CEKEnv b i m - -> Guard FullyQualifiedName PactValue + -> Guard QualifiedName PactValue -> m (EvalResult b i m) enforceGuard info cont handler env g = case g of GKeyset ks -> do @@ -693,7 +693,7 @@ enforceGuardCont -> Cont b i m -> CEKErrorHandler b i m -> CEKEnv b i m - -> Guard FullyQualifiedName PactValue + -> Guard QualifiedName PactValue -> m (EvalResult b i m) -> m (EvalResult b i m) enforceGuardCont info cekCont cekHandler env g successCont = @@ -778,7 +778,7 @@ coreReadString info b cont handler _env = \case _ -> returnCEK cont handler (VError "read-integer failure" info) args -> argsError info b args -readKeyset' :: (MonadEval b i m) => T.Text -> m (Maybe (KeySet FullyQualifiedName)) +readKeyset' :: (MonadEval b i m) => T.Text -> m (Maybe (KeySet QualifiedName)) readKeyset' ksn = do ObjectData envData <- viewEvalEnv eeMsgBody case M.lookup (Field ksn) envData of @@ -824,9 +824,9 @@ enforceCapGuard => i -> Cont b i m -> CEKErrorHandler b i m - -> CapabilityGuard FullyQualifiedName PactValue + -> CapabilityGuard QualifiedName PactValue -> m (EvalResult b i m) -enforceCapGuard info cont handler (CapabilityGuard fqn args mpid) = case mpid of +enforceCapGuard info cont handler (CapabilityGuard qn args mpid) = case mpid of Nothing -> enforceCap Just pid -> do currPid <- getDefPactId info @@ -834,10 +834,10 @@ enforceCapGuard info cont handler (CapabilityGuard fqn args mpid) = case mpid of else returnCEK cont handler (VError "Capability pact guard failed: invalid pact id" info) where enforceCap = do - cond <- isCapInStack (CapToken fqn args) + cond <- isCapInStack (CapToken qn args) if cond then returnCEKValue cont handler (VBool True) else do - let errMsg = "Capability guard enforce failure cap not in scope: " <> renderQualName (fqnToQualName fqn) + let errMsg = "Capability guard enforce failure cap not in scope: " <> renderQualName qn returnCEK cont handler (VError errMsg info) runUserGuard @@ -846,18 +846,17 @@ runUserGuard -> Cont b i m -> CEKErrorHandler b i m -> CEKEnv b i m - -> UserGuard FullyQualifiedName PactValue + -> UserGuard QualifiedName PactValue -> m (EvalResult b i m) -runUserGuard info cont handler env (UserGuard fqn args) = - lookupFqName fqn >>= \case - Just (Dfun d) -> do +runUserGuard info cont handler env (UserGuard qn args) = + getModuleMember info (_cePactDb env) qn >>= \case + Dfun d -> do when (length (_dfunArgs d) /= length args) $ throwExecutionError info CannotApplyPartialClosure let env' = sysOnlyEnv env - clo <- mkDefunClosure d (_fqModule fqn) env' + clo <- mkDefunClosure d (_qnModName qn) env' -- Todo: sys only here applyLam (C clo) (VPactValue <$> args) (UserGuardC cont) handler - Just d -> throwExecutionError info (InvalidDefKind (defKind d) "run-user-guard") - Nothing -> throwExecutionError info (NameNotInScope fqn) + d -> throwExecutionError info (InvalidDefKind (defKind d) "run-user-guard") coreBind :: (IsBuiltin b, MonadEval b i m) => NativeFunction b i m coreBind info b cont handler _env = \case @@ -1086,7 +1085,7 @@ defineKeySet' -> CEKErrorHandler b i m -> CEKEnv b i m -> T.Text - -> KeySet FullyQualifiedName + -> KeySet QualifiedName -> m (EvalResult b i m) defineKeySet' info cont handler env ksname newKs = do let pdb = view cePactDb env @@ -1170,16 +1169,18 @@ coreEmitEvent info b cont handler env = \case createCapGuard :: (IsBuiltin b, MonadEval b i m) => NativeFunction b i m createCapGuard info b cont handler _env = \case - [VCapToken ct] -> - let cg = CapabilityGuard (_ctName ct) (_ctArgs ct) Nothing - in returnCEKValue cont handler (VGuard (GCapabilityGuard cg)) + [VCapToken ct] -> do + let qn = fqnToQualName (_ctName ct) + cg = CapabilityGuard qn (_ctArgs ct) Nothing + returnCEKValue cont handler (VGuard (GCapabilityGuard cg)) args -> argsError info b args createCapabilityPactGuard :: (IsBuiltin b, MonadEval b i m) => NativeFunction b i m createCapabilityPactGuard info b cont handler _env = \case [VCapToken ct] -> do pid <- getDefPactId info - let cg = CapabilityGuard (_ctName ct) (_ctArgs ct) (Just pid) + let qn = fqnToQualName (_ctName ct) + let cg = CapabilityGuard qn (_ctArgs ct) (Just pid) returnCEKValue cont handler (VGuard (GCapabilityGuard cg)) args -> argsError info b args @@ -1494,7 +1495,7 @@ dbDescribeTable = \info b cont handler _env -> \case returnCEKValue cont handler $ VObject $ M.fromList $ fmap (over _1 Field) [("name", PString (_tableName name)) ,("module", PString (renderModuleName (_tableModuleName name))) - ,("type", PString "asdf")] -- TODO: + ,("type", PString "asdf")] -- TODO: args -> argsError info b args dbDescribeKeySet :: (IsBuiltin b, MonadEval b i m) => NativeFunction b i m @@ -1520,7 +1521,7 @@ coreCompose info b cont handler env = \case applyLam clo1 [v] cont' handler args -> argsError info b args -createPrincipalForGuard :: Guard FullyQualifiedName PactValue -> Pr.Principal +createPrincipalForGuard :: Guard QualifiedName PactValue -> Pr.Principal createPrincipalForGuard = \case GKeyset (KeySet ks pf) -> case (toList ks, pf) of ([k], KeysAll) -> Pr.K k @@ -1530,13 +1531,13 @@ createPrincipalForGuard = \case GModuleGuard (ModuleGuard mn n) -> Pr.M mn n GUserGuard (UserGuard f args) -> let h = mkHash $ map encodeStable args - in Pr.U (renderQualName $ fqnToQualName f) (hashToText h) + in Pr.U (renderQualName f) (hashToText h) -- TODO orig pact gets here ^^^^ a Name -- which can be any of QualifiedName/BareName/DynamicName/FQN, -- and uses the rendered string here. Need to double-check equivalence. GCapabilityGuard (CapabilityGuard f args pid) -> let args' = map encodeStable args - f' = T.encodeUtf8 $ renderQualName $ fqnToQualName f + f' = T.encodeUtf8 $ renderQualName f pid' = T.encodeUtf8 . renderDefPactId <$> pid h = mkHash $ f' : args' ++ maybeToList pid' in Pr.C $ hashToText h diff --git a/pact-core/Pact/Core/IR/Eval/Runtime/Types.hs b/pact-core/Pact/Core/IR/Eval/Runtime/Types.hs index 95cd5c2e1..ee027c923 100644 --- a/pact-core/Pact/Core/IR/Eval/Runtime/Types.hs +++ b/pact-core/Pact/Core/IR/Eval/Runtime/Types.hs @@ -242,7 +242,7 @@ pattern VBool b = VLiteral (LBool b) pattern VDecimal :: Decimal -> CEKValue b i m pattern VDecimal d = VLiteral (LDecimal d) -pattern VGuard :: Guard FullyQualifiedName PactValue -> CEKValue b i m +pattern VGuard :: Guard QualifiedName PactValue -> CEKValue b i m pattern VGuard g = VPactValue (PGuard g) pattern VList :: Vector PactValue -> CEKValue b i m diff --git a/pact-core/Pact/Core/IR/ModuleHashing.hs b/pact-core/Pact/Core/IR/ModuleHashing.hs index 222274315..e4a0be1fa 100644 --- a/pact-core/Pact/Core/IR/ModuleHashing.hs +++ b/pact-core/Pact/Core/IR/ModuleHashing.hs @@ -90,34 +90,34 @@ updateFqNameHash mname mhash (FullyQualifiedName tlmod n mh) | tlmod == mname = FullyQualifiedName tlmod n mhash | otherwise = FullyQualifiedName tlmod n mh -updateGuardHash - :: ModuleName - -> ModuleHash - -> Guard FullyQualifiedName PactValue - -> Guard FullyQualifiedName PactValue -updateGuardHash mname mhash = \case - GKeyset ks -> GKeyset ks - GKeySetRef ksn -> GKeySetRef ksn - GUserGuard (UserGuard fqn pvs) -> - GUserGuard $ - UserGuard - (updateFqNameHash mname mhash fqn) - (updatePactValueHash mname mhash <$> pvs) - GCapabilityGuard (CapabilityGuard fqn pvs pid) -> - GCapabilityGuard $ - CapabilityGuard - (updateFqNameHash mname mhash fqn) - (updatePactValueHash mname mhash <$> pvs) - pid - GModuleGuard mg -> GModuleGuard mg - g@GDefPactGuard{} -> g +-- updateGuardHash +-- :: ModuleName +-- -> ModuleHash +-- -> Guard QualifiedName PactValue +-- -> Guard QualifiedName PactValue +-- updateGuardHash mname mhash = \case +-- GKeyset ks -> GKeyset ks +-- GKeySetRef ksn -> GKeySetRef ksn +-- GUserGuard (UserGuard fqn pvs) -> +-- GUserGuard $ +-- UserGuard +-- (updateFqNameHash mname mhash fqn) +-- (updatePactValueHash mname mhash <$> pvs) +-- GCapabilityGuard (CapabilityGuard fqn pvs pid) -> +-- GCapabilityGuard $ +-- CapabilityGuard +-- (updateFqNameHash mname mhash fqn) +-- (updatePactValueHash mname mhash <$> pvs) +-- pid +-- GModuleGuard mg -> GModuleGuard mg +-- g@GDefPactGuard{} -> g updatePactValueHash :: ModuleName -> ModuleHash -> PactValue -> PactValue updatePactValueHash mname mhash = \case PLiteral l -> PLiteral l PList l -> PList $ updatePactValueHash mname mhash <$> l - PGuard g -> PGuard $ updateGuardHash mname mhash g + PGuard g -> PGuard g PObject o -> PObject $ updatePactValueHash mname mhash <$> o PModRef m -> PModRef m PCapToken (CapToken ct pvs) -> @@ -208,7 +208,7 @@ encodePactValue = \case PTime time -> B.int64HexFixed (PactTime.toPosixTimestampMicros time) -encodeGuard :: Guard FullyQualifiedName PactValue -> Builder +encodeGuard :: Guard QualifiedName PactValue -> Builder encodeGuard = \case GKeyset (KeySet ks pf) -> brackets $ commaSep @@ -221,9 +221,9 @@ encodeGuard = \case KeysAny -> "keys-any" GKeySetRef (KeySetName name mNs) -> "KeySetName" <> parens (encodeMNamespace mNs <> encodeText name) GUserGuard (UserGuard fn args) -> - "UG" <> encodeApp (encodeFqnAsQual fn) (encodePactValue <$> args) + "UG" <> encodeApp (encodeQualName fn) (encodePactValue <$> args) GCapabilityGuard (CapabilityGuard ct args _) -> - "CapGuard" <> encodeApp (encodeFqnAsQual ct) (encodePactValue <$> args) + "CapGuard" <> encodeApp (encodeQualName ct) (encodePactValue <$> args) GModuleGuard (ModuleGuard mg n) -> "ModuleGuard" <> parens (encodeModuleName mg <+> encodeText n) GDefPactGuard (DefPactGuard (DefPactId dpid) name) -> "DefPactGuard" <> parens (encodeText dpid <+> encodeText name) diff --git a/pact-core/Pact/Core/Interpreter.hs b/pact-core/Pact/Core/Interpreter.hs index e60fef968..ee3421875 100644 --- a/pact-core/Pact/Core/Interpreter.hs +++ b/pact-core/Pact/Core/Interpreter.hs @@ -19,7 +19,7 @@ import Pact.Core.Persistence(Purity) data Interpreter b i m = Interpreter { _interpret :: !(Purity -> Term Name Type b i -> m InterpretValue) - , _interpretGuard :: !(i -> Guard FullyQualifiedName PactValue -> m InterpretValue) + , _interpretGuard :: !(i -> Guard QualifiedName PactValue -> m InterpretValue) } data InterpretValue diff --git a/pact-core/Pact/Core/Names.hs b/pact-core/Pact/Core/Names.hs index 451198f64..1036ce197 100644 --- a/pact-core/Pact/Core/Names.hs +++ b/pact-core/Pact/Core/Names.hs @@ -18,6 +18,8 @@ module Pact.Core.Names , NameKind(..) , BareName(..) , QualifiedName(..) + , qnName + , qnModName , renderQualName , renderModuleName , TypeVar(..) @@ -350,6 +352,7 @@ instance Eq (FQNameRef name) where (FQName fqn) == (FQName fqn') = fqn == fqn' makeLenses ''FullyQualifiedName +makeLenses ''QualifiedName -- | The identifier that indexes defpacts in the db, -- generally computed from the continuation, or diff --git a/pact-core/Pact/Core/Namespace.hs b/pact-core/Pact/Core/Namespace.hs index 69cf62994..45789bf9f 100644 --- a/pact-core/Pact/Core/Namespace.hs +++ b/pact-core/Pact/Core/Namespace.hs @@ -14,8 +14,8 @@ import Pact.Core.PactValue data Namespace = Namespace { _nsName :: !NamespaceName - , _nsUser :: !(Guard FullyQualifiedName PactValue) - , _nsAdmin :: !(Guard FullyQualifiedName PactValue) + , _nsUser :: !(Guard QualifiedName PactValue) + , _nsAdmin :: !(Guard QualifiedName PactValue) } deriving (Eq, Show) makeLenses ''Namespace diff --git a/pact-core/Pact/Core/PactValue.hs b/pact-core/Pact/Core/PactValue.hs index 40a96c599..c5f78b406 100644 --- a/pact-core/Pact/Core/PactValue.hs +++ b/pact-core/Pact/Core/PactValue.hs @@ -46,7 +46,7 @@ import qualified Pact.Core.Pretty as Pretty data PactValue = PLiteral Literal | PList (Vector PactValue) - | PGuard (Guard FullyQualifiedName PactValue) + | PGuard (Guard QualifiedName PactValue) | PObject (Map Field PactValue) | PModRef ModRef | PCapToken (CapToken FullyQualifiedName PactValue) @@ -80,7 +80,7 @@ instance Pretty PactValue where objPair (f, t) = pretty f <> ":" <> pretty t PModRef md -> pretty md PCapToken (CapToken fqn args) -> - parens (pretty (fqnToQualName fqn) <> if null args then mempty else hsep (pretty <$> args)) + parens (pretty fqn) <> if null args then mempty else hsep (pretty <$> args) PTime t -> pretty (PactTime.formatTime "%Y-%m-%d %H:%M:%S%Q %Z" t) synthesizePvType :: PactValue -> Type diff --git a/pact-core/Pact/Core/Persistence.hs b/pact-core/Pact/Core/Persistence.hs index e5aeca9a1..5882930c0 100644 --- a/pact-core/Pact/Core/Persistence.hs +++ b/pact-core/Pact/Core/Persistence.hs @@ -76,7 +76,7 @@ mdModuleHash f = \case InterfaceData iface deps -> ifHash f iface <&> \ev' -> InterfaceData ev' deps -type FQKS = KeySet FullyQualifiedName +type FQKS = KeySet QualifiedName -- | Data reflecting Key/Value storage in user-tables. newtype RowData @@ -129,7 +129,7 @@ data Domain k v b i where -- | User tables accept a TableName and map to an 'ObjectMap PactValue' DUserTables :: !TableName -> Domain RowKey RowData b i -- | Keysets - DKeySets :: Domain KeySetName (KeySet FullyQualifiedName) b i + DKeySets :: Domain KeySetName (KeySet QualifiedName) b i -- | Modules DModules :: Domain ModuleName (ModuleData b i) b i -- | Namespaces diff --git a/pact-core/Pact/Core/Serialise.hs b/pact-core/Pact/Core/Serialise.hs index f44e99ad3..93c8ff363 100644 --- a/pact-core/Pact/Core/Serialise.hs +++ b/pact-core/Pact/Core/Serialise.hs @@ -62,8 +62,8 @@ data PactSerialise b i = PactSerialise { _encodeModuleData :: ModuleData b i -> ByteString , _decodeModuleData :: ByteString -> Maybe (Document (ModuleData b i)) - , _encodeKeySet :: KeySet FullyQualifiedName -> ByteString - , _decodeKeySet :: ByteString -> Maybe (Document (KeySet FullyQualifiedName)) + , _encodeKeySet :: KeySet QualifiedName -> ByteString + , _decodeKeySet :: ByteString -> Maybe (Document (KeySet QualifiedName)) , _encodeDefPactExec :: Maybe DefPactExec -> ByteString , _decodeDefPactExec :: ByteString -> Maybe (Document (Maybe DefPactExec)) , _encodeNamespace :: Namespace -> ByteString diff --git a/pact-core/Pact/Core/Serialise/CBOR_V1.hs b/pact-core/Pact/Core/Serialise/CBOR_V1.hs index bcc7051db..7d23a7cac 100644 --- a/pact-core/Pact/Core/Serialise/CBOR_V1.hs +++ b/pact-core/Pact/Core/Serialise/CBOR_V1.hs @@ -1,6 +1,5 @@ --- | +-- | {-# LANGUAGE GADTs #-} -{-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} @@ -58,10 +57,10 @@ decodeModuleData_repl_spaninfo bs = either (const Nothing) (Just . snd) (deseria decodeModuleData_raw_spaninfo :: ByteString -> Maybe (ModuleData RawBuiltin SpanInfo) decodeModuleData_raw_spaninfo bs = either (const Nothing) (Just . snd) (deserialiseFromBytes decode (fromStrict bs)) -encodeKeySet :: KeySet FullyQualifiedName -> ByteString +encodeKeySet :: KeySet QualifiedName -> ByteString encodeKeySet = toStrictByteString . encode -decodeKeySet :: ByteString -> Maybe (KeySet FullyQualifiedName) +decodeKeySet :: ByteString -> Maybe (KeySet QualifiedName) decodeKeySet bs = either (const Nothing) (Just . snd) (deserialiseFromBytes decode (fromStrict bs)) @@ -107,7 +106,7 @@ instance Serialise PublicKeyText where encode (PublicKeyText t) = encode t decode = PublicKeyText <$> decode -instance Serialise (KeySet FullyQualifiedName) where +instance Serialise (KeySet QualifiedName) where encode (KeySet ks p) = encode ks <> encode p decode = KeySet <$> decode <*> decode @@ -353,12 +352,13 @@ instance Serialise (DefCapMeta (FQNameRef Name)) where 2 -> pure Unmanaged _ -> fail "unexpected decoding" -instance - (Serialise b, - Serialise i, - Serialise (Term name Type b i), - Serialise (DefCapMeta (FQNameRef name))) - => Serialise (DefCap name Type b i) where +-- instance +-- (Serialise b, +-- Serialise i, +-- Serialise (Term name Type b i), +-- Serialise (DefCapMeta (FQNameRef name))) +-- => Serialise (DefCap name Type b i) where +instance (Serialise b, Serialise i) => Serialise (DefCap Name Type b i) where encode (DefCap n arity args ret term meta i) = encode n <> encode arity @@ -914,7 +914,7 @@ instance Serialise ReplRawBuiltin where -- DefPacts -instance Serialise (UserGuard FullyQualifiedName PactValue) where +instance Serialise (UserGuard QualifiedName PactValue) where encode (UserGuard f a) = encode f <> encode a decode = UserGuard <$> decode <*> decode @@ -922,7 +922,7 @@ instance Serialise DefPactId where encode (DefPactId pid) = encode pid decode = DefPactId <$> decode -instance Serialise (CapabilityGuard FullyQualifiedName PactValue) where +instance Serialise (CapabilityGuard QualifiedName PactValue) where encode (CapabilityGuard n a pid) = encode n <> encode a <> encode pid decode = CapabilityGuard <$> decode <*> decode <*> decode @@ -930,7 +930,7 @@ instance Serialise ModuleGuard where encode (ModuleGuard mn n) = encode mn <> encode n decode = ModuleGuard <$> decode <*> decode -instance Serialise (Guard FullyQualifiedName PactValue) where +instance Serialise (Guard QualifiedName PactValue) where encode = \case GKeyset ks -> encodeWord 0 <> encode ks GKeySetRef ksn -> encodeWord 1 <> encode ksn @@ -990,7 +990,7 @@ instance Serialise Yield where encode (Yield d p s) = encode d <> encode p <> encode s decode = Yield <$> decode <*> decode <*> decode -instance Serialise (DefPactContinuation FullyQualifiedName PactValue) where +instance Serialise (DefPactContinuation QualifiedName PactValue) where encode (DefPactContinuation n a) = encode n <> encode a decode = DefPactContinuation <$> decode <*> decode diff --git a/pact-core/Pact/Core/Serialise/LegacyPact.hs b/pact-core/Pact/Core/Serialise/LegacyPact.hs index 4c43f31d2..6ee3f068c 100644 --- a/pact-core/Pact/Core/Serialise/LegacyPact.hs +++ b/pact-core/Pact/Core/Serialise/LegacyPact.hs @@ -1,6 +1,7 @@ -- | {-# LANGUAGE ScopedTypeVariables #-} {-# OPTIONS_GHC -fno-warn-orphans #-} +{-# LANGUAGE InstanceSigs #-} module Pact.Core.Serialise.LegacyPact ( decodeModuleData , decodeKeySet @@ -27,7 +28,7 @@ import Data.Maybe (fromMaybe) import Pact.Core.ChainData import Pact.Core.Hash import Pact.Core.ModRefs -import Pact.Core.Literal +import Pact.Core.Literal import Data.Decimal import Pact.Time import qualified Pact.JSON.Decode as JD @@ -40,7 +41,7 @@ import Text.Read (readMaybe) decodeModuleData :: ByteString -> Maybe (ModuleData RawBuiltin ()) decodeModuleData = JD.decodeStrict' -decodeKeySet :: ByteString -> Maybe (KeySet FullyQualifiedName) +decodeKeySet :: ByteString -> Maybe (KeySet QualifiedName) decodeKeySet = JD.decodeStrict' decodeDefPactExec :: ByteString -> Maybe (Maybe DefPactExec) @@ -59,7 +60,7 @@ instance JD.FromJSON NamespaceName where parseJSON = JD.withText "NamespaceName" (pure . NamespaceName) -instance JD.FromJSON (KeySet FullyQualifiedName) where +instance JD.FromJSON (KeySet QualifiedName) where parseJSON v = JD.withObject "KeySet" keyListPred v <|> keyListOnly where defPred = KeysAll @@ -70,7 +71,7 @@ instance JD.FromJSON (KeySet FullyQualifiedName) where keyListOnly = KeySet <$> JD.parseJSON v <*> pure defPred -instance JD.FromJSON (KSPredicate FullyQualifiedName) where +instance JD.FromJSON (KSPredicate QualifiedName) where parseJSON = JD.withText "KSPredicate" $ \case "keys-all" -> pure KeysAll "keys-2" -> pure Keys2 @@ -138,29 +139,23 @@ instance JD.FromJSON RowData where parseJSON = JD.withObject "RowData" $ \o -> RowData <$> o JD..: "$d" -instance JD.FromJSON (DefPactContinuation FullyQualifiedName PactValue) where +instance JD.FromJSON (DefPactContinuation QualifiedName PactValue) where parseJSON = JD.withObject "DefPactContinuation" $ \o -> DefPactContinuation <$> o JD..: "def" <*> o JD..: "args" --- TODO: This feels awkward, legacy pact uses qualified names in defpactexec continuations --- pact-core relies on fullyqualified names. @Jose, is this a valid approach to overcome the --- current issue? - -instance JD.FromJSON FullyQualifiedName where +instance JD.FromJSON QualifiedName where parseJSON = JD.withText "QualifiedName" $ \n -> case T.split (== '.') n of - [mod', name] -> pure (FullyQualifiedName (ModuleName mod' Nothing) name mh) - [ns, mod', name] -> pure (FullyQualifiedName (ModuleName mod' (Just (NamespaceName ns))) name mh) + [mod', name] -> pure (QualifiedName name (ModuleName mod' Nothing)) + [ns, mod', name] -> pure (QualifiedName name (ModuleName mod' (Just (NamespaceName ns)))) _ -> fail "unexpeced parsing" - where - mh = ModuleHash defaultPactHash - + -- instance JD.FromJSON QualifiedName where -- parseJSON = JD.withText "QualifiedName" $ \n -> case T.split (== '.') n of -- [mod', name] -> pure (QualifiedName name (ModuleName mod' Nothing)) -- _ -> fail "unexpeced parsing" - + -- instance JD.FromJSON (DefPactContinuation FullyQualifiedName PactValue) where -- parseJSON = JD.withObject "DefPactContinuation" $ \o -> -- DefPactContinuation @@ -189,7 +184,7 @@ instance JD.FromJSON ModuleName where instance JD.FromJSON ModRef where parseJSON = JD.withObject "ModRef" $ \o -> ModRef - <$> o JD..: "refName" + <$> o JD..: "refName" <*> o JD..: "refSpec" <*> pure Nothing @@ -211,7 +206,7 @@ data LegacyPactValue = Legacy_PLiteral LegacyLiteral | Legacy_PList (Vector LegacyPactValue) | Legacy_PObject (Map Field LegacyPactValue) - | Legacy_PGuard (Guard FullyQualifiedName LegacyPactValue) + | Legacy_PGuard (Guard QualifiedName LegacyPactValue) | Legacy_PModRef ModRef instance JD.FromJSON LegacyPactValue where @@ -268,12 +263,12 @@ instance JD.FromJSON LegacyLiteral where highPrecFormat = "%Y-%m-%dT%H:%M:%S.%vZ" -instance JD.FromJSON (Guard FullyQualifiedName PactValue) where - parseJSON = error "guards" -- fromLegacyPactValue <$> JD.parseJSON v +instance JD.FromJSON (Guard QualifiedName PactValue) where + parseJSON v = guardToPactValue <$> JD.parseJSON v -- https://github.com/kadena-io/pact/blob/ba15517b56eba4fdaf6b2fbd3e5245eeedd0fc9f/src/Pact/Types/Term/Internal.hs#L802 -instance JD.FromJSON (Guard FullyQualifiedName LegacyPactValue) where +instance JD.FromJSON (Guard QualifiedName LegacyPactValue) where parseJSON v = GKeyset <$> JD.parseJSON v <|> GKeySetRef <$> parseRef v <|> GUserGuard <$> JD.parseJSON v @@ -286,13 +281,13 @@ instance JD.FromJSON (Guard FullyQualifiedName LegacyPactValue) where pure (KeySetName ref ns) -instance JD.FromJSON (UserGuard FullyQualifiedName LegacyPactValue) where +instance JD.FromJSON (UserGuard QualifiedName LegacyPactValue) where parseJSON = JD.withObject "UserGuard" $ \o -> UserGuard <$> o JD..: "fun" <*> o JD..: "args" -instance JD.FromJSON (CapabilityGuard FullyQualifiedName LegacyPactValue) where +instance JD.FromJSON (CapabilityGuard QualifiedName LegacyPactValue) where parseJSON = JD.withObject "CapabilityGuard" $ \o -> CapabilityGuard <$> o JD..: "cgName" @@ -319,7 +314,7 @@ fromLegacyPactValue = \case Legacy_PModRef mref -> PModRef mref -guardToPactValue :: Guard FullyQualifiedName LegacyPactValue -> Guard FullyQualifiedName PactValue +guardToPactValue :: Guard QualifiedName LegacyPactValue -> Guard QualifiedName PactValue guardToPactValue = \case (GKeyset ks) -> GKeyset ks (GKeySetRef kref) -> GKeySetRef kref diff --git a/pact-core/Pact/Core/StableEncoding.hs b/pact-core/Pact/Core/StableEncoding.hs index 411579dc3..6885cd70e 100644 --- a/pact-core/Pact/Core/StableEncoding.hs +++ b/pact-core/Pact/Core/StableEncoding.hs @@ -15,7 +15,6 @@ import Pact.Core.Guards import Pact.Core.Names import Pact.Core.ModRefs import Pact.Core.Hash -import Pact.Core.Principal import Pact.Core.DefPacts.Types import Pact.Time @@ -64,7 +63,7 @@ instance J.Encode (StableEncoding Literal) where -- | Stable encoding of `Guard FullyQualifiedName PactValue` -instance J.Encode (StableEncoding (Guard FullyQualifiedName PactValue)) where +instance J.Encode (StableEncoding (Guard QualifiedName PactValue)) where build (StableEncoding g) = case g of GKeyset ks -> J.build (StableEncoding ks) GKeySetRef ksn -> J.object ["keysetref" J..= StableEncoding ksn] @@ -75,7 +74,7 @@ instance J.Encode (StableEncoding (Guard FullyQualifiedName PactValue)) where {-# INLINABLE build #-} -- | Stable encoding of `CapabilityGuard FullyQualifiedName PactValue` -instance J.Encode (StableEncoding (CapabilityGuard FullyQualifiedName PactValue)) where +instance J.Encode (StableEncoding (CapabilityGuard QualifiedName PactValue)) where build (StableEncoding (CapabilityGuard name args mpid)) = J.object [ "cgPactId" J..= fmap StableEncoding mpid , "cgArgs" J..= J.Array (StableEncoding <$> args) @@ -111,10 +110,10 @@ instance J.Encode (StableEncoding DefPactGuard) where {-# INLINABLE build #-} -- | Stable encoding of `UserGuard FullyQualifiedName PactValue` -instance J.Encode (StableEncoding (UserGuard FullyQualifiedName PactValue)) where +instance J.Encode (StableEncoding (UserGuard QualifiedName PactValue)) where build (StableEncoding (UserGuard fun args)) = J.object [ "args" J..= J.array (StableEncoding <$> args) - , "fun" J..= StableEncoding (fqnToQualName fun) + , "fun" J..= StableEncoding fun ] {-# INLINABLE build #-} @@ -128,7 +127,7 @@ instance J.Encode (StableEncoding KeySetName) where {-# INLINABLE build #-} -- | Stable encoding of `KeySet FullyQualifiedName` -instance J.Encode (StableEncoding (KeySet FullyQualifiedName)) where +instance J.Encode (StableEncoding (KeySet QualifiedName)) where build (StableEncoding (KeySet keys predFun)) =J.object [ "pred" J..= StableEncoding predFun , "keys" J..= J.Array (Set.map StableEncoding keys) -- TODO: is this valid? @@ -141,7 +140,7 @@ instance J.Encode (StableEncoding (Map Field PactValue)) where {-# INLINABLE build #-} -- | Stable encoding of `KSPredicate FullyQualifiedName` -instance J.Encode (StableEncoding (KSPredicate FullyQualifiedName)) where +instance J.Encode (StableEncoding (KSPredicate QualifiedName)) where build (StableEncoding ksp) = case ksp of KeysAll -> J.build ("keys-all" :: T.Text) Keys2 -> J.build ("keys-2" :: T.Text) @@ -187,19 +186,6 @@ instance J.Encode (StableEncoding UTCTime) where denom = denominator . (% 1000) . fromIntegral . toPosixTimestampMicros {-# INLINABLE build #-} --- | Stable encoding of `Principal`. -instance J.Encode (StableEncoding Principal) where - build (StableEncoding principal) = case principal of - K pk -> kind 'K' [ "pk" J..= StableEncoding pk ] - W ph n -> kind 'W' [ "ph" J..= ph, "pred" J..= n ] - R ksn -> kind 'R' [ "ksn" J..= StableEncoding ksn ] - U fqn args -> kind 'U' [ "fqn" J..= fqn, "args" J..= args ] - M mn n -> kind 'M' [ "modname" J..= StableEncoding mn, "guard" J..= n ] - P pid n -> kind 'P' [ "pid" J..= StableEncoding pid, "fun" J..= n ] - C c -> kind 'C' [ "cap" J..= c ] - where - kind c rest = J.object $ "kind" J..= T.singleton c : rest - -- | Stable encoding of `PactValue` instance J.Encode (StableEncoding PactValue) where build (StableEncoding pv) = case pv of @@ -208,14 +194,15 @@ instance J.Encode (StableEncoding PactValue) where PGuard g -> J.build (StableEncoding g) PObject o -> J.build (StableEncoding o) PModRef mr -> J.build (StableEncoding mr) + -- TODO: implement/figure this out PCapToken _ct -> error "not implemented" PTime pt -> J.build (StableEncoding pt) {-# INLINABLE build #-} -- | Stable encoding of `DefPactContinuation FullyQualifiedName PactValue` -instance J.Encode (StableEncoding (DefPactContinuation FullyQualifiedName PactValue)) where +instance J.Encode (StableEncoding (DefPactContinuation QualifiedName PactValue)) where build (StableEncoding (DefPactContinuation name args))= J.object [ "args" J..= J.Array (StableEncoding <$> args) - , "def" J..= J.build (StableEncoding (fqnToQualName name)) + , "def" J..= J.build (StableEncoding name) ] {-# INLINABLE build #-}