Skip to content

Commit bbde983

Browse files
committed
Update to mel-bew3 12.0.0
1 parent afd3be2 commit bbde983

File tree

9 files changed

+82
-54
lines changed

9 files changed

+82
-54
lines changed

changelog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Changelog
2+
3+
## 1.1.0
4+
- Change all occurences of Evm to Abi
5+
- Add "Contracts." for generated module name
6+
- De-pluralize "s" in type-alias names.
7+
(Though not handling "ies")

elm-ethereum-generator.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: elm-ethereum-generator
2-
version: 1.0.1
2+
version: 1.1.0
33
-- synopsis:
44
-- description:
55
homepage: https://github.com/cmditch/elm-ethereum-generator

package/npm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elm-ethereum-generator",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Install elm-ethereum-generator",
55
"preferGlobal": true,
66
"main": "index.js",

src/Generator.hs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ decExports :: Declaration -> [Text]
5252
decExports DFunction { funName, funOutputs } =
5353
let
5454
decoderName = funName <> "Decoder"
55-
typeAlias = U.textUpperFirst funName
55+
typeAlias = typeAliasName funName
5656
in
5757
case funOutputs of
5858
[] -> [ funName ]
@@ -63,7 +63,7 @@ decExports DEvent { eveName } =
6363
let
6464
logFilterName = U.textLowerFirst eveName <> "Event"
6565
decoderName = U.textLowerFirst eveName <> "Decoder"
66-
typeAlias = U.textUpperFirst eveName
66+
typeAlias = typeAliasName eveName
6767
in
6868
[ typeAlias, logFilterName, decoderName ]
6969

@@ -89,12 +89,12 @@ decComment _ = []
8989
9090
-}
9191
decTypeAlias :: Declaration -> [Text]
92-
decTypeAlias DEvent { eveName, eveInputs } = EL.typeAlias (U.textUpperFirst eveName) (C.normalize eveInputs)
92+
decTypeAlias DEvent { eveName, eveInputs } = EL.typeAlias (typeAliasName eveName) (C.normalize eveInputs)
9393
decTypeAlias DFunction { funName, funOutputs } =
9494
case funOutputs of
9595
[] -> []
9696
[_] -> []
97-
_ -> EL.typeAlias (U.textUpperFirst funName) (C.normalize funOutputs)
97+
_ -> EL.typeAlias (typeAliasName funName) (C.normalize funOutputs)
9898
decTypeAlias _ = []
9999

100100

@@ -126,7 +126,7 @@ decBody isDebug (func@DFunction { funName, funOutputs, funInputs }) = sig <> dec
126126

127127
toElmDecoder =
128128
if isDebug then
129-
"Evm.toElmDecoderWithDebug " <> (C.methodSignature func) <> " "
129+
"Abi.toElmDecoderWithDebug " <> (C.methodSignature func) <> " "
130130
else
131131
"toElmDecoder "
132132

@@ -170,14 +170,14 @@ decDecoder :: Bool -> Declaration -> [Text]
170170
171171
someCallDecoder : Decoder SomeCall
172172
someCallDecoder =
173-
evmDecode SomeEvent
173+
abiDecode SomeEvent
174174
|> andMap address
175175
|> andMap uint
176176
|> toElmDecoder
177177
-}
178178
decDecoder isDebug (func@DFunction { funName, funOutputs }) =
179179
let
180-
sig = [ funName <> "Decoder : Decoder " <> U.textUpperFirst funName ]
180+
sig = [ funName <> "Decoder : Decoder " <> typeAliasName funName ]
181181

182182
declaration = [ funName <> "Decoder =" ]
183183

@@ -188,13 +188,13 @@ decDecoder isDebug (func@DFunction { funName, funOutputs }) =
188188

189189
toElmDecoder =
190190
if isDebug then
191-
[ U.indent 2 "|> Evm.toElmDecoderWithDebug " <> C.methodSignature func ]
191+
[ U.indent 2 "|> Abi.toElmDecoderWithDebug " <> C.methodSignature func ]
192192
else
193193
[ U.indent 2 "|> toElmDecoder" ]
194194

195195

196196

