Skip to content

Commit

Permalink
0.12 Updates (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
safareli authored Dec 14, 2018
1 parent c4fca1b commit 40d2d4a
Show file tree
Hide file tree
Showing 28 changed files with 331 additions and 412 deletions.
27 changes: 14 additions & 13 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
"output"
],
"dependencies": {
"purescript-prelude": "^3.1.1",
"purescript-web3": "^0.25.0",
"purescript-web3-generator": "^0.24.0",
"purescript-console": "^3.0.0",
"purescript-errors": "^3.0.0",
"purescript-node-process": "^5.0.0",
"purescript-debug": "^3.0.0",
"purescript-mkdirp": "^0.3.0",
"purescript-logging": "^2.0.0",
"purescript-validation": "^3.2.0",
"purescript-random": "^3.0.0"
"purescript-prelude": "^4.0.0",
"purescript-web3": "^1.0.0",
"purescript-web3-generator": "^1.0.0",
"purescript-console": "^4.0.0",
"purescript-errors": "^4.0.0",
"purescript-node-process": "^6.0.0",
"purescript-debug": "^4.0.0",
"purescript-mkdirp": "joshuahhh/purescript-mkdirp#48ecb4039d5fe3be82d0e82c3a9f2338d1af82d2",
"purescript-logging": "^3.0.0",
"purescript-validation": "^4.0.0",
"purescript-random": "^4.0.0",
"purescript-foreign-object": "^1.1.0"
},
"devDependencies": {
"purescript-psci-support": "^3.0.0",
"purescript-spec": "^2.0.0"
"purescript-psci-support": "^4.0.0",
"purescript-spec": "^3.0.0"
}
}
18 changes: 2 additions & 16 deletions docs/compiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,9 @@ if this functionality is not required. One may want to store this script in a di
import Prelude
import Chanterelle (compileMain)
import Chanterelle.Genesis (runGenesisGenerator)
import Control.Monad.Aff.Console (CONSOLE)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION)
import Node.FS.Aff (FS)
import Node.Process (PROCESS)
import Network.Ethereum.Web3 (ETH)
import Control.Monad.Eff (Effect)
main :: forall eff.
Eff
( console :: CONSOLE
, fs :: FS
, process :: PROCESS
, exception :: EXCEPTION
, eth :: ETH
| eff
)
Unit
main :: Eff Unit
main = do
compileMain
runGenesisGenerator "./base-genesis-block.json" "./injected-genesis-block.json"
Expand Down
17 changes: 6 additions & 11 deletions docs/deployments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The type ``Constructor args`` is a type synonym:

.. code-block:: haskell
type Constructor args = forall eff. TransactionOptions NoPay -> HexString -> Record args -> Web3 eff HexString
type Constructor args = forall eff. TransactionOptions NoPay -> HexString -> Record args -> Web3 HexString
In other words, ``Constructor args`` is the type a function taking in some ``TransactionOptions NoPay`` (constructors are not payable transactions), the deployment bytepurescriptcode, and a record of type ``Record args``. It will format the transaction and submit it via an ``eth_sendTransaction`` RPC call, returning the transaction hash as a ``HexString``.

Expand Down Expand Up @@ -74,7 +74,7 @@ In the PureScript module ``Contracts.SimpleStorage``, you will find a function

.. code-block:: haskell
constructor :: forall e. TransactionOptions NoPay -> HexString -> {initialCount :: UIntN (D2 :& D5 :& DOne D6)} -> Web3 e HexString
constructor :: TransactionOptions NoPay -> HexString -> {initialCount :: UIntN (D2 :& D5 :& DOne D6)} -> Web3 HexString
Blurring your eyes a little bit, it's easy to see that this indeed matches up to the constructor defined in the Solidity file. We could then define the deployment configuration for ``SimpleStorage`` as

