diff --git a/.travis.yml b/.travis.yml index 9f95347..576fb7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js -dist: trusty +dist: focal sudo: required node_js: stable install: diff --git a/README.md b/README.md index d36ca3d..2ab55f2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Latest release](http://img.shields.io/github/release/f-o-a-m/purescript-web3-generator.svg?branch=master)](https://github.com/f-o-a-m/purescript-web3-generator/releases) [![purescript-web3-generator on Pursuit](https://pursuit.purescript.org/packages/purescript-web3-generator/badge)](https://pursuit.purescript.org/packages/purescript-web3-generator) -[![Build status](https://travis-ci.org/f-o-a-m/purescript-web3-generator.svg?branch=master)](https://travis-ci.org/f-o-a-m/purescript-web3-generator?branch=master) +[![Build status](https://travis-ci.com/f-o-a-m/purescript-web3-generator.svg?branch=master)](https://travis-ci.com/f-o-a-m/purescript-web3-generator?branch=master) Generats purescript modules from Solidity ABIs @@ -35,7 +35,6 @@ module Generator where import Data.GeneratorMain (generatorMain) main = generatorMain - ``` 2. From there, add a build step @@ -43,7 +42,6 @@ main = generatorMain ```sh pulp run -m Generator --src-path generator -- --abis --dest src --module Contracts - ``` (note that we specify both a different source directory than `src` and a different module `Generator` that `purs` is looking for `main` in) diff --git a/package.json b/package.json index e0efb4f..d7e8df7 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,8 @@ "yargs": "^8.0.2" }, "devDependencies": { - "pulp": "^15.0.0", - "purescript": "^0.13.0", - "purescript-psa": "^0.7.3", - "spago": "^0.16.0" + "purescript": "^0.14.2", + "purescript-psa": "^0.8.2", + "spago": "^0.20.3" } } diff --git a/packages.dhall b/packages.dhall index ee3e176..814d1ca 100644 --- a/packages.dhall +++ b/packages.dhall @@ -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 = {=} @@ -24,7 +24,6 @@ let additions = , "parsing" , "partial" , "profunctor-lenses" - , "proxy" , "psci-support" , "tagged" , "transformers" @@ -32,7 +31,7 @@ let additions = , "variant" ] , repo = "https://github.com/f-o-a-m/purescript-web3" - , version = "v3.0.0" + , version = "v4.0.0" } , eth-core = { dependencies = @@ -52,7 +51,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 = @@ -90,9 +89,9 @@ let additions = , "profunctor" ] , repo = - "https://github.com/LiamGoodacre/purescript-tagged" + "https://github.com/kejace/purescript-tagged" , version = - "v3.0.0" + "v0.14" } } diff --git a/spago.dhall b/spago.dhall index e75ad31..4c4bf05 100644 --- a/spago.dhall +++ b/spago.dhall @@ -4,20 +4,43 @@ You can edit this file as you like. -} { name = "web3-generator" , dependencies = - [ "ansi" + [ "aff" + , "ansi" , "argonaut" + , "argonaut-codecs" + , "argonaut-core" + , "argonaut-traversals" + , "arrays" + , "bifunctors" , "console" + , "control" , "effect" + , "either" , "errors" , "eth-core" + , "exceptions" , "fixed-points" + , "foldable-traversable" + , "identity" + , "integers" + , "lists" + , "maybe" , "mkdirp" + , "newtype" + , "node-buffer" + , "node-fs" , "node-fs-aff" + , "node-path" + , "nonempty" , "ordered-collections" + , "partial" , "prelude" + , "profunctor-lenses" , "psci-support" - , "record-extra" , "string-parsers" + , "strings" + , "transformers" + , "tuples" , "web3" , "yargs" ] diff --git a/src/Data/AbiParser.purs b/src/Data/AbiParser.purs index d5c7a97..1d5f38e 100644 --- a/src/Data/AbiParser.purs +++ b/src/Data/AbiParser.purs @@ -16,8 +16,8 @@ import Data.Either (Either(..)) import Data.Foldable (all, foldMap) import Data.FunctorWithIndex (mapWithIndex) import Data.Generic.Rep (class Generic) -import Data.Generic.Rep.Eq (genericEq) -import Data.Generic.Rep.Show (genericShow) +import Data.Eq.Generic (genericEq) +import Data.Show.Generic (genericShow) import Data.Int (fromString) import Data.List.Types (List(..), NonEmptyList(..)) import Data.Maybe (Maybe(..)) @@ -305,7 +305,7 @@ instance showSolidityFallback :: Show SolidityFallback where show = genericShow instance decodeJsonSolidityFallback :: DecodeJson SolidityFallback where - decodeJson json = do + decodeJson _ = do pure $ SolidityFallback -------------------------------------------------------------------------------- diff --git a/src/Data/CodeGen.purs b/src/Data/CodeGen.purs index 2a9a1d6..d71ea4f 100644 --- a/src/Data/CodeGen.purs +++ b/src/Data/CodeGen.purs @@ -27,7 +27,7 @@ import Data.Identity (Identity(..)) import Data.Lens ((^?)) import Data.Array as Array import Data.Lens.Index (ix) -import Data.Map (Map, fromFoldableWith, insert, lookup, member, toUnfoldable) +import Data.Map (Map, fromFoldableWith, insert, lookup, member, toUnfoldable, empty) import Data.Maybe (Maybe(..), isNothing) import Data.Newtype (un) import Data.Map as Map @@ -68,7 +68,7 @@ runImports = mergeImports >>> map runImport >>> newLine1 >>> ("import Prelude \n runImport (Tuple mName mImports) = "import " <> mName <> " (" <> joinWith ", " (runModuleImports mImports) <> ")" runModuleImports :: ModuleImports -> Array String runModuleImports = - runAcc <<< foldl f { types: mempty, imports: mempty } + runAcc <<< foldl f { types: empty, imports: mempty } where runAcc :: ModuleImportsAcc -> Array String runAcc acc = sort $ nub $ append acc.imports $ (toUnfoldable acc.types) >>= resolveCtrImports @@ -267,7 +267,6 @@ getAllJsonFiles root = evalStateT getAllJsonFiles' root where getAllJsonFiles' :: StateT FilePath m (Array FilePath) getAllJsonFiles' = do - cd <- get hereFiles <- getJsonFilesInDirectory hereDirectories <- getAllDirectories if null hereDirectories diff --git a/src/Data/Generator.purs b/src/Data/Generator.purs index 65d9105..5579950 100644 --- a/src/Data/Generator.purs +++ b/src/Data/Generator.purs @@ -145,8 +145,8 @@ data FunTypeDecl = , typeName :: String } -funToTypeDecl :: SolidityFunction -> CodeOptions -> Imported FunTypeDecl -funToTypeDecl fun@(SolidityFunction f) opts = do +funToTypeDecl :: SolidityFunction -> Imported FunTypeDecl +funToTypeDecl fun@(SolidityFunction f) = do factorTypes <- if f.isUnCurried then for f.inputs tagInput @@ -164,14 +164,14 @@ instance codeDataDecl :: Code FunTypeDecl where nArgs = length decl.factorTypes tupleType = "Tuple" <> show nArgs import' "Data.Functor.Tagged" [IType "Tagged"] - import' "Data.Symbol" [IType "SProxy"] + import' "Type.Proxy" [IType "Proxy"] import' "Network.Ethereum.Web3.Solidity" [ITypeCtr tupleType] pure $ fold ["type " , decl.typeName , " = " - , "Tagged (SProxy \"" <> decl.signature <> "\") (" <> tupleType <> " " <> joinWith " " decl.factorTypes <> ")" + , "Tagged (Proxy \"" <> decl.signature <> "\") (" <> tupleType <> " " <> joinWith " " decl.factorTypes <> ")" ] -------------------------------------------------------------------------------- @@ -199,7 +199,7 @@ data HelperFunction funToHelperFunction :: Boolean -> SolidityFunction -> CodeOptions -> Imported CurriedHelperFunctionR funToHelperFunction isWhereClause fun@(SolidityFunction f) opts = do - (FunTypeDecl decl) <- funToTypeDecl fun opts + (FunTypeDecl decl) <- funToTypeDecl fun import' "Network.Ethereum.Web3.Types" [IType "TransactionOptions"] sigPrefix <- if f.isConstructor @@ -233,7 +233,7 @@ funToHelperFunction isWhereClause fun@(SolidityFunction f) opts = do inputs' = map (\(FunctionInput fi) -> fi.type) f.inputs conVars = mapWithIndex (\i _ -> var <> show (offset + i)) inputs' helperTransport <- toTransportPrefix f.isConstructor f.constant $ length f.outputs - helperPayload <- toPayload isWhereClause decl.typeName conVars + helperPayload <- toPayload decl.typeName conVars returnType <- toReturnType f.constant f.outputs ins <- if f.isUnCurried @@ -254,7 +254,7 @@ funToHelperFunction isWhereClause fun@(SolidityFunction f) opts = do funToHelperFunction' :: SolidityFunction -> CodeOptions -> Imported HelperFunction funToHelperFunction' fun@(SolidityFunction f) opts = do - (FunTypeDecl decl) <- funToTypeDecl fun opts + (FunTypeDecl decl) <- funToTypeDecl fun import' "Network.Ethereum.Web3.Types" [IType "TransactionOptions"] sigPrefix <- if f.isConstructor @@ -284,7 +284,7 @@ funToHelperFunction' fun@(SolidityFunction f) opts = do else ["x0"] returnType <- toReturnType f.constant f.outputs recIn <- recordInput f.inputs - whereC <- whereHelper decl sigPrefix f.inputs returnType >>= \h -> genCode h opts {indentationLevel = opts.indentationLevel + 4} + whereC <- whereHelper sigPrefix returnType >>= \h -> genCode h opts {indentationLevel = opts.indentationLevel + 4} pure $ UnCurriedHelperFunction { signature: sigPrefix <> [recIn, returnType] @@ -303,7 +303,7 @@ funToHelperFunction' fun@(SolidityFunction f) opts = do ty <- toPSType fi.type pure $ fi.name <> " :: " <> ty pure $ "{ " <> joinWith ", " rowElems <> " }" - whereHelper d pre is ret = do + whereHelper pre ret = do helper <- funToHelperFunction true fun opts tys <- if f.isUnCurried @@ -322,8 +322,8 @@ tagInput tagInput (FunctionInput fi) = do ty <- toPSType fi.type import' "Data.Functor.Tagged" [IType "Tagged"] - import' "Data.Symbol" [IType "SProxy"] - pure $ "(Tagged (SProxy " <> "\"" <> fi.name <> "\") " <> ty <> ")" + import' "Type.Proxy" [IType "Proxy"] + pure $ "(Tagged (Proxy " <> "\"" <> fi.name <> "\") " <> ty <> ")" toTransportPrefix :: Boolean -> Boolean -> Int -> Imported String toTransportPrefix isConstructor isCall outputCount = do @@ -348,8 +348,8 @@ toTransportPrefix isConstructor isCall outputCount = do pure "" pure $ modifier <> fun -toPayload :: Boolean -> String -> Array String -> Imported String -toPayload isWhereClause typeName args = do +toPayload :: String -> Array String -> Imported String +toPayload typeName args = do import' "Data.Functor.Tagged" [IVal "tagged"] let tupleType = "Tuple" <> show (length args) import' "Network.Ethereum.Web3.Solidity" [ITypeCtr tupleType] @@ -453,11 +453,11 @@ instance codeEventGenericInstance :: Code EventGenericInstance where in pure $ newLine2 $ i.genericDeriving : instances eventToEventGenericInstance :: SolidityEvent -> Imported EventGenericInstance -eventToEventGenericInstance ev@(SolidityEvent e) = do +eventToEventGenericInstance ev@(SolidityEvent _) = do (EventDataDecl decl) <- eventToDataDecl ev let capConst = capitalize decl.constructor - import' "Data.Generic.Rep.Eq" [IVal "genericEq"] - import' "Data.Generic.Rep.Show" [IVal "genericShow"] + import' "Data.Eq.Generic" [IVal "genericEq"] + import' "Data.Show.Generic" [IVal "genericShow"] import' "Data.Generic.Rep" [IClass "Generic"] pure $ EventGenericInstance @@ -500,8 +500,8 @@ eventToDecodeEventInstance event@(SolidityEvent ev) = do where taggedFactor (Tuple label value) = do import' "Data.Functor.Tagged" [IType "Tagged"] - import' "Data.Symbol" [IType "SProxy"] - pure $ "(Tagged (SProxy \"" <> label <> "\") " <> value <> ")" + import' "Type.Proxy" [IType "Proxy"] + pure $ "(Tagged (Proxy \"" <> label <> "\") " <> value <> ")" data EventFilterInstance = @@ -561,7 +561,7 @@ eventToEventFilterInstance ev@(SolidityEvent e) = do eventToEventCodeBlock :: SolidityEvent -> Imported CodeBlock -eventToEventCodeBlock ev@(SolidityEvent e) = do +eventToEventCodeBlock ev@(SolidityEvent _) = do eventDec <- eventToDataDecl ev eventFilterInstance <- eventToEventFilterInstance ev decodeEventInstance <- eventToDecodeEventInstance ev @@ -580,7 +580,7 @@ data CodeBlock = funToFunctionCodeBlock :: SolidityFunction -> CodeOptions -> Imported CodeBlock funToFunctionCodeBlock fun@(SolidityFunction f) opts = do - typeDecl <- funToTypeDecl fun opts + typeDecl <- funToTypeDecl fun helperFunction <- if f.isUnCurried then funToHelperFunction' fun opts else funToHelperFunction false fun opts <#> CurriedHelperFunction diff --git a/test.dhall b/test.dhall index 3441669..f0fd12a 100644 --- a/test.dhall +++ b/test.dhall @@ -1,6 +1,33 @@ let conf = ./spago.dhall -in conf // { - sources = conf.sources # [ "test/**/*.purs" ], - dependencies = conf.dependencies # [ "spec" ] -} +in conf + ⫽ { sources = conf.sources # [ "test/**/*.purs" ] + , dependencies = + conf.dependencies + # [ "spec" + , "arrays" + , "aff" + , "control" + , "argonaut-codecs" + , "argonaut-core" + , "argonaut-traversals" + , "bifunctors" + , "either" + , "exceptions" + , "foldable-traversable" + , "identity" + , "integers" + , "lists" + , "maybe" + , "newtype" + , "node-buffer" + , "node-fs" + , "node-path" + , "nonempty" + , "partial" + , "profunctor-lenses" + , "strings" + , "transformers" + , "tuples" + ] + } diff --git a/test/Main.purs b/test/Main.purs index 00c845d..431df52 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -30,13 +30,13 @@ simpleStorageParserSpec = parseSolidityType' "bytes32[2147483647][12][]" `shouldEqual` Right (SolidityArray $ SolidityVector (pure top <> pure 12) (SolidityBytesN 32)) parseSolidityType' "bytes32[1asd][]" `shouldEqual` - Left "Failed to parse SolidityType \"bytes32[1asd][]\" with error: Could not match character ']'" + Left "Failed to parse SolidityType \"bytes32[1asd][]\" with error: { error: \"Could not match character ']'\", pos: 9 }" parseSolidityType' "bytes32[21474836471][12][]" `shouldEqual` - Left "Failed to parse SolidityType \"bytes32[21474836471][12][]\" with error: Couldn't parse as Int : 21474836471" + Left "Failed to parse SolidityType \"bytes32[21474836471][12][]\" with error: { error: \"Couldn't parse as Int : 21474836471\", pos: 19 }" parseSolidityType' "bytes999[]" `shouldEqual` Right (SolidityArray $ SolidityBytesN 999) parseSolidityType' "bytes32[] " `shouldEqual` - Left "Failed to parse SolidityType \"bytes32[] \" with error: Expected EOF" + Left "Failed to parse SolidityType \"bytes32[] \" with error: { error: \"Expected EOF\", pos: 9 }" it "can parse the simple storage abi" do ejson <- jsonParser <$> readTextFile UTF8 "./abi-data/truffle/build/contracts/SimpleStorage.json"