web3 0.5.2.1 → 0.5.3.0
raw patch · 13 files changed
+133/−114 lines, 13 filesdep ~cryptonitedep ~web3
Dependency ranges changed: cryptonite, web3
Files
- src/Network/Ethereum/Unit.hs +12/−12
- src/Network/Ethereum/Web3/Address.hs +1/−1
- src/Network/Ethereum/Web3/Api.hs +12/−0
- src/Network/Ethereum/Web3/Contract.hs +7/−8
- src/Network/Ethereum/Web3/Encoding.hs +2/−0
- src/Network/Ethereum/Web3/Encoding/Bytes.hs +4/−1
- src/Network/Ethereum/Web3/Encoding/Internal.hs +3/−2
- src/Network/Ethereum/Web3/Encoding/Tuple.hs +1/−1
- src/Network/Ethereum/Web3/Encoding/TupleTH.hs +10/−10
- src/Network/Ethereum/Web3/JsonRpc.hs +8/−8
- src/Network/Ethereum/Web3/TH.hs +16/−14
- src/Network/Ethereum/Web3/Types.hs +54/−54
- web3.cabal +3/−3
src/Network/Ethereum/Unit.hs view
@@ -45,9 +45,9 @@ module Network.Ethereum.Unit ( Unit(..) , Wei- , KWei- , MWei- , GWei+ , Babbage+ , Lovelace+ , Shannon , Szabo , Finney , Ether@@ -138,26 +138,26 @@ divider = const 1 name = const "wei" --- | KWei unit type-type KWei = Value U1+-- | Babbage unit type+type Babbage = Value U1 instance UnitSpec U1 where divider = const 1e3- name = const "kwei"+ name = const "babbage" --- | MWei unit type-type MWei = Value U2+-- | Lovelace unit type+type Lovelace = Value U2 instance UnitSpec U2 where divider = const 1e6- name = const "mwei"+ name = const "lovelace" --- | GWei unit type-type GWei = Value U3+-- | Shannon unit type+type Shannon = Value U3 instance UnitSpec U3 where divider = const 1e9- name = const "gwei"+ name = const "shannon" -- | Szabo unit type type Szabo = Value U4
src/Network/Ethereum/Web3/Address.hs view
@@ -50,7 +50,7 @@ fromText :: Text -> Either String Address fromText = fmap (Address . fst) . R.hexadecimal <=< check where check t | T.take 2 t == "0x" = check (T.drop 2 t)- | otherwise = if T.length t == 40 && T.all (flip elem valid) t+ | otherwise = if T.length t == 40 && T.all (`elem` valid) t then Right t else Left "This is not seems like address." valid = ['0'..'9'] ++ ['a'..'f'] ++ ['A'..'F']
src/Network/Ethereum/Web3/Api.hs view
@@ -19,54 +19,66 @@ -- | Returns current node version string. web3_clientVersion :: Provider a => Web3 a Text+{-# INLINE web3_clientVersion #-} web3_clientVersion = remote "web3_clientVersion" -- | Returns Keccak-256 (not the standardized SHA3-256) of the given data. web3_sha3 :: Provider a => Text -> Web3 a Text+{-# INLINE web3_sha3 #-} web3_sha3 = remote "web3_sha3" -- | Returns the balance of the account of given address. eth_getBalance :: Provider a => Address -> CallMode -> Web3 a Text+{-# INLINE eth_getBalance #-} eth_getBalance = remote "eth_getBalance" -- | Creates a filter object, based on filter options, to notify when the -- state changes (logs). To check if the state has changed, call -- 'getFilterChanges'. eth_newFilter :: Provider a => Filter -> Web3 a FilterId+{-# INLINE eth_newFilter #-} eth_newFilter = remote "eth_newFilter" -- | Polling method for a filter, which returns an array of logs which -- occurred since last poll. eth_getFilterChanges :: Provider a => FilterId -> Web3 a [Change]+{-# INLINE eth_getFilterChanges #-} eth_getFilterChanges = remote "eth_getFilterChanges" -- | Uninstalls a filter with given id. -- Should always be called when watch is no longer needed. eth_uninstallFilter :: Provider a => FilterId -> Web3 a Bool+{-# INLINE eth_uninstallFilter #-} eth_uninstallFilter = remote "eth_uninstallFilter" -- | Executes a new message call immediately without creating a -- transaction on the block chain. eth_call :: Provider a => Call -> CallMode -> Web3 a Text+{-# INLINE eth_call #-} eth_call = remote "eth_call" -- | Creates new message call transaction or a contract creation, -- if the data field contains code. eth_sendTransaction :: Provider a => Call -> Web3 a Text+{-# INLINE eth_sendTransaction #-} eth_sendTransaction = remote "eth_sendTransaction" -- | Returns a list of addresses owned by client. eth_accounts :: Provider a => Web3 a [Address]+{-# INLINE eth_accounts #-} eth_accounts = remote "eth_accounts" eth_newBlockFilter :: Provider a => Web3 a Text+{-# INLINE eth_newBlockFilter #-} eth_newBlockFilter = remote "eth_newBlockFilter" -- | Polling method for a block filter, which returns an array of block hashes -- occurred since last poll. eth_getBlockFilterChanges :: Provider a => Text -> Web3 a [Text]+{-# INLINE eth_getBlockFilterChanges #-} eth_getBlockFilterChanges = remote "eth_getFilterChanges" -- | Returns information about a block by hash. eth_getBlockByHash :: Provider a => Text -> Web3 a Block+{-# INLINE eth_getBlockByHash #-} eth_getBlockByHash = flip (remote "eth_getBlockByHash") True
src/Network/Ethereum/Web3/Contract.hs view
@@ -36,11 +36,12 @@ import qualified Data.Text.Lazy.Builder.Int as B import qualified Data.Text.Lazy.Builder as B import Control.Concurrent (ThreadId, threadDelay)-import Data.Maybe (catMaybes, listToMaybe)+import Data.Maybe (mapMaybe, listToMaybe) import Control.Monad.IO.Class (liftIO) import Control.Exception (throwIO) import Data.Text.Lazy (toStrict) import qualified Data.Text as T+import Control.Monad (when) import Data.Monoid ((<>)) import Network.Ethereum.Web3.Provider@@ -66,7 +67,7 @@ event :: Provider p => Address -- ^ Contract address- -> (a -> IO EventAction)+ -> (a -> Web3 p EventAction) -- ^ 'Event' handler -> Web3 p ThreadId -- ^ 'Web3' wrapped event handler spawn ident@@ -74,7 +75,7 @@ _event :: (Provider p, Event a) => Address- -> (a -> IO EventAction)+ -> (a -> Web3 p EventAction) -> Web3 p ThreadId _event a f = do fid <- let ftyp = snd $ let x = undefined :: Event a => a@@ -83,11 +84,9 @@ forkWeb3 $ let loop = do liftIO (threadDelay 1000000)- changes <- fmap parseChange <$> eth_getFilterChanges fid- acts <- mapM (liftIO . f) (catMaybes changes)- if any (== TerminateEvent) acts- then return ()- else loop+ changes <- eth_getFilterChanges fid+ acts <- mapM f (mapMaybe parseChange changes)+ when (TerminateEvent `notElem` acts) loop in do loop eth_uninstallFilter fid return ()
src/Network/Ethereum/Web3/Encoding.hs view
@@ -29,10 +29,12 @@ -- | Encode value into abi-encoding represenation toData :: a -> Text+ {-# INLINE toData #-} toData = LT.toStrict . toLazyText . toDataBuilder -- | Parse encoded value fromData :: Text -> Maybe a+ {-# INLINE fromData #-} fromData = maybeResult . parse fromDataParser . LT.fromStrict instance ABIEncoding Bool where
src/Network/Ethereum/Web3/Encoding/Bytes.hs view
@@ -35,7 +35,8 @@ deriving (Eq, Ord) update :: BytesN a -> Bytes -> BytesN a-update _ a = BytesN a+{-# INLINE update #-}+update _ = BytesN instance KnownNat n => EncodingType (BytesN n) where typeName = const "bytes[N]"@@ -53,10 +54,12 @@ show = show . BS16.encode . BA.convert . unBytesN bytesBuilder :: Bytes -> B.Builder+{-# INLINE bytesBuilder #-} bytesBuilder = alignL . B.fromText . T.decodeUtf8 . BS16.encode . BA.convert bytesDecode :: T.Text -> Bytes+{-# INLINE bytesDecode #-} bytesDecode = BA.convert . fst . BS16.decode . T.encodeUtf8 -- | Dynamic length byte array
src/Network/Ethereum/Web3/Encoding/Internal.hs view
@@ -74,8 +74,9 @@ alignR = snd . align int256HexBuilder :: Integral a => a -> Builder-int256HexBuilder x | x < 0 = int256HexBuilder (2^256 + fromIntegral x)- | otherwise = alignR (B.hexadecimal x)+int256HexBuilder x+ | x < 0 = int256HexBuilder (2^256 + fromIntegral x)+ | otherwise = alignR (B.hexadecimal x) int256HexParser :: (Bits a, Integral a) => Parser a int256HexParser = do
src/Network/Ethereum/Web3/Encoding/Tuple.hs view
@@ -20,7 +20,7 @@ newtype Singleton a = Singleton { unSingleton :: a } instance (EncodingType a, ABIEncoding a) => ABIEncoding (Singleton a) where- toDataBuilder = _serialize (1, []) . unSingleton+ toDataBuilder = _serialize (1, []) . unSingleton fromDataParser = Singleton <$> (withParser sParser >>= dParser) where withParser f = f undefined
src/Network/Ethereum/Web3/Encoding/TupleTH.hs view
@@ -24,6 +24,7 @@ import qualified Data.Text.Lazy as LT import Network.Ethereum.Web3.Encoding import Data.Attoparsec.Text (Parser)+import Control.Monad (replicateM) import Language.Haskell.TH -- | Argument offset calculator@@ -68,10 +69,9 @@ -- | Generator for tupleP{N} function signature mkTuplePType :: Int -> DecQ mkTuplePType n = do- vars <- sequence (replicate n $ newName "t")- let varsT = fmap varT vars- contextT = fmap (appT [t|ABIEncoding|]) varsT- ++ fmap (appT [t|EncodingType|]) varsT+ varsT <- fmap varT <$> replicateM n (newName "t")+ let contextT = concat+ [[[t|ABIEncoding $x|], [t|EncodingType $x|]] | x <- varsT] varsTupleT = foldl appT (tupleT n) varsT sigD (mkName $ "tupleP" ++ show n) (forallT [] (cxt contextT) [t|Parser $(varsTupleT)|])@@ -79,7 +79,7 @@ -- | Generator for tupleP{N} function mkTupleP :: Int -> DecQ mkTupleP n = do- vars <- sequence (replicate n $ newName "t")+ vars <- replicateM n (newName "t") funD (mkName $ "tupleP" ++ show n) $ pure $ clause [] (normalB [|$(varE withPN) $(varE staticPN) >>= $(varE dynamicPN)|])@@ -127,14 +127,14 @@ eTupleE 13 = [|(,,,,,,,,,,,,)|] eTupleE 14 = [|(,,,,,,,,,,,,,)|] eTupleE 15 = [|(,,,,,,,,,,,,,,)|]-eTupleE _ = error "Unsupported empty tuple"+eTupleE _ = error "Unsupported tuple size" mkEncodingInst :: Int -> DecQ mkEncodingInst n = do- vars <- sequence (replicate n $ newName "t")+ vars <- replicateM n (newName "t") let varsT = fmap varT vars- contextT = fmap (appT [t|ABIEncoding|]) varsT- ++ fmap (appT [t|EncodingType|]) varsT+ contextT = concat+ [[[t|ABIEncoding $x|], [t|EncodingType $x|]] | x <- varsT] varsTupleT = foldl appT (tupleT n) varsT instanceD (cxt contextT) (appT [t|ABIEncoding|] varsTupleT) [ funD (mkName "toDataBuilder") [@@ -146,7 +146,7 @@ -- | Make a ABIEncoding tuple instance with given count of arguments mkTupleInst :: Int -> Q [Dec]-mkTupleInst n = sequence $+mkTupleInst n = sequence [ mkTuplePType n , mkTupleP n , mkEncodingInst n ]
src/Network/Ethereum/Web3/JsonRpc.hs view
@@ -73,19 +73,19 @@ remote_ f = (\u -> Web3 (decodeResponse =<< f u [])) =<< rpcUri -- | JSON-RPC request.-data Request = Request { rqMethod :: Text- , rqId :: Int- , rqParams :: Value }+data Request = Request { rqMethod :: !Text+ , rqId :: !Int+ , rqParams :: !Value } instance ToJSON Request where- toJSON rq = object $ [ "jsonrpc" .= String "2.0"- , "method" .= rqMethod rq- , "params" .= rqParams rq- , "id" .= rqId rq ]+ toJSON rq = object [ "jsonrpc" .= String "2.0"+ , "method" .= rqMethod rq+ , "params" .= rqParams rq+ , "id" .= rqId rq ] -- | JSON-RPC response. data Response = Response- { rsResult :: Either RpcError Value+ { rsResult :: !(Either RpcError Value) } deriving (Show) instance FromJSON Response where
src/Network/Ethereum/Web3/TH.hs view
@@ -18,8 +18,8 @@ -- -- main = do -- runWeb3 $ event "0x..." $--- \(Action2 n x) -> do print n--- print x+-- \(Action2 n x) -> liftIO $ do print n+-- print x -- wait -- where wait = threadDelay 1000000 >> wait -- @@@ -51,6 +51,8 @@ import Network.Ethereum.Web3.Types import Network.Ethereum.Unit +import Control.Monad (replicateM)+ import Data.Text (Text, isPrefixOf) import Data.List (groupBy, sortBy) import Data.Monoid (mconcat, (<>))@@ -76,8 +78,8 @@ -- | Instance declaration with empty context instanceD' :: Name -> TypeQ -> [DecQ] -> DecQ-instanceD' name insType insDecs =- instanceD (cxt []) (appT insType (conT name)) insDecs+instanceD' name insType =+ instanceD (cxt []) (appT insType (conT name)) -- | Simple data type declaration with one constructor dataD' :: Name -> ConQ -> [Name] -> DecQ@@ -131,7 +133,7 @@ , funD' (mkName "fromDataParser") [] fromDataP ] where indexed = map eveArgIndexed args- newVars = sequence $ replicate (length args) (newName "t")+ newVars = replicateM (length args) (newName "t") parseArg v = bindS (varP v) [|fromDataParser|] @@ -154,7 +156,7 @@ , funD' (mkName "fromDataParser") [] [|error "Function from data conversion isn't available!"|] ] where- newVars = sequence $ replicate paramLen (newName "t")+ newVars = replicateM paramLen (newName "t") sVar = mkName "a" funDtoDataB | paramLen == 0 = funD' (mkName "toDataBuilder") [conP funName []] [|ident|]@@ -189,11 +191,11 @@ -- ^ Results -> Q [Dec] funWrapper c name dname args result = do- a : b : vars <- sequence $ replicate (length args + 2) (newName "t")- let params = appsE $ (conE dname) : fmap varE vars+ a : b : vars <- replicateM (length args + 2) (newName "t")+ let params = appsE $ conE dname : fmap varE vars - sequence $ case c of- True ->+ sequence $ if c+ then [ sigD name $ [t|Provider $p => $(arrowing $ [t|Address|] : inputT ++ [outputT]) |]@@ -203,7 +205,7 @@ _ -> [|call $(varE a) Latest $(params)|] ] - False ->+ else [ sigD name $ [t|(Provider $p, Unit $(varT b)) => $(arrowing $ [t|Address|] : varT b : inputT ++ [[t|Web3 $p TxHash|]]) |]@@ -222,7 +224,7 @@ -- | Event declarations maker mkEvent :: Declaration -> Q [Dec]-mkEvent eve@(DEvent name inputs _) = sequence $+mkEvent eve@(DEvent name inputs _) = sequence [ dataD' eventName eventFields derivingD , instanceD' eventName encodingT (eventEncodigD eventName inputs) , instanceD' eventName eventT (eventFilterD (T.unpack $ eventId eve))@@ -265,8 +267,8 @@ -- | Declaration parser mkDecl :: Declaration -> Q [Dec]-mkDecl x@(DFunction{}) = mkFun x-mkDecl x@(DEvent{}) = mkEvent x+mkDecl x@DFunction{} = mkFun x+mkDecl x@DEvent{} = mkEvent x mkDecl _ = return [] -- | ABI to declarations converter
src/Network/Ethereum/Web3/Types.hs view
@@ -33,11 +33,11 @@ -- | Some peace of error response data Web3Error- = JsonRpcFail RpcError+ = JsonRpcFail !RpcError -- ^ JSON-RPC communication error- | ParserFail String+ | ParserFail !String -- ^ Error in parser state- | UserFail String+ | UserFail !String -- ^ Common head for user errors deriving (Typeable, Show, Eq) @@ -45,9 +45,9 @@ -- | JSON-RPC error message data RpcError = RpcError- { errCode :: Int- , errMessage :: Text- , errData :: Maybe Value+ { errCode :: !Int+ , errMessage :: !Text+ , errData :: !(Maybe Value) } deriving (Show, Eq) $(deriveJSON (defaultOptions@@ -55,10 +55,10 @@ -- | Low-level event filter data structure data Filter = Filter- { filterAddress :: Maybe Address- , filterTopics :: Maybe [Maybe Text]- , filterFromBlock :: Maybe Text- , filterToBlock :: Maybe Text+ { filterAddress :: !(Maybe Address)+ , filterTopics :: !(Maybe [Maybe Text])+ , filterFromBlock :: !(Maybe Text)+ , filterToBlock :: !(Maybe Text) } deriving Show $(deriveJSON (defaultOptions@@ -82,14 +82,14 @@ -- | Changes pulled by low-level call 'eth_getFilterChanges' data Change = Change- { changeLogIndex :: Text- , changeTransactionIndex :: Text- , changeTransactionHash :: Text- , changeBlockHash :: Text- , changeBlockNumber :: Text- , changeAddress :: Address- , changeData :: Text- , changeTopics :: [Text]+ { changeLogIndex :: !Text+ , changeTransactionIndex :: !Text+ , changeTransactionHash :: !Text+ , changeBlockHash :: !Text+ , changeBlockNumber :: !Text+ , changeAddress :: !Address+ , changeData :: !Text+ , changeTopics :: ![Text] } deriving Show $(deriveJSON (defaultOptions@@ -97,12 +97,12 @@ -- | The contract call params data Call = Call- { callFrom :: Maybe Address- , callTo :: Address- , callGas :: Maybe Text- , callGasPrice:: Maybe Text- , callValue :: Maybe Text- , callData :: Maybe Text+ { callFrom :: !(Maybe Address)+ , callTo :: !Address+ , callGas :: !(Maybe Text)+ , callGasPrice:: !(Maybe Text)+ , callValue :: !(Maybe Text)+ , callData :: !(Maybe Text) } deriving Show $(deriveJSON (defaultOptions@@ -121,27 +121,27 @@ -- | Transaction information data Transaction = Transaction- { txHash :: TxHash+ { txHash :: !TxHash -- ^ DATA, 32 Bytes - hash of the transaction.- , txNonce :: Text+ , txNonce :: !Text -- ^ QUANTITY - the number of transactions made by the sender prior to this one.- , txBlockHash :: Text+ , txBlockHash :: !Text -- ^ DATA, 32 Bytes - hash of the block where this transaction was in. null when its pending.- , txBlockNumber :: Text+ , txBlockNumber :: !Text -- ^ QUANTITY - block number where this transaction was in. null when its pending.- , txTransactionIndex :: Text+ , txTransactionIndex :: !Text -- ^ QUANTITY - integer of the transactions index position in the block. null when its pending.- , txFrom :: Address+ , txFrom :: !Address -- ^ DATA, 20 Bytes - address of the sender.- , txTo :: Maybe Address+ , txTo :: !(Maybe Address) -- ^ DATA, 20 Bytes - address of the receiver. null when its a contract creation transaction.- , txValue :: Text+ , txValue :: !Text -- ^ QUANTITY - value transferred in Wei.- , txGasPrice :: Text+ , txGasPrice :: !Text -- ^ QUANTITY - gas price provided by the sender in Wei.- , txGas :: Text+ , txGas :: !Text -- ^ QUANTITY - gas provided by the sender.- , txInput :: Text+ , txInput :: !Text -- ^ DATA - the data send along with the transaction. } deriving Show @@ -150,43 +150,43 @@ -- | Block information data Block = Block- { blockNumber :: Text+ { blockNumber :: !Text -- ^ QUANTITY - the block number. null when its pending block.- , blockHash :: Text+ , blockHash :: !Text -- ^ DATA, 32 Bytes - hash of the block. null when its pending block.- , blockParentHash :: Text+ , blockParentHash :: !Text -- ^ DATA, 32 Bytes - hash of the parent block.- , blockNonce :: Maybe Text+ , blockNonce :: !(Maybe Text) -- ^ DATA, 8 Bytes - hash of the generated proof-of-work. null when its pending block.- , blockSha3Uncles :: Text+ , blockSha3Uncles :: !Text -- ^ DATA, 32 Bytes - SHA3 of the uncles data in the block.- , blockLogsBloom :: Text+ , blockLogsBloom :: !Text -- ^ DATA, 256 Bytes - the bloom filter for the logs of the block. null when its pending block.- , blockTransactionsRoot :: Text+ , blockTransactionsRoot :: !Text -- ^ DATA, 32 Bytes - the root of the transaction trie of the block.- , blockStateRoot :: Text+ , blockStateRoot :: !Text -- ^ DATA, 32 Bytes - the root of the final state trie of the block.- , blockReceiptRoot :: Maybe Text+ , blockReceiptRoot :: !(Maybe Text) -- ^ DATA, 32 Bytes - the root of the receipts trie of the block.- , blockMiner :: Address+ , blockMiner :: !Address -- ^ DATA, 20 Bytes - the address of the beneficiary to whom the mining rewards were given.- , blockDifficulty :: Text+ , blockDifficulty :: !Text -- ^ QUANTITY - integer of the difficulty for this block.- , blockTotalDifficulty :: Text+ , blockTotalDifficulty :: !Text -- ^ QUANTITY - integer of the total difficulty of the chain until this block.- , blockExtraData :: Text+ , blockExtraData :: !Text -- ^ DATA - the "extra data" field of this block.- , blockSize :: Text+ , blockSize :: !Text -- ^ QUANTITY - integer the size of this block in bytes.- , blockGasLimit :: Text+ , blockGasLimit :: !Text -- ^ QUANTITY - the maximum gas allowed in this block.- , blockGasUsed :: Text+ , blockGasUsed :: !Text -- ^ QUANTITY - the total used gas by all transactions in this block.- , blockTimestamp :: Text+ , blockTimestamp :: !Text -- ^ QUANTITY - the unix timestamp for when the block was collated.- , blockTransactions :: [Transaction]+ , blockTransactions :: ![Transaction] -- ^ Array of transaction objects.- , blockUncles :: [Text]+ , blockUncles :: ![Text] -- ^ Array - Array of uncle hashes. } deriving Show
web3.cabal view
@@ -1,5 +1,5 @@ name: web3-version: 0.5.2.1+version: 0.5.3.0 cabal-version: >=1.10 build-type: Simple license: BSD3@@ -43,7 +43,7 @@ http-client >=0.4.31.2 && <0.5, attoparsec >=0.13.1.0 && <0.14, bytestring >=0.10.8.1 && <0.11,- cryptonite ==0.19.*,+ cryptonite ==0.21.*, vector >=0.11.0.0 && <0.12, memory ==0.13.*, aeson >=0.11.2.1 && <0.12,@@ -64,7 +64,7 @@ base >=4.9.0.0 && <4.10, memory ==0.13.*, text >=1.2.2.1 && <1.3,- web3 >=0.5.2.1 && <0.6+ web3 >=0.5.3.0 && <0.6 default-language: Haskell2010 default-extensions: OverloadedStrings hs-source-dirs: test