Expand Down Expand Up @@ -122,7 +122,7 @@ Consider this example take from the parking-dao example project:
type DeployResults = (foamCSR :: Address, simpleStorage :: Address, parkingAuthority :: Address)
deployScript :: forall eff. DeployM eff (Record DeployResults)
deployScript :: forall eff. DeployM (Record DeployResults)
deployScript = do
deployCfg@(DeployConfig {primaryAccount}) <- ask
let bigGasLimit = unsafePartial fromJust $ parseBigNumber decimal "4712388"
Expand Down Expand Up @@ -155,15 +155,10 @@ methodically in a separate ``deploy/`` subproject. The latter is demonstrated be
import Prelude
import Chanterelle (deployMain)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE)
import Control.Monad.Eff.Exception (EXCEPTION)
import Network.Ethereum.Web3 (ETH)
import Node.FS.Aff (FS)
import Node.Process (PROCESS)
import MyDeployScript (deployScript) as MyDeployScript
import Control.Monad.Eff (Effect)
import MyDeployScript (deployScript) as MyDeployScript
main :: forall e. Eff (console :: CONSOLE, eth :: ETH, fs :: FS, process :: PROCESS, exception :: EXCEPTION | e) Unit
main :: Eff Unit
main = deployMain MyDeployScript.deployScript
We can then invoke this script as follows:
Expand Down
13 changes: 4 additions & 9 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ There are various testing utility functions in ``Chanterelle.Test``, probably th
buildTestConfig
:: String
-> Int
-> DeployM eff (Record r)
-> Aff (console :: CONSOLE, eth :: ETH, fs :: FS | eff) (TestConfig r)
-> DeployM (Record r)
-> Aff (TestConfig r)
This function takes in some test configuration options and a deploy script, and outputs a record containing all of the unlocked accounts on the test node, a connection to the node, and whatever the output of your deployment script is. This output is then meant to be threaded through as an environment to the rest of your test suites.

Expand All @@ -39,14 +39,9 @@ Here's an example test suite for our ``SimpleStorage`` contract:
.. code-block:: haskell
simpleStorageSpec
:: forall e r.
:: forall r.
TestConfig (simpleStorage :: Address | r)
-> Spec ( fs :: FS
, eth :: ETH
, avar :: AVAR
, console :: CONSOLE
| e
) Unit
-> Spec Unit
simpleStorageSpec {provider, accounts, simpleStorage} = do
describe "Setting the value of a SimpleStorage Contract" do
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
"ethjs-provider-http": "^0.1.6",
"keccak": "^1.0.2",
"mkdirp": "^0.5.1",
"pulp": "^12.0.1",
"purescript": "^0.11.7",
"purescript": "^0.12.0",
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0",
"rlp": "^2.0.0",
"secp256k1": "^3.0.1",
"solc": "^0.4.24"
Expand Down
19 changes: 6 additions & 13 deletions src/Chanterelle.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,14 @@ import Chanterelle.Compile (compileProject)
import Chanterelle.Deploy (deploy)
import Chanterelle.Internal.Logging (setLogLevel, readLogLevel)
import Chanterelle.Internal.Types.Deploy (DeployM)
import Control.Monad.Aff.Console (CONSOLE)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION)
import Control.Monad.Eff.Unsafe (unsafeCoerceEff)
import Effect (Effect)
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Network.Ethereum.Web3 (ETH)
import Node.FS.Aff (FS)
import Node.Process (PROCESS)
import Node.Yargs.Applicative (yarg, runY)
import Node.Yargs.Setup (usage, defaultVersion, defaultHelp, example)

compileMain
:: forall eff.
Eff (console :: CONSOLE, fs :: FS, process :: PROCESS, exception :: EXCEPTION| eff) Unit
:: Effect Unit
compileMain =
let setup = usage "$0 --log-level <level>"
<> example "$0 --log-level debug" "Run the compile phase with the given log level."
Expand All @@ -36,9 +29,9 @@ compileMain =
compileProject

