Skip to content

Commit

Permalink
start on legacy module parser
Browse files Browse the repository at this point in the history
  • Loading branch information
imalsogreg committed Nov 30, 2023
1 parent 0ec10db commit 146cc19
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
22 changes: 11 additions & 11 deletions pact-core-tests/Pact/Core/Test/ReplTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ enhanceEvalModule Module
} = Module
{ _mName
, _mGovernance
, _mDefs = _ _mDefs
, _mDefs = undefined _mDefs
, _mBlessed
, _mImports
, _mImplements
Expand Down Expand Up @@ -133,21 +133,21 @@ runFileReplTest mkPactDb file = testCase file $ do
-- & moduleDataInfo %~ const ()
-- & moduleDataBuiltin %~ \(RBuiltinWrap b) -> b

deriving instance Read (ModuleData ReplRawBuiltin SpanInfo)
deriving instance Read (EvalDef ReplRawBuiltin SpanInfo)
deriving instance Read (EvalModule ReplRawBuiltin SpanInfo)
deriving instance Read (Governance Name)
-- deriving instance Read (ModuleData ReplRawBuiltin SpanInfo)
-- deriving instance Read (EvalDef ReplRawBuiltin SpanInfo)
-- deriving instance Read (EvalModule ReplRawBuiltin SpanInfo)
-- deriving instance Read (Governance Name)

sillySerialise :: PactSerialise ReplRawBuiltin SpanInfo
sillySerialise = serialisePact
{ _encodeModuleData = BSC.pack . show
, _decodeModuleData = Just . LegacyDocument . read . BSC.unpack
}
-- sillySerialise :: PactSerialise ReplRawBuiltin SpanInfo
-- sillySerialise = serialisePact
-- { _encodeModuleData = BSC.pack . show
-- , _decodeModuleData = Just . LegacyDocument . read . BSC.unpack
-- }

runFileReplTestSqlite :: TestName -> TestTree
runFileReplTestSqlite file = testCase file $ do
ctnt <- B.readFile (replTestDir </> file)
withSqlitePactDb sillySerialise ":memory:" $ \pdb -> do
withSqlitePactDb undefined ":memory:" $ \pdb -> do
runReplTest pdb file ctnt


Expand Down
21 changes: 20 additions & 1 deletion pact-core/Pact/Core/Serialise/LegacyPact.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-- |
-- |
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Pact.Core.Serialise.LegacyPact
( decodeModuleData
Expand All @@ -15,11 +16,15 @@ import Pact.Core.Builtin
import Pact.Core.DefPacts.Types
import Pact.Core.Namespace
import Pact.Core.PactValue

import Data.ByteString (ByteString)
import qualified Data.ByteString.Short as SB
import qualified Data.Text.Encoding as T
import Control.Applicative ((<|>))
import Data.Foldable (toList)
import Data.Maybe (fromMaybe)
import Data.Text (Text)

import Pact.Core.ChainData
import Pact.Core.Hash
import Pact.Core.Parser
Expand All @@ -39,6 +44,20 @@ import Text.Read (readMaybe)
decodeModuleData :: ByteString -> Maybe (ModuleData RawBuiltin ())
decodeModuleData = JD.decodeStrict'

instance JD.FromJSON (ModuleData ReplRawBuiltin SpanInfo) where
parseJSON = JD.withObject "ModuleData" $ \o -> do
key :: Text <- o JD..: "key"
value <- o JD..: "value"
case key of
"ModuleData" -> parseModuleDataCtor value
"InterfaceData" -> parseInterfaceDataCtor value
where
parseModuleDataCtor = JD.withArray "ModuleData" $ \arr -> case toList arr of
[e1, e2] -> undefined
_ -> undefined
parseInterfaceDataCtor = undefined


decodeModuleData_Repl_Info :: ByteString -> Maybe (ModuleData ReplRawBuiltin SpanInfo)
decodeModuleData_Repl_Info = JD.decodeStrict'

Expand Down

0 comments on commit 146cc19

Please sign in to comment.