Skip to content

Commit

Permalink
Update for new elm-ethereum API
Browse files Browse the repository at this point in the history
  • Loading branch information
cmditch committed May 10, 2018
1 parent 64f8d85 commit dcad877
Show file tree
Hide file tree
Showing 13 changed files with 2,330 additions and 178 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# elm-web3-contract
Generate an [elm-web3](https://github.com/cmditch/elm-web3) binding for an Ethereum smart contract from it's ABI
# elm-ethereum-generator
Generate an [elm-ethereum](https://github.com/cmditch/elm-ethereum) binding for an Ethereum smart contract from it's ABI

Example usage:
`elm-web3-contract some-abi.json src/MyContract.elm`
`elm-ethereum-generator some-abi.json src/MyContract.elm`
14 changes: 7 additions & 7 deletions elm-web3-contract.cabal → elm-ethereum-generator.cabal
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: elm-web3-contract
version: 0.2.0.0
name: elm-ethereum-generator
version: 1.0.0
-- synopsis:
-- description:
homepage: https://github.com/githubuser/elm-web3-contract#readme
homepage: https://github.com/cmditch/elm-ethereum-generator
license: BSD3
license-file: LICENSE
author: Author name here
maintainer: example@example.com
copyright: 2018 Author name here
author: Coury Ditch
maintainer: Coury Ditch
copyright: 2018 Coury Ditch
category: Web
build-type: Simple
cabal-version: >=1.10
extra-source-files: README.md

executable elm-web3-contract
executable elm-ethereum-generator
hs-source-dirs: src
main-is: Main.hs
default-language: Haskell2010
Expand Down
76 changes: 38 additions & 38 deletions examples/ERC20.elm
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ module ERC20
import BigInt exposing (BigInt)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (custom, decode)
import Web3.Eth.Types exposing (..)
import Web3.Evm.Decode exposing (..)
import Web3.Evm.Encode as Evm exposing (..)
import Web3.Utils exposing (keccak256)
import Eth.Types exposing (..)
import Eth.Utils as U
import Evm.Decode as Evm exposing (evmDecode, andMap, toElmDecoder, topic, data)
import Evm.Encode as Evm exposing (Encoding(..), evmEncode)


{-| "allowance(address,address)" function
Expand All @@ -37,9 +37,9 @@ allowance contractAddress owner spender =
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just <| encodeData "allowance(address,address)" [ AddressE owner, AddressE spender ]
, data = Just <| Evm.encodeFunctionCall "allowance(address,address)" [ AddressE owner, AddressE spender ]
, nonce = Nothing
, decoder = toElmDecoder uint
, decoder = toElmDecoder Evm.uint
}


Expand All @@ -52,9 +52,9 @@ allowed contractAddress a b =
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just <| encodeData "allowed(address,address)" [ AddressE a, AddressE b ]
, data = Just <| Evm.encodeFunctionCall "allowed(address,address)" [ AddressE a, AddressE b ]
, nonce = Nothing
, decoder = toElmDecoder uint
, decoder = toElmDecoder Evm.uint
}


Expand All @@ -67,9 +67,9 @@ approve contractAddress spender value =
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just <| encodeData "approve(address,uint256)" [ AddressE spender, UintE value ]
, data = Just <| Evm.encodeFunctionCall "approve(address,uint256)" [ AddressE spender, UintE value ]
, nonce = Nothing
, decoder = toElmDecoder bool
, decoder = toElmDecoder Evm.bool
}


Expand All @@ -82,9 +82,9 @@ balanceOf contractAddress owner =
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just <| encodeData "balanceOf(address)" [ AddressE owner ]
, data = Just <| Evm.encodeFunctionCall "balanceOf(address)" [ AddressE owner ]
, nonce = Nothing
, decoder = toElmDecoder uint
, decoder = toElmDecoder Evm.uint
}


Expand All @@ -97,9 +97,9 @@ balances contractAddress a =
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just <| encodeData "balances(address)" [ AddressE a ]
, data = Just <| Evm.encodeFunctionCall "balances(address)" [ AddressE a ]
, nonce = Nothing
, decoder = toElmDecoder uint
, decoder = toElmDecoder Evm.uint
}


