Skip to content

Commit 99075e3

Browse files
committed
Update examples. Remove npm stuff from root
1 parent 885197d commit 99075e3

File tree

4 files changed

+918
-725
lines changed

4 files changed

+918
-725
lines changed

examples/ERC20.elm

Lines changed: 94 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -18,190 +18,201 @@ module Contracts.ERC20 exposing
1818
, transferFrom
1919
)
2020

21-
import Abi.Decode as AbiDecode exposing (abiDecode, andMap, data, toElmDecoder, topic)
22-
import Abi.Encode as AbiEncode exposing (Encoding(..), abiEncode)
21+
import Eth.Abi.Decode as D exposing (abiDecode, andMap, data, toElmDecoder, topic)
22+
import Eth.Abi.Encode as E exposing (Encoding(..), abiEncode)
2323
import BigInt exposing (BigInt)
2424
import Eth.Types exposing (..)
2525
import Eth.Utils as U
26-
import Json.Decode as Decode exposing (Decoder)
27-
import Json.Decode.Pipeline exposing (custom, decode)
26+
import Json.Decode as Decode exposing (Decoder, succeed)
27+
import Json.Decode.Pipeline exposing (custom)
2828

2929

3030

3131
{-
3232
33-
This file was generated by https://github.com/cmditch/elm-ethereum-generator
33+
This file was generated by https://github.com/cmditch/elm-ethereum-generator v3.0.0
34+
Compatible with elm-ethereum v4.0.0
3435
3536
-}
37+
-- allowance(address,address) function
3638

3739

38-
{-| "allowance(address,address)" function
39-
-}
4040
allowance : Address -> Address -> Address -> Call BigInt
41-
allowance contractAddress owner spender =
41+
allowance contractAddress owner_ spender_ =
4242
{ to = Just contractAddress
4343
, from = Nothing
4444
, gas = Nothing
4545
, gasPrice = Nothing
4646
, value = Nothing
47-
, data = Just <| AbiEncode.functionCall "allowance(address,address)" [ AbiEncode.address owner, AbiEncode.address spender ]
47+
, data = Just <| E.functionCall "dd62ed3e" [ E.address owner_, E.address spender_ ]
4848
, nonce = Nothing
49-
, decoder = toElmDecoder AbiDecode.uint
49+
, decoder = toElmDecoder D.uint
5050
}
5151

5252

53-
{-| "allowed(address,address)" function
54-
-}
53+
-- allowed(address,address) function
54+
55+
5556
allowed : Address -> Address -> Address -> Call BigInt
56-
allowed contractAddress a b =
57+
allowed contractAddress a_ b_ =
5758
{ to = Just contractAddress
5859
, from = Nothing
5960
, gas = Nothing
6061
, gasPrice = Nothing
6162
, value = Nothing
62-
, data = Just <| AbiEncode.functionCall "allowed(address,address)" [ AbiEncode.address a, AbiEncode.address b ]
63+
, data = Just <| E.functionCall "5c658165" [ E.address a_, E.address b_ ]
6364
, nonce = Nothing
64-
, decoder = toElmDecoder AbiDecode.uint
65+
, decoder = toElmDecoder D.uint
6566
}
6667

6768

68-
{-| "approve(address,uint256)" function
69-
-}
69+
-- approve(address,uint256) function
70+
71+
7072
approve : Address -> Address -> BigInt -> Call Bool
71-
approve contractAddress spender value =
73+
approve contractAddress spender_ value_ =
7274
{ to = Just contractAddress
7375
, from = Nothing
7476
, gas = Nothing
7577
, gasPrice = Nothing
7678
, value = Nothing
77-
, data = Just <| AbiEncode.functionCall "approve(address,uint256)" [ AbiEncode.address spender, AbiEncode.uint value ]
79+
, data = Just <| E.functionCall "095ea7b3" [ E.address spender_, E.uint value_ ]
7880
, nonce = Nothing
79-
, decoder = toElmDecoder AbiDecode.bool
81+
, decoder = toElmDecoder D.bool
8082
}
8183

8284