deployMain
:: forall eff a.
DeployM eff a
-> Eff (console :: CONSOLE, fs :: FS, eth :: ETH, exception :: EXCEPTION | eff) Unit
:: forall a.
DeployM a
-> Effect Unit
deployMain deployScript =
let setup = usage "$0 --log-level <level> --node-url <url> --timeout <seconds>"
<> example "$0 --log-level debug" "Run the deployment script with the given log level, node url, and timeout"
Expand All @@ -48,6 +41,6 @@ deployMain deployScript =
<*> yarg "node-url" [] Nothing (Left "http://localhost:8545") false
<*> yarg "timeout" [] Nothing (Left 60) false
where
go level nodeUrl timeout = unsafeCoerceEff $ do
go level nodeUrl timeout = do
setLogLevel $ readLogLevel level
deploy nodeUrl timeout deployScript
21 changes: 8 additions & 13 deletions src/Chanterelle/Compile.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,23 @@ import Chanterelle.Internal.Compile (compile) as Chanterelle
import Chanterelle.Internal.Logging (logCompileError)
import Chanterelle.Internal.Types.Compile (CompileError(..), runCompileM)
import Chanterelle.Project (loadProject)
import Control.Monad.Aff (launchAff)
import Control.Monad.Aff.Console (CONSOLE)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Exception (EXCEPTION, message, throw)
import Effect.Aff (launchAff)
import Effect (Effect)
import Effect.Class (liftEffect)
import Effect.Exception (message, throw)
import Control.Monad.Error.Class (try)
import Data.Either (Either(..))
import Node.FS (FS)
import Node.Process (PROCESS)
import Node.Process as P

compileProject
:: forall e.
Eff (console :: CONSOLE, fs :: FS, process :: PROCESS, exception :: EXCEPTION | e) Unit
compileProject :: Effect Unit
compileProject = do
root <- liftEff P.cwd
root <- liftEffect P.cwd
void $ launchAff $ do
proj <- try $ loadProject root
case proj of
Left err -> do
logCompileError $ MalformedProjectError (message err)
liftEff $ throw "LoadProject Error"
liftEffect $ throw "LoadProject Error"
Right project -> do
eres <- flip runCompileM project $ do
_ <- Chanterelle.compile
Expand All @@ -37,4 +32,4 @@ compileProject = do
Right _ -> pure unit
Left err -> do
logCompileError err
liftEff $ throw "Compile Error"
liftEffect $ throw "Compile Error"
27 changes: 12 additions & 15 deletions src/Chanterelle/Deploy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,35 @@ import Chanterelle.Internal.Types (runDeployM) as Exports
import Chanterelle.Internal.Types.Deploy ((??)) as Exports
import Chanterelle.Internal.Types.Deploy (DeployM, runDeployM)
import Chanterelle.Internal.Utils (makeDeployConfigWithProvider, makeProvider)
import Control.Monad.Aff (launchAff, throwError)
import Control.Monad.Aff.Console (CONSOLE)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION, error, throw)
import Control.Monad.Eff.Unsafe (unsafeCoerceEff)
import Effect.Aff (launchAff, throwError)
import Effect (Effect)
import Effect.Exception (error, throw)
import Control.Monad.Except (runExceptT)
import Data.Either (Either(..))
import Network.Ethereum.Web3 (ETH, Provider)
import Node.FS.Aff (FS)
import Network.Ethereum.Web3 (Provider)

-- | Run an arbitrary deployment script in the DeployM monad
deploy
:: forall eff a.
:: forall a.
String
-> Int
-> DeployM eff a
-> Eff (console :: CONSOLE, eth :: ETH, fs :: FS, exception :: EXCEPTION | eff) Unit
deploy url tout deployScript =
-> DeployM a
-> Effect Unit
deploy url tout deployScript =
runExceptT (makeProvider url) >>= case _ of
Left err -> do
logDeployError err
throw "DeployM error"
Right provider -> unsafeCoerceEff $
Right provider -> do
deployWithProvider provider tout deployScript