Expand All @@ -112,9 +112,9 @@ decimals contractAddress =
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just <| encodeData "decimals()" []
, data = Just <| Evm.encodeFunctionCall "decimals()" []
, nonce = Nothing
, decoder = toElmDecoder uint
, decoder = toElmDecoder Evm.uint
}


Expand All @@ -127,9 +127,9 @@ name contractAddress =
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just <| encodeData "name()" []
, data = Just <| Evm.encodeFunctionCall "name()" []
, nonce = Nothing
, decoder = toElmDecoder string
, decoder = toElmDecoder Evm.string
}


Expand All @@ -142,9 +142,9 @@ symbol contractAddress =
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just <| encodeData "symbol()" []
, data = Just <| Evm.encodeFunctionCall "symbol()" []
, nonce = Nothing
, decoder = toElmDecoder string
, decoder = toElmDecoder Evm.string
}


Expand All @@ -157,9 +157,9 @@ totalSupply contractAddress =
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just <| encodeData "totalSupply()" []
, data = Just <| Evm.encodeFunctionCall "totalSupply()" []
, nonce = Nothing
, decoder = toElmDecoder uint
, decoder = toElmDecoder Evm.uint
}


Expand All @@ -172,9 +172,9 @@ transfer contractAddress to value =
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just <| encodeData "transfer(address,uint256)" [ AddressE to, UintE value ]
, data = Just <| Evm.encodeFunctionCall "transfer(address,uint256)" [ AddressE to, UintE value ]
, nonce = Nothing
, decoder = toElmDecoder bool
, decoder = toElmDecoder Evm.bool
}


Expand All @@ -187,9 +187,9 @@ transferFrom contractAddress from to value =
, gas = Nothing
, gasPrice = Nothing
, value = Nothing
, data = Just <| encodeData "transferFrom(address,address,uint256)" [ AddressE from, AddressE to, UintE value ]
, data = Just <| Evm.encodeFunctionCall "transferFrom(address,address,uint256)" [ AddressE from, AddressE to, UintE value ]
, nonce = Nothing
, decoder = toElmDecoder bool
, decoder = toElmDecoder Evm.bool
}


Expand All @@ -208,19 +208,19 @@ approvalEvent contractAddress owner spender =
, toBlock = LatestBlock
, address = contractAddress
, topics =
[ Just <| keccak256 "Approval(address,address,uint256)"
, Maybe.map (Evm.encode << AddressE) owner
, Maybe.map (Evm.encode << AddressE) spender
[ Just <| U.keccak256 "Approval(address,address,uint256)"
, Maybe.map (evmEncode << AddressE) owner
, Maybe.map (evmEncode << AddressE) spender
]
}


approvalDecoder : Decoder Approval
approvalDecoder =
decode Approval
|> custom (topic 1 address)
|> custom (topic 2 address)
|> custom (data 0 uint)
|> custom (topic 1 Evm.address)
|> custom (topic 2 Evm.address)
|> custom (data 0 Evm.uint)


{-| "Transfer(address,address,uint256)" event
Expand All @@ -238,18 +238,18 @@ transferEvent contractAddress from to =
, toBlock = LatestBlock
, address = contractAddress
, topics =
[ Just <| keccak256 "Transfer(address,address,uint256)"
, Maybe.map (Evm.encode << AddressE) from
, Maybe.map (Evm.encode << AddressE) to
[ Just <| U.keccak256 "Transfer(address,address,uint256)"
, Maybe.map (evmEncode << AddressE) from
, Maybe.map (evmEncode << AddressE) to
]
}


transferDecoder : Decoder Transfer
transferDecoder =
decode Transfer
|> custom (topic 1 address)
|> custom (topic 2 address)
|> custom (data 0 uint)
|> custom (topic 1 Evm.address)
|> custom (topic 2 Evm.address)
|> custom (data 0 Evm.uint)


Loading

0 comments on commit dcad877

Please sign in to comment.