197-
body = [ U.indent 1 ("evmDecode " <> U.textUpperFirst funName) ]
197+
body = [ U.indent 1 ("abiDecode " <> typeAliasName funName) ]
198198
<> ( U.indent 2 <$> decoderPipline )
199199
<> toElmDecoder
200200

@@ -214,13 +214,13 @@ decDecoder isDebug (func@DFunction { funName, funOutputs }) =
214214
-}
215215
decDecoder isDebug (DEvent { eveName, eveInputs }) =
216216
let
217-
sig = [ U.textLowerFirst eveName <> "Decoder : Decoder " <> U.textUpperFirst eveName ]
217+
sig = [ U.textLowerFirst eveName <> "Decoder : Decoder " <> typeAliasName eveName ]
218218

219219
declaration = [ U.textLowerFirst eveName <> "Decoder = " ]
220220

221221
body =
222222
map (U.indent 1)
223-
([ "decode " <> U.textUpperFirst eveName ] <> eventPipelineBuilder (1,0) (C.normalize eveInputs) [])
223+
([ "decode " <> typeAliasName eveName ] <> eventPipelineBuilder (1,0) (C.normalize eveInputs) [])
224224

225225
toPipeline tipe n arg = U.indent 1 $
226226
"|> custom ("
@@ -269,7 +269,7 @@ funcTypeSig DFunction { funName, funInputs, funOutputs } = [ typeSig ]
269269
o = case C.normalize funOutputs of
270270
[] -> "()"
271271
[x] -> elmType x
272-
_ -> U.textUpperFirst funName
272+
_ -> typeAliasName funName
273273

274274

275275
-- | Generates the "topics" field within a Logfilter
@@ -284,8 +284,14 @@ topicsBuilder sig args =
284284
defaultTopic : (makeTopic <$> xs)
285285

286286
makeTopic arg =
287-
"Maybe.map (evmEncode << " <> encoding arg <> ") " <> nameAsInput arg
287+
"Maybe.map (abiEncode << " <> encoding arg <> ") " <> nameAsInput arg
288288
in
289289
case args of
290290
[] -> EL.wrapArray defaultTopic
291291
xs -> EL.multiLineArray $ multiTopic xs
292+
293+
294+
--
295+
typeAliasName :: Text -> Text
296+
typeAliasName name | Text.isSuffixOf "s" name = U.textUpperFirst $ Text.dropEnd 1 name
297+
| otherwise = U.textUpperFirst name

src/Generator/Converters.hs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,28 @@ getElmType "bool" = "Bool"
2222
getElmType "bytes" = "String"
2323
getElmType "string" = "String"
2424
getElmType tipe | Text.isPrefixOf "uint" tipe && Text.isSuffixOf "[]" tipe = "List BigInt"
25+
| Text.isPrefixOf "int" tipe && Text.isSuffixOf "[]" tipe = "List BigInt"
2526
| Text.isPrefixOf "bool" tipe && Text.isSuffixOf "[]" tipe = "List Bool"
2627
| Text.isPrefixOf "address" tipe && Text.isSuffixOf "[]" tipe = "List Address"
2728
| Text.isPrefixOf "uint" tipe = "BigInt"
29+
| Text.isPrefixOf "int" tipe = "BigInt"
2830
| Text.isPrefixOf "string" tipe = "String"
2931
| otherwise = tipe <> "-ERROR!"
3032

3133