83-
{-| "balanceOf(address)" function
84-
-}
85+
-- balanceOf(address) function
86+
87+
8588
balanceOf : Address -> Address -> Call BigInt
86-
balanceOf contractAddress owner =
89+
balanceOf contractAddress owner_ =
8790
{ to = Just contractAddress
8891
, from = Nothing
8992
, gas = Nothing
9093
, gasPrice = Nothing
9194
, value = Nothing
92-
, data = Just <| AbiEncode.functionCall "balanceOf(address)" [ AbiEncode.address owner ]
95+
, data = Just <| E.functionCall "70a08231" [ E.address owner_ ]
9396
, nonce = Nothing
94-
, decoder = toElmDecoder AbiDecode.uint
97+
, decoder = toElmDecoder D.uint
9598
}
9699

97100

98-
{-| "balances(address)" function
99-
-}
101+
-- balances(address) function
102+
103+
100104
balances : Address -> Address -> Call BigInt
101-
balances contractAddress a =
105+
balances contractAddress a_ =
102106
{ to = Just contractAddress
103107
, from = Nothing
104108
, gas = Nothing
105109
, gasPrice = Nothing
106110
, value = Nothing
107-
, data = Just <| AbiEncode.functionCall "balances(address)" [ AbiEncode.address a ]
111+
, data = Just <| E.functionCall "27e235e3" [ E.address a_ ]
108112
, nonce = Nothing
109-
, decoder = toElmDecoder AbiDecode.uint
113+
, decoder = toElmDecoder D.uint
110114
}
111115

112116

113-
{-| "decimals()" function
114-
-}
117+
-- decimals() function
118+
119+
115120
decimals : Address -> Call BigInt
116121
decimals contractAddress =
117122
{ to = Just contractAddress
118123
, from = Nothing
119124
, gas = Nothing
120125
, gasPrice = Nothing
121126
, value = Nothing
122-
, data = Just <| AbiEncode.functionCall "decimals()" []
127+
, data = Just <| E.functionCall "313ce567" []
123128
, nonce = Nothing
124-
, decoder = toElmDecoder AbiDecode.uint
129+
, decoder = toElmDecoder D.uint
125130
}
126131

127132

128-
{-| "name()" function
129-
-}
133+
-- name() function
134+
135+
130136
name : Address -> Call String
131137
name contractAddress =
132138
{ to = Just contractAddress
133139
, from = Nothing
134140
, gas = Nothing
135141
, gasPrice = Nothing
136142
, value = Nothing
137-
, data = Just <| AbiEncode.functionCall "name()" []
143+
, data = Just <| E.functionCall "06fdde03" []
138144
, nonce = Nothing
139-
, decoder = toElmDecoder AbiDecode.string
145+
, decoder = toElmDecoder D.string
140146
}
141147

142148

143-
{-| "symbol()" function
144-
-}
149+
-- symbol() function
150+
151+
145152
symbol : Address -> Call String
146153
symbol contractAddress =
147154
{ to = Just contractAddress
148155
, from = Nothing
149156
, gas = Nothing
150157
, gasPrice = Nothing
151158
, value = Nothing
152-
, data = Just <| AbiEncode.functionCall "symbol()" []
159+
, data = Just <| E.functionCall "95d89b41" []
153160
, nonce = Nothing
154-
, decoder = toElmDecoder AbiDecode.string
161+
, decoder = toElmDecoder D.string
155162
}
156163

157164

158-
{-| "totalSupply()" function
159-
-}
165+
-- totalSupply() function
166+
167+
160168
totalSupply : Address -> Call BigInt
161169
totalSupply contractAddress =
162170
{ to = Just contractAddress
163171
, from = Nothing
164172
, gas = Nothing
165173
, gasPrice = Nothing
166174
, value = Nothing
167-
, data = Just <| AbiEncode.functionCall "totalSupply()" []
175+
, data = Just <| E.functionCall "18160ddd" []
168176
, nonce = Nothing
169-
, decoder = toElmDecoder AbiDecode.uint
177+
, decoder = toElmDecoder D.uint
170178
}
171179

172180

173-
{-| "transfer(address,uint256)" function
174-
-}
181+
-- transfer(address,uint256) function
182+
183+
175184
transfer : Address -> Address -> BigInt -> Call Bool
176-
transfer contractAddress to value =
185+
transfer contractAddress to_ value_ =
177186
{ to = Just contractAddress
178187
, from = Nothing
179188
, gas = Nothing
180189
, gasPrice = Nothing
181190
, value = Nothing
182-
, data = Just <| AbiEncode.functionCall "transfer(address,uint256)" [ AbiEncode.address to, AbiEncode.uint value ]
191+
, data = Just <| E.functionCall "a9059cbb" [ E.address to_, E.uint value_ ]
183192
, nonce = Nothing
184-
, decoder = toElmDecoder AbiDecode.bool
193+
, decoder = toElmDecoder D.bool
185194
}
186195

