-
Notifications
You must be signed in to change notification settings - Fork 21
/
Notes.elm
69 lines (49 loc) · 2 KB
/
Notes.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module Notes exposing (andPrepend, callHelper, newWidget, newWidget2)
import Abi.Encode as AbiEncode
import BigInt exposing (BigInt)
import Eth.Types exposing (Address, Call, Hex, IPFSHash)
import Json.Decode as Decode
import Result.Extra
{-| TO-DO
- Remove dependency on web3.js, and work with common provider format to communicate with RPC
- Rework Sentry.Event
- initHttp, initWebsocket
- HTTP will have to handle filter installation, clearing, polling.
- withDebug, takes Debug.log from user
- Rework Abi.Encode
- Support various uint, int, and byte sizes
- Fail upon overflows
- Use more generic error type
- Helps caputure cases like uint overflows above
- Update elm-ethereum-generator
- Better parser
- Dynamic types
-}
-- newWidget : Address -> BigInt -> BigInt -> Address -> Call ()
newWidget contractAddress size_ cost_ owner_ =
(AbiEncode.uint 256 size_ :: AbiEncode.uint 256 cost_ :: AbiEncode.address owner_ :: [])
|> Result.Extra.combine
|> Result.map (AbiEncode.functionCall "newWidget(uint256,uint256,address)")
|> Result.map (callHelper contractAddress (Decode.succeed ()))
newWidget2 : Address -> BigInt -> BigInt -> Address -> Result String (Call ())
newWidget2 contractAddress size_ cost_ owner_ =
Result.Extra.singleton []
|> andPrepend (AbiEncode.uint 256 size_)
|> andPrepend (AbiEncode.uint 256 cost_)
|> andPrepend (AbiEncode.address owner_)
|> Result.map (AbiEncode.functionCall "newWidget(uint256,uint256,address)")
|> Result.map (callHelper contractAddress (Decode.succeed ()))
andPrepend : Result e a -> Result e (List a) -> Result e (List a)
andPrepend =
Result.map2 (::)
callHelper : Address -> Decode.Decoder a -> Hex -> Call a
callHelper contractAddress decoder data =
{ to = Just contractAddress
, from = Nothing
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just data
, nonce = Nothing
, decoder = decoder
}