3234
-- | Get elm decoder for solidity type
3335
getDecoder :: Text -> Text
34-
getDecoder "address" = "Evm.address"
35-
getDecoder "bool" = "Evm.bool"
36-
getDecoder "bytes" = "Evm.dynamicBytes"
37-
getDecoder "string" = "Evm.string"
38-
getDecoder tipe | Text.isPrefixOf "uint" tipe && Text.isSuffixOf "[]" tipe = "(Evm.dynamicArray Evm.uint)"
39-
| Text.isPrefixOf "bool" tipe && Text.isSuffixOf "[]" tipe = "(Evm.dynamicArray Evm.bool)"
40-
| Text.isPrefixOf "address" tipe && Text.isSuffixOf "[]" tipe = "(Evm.dynamicArray Evm.address)"
41-
| Text.isPrefixOf "uint" tipe = "Evm.uint"
42-
| Text.isPrefixOf "string" tipe = "Evm.string"
36+
getDecoder "address" = "Abi.address"
37+
getDecoder "bool" = "Abi.bool"
38+
getDecoder "bytes" = "Abi.dynamicBytes"
39+
getDecoder "string" = "Abi.string"
40+
getDecoder tipe | Text.isPrefixOf "uint" tipe && Text.isSuffixOf "[]" tipe = "(Abi.dynamicArray Abi.uint)"
41+
| Text.isPrefixOf "int" tipe && Text.isSuffixOf "[]" tipe = "(Abi.dynamicArray Abi.int)"
42+
| Text.isPrefixOf "bool" tipe && Text.isSuffixOf "[]" tipe = "(Abi.dynamicArray Abi.bool)"
43+
| Text.isPrefixOf "address" tipe && Text.isSuffixOf "[]" tipe = "(Abi.dynamicArray Abi.address)"
44+
| Text.isPrefixOf "uint" tipe = "Abi.uint"
45+
| Text.isPrefixOf "int" tipe = "Abi.int"
46+
| Text.isPrefixOf "string" tipe = "Abi.string"
4347
| otherwise = tipe <> "-ERROR!"
4448

4549

@@ -50,9 +54,11 @@ getEncodingType "bool" = "BoolE"
5054
getEncodingType "bytes" = "DBytesE"
5155
getEncodingType "string" = "StringE"
5256
getEncodingType tipe | Text.isPrefixOf "uint" tipe && Text.isSuffixOf "[]" tipe = "ListE UintE"
57+
| Text.isPrefixOf "int" tipe && Text.isSuffixOf "[]" tipe = "ListE IntE"
5358
| Text.isPrefixOf "bool" tipe && Text.isSuffixOf "[]" tipe = "ListE BoolE"
5459
| Text.isPrefixOf "address" tipe && Text.isSuffixOf "[]" tipe = "ListE AddressE"
5560
| Text.isPrefixOf "uint" tipe = "UintE"
61+
| Text.isPrefixOf "int" tipe = "IntE"
5662
| otherwise = tipe <> "-ERROR!"
5763

5864

@@ -87,6 +93,7 @@ eventDecoderName t =
8793

8894

