Skip to content

Commit

Permalink
v0.14 (#132)
Browse files Browse the repository at this point in the history
* Upgrade to purescript v0.14
  • Loading branch information
kejace authored Jul 14, 2021
1 parent 41d55ba commit 69597c8
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js: 8
dist: trusty
node_js: stable
dist: focal
sudo: required
node_js: stable
install:
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# chanterelle

[![Build Status](https://travis-ci.org/f-o-a-m/chanterelle.svg?branch=master)](https://travis-ci.org/f-o-a-m/chanterelle)
[![Build Status](https://travis-ci.com/f-o-a-m/chanterelle.svg?branch=master)](https://travis-ci.com/f-o-a-m/chanterelle)

<img src=https://github.com/f-o-a-m/chanterelle/blob/master/chanterelle-logo.svg width="150">


_a more functional truffle_

## Overview
Expand All @@ -19,5 +18,4 @@ You can find our [documentation](https://chanterelle.readthedocs.io/en/latest/)

Chanterelle includes a quasi-package-oriented project structure, to be used more thoroughly in the future when the Ethereum ecosystem settles on a contract package management system.
This is embodied in the `chanterelle.json` file which should be located in the
root of your project. It also supports the notion of dependencies (very rudimentary at the moment), as well as automatically generates PureScript bindings for your contracts using `purescript-web3-generator`.

root of your project. It also supports the notion of dependencies (very rudimentary at the moment), as well as automatically generates PureScript bindings for your contracts using `purescript-web3-generator`.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
"postinstall": "echo 'If you are installing chanterelle to use globally, you likely want to run `chanterelle global-postinstall`.'"
},
"dependencies": {
"purescript": "^0.13.0",
"purescript-psa": "^0.7.3",
"purescript": "^0.14.2",
"purescript-psa": "^0.8.2",
"bn.js": "^4.11.0",
"ethjs-provider-http": "^0.1.6",
"mkdirp": "^0.5.1",
"keccak": "^1.0.2",
"secp256k1": "^3.0.1",
"rlp": "^2.0.0",
"solc": "^0.6",
"spago": "^0.16.0"
"spago": "^0.20.3"
},
"bin": {
"chanterelle": "chanterelle-bin.sh"
Expand Down
15 changes: 7 additions & 8 deletions packages.dhall
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.13.8-20201007/packages.dhall sha256:35633f6f591b94d216392c9e0500207bb1fec42dd355f4fecdfd186956567b6b
https://github.com/purescript/package-sets/releases/download/psc-0.14.2-20210629/packages.dhall sha256:534c490bb73cae75adb5a39871142fd8db5c2d74c90509797a80b8bb0d5c3f7b

let overrides = {=}

Expand All @@ -24,15 +24,14 @@ let additions =
, "parsing"
, "partial"
, "profunctor-lenses"
, "proxy"
, "psci-support"
, "tagged"
, "transformers"
, "typelevel-prelude"
, "variant"
]
, repo = "https://github.com/f-o-a-m/purescript-web3"
, version = "v3.0.0"
, version = "v4.0.0"
}
, web3-generator =
{ dependencies =
Expand All @@ -54,7 +53,7 @@ let additions =
, "yargs"
]
, repo = "https://github.com/f-o-a-m/purescript-web3-generator"
, version = "v3.0.0"
, version = "v4.0.0"
}
, eth-core =
{ dependencies =
Expand All @@ -74,7 +73,7 @@ let additions =
, repo =
"https://github.com/f-o-a-m/purescript-eth-core.git"
, version =
"v6.0.0"
"v7.0.0"
}
, coroutine-transducers =
{ dependencies =
Expand Down Expand Up @@ -103,7 +102,7 @@ let additions =
, repo =
"https://github.com/f-o-a-m/purescript-solc"
, version =
"v2.0.2"
"v3.0.0"
}
, mkdirp =
{ dependencies =
Expand All @@ -128,9 +127,9 @@ let additions =
, "profunctor"
]
, repo =
"https://github.com/LiamGoodacre/purescript-tagged"
"https://github.com/kejace/purescript-tagged"
, version =
"v3.0.0"
"v0.14"
}
}

Expand Down
40 changes: 36 additions & 4 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,53 @@ You can edit this file as you like.
-}
{ name = "chanterelle"
, dependencies =
[ "console"
, "debug"
[ "aff"
, "ansi"
, "argonaut"
, "argonaut-core"
, "argonaut-traversals"
, "arrays"
, "avar"
, "bifunctors"
, "console"
, "control"
, "datetime"
, "effect"
, "either"
, "eth-core"
, "exceptions"
, "foldable-traversable"
, "foreign-object"
, "functions"
, "functors"
, "identity"
, "integers"
, "logging"
, "mkdirp"
, "maybe"
, "newtype"
, "node-buffer"
, "node-fs"
, "node-fs-aff"
, "node-path"
, "node-process"
, "optparse"
, "ordered-collections"
, "parallel"
, "partial"
, "prelude"
, "profunctor-lenses"
, "psci-support"
, "record"
, "refs"
, "solc"
, "strings"
, "transformers"
, "tuples"
, "unfoldable"
, "validation"
, "web3"
, "web3-generator"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs"]
, sources = [ "src/**/*.purs" ]
}
7 changes: 4 additions & 3 deletions src/Chanterelle.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import Chanterelle.Project (loadProject)
import Control.Monad.Error.Class (try)
import Data.Either (Either(..))
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Show.Generic (genericShow)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Node.Path (resolve)
import Node.Process (cwd, exit)

data SelectCLI (a :: Type) (b :: Type) = SelectCLI a

data SelectPS (a :: Type) (b :: Type) = SelectPS b

data SelectCLI a b = SelectCLI a
data SelectPS a b = SelectPS b
instance showSelectDeployM :: Show (SelectPS a (DeployM Unit)) where show (SelectPS _ ) = "<DeployM Unit>"
instance showSelectDeployPath :: Show a => Show (SelectCLI a b) where show (SelectCLI a ) = show a

Expand Down
8 changes: 3 additions & 5 deletions src/Chanterelle/Internal/Codegen.purs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ generatePS = do
p@(ChanterelleProject project) <- ask
let psArgs = projectPSArgs p
void <<< for project.modules $ \(ChanterelleModule mod) -> do
(PSWeb3Gen.Abi abiWithErrors) <- loadAbi p mod.jsonPath
(PSWeb3Gen.Abi abiWithErrors) <- loadAbi mod.jsonPath
log Debug $ "generating purescript for " <> mod.moduleName
abi <- for abiWithErrors case _ of
Left (PSWeb3Gen.AbiDecodeError err) -> do
Expand Down Expand Up @@ -79,11 +79,9 @@ projectPSArgs (ChanterelleProject project) =
loadAbi :: forall m
. MonadAff m
=> MonadThrow CompileError m
=> ChanterelleProject
-> FilePath
=> FilePath
-> m PSWeb3Gen.AbiWithErrors
loadAbi (ChanterelleProject project) abiFile = do
let (ChanterelleProjectSpec spec) = project.spec
loadAbi abiFile = do
ejson <- liftAff (jsonParser <$> FS.readTextFile UTF8 abiFile)
json <- either (throwError <<< CompileParseError <<< {objectName: "Json File " <> abiFile, parseError:_}) pure ejson
either (throwError <<< CompileParseError <<< {objectName: "ABI " <> abiFile, parseError:_}) pure $ parseAbi json
Expand Down
6 changes: 2 additions & 4 deletions src/Chanterelle/Internal/Compile.purs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ compile
=> MonadAsk ChanterelleProject m
=> m (M.Object (Tuple ChanterelleModule ST.CompilerOutput))
compile = do
p@(ChanterelleProject project) <- ask
let (ChanterelleProjectSpec spec) = project.spec
dirtyModules <- modulesToCompile
solcInputs <- for dirtyModules $ \m@(ChanterelleModule mod) -> do
input <- makeSolcInput mod.solContractName mod.solPath
Expand Down Expand Up @@ -82,7 +80,7 @@ modulesToCompile = do
Just compiledAt -> do
eIsDirty <- liftAff <<< attempt $ fileIsDirty mod.solPath (Milliseconds compiledAt) project.specModTime
case eIsDirty of
Left err -> throwError $ MissingArtifactError {fileName: mod.solPath, objectName: mod.solContractName}
Left _ -> throwError $ MissingArtifactError {fileName: mod.solPath, objectName: mod.solContractName}
Right isDirty ->
if not isDirty
then log Debug ("File is clean: " <> mod.solPath) *> pure Nothing
Expand Down Expand Up @@ -128,7 +126,7 @@ loadSolcCallback
-> ChanterelleProjectSpec
-> String
-> Effect (Either String String)
loadSolcCallback (ChanterelleModule mod) root (ChanterelleProjectSpec project) filePath = do
loadSolcCallback (ChanterelleModule mod) root (ChanterelleProjectSpec _) filePath = do
let modRoot = Path.dirname mod.solPath
isAbs = Path.isAbsolute filePath
modRootWithoutRoot = fromMaybe modRoot $ stripPrefix (Pattern root) modRoot
Expand Down
12 changes: 4 additions & 8 deletions src/Chanterelle/Internal/Deploy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ getContractBytecode
getContractBytecode lc@{ filepath } = do
DeployConfig { networkID } <- ask
let fullError err = ConfigurationError $ "Couldn't find contract bytecode in artifact " <> filepath <> ": " <> err
compiledBytecodeError err = "Couldn't get compiled artifact bytecode: " <> err
networkBytecodeError err = " Couldn't get bytecode for network " <> show networkID <> ": " <> err
withExceptT' fullError $ do
artifact <- readArtifact' lc
let networkBytecode = artifact ^? _network networkID <<< _Just <<< _NetworkBytecode
Expand All @@ -148,8 +146,7 @@ deployLibrary
=> TransactionOptions NoPay
-> LibraryConfig ()
-> m (DeployReceipt LibraryMeta)
deployLibrary txo ccfg@{filepath, name} = do
DeployConfig { provider } <- ask
deployLibrary txo ccfg@{ name } = do
nbc@(ArtifactBytecode { bytecode: bc }) <- getContractBytecode ccfg
case bc of
BCUnlinked _ -> throwError $ DeployingUnlinkedBytecodeError { name, libs: CBC.unlinkedLibraryNames bc }
Expand All @@ -169,7 +166,7 @@ linkLibrary
-> Record LibraryMeta
-> m ArtifactBytecode
linkLibrary ccfg@{ filepath, name } { libraryName, libraryAddress } = do
(DeployConfig { provider, networkID, writeArtifacts }) <- ask
(DeployConfig { networkID }) <- ask
ArtifactBytecode { bytecode: originalBytecode, deployedBytecode: originalDeployedBytecode } <- getContractBytecode ccfg
bytecode <- link' "construction bytecode" originalBytecode
deployedBytecode <- link' "on-chain bytecode" originalDeployedBytecode
Expand All @@ -194,7 +191,6 @@ deployContract
-> ContractConfig args
-> m (DeployReceipt args)
deployContract txOptions ccfg@{name, constructor} = do
DeployConfig { provider } <- ask
nbc@(ArtifactBytecode { bytecode: bc }) <- getContractBytecode ccfg
case bc of
BCUnlinked _ -> throwError $ DeployingUnlinkedBytecodeError { name, libs: CBC.unlinkedLibraryNames bc }
Expand All @@ -217,7 +213,7 @@ deployContractAndWriteToArtifact
-- ^ ArtifactBytecode being deployed
-> m { deployAddress :: Address, deployHash :: HexString }
deployContractAndWriteToArtifact lc@{ filepath, name } deployAction nbc = do
(DeployConfig { provider, networkID, primaryAccount, writeArtifacts }) <- ask
(DeployConfig { provider, networkID }) <- ask
log Info $ "Deploying contract " <> name
deployHash <- withExceptM' onDeploymentError <<< liftAff $ runWeb3 provider deployAction
networkInfo <- getPublishedContractDeployInfo deployHash name nbc
Expand Down Expand Up @@ -266,7 +262,7 @@ writeArtifact'
=> LibraryConfig a
-> Artifact
-> m Unit
writeArtifact' lc@{ name, filepath } artifact = do
writeArtifact' { name, filepath } artifact = do
DeployConfig { artifactCache, writeArtifacts } <- ask
cacheVar <- liftEffect $ Ref.read artifactCache
let newCache = Map.insert { name, filepath } artifact cacheVar
Expand Down
6 changes: 3 additions & 3 deletions src/Chanterelle/Internal/Logging.purs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ readLogLevel level =
let normalized = toUpper level
in case normalized of
"DEBUG" -> Debug
"INFO" -> Info
"WARN" -> Warn
"INFO" -> Info
"WARN" -> Warn
"ERROR" -> Error
otherwise -> Info
_ -> Info

class Loggable a where
logify :: a -> String
Expand Down
1 change: 1 addition & 0 deletions src/Chanterelle/Internal/Types/Deploy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ newtype DeployConfig =
type Constructor args = TransactionOptions NoPay -> HexString -> Record args -> Web3 HexString

-- | Type alias for the empty args
type NoArgs :: forall k. Row k
type NoArgs = ()

-- | Value representing empty args
Expand Down
4 changes: 2 additions & 2 deletions src/Chanterelle/Internal/Utils.purs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Control.Parallel (parOneOf)
import Data.Either (Either)
import Data.Int (toNumber)
import Data.Map as Map
import Data.Validation.Semigroup (unV)
import Data.Validation.Semigroup (validation)
import Effect.Aff (Aff, Milliseconds(..), attempt, delay)
import Effect.Aff.Class (class MonadAff)
import Effect.Ref as Ref
Expand Down Expand Up @@ -83,4 +83,4 @@ validateDeployArgs
validateDeployArgs cfg =
let onErr msg = throwError $ ConfigurationError ("Couldn't validate args for contract deployment " <> cfg.name <> ": " <> show msg)
onSucc = pure
in unV onErr onSucc cfg.unvalidatedArgs
in validation onErr onSucc cfg.unvalidatedArgs
2 changes: 1 addition & 1 deletion src/Chanterelle/Project.purs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mkProjectSolc version artifactPath = runExceptT $
log Info $ "Using cached solc " <> v <> " at " <> compilerCacheFile
let compiler = Solc.useCompiler src
pure { compilerOrigin: "Cached", compiler }
Left err -> do
Left _ -> do
log Info $ "Downloading solc " <> v <> " to " <> compilerCacheFile
assertDirectory compilerCacheDirectory
source <- ExceptT $ SolcReleases.getReleaseSource SolcReleases.defaultReleaseRepo v
Expand Down

0 comments on commit 69597c8

Please sign in to comment.