diff --git a/elm.json b/elm.json index a32e492..f420a9d 100644 --- a/elm.json +++ b/elm.json @@ -3,20 +3,21 @@ "name": "cmditch/elm-ethereum", "summary": "feed the tree some ether.", "license": "MIT", - "version": "1.0.3", + "version": "2.0.0", "exposed-modules": [ "Eth", "Eth.Decode", "Eth.Defaults", "Eth.Net", "Eth.RPC", - "Eth.Sentry.ChainCmd", - "Eth.Sentry.Event", "Eth.Sentry.Tx", "Eth.Sentry.Wallet", "Eth.Types", "Eth.Units", "Eth.Utils", + "Internal.Encode", + "Internal.Decode", + "Internal.Utils", "Abi.Decode", "Abi.Encode", "Shh" diff --git a/src/Abi/Decode.elm b/src/Abi/Decode.elm index 015a752..483a48a 100644 --- a/src/Abi/Decode.elm +++ b/src/Abi/Decode.elm @@ -116,15 +116,14 @@ toElmDecoderWithDebug functionName = {-| -} decodeStringWithDebug : Maybe String -> AbiDecoder a -> String -> Result String a decodeStringWithDebug debug (AbiDecoder abiDecoder) abiString = - let - _ = - case debug of - Just function -> - Debug.log ("Debug Contract Call Response " ++ function) abiString - - Nothing -> - abiString - in + -- let + -- _ = + -- case debug of + -- Just function -> + -- Debug.log ("Debug Contract Call Response " ++ function) abiString + -- Nothing -> + -- abiString + -- in remove0x abiString |> (\a -> Tape a a) |> abiDecoder @@ -394,6 +393,7 @@ topic index abiDecoder = TODO - Will this work if dynamic types are in the log data? dropBytes might mess with the length of grabbing dyn vals off the Original Tape + -} data : Int -> AbiDecoder a -> Decoder a data index abiDecoder = @@ -405,8 +405,7 @@ data index abiDecoder = -- Internal -{-| -Eat and accumulate. Travel down the tape one word at a time, and return the value from what was just eaten. +{-| Eat and accumulate. Travel down the tape one word at a time, and return the value from what was just eaten. -} newTape : String -> String -> a -> ( Tape, a ) newTape original altered val = diff --git a/src/Abi/Encode.elm b/src/Abi/Encode.elm index b61d5e4..172106a 100644 --- a/src/Abi/Encode.elm +++ b/src/Abi/Encode.elm @@ -1,11 +1,9 @@ module Abi.Encode exposing - ( Encoding, functionCall - , uint8, uint16, uint24, uint32, uint40, uint48, uint56, uint64, uint72, uint80, uint88, uint96, uint104, uint112, uint120, uint128, uint136, uint144, uint152, uint160, uint168, uint176, uint184, uint192, uint200, uint208, uint216, uint224, uint232, uint240, uint248, uint256 - , int8, int16, int24, int32, int40, int48, int56, int64, int72, int80, int88, int96, int104, int112, int120, int128, int136, int144, int152, int160, int168, int176, int184, int192, int200, int208, int216, int224, int232, int240, int248, int256 - , bytes1, bytes2, bytes3, bytes4, bytes5, bytes6, bytes7, bytes8, bytes9, bytes10, bytes11, bytes12, bytes13, bytes14, bytes15, bytes16, bytes17, bytes18, bytes19, bytes20, bytes21, bytes22, bytes23, bytes24, bytes25, bytes26, bytes27, bytes28, bytes29, bytes30, bytes31, bytes32 - , bytes, string - , bool, ipfsHash, custom - , abiEncode + ( Encoding(..), functionCall + , uint, int, staticBytes + , string, list, bytes + , address, bool, ipfsHash, custom + , abiEncode, abiEncodeList ) {-| Encode before sending RPC Calls @@ -13,24 +11,14 @@ module Abi.Encode exposing @docs Encoding, functionCall -# Uint Encoding +# Static Type Encoding -@docs uint8, uint16, uint24, uint32, uint40, uint48, uint56, uint64, uint72, uint80, uint88, uint96, uint104, uint112, uint120, uint128, uint136, uint144, uint152, uint160, uint168, uint176, uint184, uint192, uint200, uint208, uint216, uint224, uint232, uint240, uint248, uint256 - - -# Int Encoding - -@docs int8, int16, int24, int32, int40, int48, int56, int64, int72, int80, int88, int96, int104, int112, int120, int128, int136, int144, int152, int160, int168, int176, int184, int192, int200, int208, int216, int224, int232, int240, int248, int256 - - -# Static Bytes - -@docs bytes1, bytes2, bytes3, bytes4, bytes5, bytes6, bytes7, bytes8, bytes9, bytes10, bytes11, bytes12, bytes13, bytes14, bytes15, bytes16, bytes17, bytes18, bytes19, bytes20, bytes21, bytes22, bytes23, bytes24, bytes25, bytes26, bytes27, bytes28, bytes29, bytes30, bytes31, bytes32 +@docs uint, int, staticBytes # Dynamic Types -@docs bytes, string, list +@docs string, list, bytes # Misc @@ -107,579 +95,408 @@ functionCallWithDebug logger sig encodings = {-| -} -uint8 : BigInt -> Result String Encoding -uint8 = - uint 8 - - -{-| -} -uint16 : BigInt -> Result String Encoding -uint16 = - uint 16 - - -{-| -} -uint24 : BigInt -> Result String Encoding -uint24 = - uint 24 - - -{-| -} -uint32 : BigInt -> Result String Encoding -uint32 = - uint 32 - - -{-| -} -uint40 : BigInt -> Result String Encoding -uint40 = - uint 40 - - -{-| -} -uint48 : BigInt -> Result String Encoding -uint48 = - uint 48 - - -{-| -} -uint56 : BigInt -> Result String Encoding -uint56 = - uint 56 - - -{-| -} -uint64 : BigInt -> Result String Encoding -uint64 = - uint 64 - - -{-| -} -uint72 : BigInt -> Result String Encoding -uint72 = - uint 72 - - -{-| -} -uint80 : BigInt -> Result String Encoding -uint80 = - uint 80 - - -{-| -} -uint88 : BigInt -> Result String Encoding -uint88 = - uint 88 - - -{-| -} -uint96 : BigInt -> Result String Encoding -uint96 = - uint 96 - - -{-| -} -uint104 : BigInt -> Result String Encoding -uint104 = - uint 104 - - -{-| -} -uint112 : BigInt -> Result String Encoding -uint112 = - uint 112 - - -{-| -} -uint120 : BigInt -> Result String Encoding -uint120 = - uint 120 - - -{-| -} -uint128 : BigInt -> Result String Encoding -uint128 = - uint 128 - - -{-| -} -uint136 : BigInt -> Result String Encoding -uint136 = - uint 136 - - -{-| -} -uint144 : BigInt -> Result String Encoding -uint144 = - uint 144 - - -{-| -} -uint152 : BigInt -> Result String Encoding -uint152 = - uint 152 - - -{-| -} -uint160 : BigInt -> Result String Encoding -uint160 = - uint 160 - - -{-| -} -uint168 : BigInt -> Result String Encoding -uint168 = - uint 168 - - -{-| -} -uint176 : BigInt -> Result String Encoding -uint176 = - uint 176 - - -{-| -} -uint184 : BigInt -> Result String Encoding -uint184 = - uint 184 - - -{-| -} -uint192 : BigInt -> Result String Encoding -uint192 = - uint 192 - - -{-| -} -uint200 : BigInt -> Result String Encoding -uint200 = - uint 200 - - -{-| -} -uint208 : BigInt -> Result String Encoding -uint208 = - uint 208 - - -{-| -} -uint216 : BigInt -> Result String Encoding -uint216 = - uint 216 - - -{-| -} -uint224 : BigInt -> Result String Encoding -uint224 = - uint 224 - - -{-| -} -uint232 : BigInt -> Result String Encoding -uint232 = - uint 232 - - -{-| -} -uint240 : BigInt -> Result String Encoding -uint240 = - uint 240 - - -{-| -} -uint248 : BigInt -> Result String Encoding -uint248 = - uint 248 - - -{-| -} -uint256 : BigInt -> Result String Encoding -uint256 = - uint 256 - - -{-| -} -int8 : BigInt -> Result String Encoding -int8 = - int 8 - - -{-| -} -int16 : BigInt -> Result String Encoding -int16 = - int 16 - - -{-| -} -int24 : BigInt -> Result String Encoding -int24 = - int 24 - - -{-| -} -int32 : BigInt -> Result String Encoding -int32 = - int 32 - - -{-| -} -int40 : BigInt -> Result String Encoding -int40 = - int 40 - - -{-| -} -int48 : BigInt -> Result String Encoding -int48 = - int 48 - - -{-| -} -int56 : BigInt -> Result String Encoding -int56 = - int 56 - - -{-| -} -int64 : BigInt -> Result String Encoding -int64 = - int 64 - - -{-| -} -int72 : BigInt -> Result String Encoding -int72 = - int 72 - - -{-| -} -int80 : BigInt -> Result String Encoding -int80 = - int 80 - - -{-| -} -int88 : BigInt -> Result String Encoding -int88 = - int 88 - - -{-| -} -int96 : BigInt -> Result String Encoding -int96 = - int 96 - - -{-| -} -int104 : BigInt -> Result String Encoding -int104 = - int 104 - - -{-| -} -int112 : BigInt -> Result String Encoding -int112 = - int 112 - - -{-| -} -int120 : BigInt -> Result String Encoding -int120 = - int 120 - - -{-| -} -int128 : BigInt -> Result String Encoding -int128 = - int 128 - - -{-| -} -int136 : BigInt -> Result String Encoding -int136 = - int 136 - - -{-| -} -int144 : BigInt -> Result String Encoding -int144 = - int 144 - - -{-| -} -int152 : BigInt -> Result String Encoding -int152 = - int 152 - - -{-| -} -int160 : BigInt -> Result String Encoding -int160 = - int 160 - - -{-| -} -int168 : BigInt -> Result String Encoding -int168 = - int 168 - - -{-| -} -int176 : BigInt -> Result String Encoding -int176 = - int 176 - - -{-| -} -int184 : BigInt -> Result String Encoding -int184 = - int 184 - - -{-| -} -int192 : BigInt -> Result String Encoding -int192 = - int 192 - - -{-| -} -int200 : BigInt -> Result String Encoding -int200 = - int 200 - - -{-| -} -int208 : BigInt -> Result String Encoding -int208 = - int 208 - - -{-| -} -int216 : BigInt -> Result String Encoding -int216 = - int 216 - - -{-| -} -int224 : BigInt -> Result String Encoding -int224 = - int 224 - - -{-| -} -int232 : BigInt -> Result String Encoding -int232 = - int 232 - - -{-| -} -int240 : BigInt -> Result String Encoding -int240 = - int 240 - - -{-| -} -int248 : BigInt -> Result String Encoding -int248 = - int 248 - - -{-| -} -int256 : BigInt -> Result String Encoding -int256 = - int 256 - - -{-| -} -bytes1 : Hex -> Result String Encoding -bytes1 = - staticBytes 1 - - -{-| -} -bytes2 : Hex -> Result String Encoding -bytes2 = - staticBytes 2 - - -{-| -} -bytes3 : Hex -> Result String Encoding -bytes3 = - staticBytes 3 - - -{-| -} -bytes4 : Hex -> Result String Encoding -bytes4 = - staticBytes 4 - - -{-| -} -bytes5 : Hex -> Result String Encoding -bytes5 = - staticBytes 5 - - -{-| -} -bytes6 : Hex -> Result String Encoding -bytes6 = - staticBytes 6 - - -{-| -} -bytes7 : Hex -> Result String Encoding -bytes7 = - staticBytes 7 - - -{-| -} -bytes8 : Hex -> Result String Encoding -bytes8 = - staticBytes 8 - - -{-| -} -bytes9 : Hex -> Result String Encoding -bytes9 = - staticBytes 9 - - -{-| -} -bytes10 : Hex -> Result String Encoding -bytes10 = - staticBytes 10 - - -{-| -} -bytes11 : Hex -> Result String Encoding -bytes11 = - staticBytes 11 - - -{-| -} -bytes12 : Hex -> Result String Encoding -bytes12 = - staticBytes 12 - - -{-| -} -bytes13 : Hex -> Result String Encoding -bytes13 = - staticBytes 13 - - -{-| -} -bytes14 : Hex -> Result String Encoding -bytes14 = - staticBytes 14 - - -{-| -} -bytes15 : Hex -> Result String Encoding -bytes15 = - staticBytes 15 - - -{-| -} -bytes16 : Hex -> Result String Encoding -bytes16 = - staticBytes 16 - - -{-| -} -bytes17 : Hex -> Result String Encoding -bytes17 = - staticBytes 17 - - -{-| -} -bytes18 : Hex -> Result String Encoding -bytes18 = - staticBytes 18 - - -{-| -} -bytes19 : Hex -> Result String Encoding -bytes19 = - staticBytes 19 - - -{-| -} -bytes20 : Hex -> Result String Encoding -bytes20 = - staticBytes 20 - - -{-| -} -bytes21 : Hex -> Result String Encoding -bytes21 = - staticBytes 21 - - -{-| -} -bytes22 : Hex -> Result String Encoding -bytes22 = - staticBytes 22 - - -{-| -} -bytes23 : Hex -> Result String Encoding -bytes23 = - staticBytes 23 - - -{-| -} -bytes24 : Hex -> Result String Encoding -bytes24 = - staticBytes 24 - - -{-| -} -bytes25 : Hex -> Result String Encoding -bytes25 = - staticBytes 25 - - -{-| -} -bytes26 : Hex -> Result String Encoding -bytes26 = - staticBytes 26 - - -{-| -} -bytes27 : Hex -> Result String Encoding -bytes27 = - staticBytes 27 - - -{-| -} -bytes28 : Hex -> Result String Encoding -bytes28 = - staticBytes 28 - - -{-| -} -bytes29 : Hex -> Result String Encoding -bytes29 = - staticBytes 29 - - -{-| -} -bytes30 : Hex -> Result String Encoding -bytes30 = - staticBytes 30 - - -{-| -} -bytes31 : Hex -> Result String Encoding -bytes31 = - staticBytes 31 - - -{-| -} -bytes32 : Hex -> Result String Encoding -bytes32 = - staticBytes 32 +uint : BigInt -> Encoding +uint = + UintE + + +{-| -} +int : BigInt -> Encoding +int = + IntE + + +{-| -} +address : Address -> Encoding +address = + AddressE + + + +-- {-| -} +-- uint8 : BigInt -> Result String Encoding +-- uint8 = +-- uint 8 +-- {-| -} +-- uint16 : BigInt -> Result String Encoding +-- uint16 = +-- uint 16 +-- {-| -} +-- uint24 : BigInt -> Result String Encoding +-- uint24 = +-- uint 24 +-- {-| -} +-- uint32 : BigInt -> Result String Encoding +-- uint32 = +-- uint 32 +-- {-| -} +-- uint40 : BigInt -> Result String Encoding +-- uint40 = +-- uint 40 +-- {-| -} +-- uint48 : BigInt -> Result String Encoding +-- uint48 = +-- uint 48 +-- {-| -} +-- uint56 : BigInt -> Result String Encoding +-- uint56 = +-- uint 56 +-- {-| -} +-- uint64 : BigInt -> Result String Encoding +-- uint64 = +-- uint 64 +-- {-| -} +-- uint72 : BigInt -> Result String Encoding +-- uint72 = +-- uint 72 +-- {-| -} +-- uint80 : BigInt -> Result String Encoding +-- uint80 = +-- uint 80 +-- {-| -} +-- uint88 : BigInt -> Result String Encoding +-- uint88 = +-- uint 88 +-- {-| -} +-- uint96 : BigInt -> Result String Encoding +-- uint96 = +-- uint 96 +-- {-| -} +-- uint104 : BigInt -> Result String Encoding +-- uint104 = +-- uint 104 +-- {-| -} +-- uint112 : BigInt -> Result String Encoding +-- uint112 = +-- uint 112 +-- {-| -} +-- uint120 : BigInt -> Result String Encoding +-- uint120 = +-- uint 120 +-- {-| -} +-- uint128 : BigInt -> Result String Encoding +-- uint128 = +-- uint 128 +-- {-| -} +-- uint136 : BigInt -> Result String Encoding +-- uint136 = +-- uint 136 +-- {-| -} +-- uint144 : BigInt -> Result String Encoding +-- uint144 = +-- uint 144 +-- {-| -} +-- uint152 : BigInt -> Result String Encoding +-- uint152 = +-- uint 152 +-- {-| -} +-- uint160 : BigInt -> Result String Encoding +-- uint160 = +-- uint 160 +-- {-| -} +-- uint168 : BigInt -> Result String Encoding +-- uint168 = +-- uint 168 +-- {-| -} +-- uint176 : BigInt -> Result String Encoding +-- uint176 = +-- uint 176 +-- {-| -} +-- uint184 : BigInt -> Result String Encoding +-- uint184 = +-- uint 184 +-- {-| -} +-- uint192 : BigInt -> Result String Encoding +-- uint192 = +-- uint 192 +-- {-| -} +-- uint200 : BigInt -> Result String Encoding +-- uint200 = +-- uint 200 +-- {-| -} +-- uint208 : BigInt -> Result String Encoding +-- uint208 = +-- uint 208 +-- {-| -} +-- uint216 : BigInt -> Result String Encoding +-- uint216 = +-- uint 216 +-- {-| -} +-- uint224 : BigInt -> Result String Encoding +-- uint224 = +-- uint 224 +-- {-| -} +-- uint232 : BigInt -> Result String Encoding +-- uint232 = +-- uint 232 +-- {-| -} +-- uint240 : BigInt -> Result String Encoding +-- uint240 = +-- uint 240 +-- {-| -} +-- uint248 : BigInt -> Result String Encoding +-- uint248 = +-- uint 248 +-- {-| -} +-- uint256 : BigInt -> Result String Encoding +-- uint256 = +-- uint 256 +-- {-| -} +-- int8 : BigInt -> Result String Encoding +-- int8 = +-- int 8 +-- {-| -} +-- int16 : BigInt -> Result String Encoding +-- int16 = +-- int 16 +-- {-| -} +-- int24 : BigInt -> Result String Encoding +-- int24 = +-- int 24 +-- {-| -} +-- int32 : BigInt -> Result String Encoding +-- int32 = +-- int 32 +-- {-| -} +-- int40 : BigInt -> Result String Encoding +-- int40 = +-- int 40 +-- {-| -} +-- int48 : BigInt -> Result String Encoding +-- int48 = +-- int 48 +-- {-| -} +-- int56 : BigInt -> Result String Encoding +-- int56 = +-- int 56 +-- {-| -} +-- int64 : BigInt -> Result String Encoding +-- int64 = +-- int 64 +-- {-| -} +-- int72 : BigInt -> Result String Encoding +-- int72 = +-- int 72 +-- {-| -} +-- int80 : BigInt -> Result String Encoding +-- int80 = +-- int 80 +-- {-| -} +-- int88 : BigInt -> Result String Encoding +-- int88 = +-- int 88 +-- {-| -} +-- int96 : BigInt -> Result String Encoding +-- int96 = +-- int 96 +-- {-| -} +-- int104 : BigInt -> Result String Encoding +-- int104 = +-- int 104 +-- {-| -} +-- int112 : BigInt -> Result String Encoding +-- int112 = +-- int 112 +-- {-| -} +-- int120 : BigInt -> Result String Encoding +-- int120 = +-- int 120 +-- {-| -} +-- int128 : BigInt -> Result String Encoding +-- int128 = +-- int 128 +-- {-| -} +-- int136 : BigInt -> Result String Encoding +-- int136 = +-- int 136 +-- {-| -} +-- int144 : BigInt -> Result String Encoding +-- int144 = +-- int 144 +-- {-| -} +-- int152 : BigInt -> Result String Encoding +-- int152 = +-- int 152 +-- {-| -} +-- int160 : BigInt -> Result String Encoding +-- int160 = +-- int 160 +-- {-| -} +-- int168 : BigInt -> Result String Encoding +-- int168 = +-- int 168 +-- {-| -} +-- int176 : BigInt -> Result String Encoding +-- int176 = +-- int 176 +-- {-| -} +-- int184 : BigInt -> Result String Encoding +-- int184 = +-- int 184 +-- {-| -} +-- int192 : BigInt -> Result String Encoding +-- int192 = +-- int 192 +-- {-| -} +-- int200 : BigInt -> Result String Encoding +-- int200 = +-- int 200 +-- {-| -} +-- int208 : BigInt -> Result String Encoding +-- int208 = +-- int 208 +-- {-| -} +-- int216 : BigInt -> Result String Encoding +-- int216 = +-- int 216 +-- {-| -} +-- int224 : BigInt -> Result String Encoding +-- int224 = +-- int 224 +-- {-| -} +-- int232 : BigInt -> Result String Encoding +-- int232 = +-- int 232 +-- {-| -} +-- int240 : BigInt -> Result String Encoding +-- int240 = +-- int 240 +-- {-| -} +-- int248 : BigInt -> Result String Encoding +-- int248 = +-- int 248 +-- {-| -} +-- int256 : BigInt -> Result String Encoding +-- int256 = +-- int 256 +-- {-| -} +-- bytes1 : Hex -> Result String Encoding +-- bytes1 = +-- staticBytes 1 +-- {-| -} +-- bytes2 : Hex -> Result String Encoding +-- bytes2 = +-- staticBytes 2 +-- {-| -} +-- bytes3 : Hex -> Result String Encoding +-- bytes3 = +-- staticBytes 3 +-- {-| -} +-- bytes4 : Hex -> Result String Encoding +-- bytes4 = +-- staticBytes 4 +-- {-| -} +-- bytes5 : Hex -> Result String Encoding +-- bytes5 = +-- staticBytes 5 +-- {-| -} +-- bytes6 : Hex -> Result String Encoding +-- bytes6 = +-- staticBytes 6 +-- {-| -} +-- bytes7 : Hex -> Result String Encoding +-- bytes7 = +-- staticBytes 7 +-- {-| -} +-- bytes8 : Hex -> Result String Encoding +-- bytes8 = +-- staticBytes 8 +-- {-| -} +-- bytes9 : Hex -> Result String Encoding +-- bytes9 = +-- staticBytes 9 +-- {-| -} +-- bytes10 : Hex -> Result String Encoding +-- bytes10 = +-- staticBytes 10 +-- {-| -} +-- bytes11 : Hex -> Result String Encoding +-- bytes11 = +-- staticBytes 11 +-- {-| -} +-- bytes12 : Hex -> Result String Encoding +-- bytes12 = +-- staticBytes 12 +-- {-| -} +-- bytes13 : Hex -> Result String Encoding +-- bytes13 = +-- staticBytes 13 +-- {-| -} +-- bytes14 : Hex -> Result String Encoding +-- bytes14 = +-- staticBytes 14 +-- {-| -} +-- bytes15 : Hex -> Result String Encoding +-- bytes15 = +-- staticBytes 15 +-- {-| -} +-- bytes16 : Hex -> Result String Encoding +-- bytes16 = +-- staticBytes 16 +-- {-| -} +-- bytes17 : Hex -> Result String Encoding +-- bytes17 = +-- staticBytes 17 +-- {-| -} +-- bytes18 : Hex -> Result String Encoding +-- bytes18 = +-- staticBytes 18 +-- {-| -} +-- bytes19 : Hex -> Result String Encoding +-- bytes19 = +-- staticBytes 19 +-- {-| -} +-- bytes20 : Hex -> Result String Encoding +-- bytes20 = +-- staticBytes 20 +-- {-| -} +-- bytes21 : Hex -> Result String Encoding +-- bytes21 = +-- staticBytes 21 +-- {-| -} +-- bytes22 : Hex -> Result String Encoding +-- bytes22 = +-- staticBytes 22 +-- {-| -} +-- bytes23 : Hex -> Result String Encoding +-- bytes23 = +-- staticBytes 23 +-- {-| -} +-- bytes24 : Hex -> Result String Encoding +-- bytes24 = +-- staticBytes 24 +-- {-| -} +-- bytes25 : Hex -> Result String Encoding +-- bytes25 = +-- staticBytes 25 +-- {-| -} +-- bytes26 : Hex -> Result String Encoding +-- bytes26 = +-- staticBytes 26 +-- {-| -} +-- bytes27 : Hex -> Result String Encoding +-- bytes27 = +-- staticBytes 27 +-- {-| -} +-- bytes28 : Hex -> Result String Encoding +-- bytes28 = +-- staticBytes 28 +-- {-| -} +-- bytes29 : Hex -> Result String Encoding +-- bytes29 = +-- staticBytes 29 +-- {-| -} +-- bytes30 : Hex -> Result String Encoding +-- bytes30 = +-- staticBytes 30 +-- {-| -} +-- bytes31 : Hex -> Result String Encoding +-- bytes31 = +-- staticBytes 31 +-- {-| -} +-- bytes32 : Hex -> Result String Encoding +-- bytes32 = +-- staticBytes 32 {-| -} @@ -765,45 +582,37 @@ abiEncodeList = -- Internal - - -{-| Low level uint helper --} -uint : Int -> BigInt -> Result String Encoding -uint size num = - if modBy 8 size /= 0 || size <= 0 || size > 256 then - Err <| "Invalid size: " ++ String.fromInt size - - else if BigInt.lt num (BigInt.pow (BigInt.fromInt 2) (BigInt.fromInt size)) then - -- TODO Figure out if it's 2^n or (2^n - 1), e.g. uint8 should not be over 255 or 256 ? - Ok <| UintE num - - else - Err <| - "Uint overflow: " - ++ BigInt.toString num - ++ " is larger than uint" - ++ String.fromInt size - - -{-| Low level int helper --} -int : Int -> BigInt -> Result String Encoding -int size num = - if modBy 8 size /= 0 || size <= 0 || size > 256 then - Err <| "Invalid size: " ++ String.fromInt size - - else if ... then - -- TODO Figure out if int8 should not be over 127 or 128 ? - Ok <| IntE num - - else - -- Account for overflow and underflow - Err <| - "Int overflow/underflow: " - ++ BigInt.toString num - ++ " is larger than uint" - ++ String.fromInt size +-- {-| Low level uint helper +-- -} +-- uint : Int -> BigInt -> Result String Encoding +-- uint size num = +-- if modBy 8 size /= 0 || size <= 0 || size > 256 then +-- Err <| "Invalid size: " ++ String.fromInt size +-- else if BigInt.lt num (BigInt.pow (BigInt.fromInt 2) (BigInt.fromInt size)) then +-- -- TODO Figure out if it's 2^n or (2^n - 1), e.g. uint8 should not be over 255 or 256 ? +-- Ok <| UintE num +-- else +-- Err <| +-- "Uint overflow: " +-- ++ BigInt.toString num +-- ++ " is larger than uint" +-- ++ String.fromInt size +-- {-| Low level int helper +-- -} +-- int : Int -> BigInt -> Result String Encoding +-- int size num = +-- if modBy 8 size /= 0 || size <= 0 || size > 256 then +-- Err <| "Invalid size: " ++ String.fromInt size +-- else if ... then +-- -- TODO Figure out if int8 should not be over 127 or 128 ? +-- Ok <| IntE num +-- else +-- -- Account for overflow and underflow +-- Err <| +-- "Int overflow/underflow: " +-- ++ BigInt.toString num +-- ++ " is larger than uint" +-- ++ String.fromInt size {-| (Maybe (Size of Dynamic Value), Value) @@ -816,7 +625,7 @@ type alias LowLevelEncoding = toStaticLLEncoding : String -> LowLevelEncoding toStaticLLEncoding strVal = ( Nothing - , IU.leftPadMod64 strVal + , IU.leftPadTo64 strVal ) @@ -918,6 +727,7 @@ lowLevelEncodeList vals = -- Helpers -- Move to utils + {-| Right pads a string with "0"'s till (strLength % 64 == 0) 64 chars or 32 bytes is the size of an EVM word -} diff --git a/src/Eth.elm b/src/Eth.elm index cde6f91..2b65a5c 100644 --- a/src/Eth.elm +++ b/src/Eth.elm @@ -1,5 +1,5 @@ module Eth exposing - ( call, estimateGas, getStorageAt, getCode, callAtBlock, getStorageAtBlock, getCodeAtBlock + ( call, getStorageAt, getCode, callAtBlock, getStorageAtBlock, getCodeAtBlock , getTx, getTxReceipt, toSend, encodeSend, sendTx, sendRawTx, getTxByBlockHashAndIndex, getTxByBlockNumberAndIndex , getBalance, getTxCount, getBalanceAtBlock, getTxCountAtBlock , getBlockNumber, getBlock, getBlockByHash, getBlockWithTxObjs, getBlockByHashWithTxObjs, getBlockTxCount, getBlockTxCountByHash, getUncleCount, getUncleCountByHash, getUncleAtIndex, getUncleByBlockHashAtIndex @@ -27,7 +27,7 @@ convert it to a `Send`, and use `Eth.Sentry.Tx` to hand it off to your browser's |> Eth.toSend |> TxSentry.send TxSendResponse model.txSentry -@docs call, estimateGas, getStorageAt, getCode, callAtBlock, getStorageAtBlock, getCodeAtBlock +@docs call, getStorageAt, getCode, callAtBlock, getStorageAtBlock, getCodeAtBlock # Transactions @@ -87,25 +87,23 @@ call ethNode txParams = callAtBlock ethNode txParams LatestBlock -{-| Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. -**Note** that the estimate may be significantly more than the amount of gas actually used by the transaction, -for a variety of reasons including EVM mechanics and node performance. - --} -estimateGas : HttpProvider -> Call a -> Task Http.Error Int -estimateGas ethNode txParams = - case Encode.txCall txParams of - Ok txParams_ -> - RPC.toTask - { url = ethNode - , method = "eth_estimateGas" - , params = [ txParams_ ] - , decoder = Decode.hexInt - } - - Err err -> - Task.fail err +-- {-| Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. +-- **Note** that the estimate may be significantly more than the amount of gas actually used by the transaction, +-- for a variety of reasons including EVM mechanics and node performance. +-- -} +-- estimateGas : HttpProvider -> Call a -> Task Http.Error Int +-- estimateGas ethNode txParams = +-- case Encode.txCall txParams of +-- Ok txParams_ -> +-- RPC.toTask +-- { url = ethNode +-- , method = "eth_estimateGas" +-- , params = [ txParams_ ] +-- , decoder = Decode.hexInt +-- } +-- Err err -> +-- Task.fail err {-| Returns the value from a storage position at a given address. @@ -125,19 +123,30 @@ getCode ethNode address = {-| Call a function on an Ethereum contract from a particular point in history. -} -callAtBlock : HttpProvider -> Call a -> BlockId -> Task Eth.Error a +callAtBlock : HttpProvider -> Call a -> BlockId -> Task Http.Error a callAtBlock ethNode txParams blockId = - case Encode.txCall txParams of - Ok txParams_ -> - RPC.toTask - { url = ethNode - , method = "eth_call" - , params = [ txParams_, Encode.blockId blockId ] - , decoder = txParams.decoder - } + RPC.toTask + { url = ethNode + , method = "eth_call" + , params = [ Encode.txCall txParams, Encode.blockId blockId ] + , decoder = txParams.decoder + } + + - Err err -> - Task.fail err +-- TODO: IMPLEMENT THIS SOON +-- callAtBlock : HttpProvider -> Call a -> BlockId -> Task Eth.Error a +-- callAtBlock ethNode txParams blockId = +-- case Encode.txCall txParams of +-- Ok txParams_ -> +-- RPC.toTask +-- { url = ethNode +-- , method = "eth_call" +-- , params = [ txParams_, Encode.blockId blockId ] +-- , decoder = txParams.decoder +-- } +-- Err err -> +-- Task.fail err {-| Returns the value from a storage position at a given address, at a certain block height. @@ -172,43 +181,55 @@ getCodeAtBlock ethNode address blockId = Used in `Eth.Sentry.Tx`, a means to interact with MetaMask. -} toSend : Call a -> Send -toSend { to, from, gas, gasPrice, value, data, nonce } = - { to = to - , from = from - , gas = gas - , gasPrice = gasPrice - , value = value - , data = data - , nonce = nonce +toSend callData = + { to = callData.to + , from = callData.from + , gas = callData.gas + , gasPrice = callData.gasPrice + , value = callData.value + , data = callData.data + , nonce = callData.nonce } {-| Useful if your handling txParams in javascript land yourself. Will return Error if params are invalid. e.g., buffer overflow -} -encodeSend : Send -> Result String Value -encodeSend { to, from, gas, gasPrice, value, data, nonce } = - let - paramsToValue data_ = - Encode.listOfMaybesToVal - [ ( "to", Maybe.map Encode.address to ) - , ( "from", Maybe.map Encode.address from ) - , ( "gas", Maybe.map Encode.hexInt gas ) - , ( "gasPrice", Maybe.map Encode.bigInt gasPrice ) - , ( "value", Maybe.map Encode.bigInt value ) - , ( "data", Maybe.map Encode.hex data_ ) - , ( "nonce", Maybe.map Encode.hexInt nonce ) - ] - in - case data of - Nothing -> - paramsToValue Nothing - - Just (Ok data_) -> - paramsToValue (Just data_) - - Just (Err err) -> - Err err +encodeSend : Send -> Value +encodeSend callData = + Encode.listOfMaybesToVal + [ ( "to", Maybe.map Encode.address callData.to ) + , ( "from", Maybe.map Encode.address callData.from ) + , ( "gas", Maybe.map Encode.hexInt callData.gas ) + , ( "gasPrice", Maybe.map Encode.bigInt callData.gasPrice ) + , ( "value", Maybe.map Encode.bigInt callData.value ) + , ( "data", Maybe.map Encode.hex callData.data ) + , ( "nonce", Maybe.map Encode.hexInt callData.nonce ) + ] + + + +-- encodeSend : Send -> Result String Value +-- encodeSend callData = +-- let +-- paramsToValue data_ = +-- Encode.listOfMaybesToVal +-- [ ( "to", Maybe.map Encode.address callData.to ) +-- , ( "from", Maybe.map Encode.address callData.from ) +-- , ( "gas", Maybe.map Encode.hexInt callData.gas ) +-- , ( "gasPrice", Maybe.map Encode.bigInt callData.gasPrice ) +-- , ( "value", Maybe.map Encode.bigInt callData.value ) +-- , ( "data", Maybe.map Encode.hex callData.data_ ) +-- , ( "nonce", Maybe.map Encode.hexInt callData.nonce ) +-- ] +-- in +-- case data of +-- Nothing -> +-- paramsToValue Nothing +-- Just (Ok data_) -> +-- paramsToValue (Just data_) +-- Just (Err err) -> +-- Err err {-| Get transaction information from it's hash. diff --git a/src/Eth/Sentry/Event.elm b/src/Eth/Sentry/Event.elm index 536dede..6a00fe5 100644 --- a/src/Eth/Sentry/Event.elm +++ b/src/Eth/Sentry/Event.elm @@ -1,39 +1,40 @@ -module Eth.Sentry.Event exposing - ( EventSentry, Msg, FilterKey - , init, update, changeNode, listen, withDebug - , watch, watchOnce, unWatch, toFilterKey - , newBlocks, unWatchNewBlocks, nextBlock - , pendingTxs, unWatchPendingTxs - ) +module Eth.Sentry.Event exposing (temp) -{-| Listen to contract events, and other chain activity +-- ( EventSentry, Msg, FilterKey +-- , init, update, changeNode, listen, withDebug +-- , watch, watchOnce, unWatch, toFilterKey +-- , newBlocks, unWatchNewBlocks, nextBlock +-- , pendingTxs, unWatchPendingTxs +-- ) +{- Listen to contract events, and other chain activity -# Types + # Types -@docs EventSentry, Msg, FilterKey + @docs EventSentry, Msg, FilterKey -# Core + # Core -@docs init, update, changeNode, listen, withDebug + @docs init, update, changeNode, listen, withDebug -# Contract Events/Logs + # Contract Events/Logs -@docs watch, watchOnce, unWatch, toFilterKey + @docs watch, watchOnce, unWatch, toFilterKey -# Blocks + # Blocks -@docs newBlocks, unWatchNewBlocks, nextBlock + @docs newBlocks, unWatchNewBlocks, nextBlock -# Pending Transactions + # Pending Transactions -@docs pendingTxs, unWatchPendingTxs + @docs pendingTxs, unWatchPendingTxs -} +-- import Legacy.WebSocket as WS import BigInt import Dict exposing (Dict) @@ -45,10 +46,13 @@ import Internal.Decode as Decode import Internal.Encode as Encode import Json.Decode as Decode exposing (Decoder, Value) import Json.Encode as Encode -import Legacy.WebSocket as WS import Task +temp = + 1 + + {--Internal Docs @@ -85,503 +89,376 @@ import Task -} --- API - - -{-| -} -type EventSentry msg - = EventSentry - { nodePath : String - , tagger : Msg -> msg - , filters : Dict FilteryKeyInternal (FilterState msg) - , rpcIdToFKey : Dict RpcId FilterKey - , subIdToFKey : Dict SubscriptionId FilterKey - , debug : Bool - , ref : RpcId - } - - -{-| -} -init : (Msg -> msg) -> String -> EventSentry msg -init tagger nodePath = - EventSentry - { nodePath = nodePath - , tagger = tagger - , filters = Dict.empty - , rpcIdToFKey = Dict.empty - , subIdToFKey = Dict.empty - , debug = False - , ref = 1 - } - - -{-| -} -listen : EventSentry msg -> Sub msg -listen (EventSentry sentry) = - WS.listen sentry.nodePath (nodeResponseToMsg sentry.debug << decodeMessage) - |> Sub.map sentry.tagger - - -{-| -} -watch : (Value -> msg) -> EventSentry msg -> LogFilter -> ( EventSentry msg, Cmd msg ) -watch onReceive sentry logFilter = - watch_ False [ Encode.string "logs", Encode.logFilter logFilter ] onReceive sentry (toFilterKey logFilter) - - - +-- {-| The `eventOut` port. +-- Where information from your elm app is sent OUT to javascript land. +-- port eventOut : Value -> Cmd msg +-- -} +-- type alias OutPort = +-- Value -> Cmd Msg +-- {-| The `eventIn` subscription. +-- Where information from the outside comes IN to your elm app. +-- port eventIn : (Value -> msg) -> Sub msg +-- -} +-- type alias InPort = +-- (Value -> Msg) -> Sub Msg +-- {-| -} +-- type EventSentry msg +-- = EventSentry +-- { nodePath : String +-- , tagger : Msg -> msg +-- , filters : Dict FilteryKeyInternal (FilterState msg) +-- , rpcIdToFKey : Dict RpcId FilterKey +-- , subIdToFKey : Dict SubscriptionId FilterKey +-- , ref : RpcId +-- -- , debug : Bool +-- } +-- {-| -} +-- init : ( OutPort, InPort ) -> (Msg -> msg) -> WebsocketProvider -> EventSentry msg +-- init tagger nodePath = +-- EventSentry +-- { nodePath = nodePath +-- , tagger = tagger +-- , filters = Dict.empty +-- , rpcIdToFKey = Dict.empty +-- , subIdToFKey = Dict.empty +-- , ref = 1 +-- -- , debug = False +-- } +-- {-| -} +-- listen : EventSentry msg -> Sub msg +-- listen (EventSentry sentry) = +-- WS.listen sentry.nodePath (nodeResponseToMsg sentry.debug << decodeMessage) +-- |> Sub.map sentry.tagger +-- {-| -} +-- listen : (Value -> Cmd msg) -> EventSentry msg -> Cmd msg +-- listen cmdPort (EventSentry sentry) = +-- WS.makeOpen sentry.nodePath +-- -- (nodeResponseToMsg sentry.debug << decodeMessage) +-- |> WS.send cmdPort +-- {-| -} +-- watch : (Value -> msg) -> EventSentry msg -> LogFilter -> ( EventSentry msg, Cmd msg ) +-- watch onReceive sentry logFilter = +-- watch_ False [ Encode.string "logs", Encode.logFilter logFilter ] onReceive sentry (toFilterKey logFilter) +-- -- watch_ : Bool -> List Value -> (Value -> msg) -> EventSentry msg -> FilterKey -> ( EventSentry msg, Cmd msg ) +-- {-| -} +-- watchOnce : (Value -> msg) -> EventSentry msg -> LogFilter -> ( EventSentry msg, Cmd msg ) +-- watchOnce onReceive sentry logFilter = +-- watch_ True [ Encode.string "logs", Encode.logFilter logFilter ] onReceive sentry (toFilterKey logFilter) +-- {-| -} +-- unWatch : EventSentry msg -> LogFilter -> ( EventSentry msg, Cmd msg ) +-- unWatch sentry logFilter = +-- unWatch_ sentry (toFilterKey logFilter) +-- {-| -} +-- newBlocks : (BlockHead -> msg) -> EventSentry msg -> ( EventSentry msg, Cmd msg ) +-- newBlocks onReceive sentry = +-- watch_ False [ Encode.string "newHeads" ] (decodeBlockHead >> onReceive) sentry newBlockHeadsKey +-- {-| -} +-- nextBlock : (BlockHead -> msg) -> EventSentry msg -> ( EventSentry msg, Cmd msg ) +-- nextBlock onReceive sentry = +-- watch_ True [ Encode.string "newHeads" ] (decodeBlockHead >> onReceive) sentry newBlockHeadsKey +-- {-| -} +-- unWatchNewBlocks : EventSentry msg -> ( EventSentry msg, Cmd msg ) +-- unWatchNewBlocks sentry = +-- unWatch_ sentry newBlockHeadsKey +-- {-| -} +-- pendingTxs : (TxHash -> msg) -> EventSentry msg -> ( EventSentry msg, Cmd msg ) +-- pendingTxs onReceive sentry = +-- watch_ False [ Encode.string "newPendingTransactions" ] (decodeTxHash >> onReceive) sentry pendingTxsKey +-- {-| -} +-- unWatchPendingTxs : EventSentry msg -> ( EventSentry msg, Cmd msg ) +-- unWatchPendingTxs sentry = +-- unWatch_ sentry pendingTxsKey +-- {-| -} +-- withDebug : EventSentry msg -> EventSentry msg +-- withDebug (EventSentry sentry) = +-- EventSentry { sentry | debug = True } +-- {-| -} +-- changeNode : String -> EventSentry msg -> EventSentry msg +-- changeNode newNodePath (EventSentry eventSentry) = +-- EventSentry { eventSentry | nodePath = newNodePath } +-- {-| (Contract Address, Event Topic) +-- Need to come up with a better Key scheme to avoid collisions +-- Maybe by hashing the Filter params +-- -} +-- type FilterKey +-- = FilterKey FilteryKeyInternal +-- type alias FilteryKeyInternal = +-- ( String, String ) +-- {-| -} +-- toFilterKey : LogFilter -> FilterKey +-- toFilterKey { address, topics } = +-- let +-- eventTopic = +-- List.head topics +-- |> Maybe.andThen identity +-- |> Maybe.map U.hexToString +-- |> Maybe.withDefault "" +-- in +-- FilterKey ( addressToString address, eventTopic ) +-- type alias RpcId = +-- Int +-- -- Internal -- watch_ : Bool -> List Value -> (Value -> msg) -> EventSentry msg -> FilterKey -> ( EventSentry msg, Cmd msg ) - - -{-| -} -watchOnce : (Value -> msg) -> EventSentry msg -> LogFilter -> ( EventSentry msg, Cmd msg ) -watchOnce onReceive sentry logFilter = - watch_ True [ Encode.string "logs", Encode.logFilter logFilter ] onReceive sentry (toFilterKey logFilter) - - -{-| -} -unWatch : EventSentry msg -> LogFilter -> ( EventSentry msg, Cmd msg ) -unWatch sentry logFilter = - unWatch_ sentry (toFilterKey logFilter) - - -{-| -} -newBlocks : (BlockHead -> msg) -> EventSentry msg -> ( EventSentry msg, Cmd msg ) -newBlocks onReceive sentry = - watch_ False [ Encode.string "newHeads" ] (decodeBlockHead >> onReceive) sentry newBlockHeadsKey - - -{-| -} -nextBlock : (BlockHead -> msg) -> EventSentry msg -> ( EventSentry msg, Cmd msg ) -nextBlock onReceive sentry = - watch_ True [ Encode.string "newHeads" ] (decodeBlockHead >> onReceive) sentry newBlockHeadsKey - - -{-| -} -unWatchNewBlocks : EventSentry msg -> ( EventSentry msg, Cmd msg ) -unWatchNewBlocks sentry = - unWatch_ sentry newBlockHeadsKey - - -{-| -} -pendingTxs : (TxHash -> msg) -> EventSentry msg -> ( EventSentry msg, Cmd msg ) -pendingTxs onReceive sentry = - watch_ False [ Encode.string "newPendingTransactions" ] (decodeTxHash >> onReceive) sentry pendingTxsKey - - -{-| -} -unWatchPendingTxs : EventSentry msg -> ( EventSentry msg, Cmd msg ) -unWatchPendingTxs sentry = - unWatch_ sentry pendingTxsKey - - -{-| -} -withDebug : EventSentry msg -> EventSentry msg -withDebug (EventSentry sentry) = - EventSentry { sentry | debug = True } - - -{-| -} -changeNode : String -> EventSentry msg -> EventSentry msg -changeNode newNodePath (EventSentry eventSentry) = - EventSentry { eventSentry | nodePath = newNodePath } - - -{-| (Contract Address, Event Topic) - -Need to come up with a better Key scheme to avoid collisions -Maybe by hashing the Filter params - --} -type FilterKey - = FilterKey FilteryKeyInternal - - -type alias FilteryKeyInternal = - ( String, String ) - - -{-| -} -toFilterKey : LogFilter -> FilterKey -toFilterKey { address, topics } = - let - eventTopic = - List.head topics - |> Maybe.andThen identity - |> Maybe.map U.hexToString - |> Maybe.withDefault "" - in - FilterKey ( addressToString address, eventTopic ) - - -type alias RpcId = - Int - - - --- Internal - - -watch_ : Bool -> List Value -> (Value -> msg) -> EventSentry msg -> FilterKey -> ( EventSentry msg, Cmd msg ) -watch_ isOnce rpcParams onReceive ((EventSentry sentry) as sentry_) (FilterKey filterKey) = - case Dict.get filterKey sentry.filters of - Nothing -> - ( EventSentry - { sentry - | filters = Dict.insert filterKey (makeFilter isOnce onReceive sentry.ref) sentry.filters - , rpcIdToFKey = Dict.insert sentry.ref (FilterKey filterKey) sentry.rpcIdToFKey - , ref = sentry.ref + 1 - } - , WS.send sentry.nodePath (openFilterRpc sentry.ref rpcParams) - ) - - Just _ -> - ( sentry_, Cmd.none ) - - -unWatch_ : EventSentry msg -> FilterKey -> ( EventSentry msg, Cmd msg ) -unWatch_ ((EventSentry sentry) as sentry_) (FilterKey filterKey) = - case Dict.get filterKey sentry.filters of - Nothing -> - ( sentry_, Cmd.none ) - - Just filterState -> - case filterState.subId of - Just subId -> - let - _ = - debugHelp sentry log.subClosed { rpcId = filterState.rpcId, subId = subId } - in - ( EventSentry - { sentry - | filters = Dict.remove filterKey sentry.filters - , rpcIdToFKey = Dict.remove filterState.rpcId sentry.rpcIdToFKey - , subIdToFKey = Dict.remove subId sentry.subIdToFKey - , ref = sentry.ref + 1 - } - , WS.send sentry.nodePath (closeFilterRpc sentry.ref subId) - ) - - Nothing -> - ( sentry_, Cmd.none ) - - - --- Types - - -type NodeResponse - = Subscribed OpenedMsg - | Event EventMsg - | Unsubscribed ClosedMsg - - -type alias OpenedMsg = - { rpcId : RpcId, subId : SubscriptionId } - - -type alias ClosedMsg = - { rpcId : RpcId, result : Bool } - - -type alias EventMsg = - { method : String - , params : { subId : SubscriptionId, result : Value } - } - - -type alias SubscriptionId = - String - - -type FilterStatus - = Opening - | Opened - - -type alias FilterState msg = - { tagger : Value -> msg - , status : FilterStatus - , rpcId : RpcId - , subId : Maybe SubscriptionId - , once : Bool - } - - - ---- UPDATE - - -{-| -} -type Msg - = NoOp - | SubscriptionOpened OpenedMsg - | CloseSubscription FilterKey - | SubscriptionClosed ClosedMsg - | EventReceived EventMsg - - -{-| -} -update : Msg -> EventSentry msg -> ( EventSentry msg, Cmd msg ) -update msg ((EventSentry sentry) as sentry_) = - case msg of - SubscriptionOpened openedMsg -> - case getFilterByRpcId openedMsg.rpcId sentry_ of - Just ( FilterKey filterKey, filterState ) -> - ( EventSentry - { sentry - | filters = - Dict.update filterKey - (Maybe.map (setFilterStateOpened openedMsg.subId)) - sentry.filters - , subIdToFKey = - Dict.insert openedMsg.subId - (FilterKey filterKey) - sentry.subIdToFKey - } - , Cmd.none - ) - - Nothing -> - ( sentry_, Cmd.none ) - - CloseSubscription filterKey -> - unWatch_ sentry_ filterKey - - SubscriptionClosed closedMsg -> - ( sentry_, Cmd.none ) - - EventReceived eventMsg -> - let - result = - eventMsg.params.result - - subId = - eventMsg.params.subId - in - case getFilterBySubscriptionId subId sentry_ of - Just ( FilterKey filterKey, filterState, True ) -> - ( EventSentry - { sentry - | filters = Dict.remove filterKey sentry.filters - , rpcIdToFKey = Dict.remove filterState.rpcId sentry.rpcIdToFKey - , subIdToFKey = Dict.remove subId sentry.subIdToFKey - , ref = sentry.ref + 1 - } - , Cmd.batch - [ Task.perform filterState.tagger (Task.succeed result) - , WS.send sentry.nodePath (closeFilterRpc sentry.ref subId) - ] - ) - - Just ( filterKey, filterState, False ) -> - ( sentry_, Task.perform filterState.tagger (Task.succeed result) ) - - Nothing -> - ( sentry_, Cmd.none ) - - NoOp -> - ( sentry_, Cmd.none ) - - -nodeResponseToMsg : Bool -> Maybe NodeResponse -> Msg -nodeResponseToMsg debug mNodeResponse = - let - _ = - if debug then - Debug.log "EventSentry" mNodeResponse - - else - mNodeResponse - in - case mNodeResponse of - Just (Event eventMsg) -> - EventReceived eventMsg - - Just (Subscribed openedMsg) -> - SubscriptionOpened openedMsg - - Just (Unsubscribed closedMsg) -> - NoOp - - Nothing -> - NoOp - - - --- Dict Helpers - - -getFilterByRpcId : RpcId -> EventSentry msg -> Maybe ( FilterKey, FilterState msg ) -getFilterByRpcId rpcId (EventSentry sentry) = - Dict.get rpcId sentry.rpcIdToFKey - |> Maybe.andThen - (\(FilterKey key) -> - Dict.get key sentry.filters - |> Maybe.map (\f -> ( FilterKey key, f )) - ) - - -getFilterBySubscriptionId : SubscriptionId -> EventSentry msg -> Maybe ( FilterKey, FilterState msg, Bool ) -getFilterBySubscriptionId fId (EventSentry sentry) = - Dict.get fId sentry.subIdToFKey - |> Maybe.andThen - (\(FilterKey key) -> - Dict.get key sentry.filters - |> Maybe.map (\f -> ( FilterKey key, f, f.once )) - ) - - - --- Filter Helpers - - -makeFilter : Bool -> (Value -> msg) -> RpcId -> FilterState msg -makeFilter isOnce onReceive rpcId = - { tagger = onReceive - , status = Opening - , rpcId = rpcId - , subId = Nothing - , once = isOnce - } - - -setFilterStateOpened : SubscriptionId -> FilterState msg -> FilterState msg -setFilterStateOpened subId filterState = - { filterState | status = Opened, subId = Just subId } - - - --- RPC Helpers - - -openFilterRpc : RpcId -> List Value -> String -openFilterRpc rpcId rpcParams = - RPC.encode rpcId "eth_subscribe" rpcParams - |> Encode.encode 0 - - -closeFilterRpc : RpcId -> String -> String -closeFilterRpc rpcId filterId = - RPC.encode rpcId "eth_unsubscribe" [ Encode.string filterId ] - |> Encode.encode 0 - - - --- Decoders - - -decodeMessage : String -> Maybe NodeResponse -decodeMessage = - Result.toMaybe << Decode.decodeString nodeResponseDecoder - - -nodeResponseDecoder : Decoder NodeResponse -nodeResponseDecoder = - Decode.oneOf - [ openedMsgDecoder - , eventDecoder - , closedMsgDecoder - ] - - -openedMsgDecoder : Decoder NodeResponse -openedMsgDecoder = - Decode.map Subscribed <| - Decode.map2 OpenedMsg - (Decode.field "id" Decode.int) - (Decode.field "result" Decode.string) - - -closedMsgDecoder : Decoder NodeResponse -closedMsgDecoder = - Decode.map Unsubscribed <| - Decode.map2 ClosedMsg - (Decode.field "id" Decode.int) - (Decode.field "result" Decode.bool) - - -eventDecoder : Decoder NodeResponse -eventDecoder = - let - eventParamsDecoder = - Decode.map2 (\s r -> { subId = s, result = r }) - (Decode.field "subscription" Decode.string) - (Decode.field "result" Decode.value) - in - Decode.map Event <| - Decode.map2 EventMsg - (Decode.field "method" Decode.string) - (Decode.field "params" eventParamsDecoder) - - -decodeBlockHead : Value -> BlockHead -decodeBlockHead val = - case Decode.decodeValue Decode.blockHead val of - Ok blockHead -> - blockHead - - Err error -> - Debug.log error defaultBlockHead - - -decodeTxHash : Value -> TxHash -decodeTxHash val = - case Decode.decodeValue Decode.txHash val of - Ok txHash -> - txHash - - Err error -> - Debug.log error Default.emptyTxHash - - - --- Constants - - -pendingTxsKey : FilterKey -pendingTxsKey = - FilterKey ( "pending", "txs" ) - - -newBlockHeadsKey : FilterKey -newBlockHeadsKey = - FilterKey ( "new", "heads" ) - - -debugHelp sentry logText val = - if sentry.debug then - Debug.log ("EventSentry - " ++ logText) val - - else - val - - -log = - { subOpened = "Subscription Opened" - , subClosed = "Subscription Closed" - } - - - --- Default helpers - - -defaultBlockHead : BlockHead -defaultBlockHead = - { number = 42 - , hash = Default.emptyBlockHash - , parentHash = Default.emptyBlockHash - , nonce = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" - , sha3Uncles = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" - , logsBloom = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" - , transactionsRoot = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" - , stateRoot = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" - , receiptsRoot = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" - , miner = Default.zeroAddress - , difficulty = BigInt.fromInt 0 - , extraData = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" - , gasLimit = 0 - , gasUsed = 0 - , mixHash = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" - , timestamp = 0 - } +-- watch_ isOnce rpcParams onReceive ((EventSentry sentry) as sentry_) (FilterKey filterKey) = +-- case Dict.get filterKey sentry.filters of +-- Nothing -> +-- ( EventSentry +-- { sentry +-- | filters = Dict.insert filterKey (makeFilter isOnce onReceive sentry.ref) sentry.filters +-- , rpcIdToFKey = Dict.insert sentry.ref (FilterKey filterKey) sentry.rpcIdToFKey +-- , ref = sentry.ref + 1 +-- } +-- , WS.send sentry.nodePath (openFilterRpc sentry.ref rpcParams) +-- ) +-- Just _ -> +-- ( sentry_, Cmd.none ) +-- unWatch_ : EventSentry msg -> FilterKey -> ( EventSentry msg, Cmd msg ) +-- unWatch_ ((EventSentry sentry) as sentry_) (FilterKey filterKey) = +-- case Dict.get filterKey sentry.filters of +-- Nothing -> +-- ( sentry_, Cmd.none ) +-- Just filterState -> +-- case filterState.subId of +-- Just subId -> +-- let +-- _ = +-- debugHelp sentry log.subClosed { rpcId = filterState.rpcId, subId = subId } +-- in +-- ( EventSentry +-- { sentry +-- | filters = Dict.remove filterKey sentry.filters +-- , rpcIdToFKey = Dict.remove filterState.rpcId sentry.rpcIdToFKey +-- , subIdToFKey = Dict.remove subId sentry.subIdToFKey +-- , ref = sentry.ref + 1 +-- } +-- , WS.send sentry.nodePath (closeFilterRpc sentry.ref subId) +-- ) +-- Nothing -> +-- ( sentry_, Cmd.none ) +-- -- Types +-- type NodeResponse +-- = Subscribed OpenedMsg +-- | Event EventMsg +-- | Unsubscribed ClosedMsg +-- type alias OpenedMsg = +-- { rpcId : RpcId, subId : SubscriptionId } +-- type alias ClosedMsg = +-- { rpcId : RpcId, result : Bool } +-- type alias EventMsg = +-- { method : String +-- , params : { subId : SubscriptionId, result : Value } +-- } +-- type alias SubscriptionId = +-- String +-- type FilterStatus +-- = Opening +-- | Opened +-- type alias FilterState msg = +-- { tagger : Value -> msg +-- , status : FilterStatus +-- , rpcId : RpcId +-- , subId : Maybe SubscriptionId +-- , once : Bool +-- } +-- --- UPDATE +-- {-| -} +-- type Msg +-- = NoOp +-- | SubscriptionOpened OpenedMsg +-- | CloseSubscription FilterKey +-- | SubscriptionClosed ClosedMsg +-- | EventReceived EventMsg +-- {-| -} +-- update : Msg -> EventSentry msg -> ( EventSentry msg, Cmd msg ) +-- update msg ((EventSentry sentry) as sentry_) = +-- case msg of +-- SubscriptionOpened openedMsg -> +-- case getFilterByRpcId openedMsg.rpcId sentry_ of +-- Just ( FilterKey filterKey, filterState ) -> +-- ( EventSentry +-- { sentry +-- | filters = +-- Dict.update filterKey +-- (Maybe.map (setFilterStateOpened openedMsg.subId)) +-- sentry.filters +-- , subIdToFKey = +-- Dict.insert openedMsg.subId +-- (FilterKey filterKey) +-- sentry.subIdToFKey +-- } +-- , Cmd.none +-- ) +-- Nothing -> +-- ( sentry_, Cmd.none ) +-- CloseSubscription filterKey -> +-- unWatch_ sentry_ filterKey +-- SubscriptionClosed closedMsg -> +-- ( sentry_, Cmd.none ) +-- EventReceived eventMsg -> +-- let +-- result = +-- eventMsg.params.result +-- subId = +-- eventMsg.params.subId +-- in +-- case getFilterBySubscriptionId subId sentry_ of +-- Just ( FilterKey filterKey, filterState, True ) -> +-- ( EventSentry +-- { sentry +-- | filters = Dict.remove filterKey sentry.filters +-- , rpcIdToFKey = Dict.remove filterState.rpcId sentry.rpcIdToFKey +-- , subIdToFKey = Dict.remove subId sentry.subIdToFKey +-- , ref = sentry.ref + 1 +-- } +-- , Cmd.batch +-- [ Task.perform filterState.tagger (Task.succeed result) +-- , WS.send sentry.nodePath (closeFilterRpc sentry.ref subId) +-- ] +-- ) +-- Just ( filterKey, filterState, False ) -> +-- ( sentry_, Task.perform filterState.tagger (Task.succeed result) ) +-- Nothing -> +-- ( sentry_, Cmd.none ) +-- NoOp -> +-- ( sentry_, Cmd.none ) +-- nodeResponseToMsg : Bool -> Maybe NodeResponse -> Msg +-- nodeResponseToMsg debug mNodeResponse = +-- let +-- _ = +-- if debug then +-- Debug.log "EventSentry" mNodeResponse +-- else +-- mNodeResponse +-- in +-- case mNodeResponse of +-- Just (Event eventMsg) -> +-- EventReceived eventMsg +-- Just (Subscribed openedMsg) -> +-- SubscriptionOpened openedMsg +-- Just (Unsubscribed closedMsg) -> +-- NoOp +-- Nothing -> +-- NoOp +-- -- Dict Helpers +-- getFilterByRpcId : RpcId -> EventSentry msg -> Maybe ( FilterKey, FilterState msg ) +-- getFilterByRpcId rpcId (EventSentry sentry) = +-- Dict.get rpcId sentry.rpcIdToFKey +-- |> Maybe.andThen +-- (\(FilterKey key) -> +-- Dict.get key sentry.filters +-- |> Maybe.map (\f -> ( FilterKey key, f )) +-- ) +-- getFilterBySubscriptionId : SubscriptionId -> EventSentry msg -> Maybe ( FilterKey, FilterState msg, Bool ) +-- getFilterBySubscriptionId fId (EventSentry sentry) = +-- Dict.get fId sentry.subIdToFKey +-- |> Maybe.andThen +-- (\(FilterKey key) -> +-- Dict.get key sentry.filters +-- |> Maybe.map (\f -> ( FilterKey key, f, f.once )) +-- ) +-- -- Filter Helpers +-- makeFilter : Bool -> (Value -> msg) -> RpcId -> FilterState msg +-- makeFilter isOnce onReceive rpcId = +-- { tagger = onReceive +-- , status = Opening +-- , rpcId = rpcId +-- , subId = Nothing +-- , once = isOnce +-- } +-- setFilterStateOpened : SubscriptionId -> FilterState msg -> FilterState msg +-- setFilterStateOpened subId filterState = +-- { filterState | status = Opened, subId = Just subId } +-- -- RPC Helpers +-- openFilterRpc : RpcId -> List Value -> String +-- openFilterRpc rpcId rpcParams = +-- RPC.encode rpcId "eth_subscribe" rpcParams +-- |> Encode.encode 0 +-- closeFilterRpc : RpcId -> String -> String +-- closeFilterRpc rpcId filterId = +-- RPC.encode rpcId "eth_unsubscribe" [ Encode.string filterId ] +-- |> Encode.encode 0 +-- -- Decoders +-- decodeMessage : String -> Maybe NodeResponse +-- decodeMessage = +-- Result.toMaybe << Decode.decodeString nodeResponseDecoder +-- nodeResponseDecoder : Decoder NodeResponse +-- nodeResponseDecoder = +-- Decode.oneOf +-- [ openedMsgDecoder +-- , eventDecoder +-- , closedMsgDecoder +-- ] +-- openedMsgDecoder : Decoder NodeResponse +-- openedMsgDecoder = +-- Decode.map Subscribed <| +-- Decode.map2 OpenedMsg +-- (Decode.field "id" Decode.int) +-- (Decode.field "result" Decode.string) +-- closedMsgDecoder : Decoder NodeResponse +-- closedMsgDecoder = +-- Decode.map Unsubscribed <| +-- Decode.map2 ClosedMsg +-- (Decode.field "id" Decode.int) +-- (Decode.field "result" Decode.bool) +-- eventDecoder : Decoder NodeResponse +-- eventDecoder = +-- let +-- eventParamsDecoder = +-- Decode.map2 (\s r -> { subId = s, result = r }) +-- (Decode.field "subscription" Decode.string) +-- (Decode.field "result" Decode.value) +-- in +-- Decode.map Event <| +-- Decode.map2 EventMsg +-- (Decode.field "method" Decode.string) +-- (Decode.field "params" eventParamsDecoder) +-- decodeBlockHead : Value -> BlockHead +-- decodeBlockHead val = +-- case Decode.decodeValue Decode.blockHead val of +-- Ok blockHead -> +-- blockHead +-- Err error -> +-- Debug.log error defaultBlockHead +-- decodeTxHash : Value -> TxHash +-- decodeTxHash val = +-- case Decode.decodeValue Decode.txHash val of +-- Ok txHash -> +-- txHash +-- Err error -> +-- Debug.log error Default.emptyTxHash +-- -- Constants +-- pendingTxsKey : FilterKey +-- pendingTxsKey = +-- FilterKey ( "pending", "txs" ) +-- newBlockHeadsKey : FilterKey +-- newBlockHeadsKey = +-- FilterKey ( "new", "heads" ) +-- debugHelp sentry logText val = +-- if sentry.debug then +-- Debug.log ("EventSentry - " ++ logText) val +-- else +-- val +-- log = +-- { subOpened = "Subscription Opened" +-- , subClosed = "Subscription Closed" +-- } +-- -- Default helpers +-- defaultBlockHead : BlockHead +-- defaultBlockHead = +-- { number = 42 +-- , hash = Default.emptyBlockHash +-- , parentHash = Default.emptyBlockHash +-- , nonce = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" +-- , sha3Uncles = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" +-- , logsBloom = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" +-- , transactionsRoot = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" +-- , stateRoot = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" +-- , receiptsRoot = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" +-- , miner = Default.zeroAddress +-- , difficulty = BigInt.fromInt 0 +-- , extraData = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" +-- , gasLimit = 0 +-- , gasUsed = 0 +-- , mixHash = "open up a github issue on elm-ethereum, you should not see this, the shape of a blockhead must've changed" +-- , timestamp = 0 +-- } diff --git a/src/Eth/Sentry/Tx.elm b/src/Eth/Sentry/Tx.elm index a5a3a47..6ceba10 100644 --- a/src/Eth/Sentry/Tx.elm +++ b/src/Eth/Sentry/Tx.elm @@ -2,7 +2,7 @@ module Eth.Sentry.Tx exposing ( TxSentry, Msg, update, init, OutPort, InPort, listen , send, sendWithReceipt , CustomSend, TxTracker, customSend - , withDebug, changeNode + , changeNode -- , Error(..) ) @@ -26,7 +26,7 @@ module Eth.Sentry.Tx exposing # Utils -@docs withDebug, changeNode +@docs changeNode -} @@ -51,8 +51,9 @@ type TxSentry msg , nodePath : HttpProvider , tagger : Msg -> msg , txs : Dict Int (TxState msg) - , debug : Maybe (String -> a -> a) , ref : Int + + -- , debug : Maybe (String -> a -> a) } @@ -79,8 +80,9 @@ init ( outPort, inPort ) tagger nodePath = , nodePath = nodePath , tagger = tagger , txs = Dict.empty - , debug = Nothing , ref = 1 + + -- , debug = Nothing } @@ -159,10 +161,11 @@ customSend = send_ -{-| -} -withDebug : (String -> a -> a) -> TxSentry msg -> TxSentry msg -withDebug logFunc (TxSentry sentry) = - TxSentry { sentry | debug = Just logFunc } + +-- {-| -} +-- withDebug : (String -> a -> a) -> TxSentry msg -> TxSentry msg +-- withDebug logFunc (TxSentry sentry) = +-- TxSentry { sentry | debug = Just logFunc } {-| Look into the errors this might cause, @@ -170,43 +173,54 @@ some kind of cleanup process should probably occur on changing a node. -} changeNode : HttpProvider -> TxSentry msg -> TxSentry msg changeNode newNodePath (TxSentry sentry) = - let - _ = - debugHelp sentry.debug log.nodeChanged newNodePath - in + -- let + -- _ = + -- debugHelp sentry.debug log.nodeChanged newNodePath + -- in TxSentry { sentry | nodePath = newNodePath } -- INTERNAL +-- send_ : TxSentry msg -> CustomSend msg -> Send -> ( TxSentry msg, Cmd msg ) +-- send_ (TxSentry sentry) sendParams txParams = +-- case Encode.encodeSend txParams of +-- Ok txParamVal -> +-- let +-- newTxs = +-- Dict.insert sentry.ref (newTxState txParams sendParams) sentry.txs +-- in +-- ( TxSentry { sentry | txs = newTxs, ref = sentry.ref + 1 } +-- , Cmd.map sentry.tagger <| sentry.outPort (encodeTxData sentry.ref txParamVal) +-- ) +-- Err err -> +-- let +-- sendError : Maybe (Result String a -> msg) -> Cmd msg +-- sendError maybeTagger = +-- Maybe.map (\tagger -> Task.perform tagger (Task.succeed <| Err err)) maybeTagger +-- |> Maybe.withDefault Cmd.none +-- in +-- ( TxSentry sentry +-- , Cmd.batch +-- [ sendError sendParams.onSignedTagger +-- , sendError sendParams.onBroadcastTagger +-- , sendError sendParams.onMinedTagger +-- ] +-- ) send_ : TxSentry msg -> CustomSend msg -> Send -> ( TxSentry msg, Cmd msg ) send_ (TxSentry sentry) sendParams txParams = - case Encode.encodeSend txParams of - Ok txParamVal -> - let - newTxs = - Dict.insert sentry.ref (newTxState txParams sendParams) sentry.txs - in - ( TxSentry { sentry | txs = newTxs, ref = sentry.ref + 1 } - , Cmd.map sentry.tagger <| sentry.outPort (encodeTxData sentry.ref txParamVal) - ) + let + txParamVal = + Eth.encodeSend txParams - Err err -> - let - sendError : Maybe (Result String a -> msg) -> Cmd msg - sendError maybeTagger = - Maybe.map (\tagger -> Task.perform tagger (Task.succeed <| Err err)) maybeTagger - |> Maybe.withDefault Cmd.none - in - ( TxSentry sentry - , Cmd.batch - [ sendError sendParams.onSignedTagger - , sendError sendParams.onBroadcastTagger - , sendError sendParams.onMinedTagger - ] - ) + newTxs = + Dict.insert sentry.ref (newTxState txParams sendParams) sentry.txs + in + ( TxSentry { sentry | txs = newTxs, ref = sentry.ref + 1 } + , Cmd.map sentry.tagger <| sentry.outPort (encodeTxData sentry.ref txParamVal) + ) type TxStatus @@ -254,9 +268,8 @@ update msg (TxSentry sentry) = case Dict.get ref sentry.txs of Just txState -> let - _ = - debugHelp sentry.debug log.signed (toString txHashResult) - + -- _ = + -- debugHelp sentry.debug log.signed (toString txHashResult) txSignedCmd = case txState.onSignedTagger of Just txHashToMsg -> @@ -318,10 +331,10 @@ update msg (TxSentry sentry) = -- When Tx has been sucessfully broadcast and verifiably sits within the networks Tx Queue, -- AND an "onBroadcastTagger" and/or "onMinedTagger" was provided by the user, -- Msg User Land accordingly. - let - _ = - debugHelp sentry.debug log.broadcast (toString txResult) - in + -- let + -- _ = + -- debugHelp sentry.debug log.broadcast (toString txResult) + -- in case Dict.get ref sentry.txs of Just txState -> case txResult of @@ -357,11 +370,13 @@ update msg (TxSentry sentry) = failOtherCallbacks = case ( txState.onBroadcastTagger, txState.onMinedTagger ) of ( Just txToMsg, _ ) -> - Task.perform txToMsg (Task.succeed <| Err <| toString error) + Task.perform txToMsg (Task.succeed <| Err "Error with TxSent stuff") + -- Task.perform txToMsg (Task.succeed <| Err <| toString error) ( _, Just ( txReceiptToMsg, _ ) ) -> - Task.perform txReceiptToMsg (Task.succeed <| Err <| toString error) + Task.perform txReceiptToMsg (Task.succeed <| Err "Error with TxSent stuff") + -- Task.perform txReceiptToMsg (Task.succeed <| Err <| toString error) ( Nothing, Nothing ) -> Cmd.none in @@ -375,10 +390,10 @@ update msg (TxSentry sentry) = TxMined ref txReceiptResult -> -- When Tx is mined because a TxReceipt was returned by the network... - let - _ = - debugHelp sentry.debug log.mined (toString txReceiptResult) - in + -- let + -- _ = + -- debugHelp sentry.debug log.mined (toString txReceiptResult) + -- in case Dict.get ref sentry.txs of Just txState -> case txReceiptResult of @@ -403,8 +418,8 @@ update msg (TxSentry sentry) = , reOrg = False } - _ = - debugHelp sentry.debug log.trackTx txTracker + -- _ = + -- debugHelp sentry.debug log.trackTx txTracker in -- ...or user DOES need to trackthe block depth of the tx, -- then Send TxReceipt and/or TxTracker to User Land @@ -430,8 +445,10 @@ update msg (TxSentry sentry) = cmdIfMinedFail = case txState.onMinedTagger of Just ( txReceiptToMsg, _ ) -> - Task.perform txReceiptToMsg (Task.succeed <| Err <| toString error) + Task.perform txReceiptToMsg (Task.succeed <| Err "TxReceipt decoding failure") + -- TODO Reimplement this better + --Task.perform txReceiptToMsg (Task.succeed <| Err <| toString error) Nothing -> Cmd.none in @@ -455,10 +472,10 @@ update msg (TxSentry sentry) = -- If block depth is reached, send DeepEnough msg case getTxTrackerToMsg sentry.txs ref of Just blockDepthToMsg -> - let - _ = - debugHelp sentry.debug log.trackTx { newTxTracker | doneWatching = True } - in + -- let + -- _ = + -- debugHelp sentry.debug log.trackTx { newTxTracker | doneWatching = True } + -- in ( TxSentry sentry , Task.perform blockDepthToMsg (Eth.getTxReceipt sentry.nodePath txTracker.txHash @@ -466,9 +483,7 @@ update msg (TxSentry sentry) = |> Task.onError (\_ -> Task.succeed <| - Debug.log - "TxTracker - Possible Chain ReOrg" - { newTxTracker | reOrg = True, doneWatching = True } + { newTxTracker | reOrg = True, doneWatching = True } ) ) ) @@ -491,10 +506,10 @@ update msg (TxSentry sentry) = -- let the user know a new block depth has been reached. case getTxTrackerToMsg sentry.txs ref of Just blockDepthToMsg -> - let - _ = - debugHelp sentry.debug log.trackTx newTxTracker - in + -- let + -- _ = + -- debugHelp sentry.debug log.trackTx newTxTracker + -- in ( TxSentry sentry , Cmd.batch [ Task.attempt (TrackTx ref newTxTracker) @@ -510,17 +525,17 @@ update msg (TxSentry sentry) = ( TxSentry sentry, Cmd.none ) TrackTx ref _ (Err error) -> - let - _ = - debugHelp sentry.debug log.trackTx ("Error getting latest block. Info: " ++ toString error) - in + -- let + -- _ = + -- debugHelp sentry.debug log.trackTx ("Error getting latest block. Info: " ++ toString error) + -- in ( TxSentry sentry, Cmd.none ) ErrorDecoding error -> - let - _ = - debugHelp sentry.debug log.decodeError error - in + -- let + -- _ = + -- debugHelp sentry.debug log.decodeError error + -- in ( TxSentry sentry, Cmd.none ) @@ -598,10 +613,11 @@ decodeTxData val = Nothing -> TxSigned result.ref - (Err <| "Problem signing/broadcasting Tx. Ref #" ++ toString result.ref) + (Err <| "Problem signing/broadcasting Tx. Ref #" ++ String.fromInt result.ref) Err error -> - ErrorDecoding error + -- TODO actually unpack `error` after I become not lazy and in a rush + ErrorDecoding "Error decoding tx data" txIdResponseDecoder : Decoder { ref : Int, txHash : Maybe TxHash } @@ -612,12 +628,12 @@ txIdResponseDecoder = newTxState : Send -> CustomSend msg -> TxState msg -newTxState send { onSign, onBroadcast, onMined } = - { params = send +newTxState sendParams { onSign, onBroadcast, onMined } = + { params = sendParams , onSignedTagger = onSign , onBroadcastTagger = onBroadcast , onMinedTagger = onMined - , status = Signing send + , status = Signing sendParams } diff --git a/src/Eth/Types.elm b/src/Eth/Types.elm index 1a3c8a6..c5bb121 100644 --- a/src/Eth/Types.elm +++ b/src/Eth/Types.elm @@ -91,7 +91,7 @@ type alias Send = , gas : Maybe Int , gasPrice : Maybe BigInt , value : Maybe BigInt - , data : Maybe (Result String Hex) + , data : Maybe Hex , nonce : Maybe Int } diff --git a/src/Internal/Decode.elm b/src/Internal/Decode.elm index 4731114..8b4ce43 100644 --- a/src/Internal/Decode.elm +++ b/src/Internal/Decode.elm @@ -1,5 +1,11 @@ module Internal.Decode exposing (address, bigInt, block, blockHash, blockHead, event, hex, hexBool, hexInt, hexTime, log, nonZero, resultToDecoder, stringInt, syncStatus, tx, txHash, txReceipt, uncle) +{-| + +@docs address, bigInt, block, blockHash, blockHead, event, hex, hexBool, hexInt, hexTime, log, nonZero, resultToDecoder, stringInt, syncStatus, tx, txHash, txReceipt, uncle + +-} + import BigInt exposing (BigInt) import Eth.Types exposing (..) import Eth.Utils exposing (toAddress, toBlockHash, toHex, toTxHash) diff --git a/src/Internal/Encode.elm b/src/Internal/Encode.elm index 69f5378..13e3986 100644 --- a/src/Internal/Encode.elm +++ b/src/Internal/Encode.elm @@ -1,5 +1,11 @@ module Internal.Encode exposing (address, bigInt, blockHash, blockId, hex, hexInt, listOfMaybesToVal, logFilter, topicsList, txCall, txHash) +{-| + +@docs address, bigInt, blockHash, blockId, hex, hexInt, listOfMaybesToVal, logFilter, topicsList, txCall, txHash + +-} + import BigInt exposing (BigInt) import Eth.Types exposing (..) import Eth.Utils exposing (..) @@ -34,6 +40,7 @@ blockHash = -- Complex +{-| -} listOfMaybesToVal : List ( String, Maybe Value ) -> Value listOfMaybesToVal keyValueList = keyValueList @@ -42,29 +49,41 @@ listOfMaybesToVal keyValueList = |> Encode.object -{-| -} -txCall : Call a -> Result Eth.Error Value -txCall { to, from, gas, gasPrice, value, data } = - let - toVal callData = - listOfMaybesToVal - [ ( "to", Maybe.map address to ) - , ( "from", Maybe.map address from ) - , ( "gas", Maybe.map hexInt gas ) - , ( "gasPrice", Maybe.map bigInt gasPrice ) - , ( "value", Maybe.map bigInt value ) - , ( "data", Maybe.map hex callData ) - ] - in - case data of - Nothing -> - Ok <| toVal Nothing - Just (Ok data_) -> - Ok <| toVal (Just data_) +-- {-| -} +-- txCall : Call a -> Value +-- txCall { to, from, gas, gasPrice, value, data } = +-- let +-- toVal callData = +-- listOfMaybesToVal +-- [ ( "to", Maybe.map address to ) +-- , ( "from", Maybe.map address from ) +-- , ( "gas", Maybe.map hexInt gas ) +-- , ( "gasPrice", Maybe.map bigInt gasPrice ) +-- , ( "value", Maybe.map bigInt value ) +-- , ( "data", Maybe.map hex callData ) +-- ] +-- in +-- case data of +-- Nothing -> +-- Ok <| toVal Nothing +-- Just (Ok data_) -> +-- Ok <| toVal (Just data_) +-- Just (Err err) -> +-- Err err + - Just (Err err) -> - Err err +{-| -} +txCall : Call a -> Value +txCall { to, from, gas, gasPrice, value, data } = + listOfMaybesToVal + [ ( "to", Maybe.map address to ) + , ( "from", Maybe.map address from ) + , ( "gas", Maybe.map hexInt gas ) + , ( "gasPrice", Maybe.map bigInt gasPrice ) + , ( "value", Maybe.map bigInt value ) + , ( "data", Maybe.map hex data ) + ] {-| -} @@ -97,6 +116,7 @@ logFilter lf = ] +{-| -} topicsList : List (Maybe Hex) -> Value topicsList topics = let diff --git a/src/Internal/Utils.elm b/src/Internal/Utils.elm index 9e0aff9..b214008 100644 --- a/src/Internal/Utils.elm +++ b/src/Internal/Utils.elm @@ -1,11 +1,19 @@ module Internal.Utils exposing (add0x, drop64, leftPadTo64, quote, remove0x, take64, toByteLength) +{-| +@docs add0x, drop64, leftPadTo64, quote, remove0x, take64, toByteLength + +-} + + +{-| -} quote : String -> String quote str = "\"" ++ str ++ "\"" +{-| -} toByteLength : String -> String toByteLength str = if String.length str == 1 then @@ -15,16 +23,19 @@ toByteLength str = str +{-| -} take64 : String -> String take64 = String.left 64 +{-| -} drop64 : String -> String drop64 = String.dropLeft 64 +{-| -} leftPadTo64 : String -> String leftPadTo64 str = String.padLeft 64 '0' str diff --git a/src/Legacy/WebSocket.elm b/src/Legacy/WebSocket.elm deleted file mode 100644 index 870c6d2..0000000 --- a/src/Legacy/WebSocket.elm +++ /dev/null @@ -1,13 +0,0 @@ -module Legacy.WebSocket exposing (listen) - --- Stubbing out websockets to compile for the time being - - -listen : String -> (String -> msg) -> Sub msg -listen a b = - Sub.none - - -send : String -> String -> Cmd msg -send a b = - Cmd.none diff --git a/src/Shh.elm b/src/Shh.elm index b1a9a12..2139cd2 100644 --- a/src/Shh.elm +++ b/src/Shh.elm @@ -46,11 +46,11 @@ type alias Post = {-| -} post : HttpProvider -> Post -> Task Http.Error Bool -post ethNode post = +post ethNode post_ = RPC.toTask { url = ethNode , method = "shh_post" - , params = [ encodePost post ] + , params = [ encodePost post_ ] , decoder = Decode.bool } @@ -112,7 +112,7 @@ encodePost { to, from, topics, payload, priority, ttl } = listOfMaybesToVal [ ( "to", Maybe.map Encode.string to ) , ( "from", Maybe.map Encode.string from ) - , ( "topics", Maybe.map Encode.list (Just <| List.map Encode.string topics) ) + , ( "topics", Just (Encode.list Encode.string topics) ) , ( "payload", Maybe.map Encode.string (Just payload) ) , ( "priority", Maybe.map Encode.hexInt (Just priority) ) , ( "ttl", Maybe.map Encode.hexInt (Just ttl) )