187196

188-
{-| "transferFrom(address,address,uint256)" function
189-
-}
197+
-- transferFrom(address,address,uint256) function
198+
199+
190200
transferFrom : Address -> Address -> Address -> BigInt -> Call Bool
191-
transferFrom contractAddress from to value =
201+
transferFrom contractAddress from_ to_ value_ =
192202
{ to = Just contractAddress
193203
, from = Nothing
194204
, gas = Nothing
195205
, gasPrice = Nothing
196206
, value = Nothing
197-
, data = Just <| AbiEncode.functionCall "transferFrom(address,address,uint256)" [ AbiEncode.address from, AbiEncode.address to, AbiEncode.uint value ]
207+
, data = Just <| E.functionCall "23b872dd" [ E.address from_, E.address to_, E.uint value_ ]
198208
, nonce = Nothing
199-
, decoder = toElmDecoder AbiDecode.bool
209+
, decoder = toElmDecoder D.bool
200210
}
201211

202212

203-
{-| "Approval(address,address,uint256)" event
204-
-}
213+
-- Approval(address,address,uint256) event
214+
215+
205216
type alias Approval =
206217
{ owner : Address
207218
, spender : Address
@@ -210,28 +221,29 @@ type alias Approval =
210221

211222

212223
approvalEvent : Address -> Maybe Address -> Maybe Address -> LogFilter
213-
approvalEvent contractAddress owner spender =
224+
approvalEvent contractAddress owner_ spender_ =
214225
{ fromBlock = LatestBlock
215226
, toBlock = LatestBlock
216227
, address = contractAddress
217-
, topics =
218-
[ Just <| U.keccak256 "Approval(address,address,uint256)"
219-
, Maybe.map (abiEncode << AbiEncode.address) owner
220-
, Maybe.map (abiEncode << AbiEncode.address) spender
228+
, topics =
229+
[ Just <| U.unsafeToHex "8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"
230+
, Maybe.map (abiEncode << E.address) owner_
231+
, Maybe.map (abiEncode << E.address) spender_
221232
]
222233
}
223234

224235

225236
approvalDecoder : Decoder Approval
226-
approvalDecoder =
227-
decode Approval
228-
|> custom (topic 1 AbiDecode.address)
229-
|> custom (topic 2 AbiDecode.address)
230-
|> custom (data 0 AbiDecode.uint)
237+
approvalDecoder =
238+
Decode.succeed Approval
239+
|> custom (topic 1 D.address)
240+
|> custom (topic 2 D.address)
241+
|> custom (data 0 D.uint)
242+
243+
244+
-- Transfer(address,address,uint256) event
231245

232246

233-
{-| "Transfer(address,address,uint256)" event
234-
-}
235247
type alias Transfer =
236248
{ from : Address
237249
, to : Address
@@ -240,21 +252,23 @@ type alias Transfer =
240252

241253

242254
transferEvent : Address -> Maybe Address -> Maybe Address -> LogFilter
243-
transferEvent contractAddress from to =
255+
transferEvent contractAddress from_ to_ =
244256
{ fromBlock = LatestBlock
245257
, toBlock = LatestBlock
246258
, address = contractAddress
247-
, topics =
248-
[ Just <| U.keccak256 "Transfer(address,address,uint256)"
249-
, Maybe.map (abiEncode << AbiEncode.address) from
250-
, Maybe.map (abiEncode << AbiEncode.address) to
259+
, topics =
260+
[ Just <| U.unsafeToHex "ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
261+
, Maybe.map (abiEncode << E.address) from_
262+
, Maybe.map (abiEncode << E.address) to_
251263
]
252264
}
253265

254266

255267
transferDecoder : Decoder Transfer
256-
transferDecoder =
257-
decode Transfer
258-
|> custom (topic 1 AbiDecode.address)
259-
|> custom (topic 2 AbiDecode.address)
260-
|> custom (data 0 AbiDecode.uint)
268+
transferDecoder =
269+
Decode.succeed Transfer
270+
|> custom (topic 1 D.address)
271+
|> custom (topic 2 D.address)
272+
|> custom (data 0 D.uint)
273+
274+

0 commit comments

Comments
 (0)