8995
-- | The below functions/class helps normalize data for unnamed inputs/outputs
96+
9097
data Arg = Arg { elmType :: Text
9198
, nameAsInput :: Text
9299
, nameAsOutput :: Text
@@ -118,9 +125,10 @@ eventTuple (i, EventArg { eveArgName, eveArgType, eveArgIndexed }) = (i, (eveArg
118125

119126

120127
rename :: (Int, (Text, Text, Bool)) -> Arg
121-
rename (index, (argName, argType, isIndexed)) = case argName of
122-
"" -> Arg type' nInput nOutput indexT decoder encoder isIndexed
123-
_ -> Arg type' (sanitizeName argName) (sanitizeName argName) argName decoder encoder isIndexed
128+
rename (index, (argName, argType, isIndexed)) =
129+
case argName of
130+
"" -> Arg type' nInput nOutput indexT decoder encoder isIndexed
131+
_ -> Arg type' (sanitizeName argName) (sanitizeName argName) argName decoder encoder isIndexed
124132
where
125133
indexT = Text.pack (show index)
126134
type' = getElmType argType

src/Generator/Templates.hs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ moduleNameAndExports name (x:xs) =
1818
let
1919
exportHelper n = U.indent 2 (", " <> n)
2020
in
21-
[ "module " <> name
21+
[ "module Contracts." <> name
2222
, U.indent 1 "exposing"
2323
, U.indent 2 ("( " <> x)
2424
] <> (exportHelper <$> xs) <> [ U.indent 2 ")\n" ]
@@ -32,8 +32,15 @@ imports =
3232
, "import Json.Decode.Pipeline exposing (custom, decode)"
3333
, "import Eth.Types exposing (..)"
3434
, "import Eth.Utils as U"
35-
, "import Evm.Decode as Evm exposing (evmDecode, andMap, toElmDecoder, topic, data)"
36-
, "import Evm.Encode as Evm exposing (Encoding(..), evmEncode)"
35+
, "import Abi.Decode as Abi exposing (abiDecode, andMap, toElmDecoder, topic, data)"
36+
, "import Abi.Encode as Abi exposing (Encoding(..), abiEncode)"
37+
, ""
38+
, ""
39+
, "{-"
40+
, ""
41+
, " This file was generated by https://github.com/cmditch/elm-ethereum-generator"
42+
, ""
43+
, "-}"
3744
, ""
3845
, ""
3946
]
@@ -45,9 +52,9 @@ callBuilder isDebug sig encodings decoder =
4552
let
4653
encodeDataFunc =
4754
if isDebug then
48-
" Evm.encodeFunctionCallWithDebug "
55+
" Abi.encodeFunctionCallWithDebug "
4956
else
50-
" Evm.encodeFunctionCall "
57+
" Abi.encodeFunctionCall "
5158
in
5259
[ "{ to = Just contractAddress"
5360
, ", from = Nothing"

src/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import qualified Text.PrettyPrint.ANSI.Leijen as PP
1818

1919
version :: String
2020
version =
21-
"1.0.1"
21+
"1.1.0"
2222

2323

2424
main :: IO ()

src/Types.hs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import Utils (toLowerFirst)
1010

1111

1212
data FunctionArg = FunctionArg
13-
{ funArgName :: Text
14-
, funArgType :: Text
13+
{ funArgName :: !Text
14+
, funArgType :: !Text
1515
} deriving (Show, Eq, Ord)
1616

1717

@@ -21,9 +21,9 @@ $(deriveJSON
2121

2222

2323
data EventArg = EventArg
24-
{ eveArgName :: Text
25-
, eveArgType :: Text
26-
, eveArgIndexed :: Bool
24+
{ eveArgName :: !Text
25+
, eveArgType :: !Text
26+
, eveArgIndexed :: !Bool
2727
} deriving (Show, Eq, Ord)
2828

2929

@@ -33,26 +33,26 @@ $(deriveJSON
3333

3434

3535
data Declaration
36-
= DConstructor { conInputs :: [FunctionArg]
37-
, conPayable :: Bool
38-
, conStateMutability :: Text
36+
= DConstructor { conInputs :: ![FunctionArg]
37+
, conPayable :: !Bool
38+
, conStateMutability :: !Text
3939
}
4040

41-
| DFunction { funName :: Text
42-
, funConstant :: Bool
43-
, funInputs :: [FunctionArg]
44-
, funOutputs :: [FunctionArg]
45-
, funPayable :: Bool
46-
, funStateMutability :: Text
41+
| DFunction { funName :: !Text
42+
, funConstant :: !Bool
43+
, funInputs :: ![FunctionArg]
44+
, funOutputs :: ![FunctionArg]
45+
, funPayable :: !Bool
46+
, funStateMutability :: !Text
4747
}
4848

49-
| DEvent { eveName :: Text
50-
, eveInputs :: [EventArg]
51-
, eveAnonymous :: Bool
49+
| DEvent { eveName :: !Text
50+
, eveInputs :: ![EventArg]
51+
, eveAnonymous :: !Bool
5252
}
5353

54-
| AFallback { falPayable :: Bool
55-
, falStateMutability :: Text
54+
| AFallback { falPayable :: !Bool
55+
, falStateMutability :: !Text
5656
}
5757
deriving (Show, Ord, Eq)
5858

src/Utils.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ indent n t =
6363

6464

6565
-- | Used to generate parameter names
66-
-- | "!" is 17th letter to cause Elm compiler to fail if function inputs > 16
66+
-- | "*!*" is 17th letter to cause Elm compiler to fail if function inputs > 16
6767
-- | Due to stack limitations on the EVM
6868
paramAlphabet :: String
6969
paramAlphabet =
70-
['a' .. 'p'] <> "!"
70+
['a' .. 'p'] <> "*!*"
7171

7272
-- | "~/some/path/ERC20.elm" to "ERC20"
7373
getFileName :: FilePath -> Text

0 commit comments

Comments
 (0)