Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoeldner committed Nov 23, 2023
1 parent 0972be3 commit 634930b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
8 changes: 4 additions & 4 deletions pact-core/Pact/Core/IR/Eval/CEK.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ evalCEK cont handler env (Var n info) = do
Just (DTable d) ->
let (ResolvedTable sc) = _dtSchema d
tn = TableName (_dtName d) mname
tbl = VTable (TableValue tn mname mh sc)
tbl = VTable (TableValue tn mh sc)
in returnCEKValue cont handler tbl
Just (DCap d) -> do
let args = _argType <$> _dcapArgs d
Expand Down Expand Up @@ -481,10 +481,10 @@ nameToFQN info env (Name n nk) = case nk of
_ -> failInvariant info ("invalid name in fq position" <> T.pack (show n))

guardTable :: (MonadEval b i m) => i -> CEKEnv b i m -> TableValue -> GuardTableOp -> m ()
guardTable i env (TableValue _ mn mh _) dbop = do
guardTable i env (TableValue tn mh _) dbop = do
checkLocalBypass $
guardForModuleCall i env mn $ do
mdl <- getModule i (view cePactDb env) mn
guardForModuleCall i env (_tableModuleName tn) $ do
mdl <- getModule i (view cePactDb env) (_tableModuleName tn)
enforceBlessedHashes i mdl mh
where
checkLocalBypass notBypassed = do
Expand Down
8 changes: 4 additions & 4 deletions pact-core/Pact/Core/IR/Eval/RawBuiltin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ coreBind = \info b cont handler _env -> \case

createTable :: (IsBuiltin b, MonadEval b i m) => NativeFunction b i m
createTable = \info b cont handler env -> \case
[VTable tv@(TableValue tn _mn _ _)] -> do
[VTable tv@(TableValue tn __ _)] -> do
enforceTopLevelOnly info b
guardTable info env tv GtCreateTable
let pdb = view cePactDb env
Expand Down Expand Up @@ -1370,11 +1370,11 @@ describeModule = \info b cont handler env -> \case

dbDescribeTable :: (IsBuiltin b, MonadEval b i m) => NativeFunction b i m
dbDescribeTable = \info b cont handler _env -> \case
[VTable (TableValue name mname _ _)] ->
[VTable (TableValue name _ _)] ->
returnCEKValue cont handler $ VObject $ M.fromList $ fmap (over _1 Field)
[("name", PString (_tableName name))
,("module", PString (renderModuleName mname))
,("type", PString "asdf")]
,("module", PString (renderModuleName (_tableModuleName name)))
,("type", PString "asdf")] -- TODO:
args -> argsError info b args

dbDescribeKeySet :: (IsBuiltin b, MonadEval b i m) => NativeFunction b i m
Expand Down
1 change: 0 additions & 1 deletion pact-core/Pact/Core/IR/Eval/Runtime/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ data CanApply b i m
data TableValue
= TableValue
{ _tvName :: !TableName
, _tvModule :: !ModuleName
, _tvHash :: !ModuleHash
, _tvSchema :: !Schema
} deriving Show
Expand Down
2 changes: 1 addition & 1 deletion pact-core/Pact/Core/Names.hs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ makeLenses ''FullyQualifiedName
-- userTable :: TableName -> TableName
-- userTable (TableName tn) = TableName ("USER_" <> tn)

-- | the identifier that indexes defpacts in the db,
-- | The identifier that indexes defpacts in the db,
-- generally computed from the continuation, or
-- in the case of nested defpacts, the hash of the
-- parent + the nested continuation
Expand Down
18 changes: 15 additions & 3 deletions pact-core/Pact/Core/Persistence/SQLite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Pact.Core.Persistence (PactDb(..), Domain(..),
Purity(PImpure)
,WriteType(..) --, RowData(..)
,toUserTable
,ExecutionMode(..), TxId
)
-- import Pact.Core.Repl.Utils (ReplEvalM)
import Pact.Core.Serialise
Expand Down Expand Up @@ -53,13 +54,24 @@ initializePactDb serial db = do
, _pdbWrite = write' serial db
, _pdbKeys = undefined
, _pdbCreateUserTable = createUserTable db
, _pdbBeginTx = undefined
, _pdbCommitTx = undefined
, _pdbRollbackTx = undefined
, _pdbBeginTx = beginTx db
, _pdbCommitTx = commitTx db
, _pdbRollbackTx = rollbackTx db
, _pdbTxIds = undefined
, _pdbGetTxLog = undefined
}

commitTx :: SQL.Database -> IO ()
commitTx db = SQL.exec db "COMMIT TRANSACTION"

beginTx :: SQL.Database -> ExecutionMode -> IO (Maybe TxId)
beginTx _db = \case
Transactional -> undefined -- SQL.exec db "BEGIN TRANSACTION"
Local -> undefined

rollbackTx :: SQL.Database -> IO ()
rollbackTx db = SQL.exec db "ROLLBACK TRANSACTION"

createUserTable :: SQL.Database -> TableName -> IO ()
createUserTable db tbl = SQL.exec db ("CREATE TABLE IF NOT EXISTS " <> tblName <> " (txid INTEGER PRIMARY KEY NOT NULL UNIQUE, rowkey TEXT NOT NULL, rowdata BLOB NOT NULL)")
where
Expand Down
2 changes: 1 addition & 1 deletion pact-core/Pact/Core/Repl/Runtime/ReplBuiltin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import Pact.Core.Repl.Utils
prettyShowValue :: CEKValue b i m -> Text
prettyShowValue = \case
VPactValue p -> renderText p
VTable (TableValue (TableName tn mn) _ _ _) -> "table{" <> renderModuleName mn <> "_" <> tn <> "}"
VTable (TableValue (TableName tn mn) _ _) -> "table{" <> renderModuleName mn <> "_" <> tn <> "}"
VClosure _ -> "<#closure>"

corePrint :: (IsBuiltin b) => NativeFunction b SpanInfo (ReplM b)
Expand Down

0 comments on commit 634930b

Please sign in to comment.