web3 0.7.1.0 → 0.7.2.0
raw patch · 14 files changed
+200/−145 lines, 14 filesdep ~aesonPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: aeson
API changes (from Hackage documentation)
- Network.Ethereum.Web3.Types: BlockNumber :: Integer -> BlockNumber
- Network.Ethereum.Web3.Types: FilterId :: Integer -> FilterId
- Network.Ethereum.Web3.Types: instance Data.Aeson.Types.FromJSON.FromJSON Network.Ethereum.Web3.Types.BlockNumber
- Network.Ethereum.Web3.Types: instance Data.Aeson.Types.FromJSON.FromJSON Network.Ethereum.Web3.Types.FilterId
- Network.Ethereum.Web3.Types: instance Data.Aeson.Types.ToJSON.ToJSON Network.Ethereum.Web3.Types.BlockNumber
- Network.Ethereum.Web3.Types: instance Data.Aeson.Types.ToJSON.ToJSON Network.Ethereum.Web3.Types.FilterId
- Network.Ethereum.Web3.Types: instance GHC.Classes.Eq Network.Ethereum.Web3.Types.BlockNumber
- Network.Ethereum.Web3.Types: instance GHC.Classes.Eq Network.Ethereum.Web3.Types.FilterId
- Network.Ethereum.Web3.Types: instance GHC.Classes.Ord Network.Ethereum.Web3.Types.BlockNumber
- Network.Ethereum.Web3.Types: instance GHC.Classes.Ord Network.Ethereum.Web3.Types.FilterId
- Network.Ethereum.Web3.Types: instance GHC.Generics.Generic Network.Ethereum.Web3.Types.BlockNumber
- Network.Ethereum.Web3.Types: instance GHC.Generics.Generic Network.Ethereum.Web3.Types.FilterId
- Network.Ethereum.Web3.Types: instance GHC.Num.Num Network.Ethereum.Web3.Types.BlockNumber
- Network.Ethereum.Web3.Types: instance GHC.Read.Read Network.Ethereum.Web3.Types.BlockNumber
- Network.Ethereum.Web3.Types: instance GHC.Show.Show Network.Ethereum.Web3.Types.BlockNumber
- Network.Ethereum.Web3.Types: instance GHC.Show.Show Network.Ethereum.Web3.Types.FilterId
- Network.Ethereum.Web3.Types: newtype BlockNumber
- Network.Ethereum.Web3.Types: newtype FilterId
- Network.Ethereum.Web3.Types: type TxHash = Bytes
+ Network.Ethereum.ABI.Prim.Bytes: instance (GHC.TypeNats.KnownNat n, n GHC.TypeNats.<= 32) => Data.Aeson.Types.FromJSON.FromJSON (Network.Ethereum.ABI.Prim.Bytes.BytesN n)
+ Network.Ethereum.ABI.Prim.Bytes: instance (GHC.TypeNats.KnownNat n, n GHC.TypeNats.<= 32) => Data.Aeson.Types.ToJSON.ToJSON (Network.Ethereum.ABI.Prim.Bytes.BytesN n)
+ Network.Ethereum.Web3: [callNonce] :: Call -> !(Maybe Quantity)
+ Network.Ethereum.Web3.Types: [callNonce] :: Call -> !(Maybe Quantity)
+ Network.Ethereum.Web3.Types: instance GHC.Classes.Eq (Network.Ethereum.Web3.Types.Filter e)
+ Network.Ethereum.Web3.Types: instance GHC.Classes.Eq Network.Ethereum.Web3.Types.Call
+ Network.Ethereum.Web3.Types: instance GHC.Classes.Eq Network.Ethereum.Web3.Types.Change
+ Network.Ethereum.Web3.Types: instance GHC.Classes.Eq Network.Ethereum.Web3.Types.Transaction
+ Network.Ethereum.Web3.Types: instance GHC.Generics.Generic Network.Ethereum.Web3.Types.DefaultBlock
+ Network.Ethereum.Web3.Types: type Hash = BytesN 32
- Network.Ethereum.Contract.Method: sendTx :: Method a => Call -> a -> Web3 TxHash
+ Network.Ethereum.Contract.Method: sendTx :: Method a => Call -> a -> Web3 Hash
- Network.Ethereum.Web3: Call :: !(Maybe Address) -> !(Maybe Address) -> !(Maybe Quantity) -> !(Maybe Quantity) -> !(Maybe Quantity) -> !(Maybe Bytes) -> Call
+ Network.Ethereum.Web3: Call :: !(Maybe Address) -> !(Maybe Address) -> !(Maybe Quantity) -> !(Maybe Quantity) -> !(Maybe Quantity) -> !(Maybe Bytes) -> !(Maybe Quantity) -> Call
- Network.Ethereum.Web3: sendTx :: Method a => Call -> a -> Web3 TxHash
+ Network.Ethereum.Web3: sendTx :: Method a => Call -> a -> Web3 Hash
- Network.Ethereum.Web3.Eth: blockNumber :: Web3 BlockNumber
+ Network.Ethereum.Web3.Eth: blockNumber :: Web3 Quantity
- Network.Ethereum.Web3.Eth: getBlockByHash :: Bytes -> Web3 Block
+ Network.Ethereum.Web3.Eth: getBlockByHash :: Hash -> Web3 Block
- Network.Ethereum.Web3.Eth: getBlockFilterChanges :: Quantity -> Web3 [Bytes]
+ Network.Ethereum.Web3.Eth: getBlockFilterChanges :: Quantity -> Web3 [Hash]
- Network.Ethereum.Web3.Eth: getBlockTransactionCountByHash :: Bytes -> Web3 Quantity
+ Network.Ethereum.Web3.Eth: getBlockTransactionCountByHash :: Hash -> Web3 Quantity
- Network.Ethereum.Web3.Eth: getFilterChanges :: FilterId -> Web3 [Change]
+ Network.Ethereum.Web3.Eth: getFilterChanges :: Quantity -> Web3 [Change]
- Network.Ethereum.Web3.Eth: getStorageAt :: Address -> Quantity -> DefaultBlock -> Web3 Bytes
+ Network.Ethereum.Web3.Eth: getStorageAt :: Address -> Quantity -> DefaultBlock -> Web3 (BytesN 32)
- Network.Ethereum.Web3.Eth: getTransactionByBlockHashAndIndex :: Bytes -> Quantity -> Web3 (Maybe Transaction)
+ Network.Ethereum.Web3.Eth: getTransactionByBlockHashAndIndex :: Hash -> Quantity -> Web3 (Maybe Transaction)
- Network.Ethereum.Web3.Eth: getTransactionByHash :: Bytes -> Web3 (Maybe Transaction)
+ Network.Ethereum.Web3.Eth: getTransactionByHash :: Hash -> Web3 (Maybe Transaction)
- Network.Ethereum.Web3.Eth: getTransactionReceipt :: TxHash -> Web3 (Maybe TxReceipt)
+ Network.Ethereum.Web3.Eth: getTransactionReceipt :: Hash -> Web3 (Maybe TxReceipt)
- Network.Ethereum.Web3.Eth: getUncleByBlockHashAndIndex :: Bytes -> Quantity -> Web3 Block
+ Network.Ethereum.Web3.Eth: getUncleByBlockHashAndIndex :: Hash -> Quantity -> Web3 Block
- Network.Ethereum.Web3.Eth: getUncleCountByBlockHash :: Bytes -> Web3 Quantity
+ Network.Ethereum.Web3.Eth: getUncleCountByBlockHash :: Hash -> Web3 Quantity
- Network.Ethereum.Web3.Eth: newBlockFilter :: Web3 Bytes
+ Network.Ethereum.Web3.Eth: newBlockFilter :: Web3 Quantity
- Network.Ethereum.Web3.Eth: newFilter :: Filter e -> Web3 FilterId
+ Network.Ethereum.Web3.Eth: newFilter :: Filter e -> Web3 Quantity
- Network.Ethereum.Web3.Eth: sendRawTransaction :: Bytes -> Web3 Bytes
+ Network.Ethereum.Web3.Eth: sendRawTransaction :: Bytes -> Web3 Hash
- Network.Ethereum.Web3.Eth: sendTransaction :: Call -> Web3 Bytes
+ Network.Ethereum.Web3.Eth: sendTransaction :: Call -> Web3 Hash
- Network.Ethereum.Web3.Eth: submitHashrate :: Bytes -> Bytes -> Web3 Bool
+ Network.Ethereum.Web3.Eth: submitHashrate :: BytesN 32 -> BytesN 32 -> Web3 Bool
- Network.Ethereum.Web3.Eth: submitWork :: Bytes -> Bytes -> Bytes -> Web3 Bool
+ Network.Ethereum.Web3.Eth: submitWork :: BytesN 8 -> BytesN 32 -> BytesN 32 -> Web3 Bool
- Network.Ethereum.Web3.Eth: uninstallFilter :: FilterId -> Web3 Bool
+ Network.Ethereum.Web3.Eth: uninstallFilter :: Quantity -> Web3 Bool
- Network.Ethereum.Web3.Net: version :: Web3 Int
+ Network.Ethereum.Web3.Net: version :: Web3 Text
- Network.Ethereum.Web3.Types: Block :: !BlockNumber -> !Bytes -> !Bytes -> !(Maybe Bytes) -> !Bytes -> !Bytes -> !Bytes -> !Bytes -> !(Maybe Bytes) -> !Address -> !Quantity -> !Quantity -> !Bytes -> !Quantity -> !Quantity -> !Quantity -> !Quantity -> ![Transaction] -> ![Bytes] -> Block
+ Network.Ethereum.Web3.Types: Block :: !Quantity -> !Hash -> !Hash -> !(Maybe Bytes) -> !(BytesN 32) -> !Bytes -> !(BytesN 32) -> !(BytesN 32) -> !(Maybe (BytesN 32)) -> !Address -> !Quantity -> !Quantity -> !Bytes -> !Quantity -> !Quantity -> !Quantity -> !Quantity -> ![Transaction] -> ![Hash] -> Block
- Network.Ethereum.Web3.Types: BlockWithNumber :: BlockNumber -> DefaultBlock
+ Network.Ethereum.Web3.Types: BlockWithNumber :: Quantity -> DefaultBlock
- Network.Ethereum.Web3.Types: Call :: !(Maybe Address) -> !(Maybe Address) -> !(Maybe Quantity) -> !(Maybe Quantity) -> !(Maybe Quantity) -> !(Maybe Bytes) -> Call
+ Network.Ethereum.Web3.Types: Call :: !(Maybe Address) -> !(Maybe Address) -> !(Maybe Quantity) -> !(Maybe Quantity) -> !(Maybe Quantity) -> !(Maybe Bytes) -> !(Maybe Quantity) -> Call
- Network.Ethereum.Web3.Types: Change :: !Quantity -> !Quantity -> !Bytes -> !Bytes -> !BlockNumber -> !Address -> !Bytes -> ![Bytes] -> Change
+ Network.Ethereum.Web3.Types: Change :: !Quantity -> !Quantity -> !Hash -> !Hash -> !Quantity -> !Address -> !Bytes -> ![BytesN 32] -> Change
- Network.Ethereum.Web3.Types: Filter :: !(Maybe Address) -> !(Maybe [Maybe Bytes]) -> !DefaultBlock -> !DefaultBlock -> Filter e
+ Network.Ethereum.Web3.Types: Filter :: !(Maybe [Address]) -> !DefaultBlock -> !DefaultBlock -> !(Maybe [Maybe (BytesN 32)]) -> Filter e
- Network.Ethereum.Web3.Types: SyncActive :: BlockNumber -> BlockNumber -> BlockNumber -> SyncActive
+ Network.Ethereum.Web3.Types: SyncActive :: !Quantity -> !Quantity -> !Quantity -> SyncActive
- Network.Ethereum.Web3.Types: Transaction :: !Bytes -> !Quantity -> !Bytes -> !BlockNumber -> !Quantity -> !Address -> !(Maybe Address) -> !Quantity -> !Quantity -> !Quantity -> !Bytes -> Transaction
+ Network.Ethereum.Web3.Types: Transaction :: !Hash -> !Quantity -> !Hash -> !Quantity -> !Quantity -> !Address -> !(Maybe Address) -> !Quantity -> !Quantity -> !Quantity -> !Bytes -> Transaction
- Network.Ethereum.Web3.Types: TxReceipt :: !TxHash -> !Quantity -> !Bytes -> !BlockNumber -> !Quantity -> !Quantity -> !(Maybe Address) -> ![Value] -> !Bytes -> !Quantity -> TxReceipt
+ Network.Ethereum.Web3.Types: TxReceipt :: !Hash -> !Quantity -> !Hash -> !Quantity -> !Quantity -> !Quantity -> !(Maybe Address) -> ![Change] -> !Bytes -> !(Maybe Quantity) -> TxReceipt
- Network.Ethereum.Web3.Types: [blockHash] :: Block -> !Bytes
+ Network.Ethereum.Web3.Types: [blockHash] :: Block -> !Hash
- Network.Ethereum.Web3.Types: [blockNumber] :: Block -> !BlockNumber
+ Network.Ethereum.Web3.Types: [blockNumber] :: Block -> !Quantity
- Network.Ethereum.Web3.Types: [blockParentHash] :: Block -> !Bytes
+ Network.Ethereum.Web3.Types: [blockParentHash] :: Block -> !Hash
- Network.Ethereum.Web3.Types: [blockReceiptRoot] :: Block -> !(Maybe Bytes)
+ Network.Ethereum.Web3.Types: [blockReceiptRoot] :: Block -> !(Maybe (BytesN 32))
- Network.Ethereum.Web3.Types: [blockSha3Uncles] :: Block -> !Bytes
+ Network.Ethereum.Web3.Types: [blockSha3Uncles] :: Block -> !(BytesN 32)
- Network.Ethereum.Web3.Types: [blockStateRoot] :: Block -> !Bytes
+ Network.Ethereum.Web3.Types: [blockStateRoot] :: Block -> !(BytesN 32)
- Network.Ethereum.Web3.Types: [blockTransactionsRoot] :: Block -> !Bytes
+ Network.Ethereum.Web3.Types: [blockTransactionsRoot] :: Block -> !(BytesN 32)
- Network.Ethereum.Web3.Types: [blockUncles] :: Block -> ![Bytes]
+ Network.Ethereum.Web3.Types: [blockUncles] :: Block -> ![Hash]
- Network.Ethereum.Web3.Types: [changeBlockHash] :: Change -> !Bytes
+ Network.Ethereum.Web3.Types: [changeBlockHash] :: Change -> !Hash
- Network.Ethereum.Web3.Types: [changeBlockNumber] :: Change -> !BlockNumber
+ Network.Ethereum.Web3.Types: [changeBlockNumber] :: Change -> !Quantity
- Network.Ethereum.Web3.Types: [changeTopics] :: Change -> ![Bytes]
+ Network.Ethereum.Web3.Types: [changeTopics] :: Change -> ![BytesN 32]
- Network.Ethereum.Web3.Types: [changeTransactionHash] :: Change -> !Bytes
+ Network.Ethereum.Web3.Types: [changeTransactionHash] :: Change -> !Hash
- Network.Ethereum.Web3.Types: [filterAddress] :: Filter e -> !(Maybe Address)
+ Network.Ethereum.Web3.Types: [filterAddress] :: Filter e -> !(Maybe [Address])
- Network.Ethereum.Web3.Types: [filterTopics] :: Filter e -> !(Maybe [Maybe Bytes])
+ Network.Ethereum.Web3.Types: [filterTopics] :: Filter e -> !(Maybe [Maybe (BytesN 32)])
- Network.Ethereum.Web3.Types: [receiptBlockHash] :: TxReceipt -> !Bytes
+ Network.Ethereum.Web3.Types: [receiptBlockHash] :: TxReceipt -> !Hash
- Network.Ethereum.Web3.Types: [receiptBlockNumber] :: TxReceipt -> !BlockNumber
+ Network.Ethereum.Web3.Types: [receiptBlockNumber] :: TxReceipt -> !Quantity
- Network.Ethereum.Web3.Types: [receiptLogs] :: TxReceipt -> ![Value]
+ Network.Ethereum.Web3.Types: [receiptLogs] :: TxReceipt -> ![Change]
- Network.Ethereum.Web3.Types: [receiptStatus] :: TxReceipt -> !Quantity
+ Network.Ethereum.Web3.Types: [receiptStatus] :: TxReceipt -> !(Maybe Quantity)
- Network.Ethereum.Web3.Types: [receiptTransactionHash] :: TxReceipt -> !TxHash
+ Network.Ethereum.Web3.Types: [receiptTransactionHash] :: TxReceipt -> !Hash
- Network.Ethereum.Web3.Types: [syncCurrentBlock] :: SyncActive -> BlockNumber
+ Network.Ethereum.Web3.Types: [syncCurrentBlock] :: SyncActive -> !Quantity
- Network.Ethereum.Web3.Types: [syncHighestBlock] :: SyncActive -> BlockNumber
+ Network.Ethereum.Web3.Types: [syncHighestBlock] :: SyncActive -> !Quantity
- Network.Ethereum.Web3.Types: [syncStartingBlock] :: SyncActive -> BlockNumber
+ Network.Ethereum.Web3.Types: [syncStartingBlock] :: SyncActive -> !Quantity
- Network.Ethereum.Web3.Types: [txBlockHash] :: Transaction -> !Bytes
+ Network.Ethereum.Web3.Types: [txBlockHash] :: Transaction -> !Hash
- Network.Ethereum.Web3.Types: [txBlockNumber] :: Transaction -> !BlockNumber
+ Network.Ethereum.Web3.Types: [txBlockNumber] :: Transaction -> !Quantity
- Network.Ethereum.Web3.Types: [txHash] :: Transaction -> !Bytes
+ Network.Ethereum.Web3.Types: [txHash] :: Transaction -> !Hash
- Network.Ethereum.Web3.Web3: sha3 :: Bytes -> Web3 Bytes
+ Network.Ethereum.Web3.Web3: sha3 :: Bytes -> Web3 Hash
Files
- CHANGELOG.md +12/−0
- src/Network/Ethereum/ABI/Json.hs +19/−2
- src/Network/Ethereum/ABI/Prim/Bytes.hs +8/−0
- src/Network/Ethereum/Contract/Event.hs +12/−17
- src/Network/Ethereum/Contract/Method.hs +2/−2
- src/Network/Ethereum/Contract/TH.hs +4/−3
- src/Network/Ethereum/Web3/Eth.hs +25/−20
- src/Network/Ethereum/Web3/Net.hs +2/−1
- src/Network/Ethereum/Web3/Types.hs +104/−89
- src/Network/Ethereum/Web3/Web3.hs +2/−1
- test/Network/Ethereum/Web3/Test/ComplexStorageSpec.hs +1/−1
- test/Network/Ethereum/Web3/Test/SimpleStorageSpec.hs +5/−5
- test/Network/Ethereum/Web3/Test/Utils.hs +2/−2
- web3.cabal +2/−2
CHANGELOG.md view
@@ -1,10 +1,22 @@ # Changelog All notable changes to this project will be documented in this file. +## [0.7.2.0] 2018-05-13+### Added+- Generic JSON-RPC API documentation improvements.+- TH generator bug fixes.++### Changed+- Generic JSON-RPC API use fixed size byte arrays.++### Removed+- 'BlockNumber', 'FilterId' types replaced by 'Quantity' type+ ## [0.7.1.0] 2018-05-02 ### Added - TxReceipt and Eth.getTransactionReceipt JSON-RPC method. - Keyword escaper for TH generated names.+- Build flag to enable TLS support. ### Changed - Library dependencies bounds fixed for GHC 8.2.2-8.4.2 (stackage LTS + Nightly).
src/Network/Ethereum/ABI/Json.hs view
@@ -89,13 +89,30 @@ (DConstructor a) == (DConstructor b) = length a == length b (DFunction a _ _ _) == (DFunction b _ _ _) = a == b (DEvent a _ _) == (DEvent b _ _) = a == b- (==) _ _ = True+ (DFallback _) == (DFallback _) = True+ (==) _ _ = False instance Ord Declaration where compare (DConstructor a) (DConstructor b) = compare (length a) (length b) compare (DFunction a _ _ _) (DFunction b _ _ _) = compare a b compare (DEvent a _ _) (DEvent b _ _) = compare a b- compare _ _ = EQ+ compare (DFallback _) (DFallback _) = EQ++ compare DConstructor {} DFunction {} = LT+ compare DConstructor {} DEvent {} = LT+ compare DConstructor {} DFallback {} = LT++ compare DFunction {} DConstructor {} = GT+ compare DFunction {} DEvent {} = LT+ compare DFunction {} DFallback {} = LT++ compare DEvent {} DConstructor {} = GT+ compare DEvent {} DFunction {} = GT+ compare DEvent {} DFallback {} = LT++ compare DFallback {} DConstructor {} = GT+ compare DFallback {} DFunction {} = GT+ compare DFallback {} DEvent {} = GT $(deriveJSON (defaultOptions { sumEncoding = TaggedObject "type" "contents"
src/Network/Ethereum/ABI/Prim/Bytes.hs view
@@ -29,6 +29,7 @@ import Data.ByteArray.Encoding (Base (Base16), convertFromBase, convertToBase) import Data.ByteArray.Sized (SizedByteArray,+ unSizedByteArray, unsafeFromByteArrayAccess) import qualified Data.ByteArray.Sized as S (take) import Data.ByteString (ByteString)@@ -95,6 +96,13 @@ instance (KnownNat n, n <= 32) => IsString (BytesN n) where fromString = unsafeFromByteArrayAccess . (fromString :: String -> Bytes)++instance (KnownNat n, n <= 32) => FromJSON (BytesN n) where+ parseJSON v = do ba <- parseJSON v+ return $ unsafeFromByteArrayAccess (ba :: Bytes)++instance (KnownNat n, n <= 32) => ToJSON (BytesN n) where+ toJSON ba = toJSON (unSizedByteArray ba :: Bytes) abiGetByteString :: Get ByteString abiGetByteString = do
src/Network/Ethereum/Contract/Event.hs view
@@ -39,9 +39,8 @@ import Network.Ethereum.ABI.Event (DecodeEvent (..)) import qualified Network.Ethereum.Web3.Eth as Eth import Network.Ethereum.Web3.Provider (Web3, forkWeb3)-import Network.Ethereum.Web3.Types (BlockNumber (..), Change (..),- DefaultBlock (..), Filter (..),- FilterId)+import Network.Ethereum.Web3.Types (Change (..), DefaultBlock (..),+ Filter (..), Quantity) -- | Event callback control response data EventAction = ContinueEvent@@ -99,7 +98,7 @@ reduceEventStream :: Monad m => MachineT m k [FilterChange a] -> (a -> ReaderT Change m EventAction)- -> m (Maybe (EventAction, BlockNumber))+ -> m (Maybe (EventAction, Quantity)) reduceEventStream filterChanges handler = fmap listToMaybe . runT $ filterChanges ~> autoM (processChanges handler)@@ -115,7 +114,7 @@ processChanges :: Monad m => (a -> ReaderT Change m EventAction) -> [FilterChange a]- -> m [(EventAction, BlockNumber)]+ -> m [(EventAction, Quantity)] processChanges handler' changes = forM changes $ \FilterChange{..} -> do act <- flip runReaderT filterChangeRawChange $@@ -136,12 +135,12 @@ -- | Polls a filter from the given filterId until the target toBlock is reached. pollFilter :: forall i ni e k . DecodeEvent i ni e- => FilterId+ => Quantity -> DefaultBlock -> MachineT Web3 k [FilterChange e] pollFilter i = construct . pollPlan i where- pollPlan :: FilterId -> DefaultBlock -> PlanT k [FilterChange e] Web3 ()+ pollPlan :: Quantity -> DefaultBlock -> PlanT k [FilterChange e] Web3 () pollPlan fid end = do bn <- lift $ Eth.blockNumber if BlockWithNumber bn > end@@ -161,7 +160,7 @@ . fmap (\c@Change{..} -> FilterChange c <$> decodeEvent c) data FilterStreamState e =- FilterStreamState { fssCurrentBlock :: BlockNumber+ FilterStreamState { fssCurrentBlock :: Quantity , fssInitialFilter :: Filter e , fssWindowSize :: Integer }@@ -169,10 +168,10 @@ -- | 'filterStream' is a machine which represents taking an initial filter -- over a range of blocks b1, ... bn (where bn is possibly `Latest` or `Pending`,--- but b1 is an actual `BlockNumber`), and making a stream of filter objects+-- but b1 is an actual block number), and making a stream of filter objects -- which cover this filter in intervals of size `windowSize`. The machine -- halts whenever the `fromBlock` of a spanning filter either (1) excedes then--- initial filter's `toBlock` or (2) is greater than the chain head's `BlockNumber`.+-- initial filter's `toBlock` or (2) is greater than the chain head's block number. filterStream :: FilterStreamState e -> MachineT Web3 k (Filter e) filterStream initialPlan = unfoldPlan initialPlan filterPlan@@ -183,19 +182,15 @@ if fssCurrentBlock > end then stop else do- let to' = newTo end fssCurrentBlock fssWindowSize+ let to' = min end $ fssCurrentBlock + fromInteger fssWindowSize filter' = fssInitialFilter { filterFromBlock = BlockWithNumber fssCurrentBlock , filterToBlock = BlockWithNumber to' } yield filter'- filterPlan $ initialState { fssCurrentBlock = succBn to' }- succBn :: BlockNumber -> BlockNumber- succBn (BlockNumber bn) = BlockNumber $ bn + 1- newTo :: BlockNumber -> BlockNumber -> Integer -> BlockNumber- newTo upper (BlockNumber current) window = min upper . BlockNumber $ current + window+ filterPlan $ initialState { fssCurrentBlock = to' + 1 } -- | Coerce a 'DefaultBlock' into a numerical block number.-mkBlockNumber :: DefaultBlock -> Web3 BlockNumber+mkBlockNumber :: DefaultBlock -> Web3 Quantity mkBlockNumber bm = case bm of BlockWithNumber bn -> return bn Earliest -> return 0
src/Network/Ethereum/Contract/Method.hs view
@@ -28,7 +28,7 @@ import qualified Network.Ethereum.Web3.Eth as Eth import Network.Ethereum.Web3.Provider (Web3, Web3Error (ParserFail)) import Network.Ethereum.Web3.Types (Call (callData), DefaultBlock,- TxHash)+ Hash) class ABIPut a => Method a where selector :: Proxy a -> Bytes@@ -48,7 +48,7 @@ -- ^ Call configuration -> a -- ^ method data- -> Web3 TxHash+ -> Web3 Hash sendTx call' (dat :: a) = let sel = selector (Proxy :: Proxy a) in Eth.sendTransaction (call' { callData = Just $ sel <> encode dat })
src/Network/Ethereum/Contract/TH.hs view
@@ -72,7 +72,7 @@ import Network.Ethereum.Contract.Method (Method (..), call, sendTx) import Network.Ethereum.Web3.Provider (Web3) import Network.Ethereum.Web3.Types (Call, DefaultBlock (..),- Filter (..), TxHash)+ Filter (..), Hash) -- | Read contract ABI from file abiFrom :: QuasiQuoter@@ -158,7 +158,7 @@ ] else- [ sigD name $ [t|$(arrowing $ [t|Call|] : inputT ++ [[t|Web3 TxHash|]])|]+ [ sigD name $ [t|$(arrowing $ [t|Call|] : inputT ++ [[t|Web3 Hash|]])|] , funD' name (varP <$> a : vars) $ [|sendTx $(varE a) $(params)|] ] where@@ -190,7 +190,7 @@ [funD' 'isAnonymous [] [|const anonymous|]] , instanceD (cxt []) (pure $ ConT ''Default `AppT` (ConT ''Filter `AppT` ConT allName))- [funD' 'def [] [|Filter Nothing (Just topics) Latest Latest|] ]+ [funD' 'def [] [|Filter Nothing Latest Latest $ Just topics|] ] ] where topics = [Just (T.unpack $ eventId ev)] <> replicate (length indexedArgs) Nothing@@ -250,6 +250,7 @@ go (x : xs) = x : zipWith appendToName xs hats hats = [T.replicate n "'" | n <- [1..]] appendToName d@(DFunction n _ _ _) a = d { funName = n <> a }+ appendToName d@(DEvent n _ _) a = d { eveName = n <> a } appendToName d _ = d escapeReservedNames :: Declaration -> Declaration
src/Network/Ethereum/Web3/Eth.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE DataKinds #-} {-# LANGUAGE OverloadedStrings #-} -- |@@ -15,9 +16,12 @@ module Network.Ethereum.Web3.Eth where import Network.Ethereum.ABI.Prim.Address (Address)-import Network.Ethereum.ABI.Prim.Bytes (Bytes)+import Network.Ethereum.ABI.Prim.Bytes (Bytes, BytesN) import Network.Ethereum.Web3.Provider (Web3)-import Network.Ethereum.Web3.Types+import Network.Ethereum.Web3.Types (Block, Call, Change,+ DefaultBlock, Filter, Hash,+ Quantity, SyncingState,+ Transaction, TxReceipt) import Network.JsonRpc.TinyClient (remote) -- | Returns the current ethereum protocol version.@@ -46,7 +50,7 @@ hashrate = remote "eth_hashrate" -- | Returns the value from a storage position at a given address.-getStorageAt :: Address -> Quantity -> DefaultBlock -> Web3 Bytes+getStorageAt :: Address -> Quantity -> DefaultBlock -> Web3 (BytesN 32) {-# INLINE getStorageAt #-} getStorageAt = remote "eth_getStorageAt" @@ -56,7 +60,7 @@ getTransactionCount = remote "eth_getTransactionCount" -- | Returns the number of transactions in a block from a block matching the given block hash.-getBlockTransactionCountByHash :: Bytes -> Web3 Quantity+getBlockTransactionCountByHash :: Hash -> Web3 Quantity {-# INLINE getBlockTransactionCountByHash #-} getBlockTransactionCountByHash = remote "eth_getBlockTransactionCountByHash" @@ -68,7 +72,7 @@ -- | Returns the number of uncles in a block from a block matching the given -- block hash.-getUncleCountByBlockHash :: Bytes -> Web3 Quantity+getUncleCountByBlockHash :: Hash -> Web3 Quantity {-# INLINE getUncleCountByBlockHash #-} getUncleCountByBlockHash = remote "eth_getUncleCountByBlockHash" @@ -91,13 +95,13 @@ -- | Creates new message call transaction or a contract creation, -- if the data field contains code.-sendTransaction :: Call -> Web3 Bytes+sendTransaction :: Call -> Web3 Hash {-# INLINE sendTransaction #-} sendTransaction = remote "eth_sendTransaction" -- | Creates new message call transaction or a contract creation for signed -- transactions.-sendRawTransaction :: Bytes -> Web3 Bytes+sendRawTransaction :: Bytes -> Web3 Hash {-# INLINE sendRawTransaction #-} sendRawTransaction = remote "eth_sendRawTransaction" @@ -109,19 +113,19 @@ -- | Creates a filter object, based on filter options, to notify when the -- state changes (logs). To check if the state has changed, call -- 'getFilterChanges'.-newFilter :: Filter e -> Web3 FilterId+newFilter :: Filter e -> Web3 Quantity {-# INLINE newFilter #-} newFilter = remote "eth_newFilter" -- | Polling method for a filter, which returns an array of logs which -- occurred since last poll.-getFilterChanges :: FilterId -> Web3 [Change]+getFilterChanges :: Quantity -> Web3 [Change] {-# INLINE getFilterChanges #-} getFilterChanges = remote "eth_getFilterChanges" -- | Uninstalls a filter with given id. -- Should always be called when watch is no longer needed.-uninstallFilter :: FilterId -> Web3 Bool+uninstallFilter :: Quantity -> Web3 Bool {-# INLINE uninstallFilter #-} uninstallFilter = remote "eth_uninstallFilter" @@ -143,7 +147,7 @@ estimateGas = remote "eth_estimateGas" -- | Returns information about a block by hash.-getBlockByHash :: Bytes -> Web3 Block+getBlockByHash :: Hash -> Web3 Block {-# INLINE getBlockByHash #-} getBlockByHash = flip (remote "eth_getBlockByHash") True @@ -153,12 +157,12 @@ getBlockByNumber = flip (remote "eth_getBlockByNumber") True -- | Returns the information about a transaction requested by transaction hash.-getTransactionByHash :: Bytes -> Web3 (Maybe Transaction)+getTransactionByHash :: Hash -> Web3 (Maybe Transaction) {-# INLINE getTransactionByHash #-} getTransactionByHash = remote "eth_getTransactionByHash" -- | Returns information about a transaction by block hash and transaction index position.-getTransactionByBlockHashAndIndex :: Bytes -> Quantity -> Web3 (Maybe Transaction)+getTransactionByBlockHashAndIndex :: Hash -> Quantity -> Web3 (Maybe Transaction) {-# INLINE getTransactionByBlockHashAndIndex #-} getTransactionByBlockHashAndIndex = remote "eth_getTransactionByBlockHashAndIndex" @@ -169,7 +173,7 @@ getTransactionByBlockNumberAndIndex = remote "eth_getTransactionByBlockNumberAndIndex" -- | Returns the receipt of a transaction by transaction hash.-getTransactionReceipt :: TxHash -> Web3 (Maybe TxReceipt)+getTransactionReceipt :: Hash -> Web3 (Maybe TxReceipt) {-# INLINE getTransactionReceipt #-} getTransactionReceipt = remote "eth_getTransactionReceipt" @@ -178,18 +182,19 @@ {-# INLINE accounts #-} accounts = remote "eth_accounts" -newBlockFilter :: Web3 Bytes+-- | Creates a filter in the node, to notify when a new block arrives.+newBlockFilter :: Web3 Quantity {-# INLINE newBlockFilter #-} newBlockFilter = remote "eth_newBlockFilter" -- | Polling method for a block filter, which returns an array of block hashes -- occurred since last poll.-getBlockFilterChanges :: Quantity -> Web3 [Bytes]+getBlockFilterChanges :: Quantity -> Web3 [Hash] {-# INLINE getBlockFilterChanges #-} getBlockFilterChanges = remote "eth_getFilterChanges" -- | Returns the number of most recent block.-blockNumber :: Web3 BlockNumber+blockNumber :: Web3 Quantity {-# INLINE blockNumber #-} blockNumber = remote "eth_blockNumber" @@ -200,7 +205,7 @@ -- | Returns information about a uncle of a block by hash and uncle index -- position.-getUncleByBlockHashAndIndex :: Bytes -> Quantity -> Web3 Block+getUncleByBlockHashAndIndex :: Hash -> Quantity -> Web3 Block {-# INLINE getUncleByBlockHashAndIndex #-} getUncleByBlockHashAndIndex = remote "eth_getUncleByBlockHashAndIndex" @@ -231,7 +236,7 @@ -- 1. DATA, 8 Bytes - The nonce found (64 bits) -- 2. DATA, 32 Bytes - The header's pow-hash (256 bits) -- 3. DATA, 32 Bytes - The mix digest (256 bits)-submitWork :: Bytes -> Bytes -> Bytes -> Web3 Bool+submitWork :: BytesN 8 -> BytesN 32 -> BytesN 32 -> Web3 Bool {-# INLINE submitWork #-} submitWork = remote "eth_submitWork" @@ -239,6 +244,6 @@ -- Parameters: -- 1. Hashrate, a hexadecimal string representation (32 bytes) of the hash rate -- 2. ID, String - A random hexadecimal(32 bytes) ID identifying the client-submitHashrate :: Bytes -> Bytes -> Web3 Bool+submitHashrate :: BytesN 32 -> BytesN 32 -> Web3 Bool {-# INLINE submitHashrate #-} submitHashrate = remote "eth_submitHashrate"
src/Network/Ethereum/Web3/Net.hs view
@@ -14,12 +14,13 @@ module Network.Ethereum.Web3.Net where +import Data.Text (Text) import Network.Ethereum.Web3.Provider (Web3) import Network.Ethereum.Web3.Types (Quantity) import Network.JsonRpc.TinyClient (remote) -- | Returns the current network id.-version :: Web3 Int+version :: Web3 Text {-# INLINE version #-} version = remote "net_version"
src/Network/Ethereum/Web3/Types.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}@@ -18,24 +19,29 @@ module Network.Ethereum.Web3.Types where -import Data.Aeson-import Data.Aeson.TH-import Data.Default+import Data.Aeson (FromJSON (..), Options (fieldLabelModifier, omitNothingFields),+ ToJSON (..),+ Value (Bool, String),+ defaultOptions, object,+ (.=))+import Data.Aeson.TH (deriveJSON)+import Data.Default (Default (..)) import Data.Monoid ((<>)) import Data.Ord (Down (..)) import Data.String (IsString (..))-import qualified Data.Text as T-import qualified Data.Text.Lazy.Builder as B-import qualified Data.Text.Lazy.Builder.Int as B-import qualified Data.Text.Read as R+import qualified Data.Text as T (pack)+import qualified Data.Text.Lazy.Builder as B (toLazyText)+import qualified Data.Text.Lazy.Builder.Int as B (hexadecimal)+import qualified Data.Text.Read as R (decimal, hexadecimal) import GHC.Generics (Generic) import Data.String.Extra (toLowerFirst) import Network.Ethereum.ABI.Prim.Address (Address)-import Network.Ethereum.ABI.Prim.Bytes (Bytes)+import Network.Ethereum.ABI.Prim.Bytes (Bytes, BytesN) import Network.Ethereum.Unit -type TxHash = Bytes+-- | 32 byte type synonym for transaction and block hashes.+type Hash = BytesN 32 -- | Should be viewed as type to representing QUANTITY in Web3 JSON RPC docs --@@ -49,8 +55,11 @@ -- WRONG: 0x0400 (no leading zeroes allowed) -- WRONG: ff (must be prefixed 0x) newtype Quantity = Quantity { unQuantity :: Integer }- deriving (Show, Read, Num, Real, Enum, Eq, Ord, Generic)+ deriving (Read, Num, Real, Enum, Eq, Ord, Generic) +instance Show Quantity where+ show = show . unQuantity+ instance IsString Quantity where fromString ('0' : 'x' : hex) = case R.hexadecimal (T.pack hex) of@@ -85,107 +94,113 @@ divider = const 1 name = const "quantity" -newtype BlockNumber = BlockNumber Integer deriving (Eq, Show, Generic, Ord, Read, Num)--instance FromJSON BlockNumber where- parseJSON (String v) =- case R.hexadecimal v of- Right (x, "") -> return (BlockNumber x)- _ -> fail "Unable to parse BlockNumber!"- parseJSON _ = fail "The string is required!"--instance ToJSON BlockNumber where- toJSON (BlockNumber x) =- let hexValue = B.toLazyText (B.hexadecimal x)- in toJSON ("0x" <> hexValue)-+-- | An object with sync status data.+data SyncActive = SyncActive+ { syncStartingBlock :: !Quantity+ -- ^ QUANTITY - The block at which the import started (will only be reset, after the sync reached his head).+ , syncCurrentBlock :: !Quantity+ -- ^ QUANTITY - The current block, same as eth_blockNumber.+ , syncHighestBlock :: !Quantity+ -- ^ QUANTITY - The estimated highest block.+ } deriving (Eq, Generic, Show) -data SyncActive = SyncActive { syncStartingBlock :: BlockNumber- , syncCurrentBlock :: BlockNumber- , syncHighestBlock :: BlockNumber- } deriving (Eq, Generic, Show)-$(deriveJSON (defaultOptions { fieldLabelModifier = toLowerFirst . drop 4 }) ''SyncActive)+$(deriveJSON (defaultOptions+ { fieldLabelModifier = toLowerFirst . drop 4 }) ''SyncActive) -data SyncingState = Syncing SyncActive | NotSyncing deriving (Eq, Generic, Show)+-- | Sync state pulled by low-level call 'eth_syncing'.+data SyncingState = Syncing SyncActive | NotSyncing+ deriving (Eq, Generic, Show) instance FromJSON SyncingState where parseJSON (Bool _) = pure NotSyncing parseJSON v = Syncing <$> parseJSON v ---- | Event filter identifier-newtype FilterId = FilterId Integer- deriving (Show, Eq, Ord, Generic)--instance FromJSON FilterId where- parseJSON (String v) =- case R.hexadecimal v of- Right (x, "") -> return (FilterId x)- _ -> fail "Unable to parse FilterId!"- parseJSON _ = fail "The string is required!"--instance ToJSON FilterId where- toJSON (FilterId x) =- let hexValue = B.toLazyText (B.hexadecimal x)- in toJSON ("0x" <> hexValue)- -- | Changes pulled by low-level call 'eth_getFilterChanges', 'eth_getLogs', -- and 'eth_getFilterLogs' data Change = Change { changeLogIndex :: !Quantity+ -- ^ QUANTITY - integer of the log index position in the block. null when its pending log. , changeTransactionIndex :: !Quantity- , changeTransactionHash :: !Bytes- , changeBlockHash :: !Bytes- , changeBlockNumber :: !BlockNumber+ -- ^ QUANTITY - integer of the transactions index position log was created from. null when its pending log.+ , changeTransactionHash :: !Hash+ -- ^ DATA, 32 Bytes - hash of the transactions this log was created from. null when its pending log.+ , changeBlockHash :: !Hash+ -- ^ DATA, 32 Bytes - hash of the block where this log was in. null when its pending. null when its pending log.+ , changeBlockNumber :: !Quantity+ -- ^ QUANTITY - the block number where this log was in. null when its pending. null when its pending log. , changeAddress :: !Address+ -- ^ DATA, 20 Bytes - address from which this log originated. , changeData :: !Bytes- , changeTopics :: ![Bytes]- } deriving (Show, Generic)+ -- ^ DATA - contains one or more 32 Bytes non-indexed arguments of the log.+ , changeTopics :: ![BytesN 32]+ -- ^ Array of DATA - Array of 0 to 4 32 Bytes DATA of indexed log arguments.+ -- (In solidity: The first topic is the hash of the signature of the event+ -- (e.g. Deposit(address, bytes32, uint256)), except you declared the event with+ -- the anonymous specifier.)+ } deriving (Eq, Show, Generic) $(deriveJSON (defaultOptions { fieldLabelModifier = toLowerFirst . drop 6 }) ''Change) --- | The contract call params+-- | The contract call params. data Call = Call { callFrom :: !(Maybe Address)+ -- ^ DATA, 20 Bytes - The address the transaction is send from. , callTo :: !(Maybe Address)+ -- ^ DATA, 20 Bytes - (optional when creating new contract) The address the transaction is directed to. , callGas :: !(Maybe Quantity)+ -- ^ QUANTITY - (optional, default: 3000000) Integer of the gas provided for the transaction execution. It will return unused gas. , callGasPrice :: !(Maybe Quantity)- , callValue :: !(Maybe Quantity) -- expressed in wei+ -- ^ QUANTITY - (optional, default: To-Be-Determined) Integer of the gasPrice used for each paid gas.+ , callValue :: !(Maybe Quantity)+ -- ^ QUANTITY - (optional) Integer of the value sent with this transaction. , callData :: !(Maybe Bytes)- } deriving (Show, Generic)+ -- ^ DATA - The compiled code of a contract OR the hash of the invoked method signature and encoded parameters.+ , callNonce :: !(Maybe Quantity)+ -- ^ QUANTITY - (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.+ } deriving (Eq, Show, Generic) $(deriveJSON (defaultOptions { fieldLabelModifier = toLowerFirst . drop 4 , omitNothingFields = True }) ''Call) instance Default Call where- def = Call Nothing Nothing (Just 3000000) Nothing (Just 0) Nothing-+ def = Call Nothing Nothing (Just 3000000) Nothing (Just 0) Nothing Nothing --- | The contract call mode describe used state: latest or pending-data DefaultBlock = BlockWithNumber BlockNumber | Earliest | Latest | Pending- deriving (Show, Eq)+-- | The state of blockchain for contract call.+data DefaultBlock = BlockWithNumber Quantity+ | Earliest+ | Latest+ | Pending+ deriving (Eq, Show, Generic) instance ToJSON DefaultBlock where toJSON (BlockWithNumber bn) = toJSON bn toJSON parameter = toJSON . toLowerFirst . show $ parameter --- | Low-level event filter data structure+-- | Low-level event filter data structure. data Filter e = Filter- { filterAddress :: !(Maybe Address)- , filterTopics :: !(Maybe [Maybe Bytes])+ { filterAddress :: !(Maybe [Address])+ -- ^ DATA|Array, 20 Bytes - (optional) Contract address or a list of addresses from which logs should originate. , filterFromBlock :: !DefaultBlock+ -- ^ QUANTITY|TAG - (optional, default: "latest") Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions. , filterToBlock :: !DefaultBlock- } deriving (Show, Generic)-+ -- ^ QUANTITY|TAG - (optional, default: "latest") Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions.+ , filterTopics :: !(Maybe [Maybe (BytesN 32)])+ -- ^ Array of DATA, - (optional) Array of 32 Bytes DATA topics. Topics are order-dependent. Each topic can also be an array of DATA with "or" options.+ -- Topics are order-dependent. A transaction with a log with topics [A, B] will be matched by the following topic filters:+ -- * [] "anything"+ -- * [A] "A in first position (and anything after)"+ -- * [null, B] "anything in first position AND B in second position (and anything after)"+ -- * [A, B] "A in first position AND B in second position (and anything after)"+ -- * [[A, B], [A, B]] "(A OR B) in first position AND (A OR B) in second position (and anything after)"+ } deriving (Eq, Show, Generic) instance ToJSON (Filter e) where- toJSON f = object [ "address" .= filterAddress f- , "topics" .= filterTopics f- , "fromBlock" .= filterFromBlock f- , "toBlock" .= filterToBlock f- ]+ toJSON f = object [ "address" .= filterAddress f+ , "fromBlock" .= filterFromBlock f+ , "toBlock" .= filterToBlock f+ , "topics" .= filterTopics f ] instance Ord DefaultBlock where compare Pending Pending = EQ@@ -200,13 +215,13 @@ -- | The Receipt of a Transaction data TxReceipt = TxReceipt- { receiptTransactionHash :: !TxHash+ { receiptTransactionHash :: !Hash -- ^ DATA, 32 Bytes - hash of the transaction. , receiptTransactionIndex :: !Quantity -- ^ QUANTITY - index of the transaction.- , receiptBlockHash :: !Bytes+ , receiptBlockHash :: !Hash -- ^ DATA, 32 Bytes - hash of the block where this transaction was in. null when its pending.- , receiptBlockNumber :: !BlockNumber+ , receiptBlockNumber :: !Quantity -- ^ QUANTITY - block number where this transaction was in. , receiptCumulativeGasUsed :: !Quantity -- ^ QUANTITY - The total amount of gas used when this transaction was executed in the block.@@ -214,26 +229,26 @@ -- ^ QUANTITY - The amount of gas used by this specific transaction alone. , receiptContractAddress :: !(Maybe Address) -- ^ DATA, 20 Bytes - The contract address created, if the transaction was a contract creation, otherwise null.- , receiptLogs :: ![Value]+ , receiptLogs :: ![Change] -- ^ Array - Array of log objects, which this transaction generated. , receiptLogsBloom :: !Bytes -- ^ DATA, 256 Bytes - Bloom filter for light clients to quickly retrieve related logs.- , receiptStatus :: !Quantity+ , receiptStatus :: !(Maybe Quantity) -- ^ QUANTITY either 1 (success) or 0 (failure) } deriving (Show, Generic) $(deriveJSON (defaultOptions { fieldLabelModifier = toLowerFirst . drop 7 }) ''TxReceipt) --- | Transaction information+-- | Transaction information. data Transaction = Transaction- { txHash :: !Bytes+ { txHash :: !Hash -- ^ DATA, 32 Bytes - hash of the transaction. , txNonce :: !Quantity -- ^ QUANTITY - the number of transactions made by the sender prior to this one.- , txBlockHash :: !Bytes+ , txBlockHash :: !Hash -- ^ DATA, 32 Bytes - hash of the block where this transaction was in. null when its pending.- , txBlockNumber :: !BlockNumber+ , txBlockNumber :: !Quantity -- ^ QUANTITY - block number where this transaction was in. null when its pending. , txTransactionIndex :: !Quantity -- ^ QUANTITY - integer of the transactions index position in the block. null when its pending.@@ -249,30 +264,30 @@ -- ^ QUANTITY - gas provided by the sender. , txInput :: !Bytes -- ^ DATA - the data send along with the transaction.- } deriving (Show, Generic)+ } deriving (Eq, Show, Generic) $(deriveJSON (defaultOptions { fieldLabelModifier = toLowerFirst . drop 2 }) ''Transaction) --- | Block information+-- | Block information. data Block = Block- { blockNumber :: !BlockNumber+ { blockNumber :: !Quantity -- ^ QUANTITY - the block number. null when its pending block.- , blockHash :: !Bytes+ , blockHash :: !Hash -- ^ DATA, 32 Bytes - hash of the block. null when its pending block.- , blockParentHash :: !Bytes+ , blockParentHash :: !Hash -- ^ DATA, 32 Bytes - hash of the parent block. , blockNonce :: !(Maybe Bytes) -- ^ DATA, 8 Bytes - hash of the generated proof-of-work. null when its pending block.- , blockSha3Uncles :: !Bytes+ , blockSha3Uncles :: !(BytesN 32) -- ^ DATA, 32 Bytes - SHA3 of the uncles data in the block. , blockLogsBloom :: !Bytes -- ^ DATA, 256 Bytes - the bloom filter for the logs of the block. null when its pending block.- , blockTransactionsRoot :: !Bytes+ , blockTransactionsRoot :: !(BytesN 32) -- ^ DATA, 32 Bytes - the root of the transaction trie of the block.- , blockStateRoot :: !Bytes+ , blockStateRoot :: !(BytesN 32) -- ^ DATA, 32 Bytes - the root of the final state trie of the block.- , blockReceiptRoot :: !(Maybe Bytes)+ , blockReceiptRoot :: !(Maybe (BytesN 32)) -- ^ DATA, 32 Bytes - the root of the receipts trie of the block. , blockMiner :: !Address -- ^ DATA, 20 Bytes - the address of the beneficiary to whom the mining rewards were given.@@ -292,7 +307,7 @@ -- ^ QUANTITY - the unix timestamp for when the block was collated. , blockTransactions :: ![Transaction] -- ^ Array of transaction objects.- , blockUncles :: ![Bytes]+ , blockUncles :: ![Hash] -- ^ Array - Array of uncle hashes. } deriving (Show, Generic)
src/Network/Ethereum/Web3/Web3.hs view
@@ -17,6 +17,7 @@ import Data.Text (Text) import Network.Ethereum.ABI.Prim.Bytes (Bytes) import Network.Ethereum.Web3.Provider (Web3)+import Network.Ethereum.Web3.Types (Hash) import Network.JsonRpc.TinyClient (remote) -- | Returns current node version string.@@ -25,6 +26,6 @@ clientVersion = remote "web3_clientVersion" -- | Returns Keccak-256 (not the standardized SHA3-256) of the given data.-sha3 :: Bytes -> Web3 Bytes+sha3 :: Bytes -> Web3 Hash {-# INLINE sha3 #-} sha3 = remote "web3_sha3"
test/Network/Ethereum/Web3/Test/ComplexStorageSpec.hs view
@@ -68,7 +68,7 @@ it "can set the values of a ComplexStorage and validate them with an event" $ \primaryAccount -> do contractAddress <- Prelude.fmap fromString . liftIO $ getEnv "COMPLEXSTORAGE_CONTRACT_ADDRESS" let theCall = callFromTo primaryAccount contractAddress- fltr = (def :: Filter ValsSet) { filterAddress = Just contractAddress }+ fltr = (def :: Filter ValsSet) { filterAddress = Just [contractAddress] } -- kick off listening for the ValsSet event vals <- newEmptyMVar fiber <- runWeb3Configured' $
test/Network/Ethereum/Web3/Test/SimpleStorageSpec.hs view
@@ -94,7 +94,7 @@ theSets = [1, 2, 3] print "Setting up the filter..." fiber <- runWeb3Configured' $ do- let fltr = (def :: Filter CountSet) { filterAddress = Just contractAddress }+ let fltr = (def :: Filter CountSet) { filterAddress = Just [contractAddress] } forkWeb3 $ processUntil' var fltr ((3 ==) . length) print "Setting the values..." setValues theCall theSets@@ -111,7 +111,7 @@ start <- runWeb3Configured Eth.blockNumber let later = BlockWithNumber (start + 3) latest = BlockWithNumber (start + 8)- fltr = (def :: Filter CountSet) { filterAddress = Just contractAddress+ fltr = (def :: Filter CountSet) { filterAddress = Just [contractAddress] , filterFromBlock = later , filterToBlock = latest } print "Setting up the filter..."@@ -133,7 +133,7 @@ theSets1 = [7, 8, 9] theSets2 = [10, 11, 12] start <- runWeb3Configured Eth.blockNumber- let fltr = (def :: Filter CountSet) { filterAddress = Just contractAddress }+ let fltr = (def :: Filter CountSet) { filterAddress = Just [contractAddress] } fiber <- runWeb3Configured' $ do forkWeb3 $ processUntil var fltr ((3 ==) . length) (liftIO . putMVar blockNumberVar . changeBlockNumber) print "Running first transactions as past transactions..."@@ -144,7 +144,7 @@ awaitBlock $ end + 1 -- make past transactions definitively in past var' <- newMVar [] fiber <- runWeb3Configured' $ do- let fltr = (def :: Filter CountSet) { filterAddress = Just contractAddress+ let fltr = (def :: Filter CountSet) { filterAddress = Just [contractAddress] , filterFromBlock = BlockWithNumber start} forkWeb3 $ processUntil' var' fltr ((6 ==) . length) print "Setting more values"@@ -161,7 +161,7 @@ theSets = [4, 5, 6] start <- runWeb3Configured Eth.blockNumber blockNumberVar <- newEmptyMVar- let fltr = (def :: Filter CountSet) { filterAddress = Just contractAddress }+ let fltr = (def :: Filter CountSet) { filterAddress = Just [contractAddress] } print "Setting up filter for past transactions..." fiber <- runWeb3Configured' $ do forkWeb3 $ processUntil var fltr ((3 ==) . length) (liftIO . putMVar blockNumberVar . changeBlockNumber)
test/Network/Ethereum/Web3/Test/Utils.hs view
@@ -28,7 +28,7 @@ import Network.Ethereum.Web3.Eth (accounts, blockNumber) import Network.Ethereum.Web3.Provider (Provider (..), Web3, Web3Error, runWeb3')-import Network.Ethereum.Web3.Types (BlockNumber, Call (..))+import Network.Ethereum.Web3.Types (Call (..), Quantity) import System.Environment (lookupEnv, setEnv) import Test.Hspec.Expectations (shouldSatisfy) @@ -93,7 +93,7 @@ microtime :: IO Integer microtime = numerator . toRational . (* 1000000) <$> getPOSIXTime -awaitBlock :: BlockNumber -> IO ()+awaitBlock :: Quantity -> IO () awaitBlock bn = do bn' <- runWeb3Configured blockNumber putStrLn $ "awaiting block " ++ show bn ++ ", currently " ++ show bn'
web3.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: web3-version: 0.7.1.0+version: 0.7.2.0 license: BSD3 license-file: LICENSE copyright: Alexander Krupenkin@@ -94,7 +94,7 @@ parsec >=3.1.13.0 && <3.2, memory >=0.14.16 && <0.15, cereal >=0.5.5.0 && <0.6,- aeson >=1.2.4.0 && <1.3,+ aeson >=1.2.4.0 && <1.4, async >=2.1.1.1 && <2.3, text >=1.2.3.0 && <1.3, mtl >=2.2.2 && <2.3