haskoin-store 0.2.1 → 0.2.2
raw patch · 6 files changed
+64/−3 lines, 6 files
Files
- CHANGELOG.md +8/−1
- app/Main.hs +1/−0
- haskoin-store.cabal +2/−2
- src/Haskoin/Store.hs +2/−0
- src/Network/Haskoin/Store/Block.hs +17/−0
- src/Network/Haskoin/Store/Types.hs +34/−0
CHANGELOG.md view
@@ -4,7 +4,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## 0.1.0+## 0.2.2+### Added+- Peer information endpoint.++### Changed+- Update `haskoin-node`.++## 0.2.1 ### Changed - Fix tests
app/Main.hs view
@@ -341,6 +341,7 @@ let bs = encode (JsonEventTx tx_hash) <> "\n" io (lazyByteString bs) _ -> return ()+ get "/peers" $ getPeersInformation (storeManager st) >>= json notFound $ raise ThingNotFound where parse_address = do
haskoin-store.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: d2db143d3299c65407b7acb184fdfa25fcc90f3a6e1c81bfc9fb15c4813ad705+-- hash: c68edb19a7064640182f5396066a228cf3a4eeacedb7b6e15a027c549bbb292f name: haskoin-store-version: 0.2.1+version: 0.2.2 synopsis: Storage and index for Bitcoin and Bitcoin Cash description: Store blocks, transactions, and balances for Bitcoin or Bitcoin Cash, and make that information via REST API. category: Bitcoin, Finance, Network
src/Haskoin/Store.hs view
@@ -22,6 +22,7 @@ , AddrOutput(..) , AddressBalance(..) , TxException(..)+ , PeerInformation(..) , withStore , getBestBlock , getBlockAtHeight@@ -32,6 +33,7 @@ , getUnspent , getBalance , getMempool+ , getPeersInformation , publishTx ) where
src/Network/Haskoin/Store/Block.hs view
@@ -20,6 +20,7 @@ , getBalance , getTx , getMempool+ , getPeersInformation ) where import Conduit@@ -1173,3 +1174,19 @@ managerGetPeer mgr p >>= \case Nothing -> return "[unknown]" Just o -> return $ fromString $ show $ onlinePeerAddress o++getPeersInformation :: MonadIO m => Manager -> m [PeerInformation]+getPeersInformation mgr = fmap toInfo <$> managerGetPeers mgr+ where+ toInfo op = PeerInformation+ { userAgent = onlinePeerUserAgent op+ , address = cs $ show $ onlinePeerAddress op+ , connected = onlinePeerConnected op+ , version = onlinePeerVersion op+ , services = onlinePeerServices op+ , relay = onlinePeerRelay op+ , block = headerHash $ nodeHeader $ onlinePeerBestBlock op+ , height = nodeHeight $ onlinePeerBestBlock op+ , nonceLocal = onlinePeerNonce op+ , nonceRemote = onlinePeerRemoteNonce op+ }
src/Network/Haskoin/Store/Types.hs view
@@ -250,6 +250,20 @@ -- ^ regular input details deriving (Show, Eq) +data PeerInformation + = PeerInformation { userAgent :: !ByteString+ , address :: !ByteString+ , connected :: !Bool+ , version :: !Word32+ , services :: !Word64+ , relay :: !Bool+ , block :: !BlockHash+ , height :: !BlockHeight+ , nonceLocal :: !Word64+ , nonceRemote :: !Word64+ }+ deriving (Show, Eq)+ isCoinbase :: DetailedInput -> Bool isCoinbase DetailedCoinbase {} = True isCoinbase _ = False@@ -800,6 +814,26 @@ instance ToJSON DetailedOutput where toJSON = object . detailedOutputPairs toEncoding = pairs . mconcat . detailedOutputPairs++-- | JSON serialization for 'PeerInformation'.+peerInformationPairs :: A.KeyValue kv => PeerInformation -> [kv]+peerInformationPairs PeerInformation {..} =+ [ "useragent" .= String (cs userAgent)+ , "address" .= String (cs address)+ , "connected" .= connected+ , "version" .= version+ , "services" .= services+ , "relay" .= relay+ , "block" .= block+ , "height" .= height+ , "noncelocal" .= nonceLocal+ , "nonceremote" .= nonceRemote+ ]++instance ToJSON PeerInformation where+ toJSON = object . peerInformationPairs+ toEncoding = pairs . mconcat . peerInformationPairs+ -- | JSON serialization for 'DetailedInput'. detailedInputPairs :: A.KeyValue kv => DetailedInput -> [kv]