-- | Run an arbitrary deployment script in the DeployM monad against a specified Provider
deployWithProvider
:: forall eff a.
:: forall a.
Provider
-> Int
-> DeployM eff a
-> Eff (console :: CONSOLE, eth :: ETH, fs :: FS | eff) Unit
-> DeployM a
-> Effect Unit
deployWithProvider provider tout deployScript = void <<< launchAff $ do
edeployConfig <- runExceptT $ makeDeployConfigWithProvider provider tout
case edeployConfig of
Expand Down
22 changes: 7 additions & 15 deletions src/Chanterelle/Genesis.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,23 @@ import Chanterelle.Internal.Logging (LogLevel(..), log, logGenesisGenerationErro
import Chanterelle.Internal.Types.Genesis (GenesisGenerationError(MalformedProjectErrorG))
import Chanterelle.Internal.Utils.Json (jsonStringifyWithSpaces)
import Chanterelle.Project (loadProject)
import Control.Monad.Aff (error, launchAff, throwError)
import Control.Monad.Aff.Class (liftAff)
import Control.Monad.Aff.Console (CONSOLE)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Exception (EXCEPTION, message)
import Effect.Aff (error, launchAff, throwError)
import Effect.Aff.Class (liftAff)
import Effect (Effect)
import Effect.Class (liftEffect)
import Effect.Exception (message)
import Control.Monad.Error.Class (try)
import Data.Argonaut as A
import Data.Either (Either(..))
import Network.Ethereum.Web3 (ETH)
import Node.Encoding (Encoding(UTF8))
import Node.FS (FS)
import Node.FS.Aff as FS
import Node.Path (FilePath)
import Node.Process (PROCESS)
import Node.Process as P
import Prelude (Unit, bind, show, void, ($), (<<<), (<>), (>>=))

runGenesisGenerator
:: forall e.
FilePath
-> FilePath
-> Eff (console :: CONSOLE, fs :: FS, process :: PROCESS, eth :: ETH, exception :: EXCEPTION | e) Unit
runGenesisGenerator :: FilePath -> FilePath -> Effect Unit
runGenesisGenerator genesisIn genesisOut = do
root <- liftEff P.cwd
root <- liftEffect P.cwd
void <<< launchAff $
(try $ loadProject root) >>= case _ of
Left err -> liftAff $ do
Expand Down
11 changes: 5 additions & 6 deletions src/Chanterelle/Internal/Codegen.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import Chanterelle.Internal.Types.Compile (CompileError(..))
import Chanterelle.Internal.Types.Project (ChanterelleProject(..), ChanterelleProjectSpec(..), ChanterelleModule(..))
import Chanterelle.Internal.Utils (assertDirectory)
import Control.Error.Util (note)
import Control.Monad.Aff.Class (class MonadAff, liftAff)
import Control.Monad.Aff.Console (CONSOLE)
import Effect.Aff.Class (class MonadAff, liftAff)
import Control.Monad.Error.Class (class MonadThrow, throwError)
import Control.Monad.Reader (class MonadAsk, ask)
import Data.AbiParser (Abi(Abi), AbiDecodeError(..), AbiWithErrors) as PSWeb3Gen
Expand All @@ -30,8 +29,8 @@ import Node.FS.Aff as FS
import Node.Path (FilePath)
import Node.Path as Path

generatePS :: forall eff m
. MonadAff (console :: CONSOLE, fs :: FS.FS | eff) m
generatePS :: forall m
. MonadAff m
=> MonadThrow CompileError m
=> MonadAsk ChanterelleProject m
=> m Unit
Expand Down Expand Up @@ -78,8 +77,8 @@ projectPSArgs (ChanterelleProject project) =
, modulePrefix: spec.psGen.modulePrefix
}

loadAbi :: forall eff m
. MonadAff (fs :: FS.FS | eff) m
loadAbi :: forall m
. MonadAff m
=> MonadThrow CompileError m
=> ChanterelleProject
-> FilePath
Expand Down
Loading

0 comments on commit 40d2d4a

Please sign in to comment.