{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# OPTIONS_GHC -Wno-deprecations #-}
module Haskoin.Store.Web
(
WebConfig (..)
, Except (..)
, WebLimits (..)
, WebTimeouts (..)
, runWeb
) where
import Conduit (ConduitT, await,
dropC, dropWhileC,
mapC, runConduit,
sinkList, takeC,
yield, (.|))
import Control.Applicative ((<|>))
import Control.Arrow (second)
import Control.Concurrent.STM (check)
import Control.Lens ((^.))
import Control.Monad (forM, forever, unless,
when, (<=<))
import Control.Monad.Logger (MonadLoggerIO,
logDebugS, logErrorS,
logInfoS, logWarnS)
import Control.Monad.Reader (ReaderT, ask, asks,
local, runReaderT)
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Control (liftWith, restoreT)
import Control.Monad.Trans.Maybe (MaybeT (..),
runMaybeT)
import Data.Aeson (Encoding, ToJSON (..),
Value, object, (.=))
import qualified Data.Aeson as A
import Data.Aeson.Encode.Pretty (Config (..),
defConfig,
encodePretty')
import Data.Aeson.Encoding (encodingToLazyByteString,
list)
import Data.Aeson.Text (encodeToLazyText)
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Base16 as B16
import Data.ByteString.Builder (lazyByteString)
import qualified Data.ByteString.Char8 as C
import qualified Data.ByteString.Lazy as L
import Data.Bytes.Get
import Data.Bytes.Put
import Data.Bytes.Serial
import Data.Char (isSpace)
import Data.Default (Default (..))
import Data.Function (on, (&))
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.HashSet (HashSet)
import qualified Data.HashSet as HashSet
import Data.Int (Int64)
import Data.List (nub)
import qualified Data.Map.Strict as Map
import Data.Maybe (catMaybes, fromJust,
fromMaybe, isJust,
listToMaybe, mapMaybe,
maybeToList)
import Data.Proxy (Proxy (..))
import qualified Data.Set as Set
import Data.String (fromString)
import Data.String.Conversions (cs)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Text.Lazy (toStrict)
import qualified Data.Text.Lazy as TL
import Data.Time.Clock (NominalDiffTime,
diffUTCTime)
import Data.Time.Clock.System (getSystemTime,
systemSeconds,
systemToUTCTime)
import qualified Data.Vault.Lazy as V
import Data.Word (Word32, Word64)
import Database.RocksDB (Property (..),
getProperty)
import Haskoin.Address
import qualified Haskoin.Block as H
import Haskoin.Constants
import Haskoin.Keys
import Haskoin.Network
import Haskoin.Node (Chain,
OnlinePeer (..),
PeerManager,
chainGetBest,
getPeers, sendMessage)
import Haskoin.Store.BlockStore
import Haskoin.Store.Cache
import Haskoin.Store.Common
import Haskoin.Store.Data
import Haskoin.Store.Database.Reader
import Haskoin.Store.Logic
import Haskoin.Store.Manager
import Haskoin.Store.Stats
import Haskoin.Store.WebCommon
import Haskoin.Transaction
import Haskoin.Util
import NQE (Inbox, receive,
withSubscription)
import Network.HTTP.Types (Status (..),
requestEntityTooLarge413,
status400, status403,
status404, status409,
status500, status503,
statusIsClientError,
statusIsServerError,
statusIsSuccessful)
import Network.Wai (Middleware,
Request (..),
Response,
getRequestBodyChunk,
responseLBS,
responseStatus)
import Network.Wai.Handler.Warp (defaultSettings,
setHost, setPort)
import Network.Wai.Middleware.RequestSizeLimit
import qualified Network.Wreq as Wreq
import System.IO.Unsafe (unsafeInterleaveIO)
import qualified System.Metrics as Metrics
import qualified System.Metrics.Counter as Metrics (Counter)
import qualified System.Metrics.Counter as Metrics.Counter
import qualified System.Metrics.Gauge as Metrics (Gauge)
import qualified System.Metrics.Gauge as Metrics.Gauge
import Text.Printf (printf)
import UnliftIO (MonadIO,
MonadUnliftIO, TVar,
askRunInIO,
atomically, bracket,
bracket_, handleAny,
liftIO, modifyTVar,
newTVarIO, readTVar,
readTVarIO, timeout,
withAsync,
withRunInIO,
writeTVar)
import UnliftIO.Concurrent (threadDelay)
import Web.Scotty.Internal.Types (ActionT)
import Web.Scotty.Trans (Parsable)
import qualified Web.Scotty.Trans as S
type WebT m = ActionT Except (ReaderT WebState m)
data WebLimits = WebLimits
{ WebLimits -> Word32
maxLimitCount :: !Word32
, WebLimits -> Word32
maxLimitFull :: !Word32
, WebLimits -> Word32
maxLimitOffset :: !Word32
, WebLimits -> Word32
maxLimitDefault :: !Word32
, WebLimits -> Word32
maxLimitGap :: !Word32
, WebLimits -> Word32
maxLimitInitialGap :: !Word32
}
deriving (WebLimits -> WebLimits -> Bool
(WebLimits -> WebLimits -> Bool)
-> (WebLimits -> WebLimits -> Bool) -> Eq WebLimits
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WebLimits -> WebLimits -> Bool
$c/= :: WebLimits -> WebLimits -> Bool
== :: WebLimits -> WebLimits -> Bool
$c== :: WebLimits -> WebLimits -> Bool
Eq, Int -> WebLimits -> ShowS
[WebLimits] -> ShowS
WebLimits -> String
(Int -> WebLimits -> ShowS)
-> (WebLimits -> String)
-> ([WebLimits] -> ShowS)
-> Show WebLimits
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WebLimits] -> ShowS
$cshowList :: [WebLimits] -> ShowS
show :: WebLimits -> String
$cshow :: WebLimits -> String
showsPrec :: Int -> WebLimits -> ShowS
$cshowsPrec :: Int -> WebLimits -> ShowS
Show)
instance Default WebLimits where
def :: WebLimits
def =
$WWebLimits :: Word32
-> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> WebLimits
WebLimits
{ maxLimitCount :: Word32
maxLimitCount = 200000
, maxLimitFull :: Word32
maxLimitFull = 5000
, maxLimitOffset :: Word32
maxLimitOffset = 50000
, maxLimitDefault :: Word32
maxLimitDefault = 100
, maxLimitGap :: Word32
maxLimitGap = 32
, maxLimitInitialGap :: Word32
maxLimitInitialGap = 20
}
data WebConfig = WebConfig
{ WebConfig -> String
webHost :: !String
, WebConfig -> Int
webPort :: !Int
, WebConfig -> Store
webStore :: !Store
, WebConfig -> Int
webMaxDiff :: !Int
, WebConfig -> Int
webMaxPending :: !Int
, WebConfig -> WebLimits
webMaxLimits :: !WebLimits
, WebConfig -> WebTimeouts
webTimeouts :: !WebTimeouts
, WebConfig -> String
webVersion :: !String
, WebConfig -> Bool
webNoMempool :: !Bool
, WebConfig -> Maybe Store
webStats :: !(Maybe Metrics.Store)
, WebConfig -> Int
webPriceGet :: !Int
}
data WebState = WebState
{ WebState -> WebConfig
webConfig :: !WebConfig
, WebState -> TVar (HashMap Text BinfoTicker)
webTicker :: !(TVar (HashMap Text BinfoTicker))
, WebState -> Maybe WebMetrics
webMetrics :: !(Maybe WebMetrics)
}
data WebMetrics = WebMetrics
{ WebMetrics -> StatDist
everyStat :: !StatDist
, WebMetrics -> StatDist
blockStat :: !StatDist
, WebMetrics -> StatDist
rawBlockStat :: !StatDist
, WebMetrics -> StatDist
txStat :: !StatDist
, WebMetrics -> StatDist
txsBlockStat :: !StatDist
, WebMetrics -> StatDist
txAfterStat :: !StatDist
, WebMetrics -> StatDist
postTxStat :: !StatDist
, WebMetrics -> StatDist
mempoolStat :: !StatDist
, WebMetrics -> StatDist
addrTxStat :: !StatDist
, WebMetrics -> StatDist
addrTxFullStat :: !StatDist
, WebMetrics -> StatDist
addrBalanceStat :: !StatDist
, WebMetrics -> StatDist
addrUnspentStat :: !StatDist
, WebMetrics -> StatDist
xPubStat :: !StatDist
, WebMetrics -> StatDist
xPubTxStat :: !StatDist
, WebMetrics -> StatDist
xPubTxFullStat :: !StatDist
, WebMetrics -> StatDist
xPubUnspentStat :: !StatDist
, WebMetrics -> StatDist
multiaddrStat :: !StatDist
, WebMetrics -> StatDist
rawaddrStat :: !StatDist
, WebMetrics -> StatDist
balanceStat :: !StatDist
, WebMetrics -> StatDist
unspentStat :: !StatDist
, WebMetrics -> StatDist
rawtxStat :: !StatDist
, WebMetrics -> StatDist
peerStat :: !StatDist
, WebMetrics -> StatDist
healthStat :: !StatDist
, WebMetrics -> StatDist
dbStatsStat :: !StatDist
, WebMetrics -> Gauge
eventsConnected :: !Metrics.Gauge
, WebMetrics -> Key (TVar (Maybe (WebMetrics -> StatDist)))
statKey :: !(V.Key (TVar (Maybe (WebMetrics -> StatDist))))
, WebMetrics -> Key (TVar Int)
itemsKey :: !(V.Key (TVar Int))
}
createMetrics :: MonadIO m => Metrics.Store -> m WebMetrics
createMetrics :: Store -> m WebMetrics
createMetrics s :: Store
s = IO WebMetrics -> m WebMetrics
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO WebMetrics -> m WebMetrics) -> IO WebMetrics -> m WebMetrics
forall a b. (a -> b) -> a -> b
$ do
StatDist
everyStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "all"
StatDist
blockStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "block"
StatDist
rawBlockStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "block_raw"
StatDist
txStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "tx"
StatDist
txsBlockStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "txs_block"
StatDist
txAfterStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "tx_after"
StatDist
postTxStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "tx_post"
StatDist
mempoolStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "mempool"
StatDist
addrBalanceStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "addr_balance"
StatDist
addrTxStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "addr_tx"
StatDist
addrTxFullStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "addr_tx_full"
StatDist
addrUnspentStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "addr_unspent"
StatDist
xPubStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "xpub_balance"
StatDist
xPubTxStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "xpub_tx"
StatDist
xPubTxFullStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "xpub_tx_full"
StatDist
xPubUnspentStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "xpub_unspent"
StatDist
rawaddrStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "rawaddr"
StatDist
multiaddrStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "multiaddr"
StatDist
balanceStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "balance"
StatDist
rawtxStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "rawtx"
StatDist
unspentStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "unspent"
StatDist
peerStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "peer"
StatDist
healthStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "health"
StatDist
dbStatsStat <- Text -> IO StatDist
forall (m :: * -> *). MonadIO m => Text -> m StatDist
d "dbstats"
Gauge
eventsConnected <- Text -> IO Gauge
g "events.connected"
Key (TVar (Maybe (WebMetrics -> StatDist)))
statKey <- IO (Key (TVar (Maybe (WebMetrics -> StatDist))))
forall a. IO (Key a)
V.newKey
Key (TVar Int)
itemsKey <- IO (Key (TVar Int))
forall a. IO (Key a)
V.newKey
WebMetrics -> IO WebMetrics
forall (m :: * -> *) a. Monad m => a -> m a
return $WWebMetrics :: StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> StatDist
-> Gauge
-> Key (TVar (Maybe (WebMetrics -> StatDist)))
-> Key (TVar Int)
-> WebMetrics
WebMetrics{..}
where
d :: Text -> m StatDist
d x :: Text
x = Text -> Store -> m StatDist
forall (m :: * -> *). MonadIO m => Text -> Store -> m StatDist
createStatDist ("web." Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x) Store
s
g :: Text -> IO Gauge
g x :: Text
x = Text -> Store -> IO Gauge
Metrics.createGauge ("web." Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x) Store
s
withGaugeIncrease :: MonadUnliftIO m
=> (WebMetrics -> Metrics.Gauge)
-> WebT m a
-> WebT m a
withGaugeIncrease :: (WebMetrics -> Gauge) -> WebT m a -> WebT m a
withGaugeIncrease gf :: WebMetrics -> Gauge
gf go :: WebT m a
go =
ReaderT WebState m (Maybe WebMetrics)
-> ActionT Except (ReaderT WebState m) (Maybe WebMetrics)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> Maybe WebMetrics)
-> ReaderT WebState m (Maybe WebMetrics)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WebState -> Maybe WebMetrics
webMetrics) ActionT Except (ReaderT WebState m) (Maybe WebMetrics)
-> (Maybe WebMetrics -> WebT m a) -> WebT m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> WebT m a
go
Just m :: WebMetrics
m -> do
(Either (ActionError Except) a, ScottyResponse)
s <- (Run (ActionT Except)
-> ReaderT
WebState m (Either (ActionError Except) a, ScottyResponse))
-> ActionT
Except
(ReaderT WebState m)
(Either (ActionError Except) a, ScottyResponse)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith ((Run (ActionT Except)
-> ReaderT
WebState m (Either (ActionError Except) a, ScottyResponse))
-> ActionT
Except
(ReaderT WebState m)
(Either (ActionError Except) a, ScottyResponse))
-> (Run (ActionT Except)
-> ReaderT
WebState m (Either (ActionError Except) a, ScottyResponse))
-> ActionT
Except
(ReaderT WebState m)
(Either (ActionError Except) a, ScottyResponse)
forall a b. (a -> b) -> a -> b
$ \run :: Run (ActionT Except)
run ->
ReaderT WebState m ()
-> ReaderT WebState m ()
-> ReaderT
WebState m (Either (ActionError Except) a, ScottyResponse)
-> ReaderT
WebState m (Either (ActionError Except) a, ScottyResponse)
forall (m :: * -> *) a b c.
MonadUnliftIO m =>
m a -> m b -> m c -> m c
bracket_
(WebMetrics -> ReaderT WebState m ()
forall (m :: * -> *). MonadIO m => WebMetrics -> m ()
start WebMetrics
m)
(WebMetrics -> ReaderT WebState m ()
forall (m :: * -> *). MonadIO m => WebMetrics -> m ()
end WebMetrics
m)
(WebT m a -> ReaderT WebState m (StT (ActionT Except) a)
Run (ActionT Except)
run WebT m a
go)
ReaderT WebState m (StT (ActionT Except) a) -> WebT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
m (StT t a) -> t m a
restoreT (ReaderT WebState m (StT (ActionT Except) a) -> WebT m a)
-> ReaderT WebState m (StT (ActionT Except) a) -> WebT m a
forall a b. (a -> b) -> a -> b
$ (Either (ActionError Except) a, ScottyResponse)
-> ReaderT
WebState m (Either (ActionError Except) a, ScottyResponse)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either (ActionError Except) a, ScottyResponse)
s
where
start :: WebMetrics -> m ()
start m :: WebMetrics
m = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Gauge -> IO ()
Metrics.Gauge.inc (WebMetrics -> Gauge
gf WebMetrics
m)
end :: WebMetrics -> m ()
end m :: WebMetrics
m = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Gauge -> IO ()
Metrics.Gauge.dec (WebMetrics -> Gauge
gf WebMetrics
m)
setMetrics :: MonadUnliftIO m
=> (WebMetrics -> StatDist)
-> Int
-> WebT m ()
setMetrics :: (WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics df :: WebMetrics -> StatDist
df i :: Int
i = (WebState -> Maybe WebMetrics)
-> ActionT Except (ReaderT WebState m) (Maybe WebMetrics)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WebState -> Maybe WebMetrics
webMetrics ActionT Except (ReaderT WebState m) (Maybe WebMetrics)
-> (Maybe WebMetrics -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> () -> WebT m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just m :: WebMetrics
m -> do
Request
req <- ActionT Except (ReaderT WebState m) Request
forall (m :: * -> *) e. Monad m => ActionT e m Request
S.request
let stat_var :: TVar (Maybe (WebMetrics -> StatDist))
stat_var = TVar (Maybe (WebMetrics -> StatDist))
-> Maybe (TVar (Maybe (WebMetrics -> StatDist)))
-> TVar (Maybe (WebMetrics -> StatDist))
forall a. a -> Maybe a -> a
fromMaybe TVar (Maybe (WebMetrics -> StatDist))
forall a. a
e (Maybe (TVar (Maybe (WebMetrics -> StatDist)))
-> TVar (Maybe (WebMetrics -> StatDist)))
-> Maybe (TVar (Maybe (WebMetrics -> StatDist)))
-> TVar (Maybe (WebMetrics -> StatDist))
forall a b. (a -> b) -> a -> b
$ Key (TVar (Maybe (WebMetrics -> StatDist)))
-> Vault -> Maybe (TVar (Maybe (WebMetrics -> StatDist)))
forall a. Key a -> Vault -> Maybe a
V.lookup (WebMetrics -> Key (TVar (Maybe (WebMetrics -> StatDist)))
statKey WebMetrics
m) (Request -> Vault
vault Request
req)
item_var :: TVar Int
item_var = TVar Int -> Maybe (TVar Int) -> TVar Int
forall a. a -> Maybe a -> a
fromMaybe TVar Int
forall a. a
e (Maybe (TVar Int) -> TVar Int) -> Maybe (TVar Int) -> TVar Int
forall a b. (a -> b) -> a -> b
$ Key (TVar Int) -> Vault -> Maybe (TVar Int)
forall a. Key a -> Vault -> Maybe a
V.lookup (WebMetrics -> Key (TVar Int)
itemsKey WebMetrics
m) (Request -> Vault
vault Request
req)
STM () -> WebT m ()
forall (m :: * -> *) a. MonadIO m => STM a -> m a
atomically (STM () -> WebT m ()) -> STM () -> WebT m ()
forall a b. (a -> b) -> a -> b
$ do
TVar (Maybe (WebMetrics -> StatDist))
-> Maybe (WebMetrics -> StatDist) -> STM ()
forall a. TVar a -> a -> STM ()
writeTVar TVar (Maybe (WebMetrics -> StatDist))
stat_var ((WebMetrics -> StatDist) -> Maybe (WebMetrics -> StatDist)
forall a. a -> Maybe a
Just WebMetrics -> StatDist
df)
TVar Int -> Int -> STM ()
forall a. TVar a -> a -> STM ()
writeTVar TVar Int
item_var Int
i
where
e :: a
e = String -> a
forall a. HasCallStack => String -> a
error "the ways of the warrior are yet to be mastered"
data WebTimeouts = WebTimeouts
{ WebTimeouts -> Word64
txTimeout :: !Word64
, WebTimeouts -> Word64
blockTimeout :: !Word64
}
deriving (WebTimeouts -> WebTimeouts -> Bool
(WebTimeouts -> WebTimeouts -> Bool)
-> (WebTimeouts -> WebTimeouts -> Bool) -> Eq WebTimeouts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WebTimeouts -> WebTimeouts -> Bool
$c/= :: WebTimeouts -> WebTimeouts -> Bool
== :: WebTimeouts -> WebTimeouts -> Bool
$c== :: WebTimeouts -> WebTimeouts -> Bool
Eq, Int -> WebTimeouts -> ShowS
[WebTimeouts] -> ShowS
WebTimeouts -> String
(Int -> WebTimeouts -> ShowS)
-> (WebTimeouts -> String)
-> ([WebTimeouts] -> ShowS)
-> Show WebTimeouts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WebTimeouts] -> ShowS
$cshowList :: [WebTimeouts] -> ShowS
show :: WebTimeouts -> String
$cshow :: WebTimeouts -> String
showsPrec :: Int -> WebTimeouts -> ShowS
$cshowsPrec :: Int -> WebTimeouts -> ShowS
Show)
data SerialAs = SerialAsBinary | SerialAsJSON | SerialAsPrettyJSON
deriving (SerialAs -> SerialAs -> Bool
(SerialAs -> SerialAs -> Bool)
-> (SerialAs -> SerialAs -> Bool) -> Eq SerialAs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SerialAs -> SerialAs -> Bool
$c/= :: SerialAs -> SerialAs -> Bool
== :: SerialAs -> SerialAs -> Bool
$c== :: SerialAs -> SerialAs -> Bool
Eq, Int -> SerialAs -> ShowS
[SerialAs] -> ShowS
SerialAs -> String
(Int -> SerialAs -> ShowS)
-> (SerialAs -> String) -> ([SerialAs] -> ShowS) -> Show SerialAs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SerialAs] -> ShowS
$cshowList :: [SerialAs] -> ShowS
show :: SerialAs -> String
$cshow :: SerialAs -> String
showsPrec :: Int -> SerialAs -> ShowS
$cshowsPrec :: Int -> SerialAs -> ShowS
Show)
instance Default WebTimeouts where
def :: WebTimeouts
def = $WWebTimeouts :: Word64 -> Word64 -> WebTimeouts
WebTimeouts {txTimeout :: Word64
txTimeout = 300, blockTimeout :: Word64
blockTimeout = 7200}
instance (MonadUnliftIO m, MonadLoggerIO m) =>
StoreReadBase (ReaderT WebState m) where
getNetwork :: ReaderT WebState m Network
getNetwork = CacheT (DatabaseReaderT m) Network -> ReaderT WebState m Network
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader CacheT (DatabaseReaderT m) Network
forall (m :: * -> *). StoreReadBase m => m Network
getNetwork
getBestBlock :: ReaderT WebState m (Maybe BlockHash)
getBestBlock = CacheT (DatabaseReaderT m) (Maybe BlockHash)
-> ReaderT WebState m (Maybe BlockHash)
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader CacheT (DatabaseReaderT m) (Maybe BlockHash)
forall (m :: * -> *). StoreReadBase m => m (Maybe BlockHash)
getBestBlock
getBlocksAtHeight :: Word32 -> ReaderT WebState m [BlockHash]
getBlocksAtHeight height :: Word32
height = CacheT (DatabaseReaderT m) [BlockHash]
-> ReaderT WebState m [BlockHash]
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (Word32 -> CacheT (DatabaseReaderT m) [BlockHash]
forall (m :: * -> *). StoreReadBase m => Word32 -> m [BlockHash]
getBlocksAtHeight Word32
height)
getBlock :: BlockHash -> ReaderT WebState m (Maybe BlockData)
getBlock bh :: BlockHash
bh = CacheT (DatabaseReaderT m) (Maybe BlockData)
-> ReaderT WebState m (Maybe BlockData)
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (BlockHash -> CacheT (DatabaseReaderT m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock BlockHash
bh)
getTxData :: TxHash -> ReaderT WebState m (Maybe TxData)
getTxData th :: TxHash
th = CacheT (DatabaseReaderT m) (Maybe TxData)
-> ReaderT WebState m (Maybe TxData)
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (TxHash -> CacheT (DatabaseReaderT m) (Maybe TxData)
forall (m :: * -> *). StoreReadBase m => TxHash -> m (Maybe TxData)
getTxData TxHash
th)
getSpender :: OutPoint -> ReaderT WebState m (Maybe Spender)
getSpender op :: OutPoint
op = CacheT (DatabaseReaderT m) (Maybe Spender)
-> ReaderT WebState m (Maybe Spender)
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (OutPoint -> CacheT (DatabaseReaderT m) (Maybe Spender)
forall (m :: * -> *).
StoreReadBase m =>
OutPoint -> m (Maybe Spender)
getSpender OutPoint
op)
getUnspent :: OutPoint -> ReaderT WebState m (Maybe Unspent)
getUnspent op :: OutPoint
op = CacheT (DatabaseReaderT m) (Maybe Unspent)
-> ReaderT WebState m (Maybe Unspent)
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (OutPoint -> CacheT (DatabaseReaderT m) (Maybe Unspent)
forall (m :: * -> *).
StoreReadBase m =>
OutPoint -> m (Maybe Unspent)
getUnspent OutPoint
op)
getBalance :: Address -> ReaderT WebState m (Maybe Balance)
getBalance a :: Address
a = CacheT (DatabaseReaderT m) (Maybe Balance)
-> ReaderT WebState m (Maybe Balance)
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (Address -> CacheT (DatabaseReaderT m) (Maybe Balance)
forall (m :: * -> *).
StoreReadBase m =>
Address -> m (Maybe Balance)
getBalance Address
a)
getMempool :: ReaderT WebState m [(Word64, TxHash)]
getMempool = CacheT (DatabaseReaderT m) [(Word64, TxHash)]
-> ReaderT WebState m [(Word64, TxHash)]
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader CacheT (DatabaseReaderT m) [(Word64, TxHash)]
forall (m :: * -> *). StoreReadBase m => m [(Word64, TxHash)]
getMempool
instance (MonadUnliftIO m, MonadLoggerIO m) =>
StoreReadExtra (ReaderT WebState m) where
getMaxGap :: ReaderT WebState m Word32
getMaxGap = CacheT (DatabaseReaderT m) Word32 -> ReaderT WebState m Word32
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader CacheT (DatabaseReaderT m) Word32
forall (m :: * -> *). StoreReadExtra m => m Word32
getMaxGap
getInitialGap :: ReaderT WebState m Word32
getInitialGap = CacheT (DatabaseReaderT m) Word32 -> ReaderT WebState m Word32
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader CacheT (DatabaseReaderT m) Word32
forall (m :: * -> *). StoreReadExtra m => m Word32
getInitialGap
getBalances :: [Address] -> ReaderT WebState m [Balance]
getBalances as :: [Address]
as = CacheT (DatabaseReaderT m) [Balance]
-> ReaderT WebState m [Balance]
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader ([Address] -> CacheT (DatabaseReaderT m) [Balance]
forall (m :: * -> *). StoreReadExtra m => [Address] -> m [Balance]
getBalances [Address]
as)
getAddressesTxs :: [Address] -> Limits -> ReaderT WebState m [TxRef]
getAddressesTxs as :: [Address]
as = CacheT (DatabaseReaderT m) [TxRef] -> ReaderT WebState m [TxRef]
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (CacheT (DatabaseReaderT m) [TxRef] -> ReaderT WebState m [TxRef])
-> (Limits -> CacheT (DatabaseReaderT m) [TxRef])
-> Limits
-> ReaderT WebState m [TxRef]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Address] -> Limits -> CacheT (DatabaseReaderT m) [TxRef]
forall (m :: * -> *).
StoreReadExtra m =>
[Address] -> Limits -> m [TxRef]
getAddressesTxs [Address]
as
getAddressesUnspents :: [Address] -> Limits -> ReaderT WebState m [Unspent]
getAddressesUnspents as :: [Address]
as = CacheT (DatabaseReaderT m) [Unspent]
-> ReaderT WebState m [Unspent]
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (CacheT (DatabaseReaderT m) [Unspent]
-> ReaderT WebState m [Unspent])
-> (Limits -> CacheT (DatabaseReaderT m) [Unspent])
-> Limits
-> ReaderT WebState m [Unspent]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Address] -> Limits -> CacheT (DatabaseReaderT m) [Unspent]
forall (m :: * -> *).
StoreReadExtra m =>
[Address] -> Limits -> m [Unspent]
getAddressesUnspents [Address]
as
xPubBals :: XPubSpec -> ReaderT WebState m [XPubBal]
xPubBals = CacheT (DatabaseReaderT m) [XPubBal]
-> ReaderT WebState m [XPubBal]
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (CacheT (DatabaseReaderT m) [XPubBal]
-> ReaderT WebState m [XPubBal])
-> (XPubSpec -> CacheT (DatabaseReaderT m) [XPubBal])
-> XPubSpec
-> ReaderT WebState m [XPubBal]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubSpec -> CacheT (DatabaseReaderT m) [XPubBal]
forall (m :: * -> *). StoreReadExtra m => XPubSpec -> m [XPubBal]
xPubBals
xPubSummary :: XPubSpec -> [XPubBal] -> ReaderT WebState m XPubSummary
xPubSummary xpub :: XPubSpec
xpub = CacheT (DatabaseReaderT m) XPubSummary
-> ReaderT WebState m XPubSummary
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (CacheT (DatabaseReaderT m) XPubSummary
-> ReaderT WebState m XPubSummary)
-> ([XPubBal] -> CacheT (DatabaseReaderT m) XPubSummary)
-> [XPubBal]
-> ReaderT WebState m XPubSummary
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubSpec -> [XPubBal] -> CacheT (DatabaseReaderT m) XPubSummary
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> m XPubSummary
xPubSummary XPubSpec
xpub
xPubUnspents :: XPubSpec -> [XPubBal] -> Limits -> ReaderT WebState m [XPubUnspent]
xPubUnspents xpub :: XPubSpec
xpub xbals :: [XPubBal]
xbals = CacheT (DatabaseReaderT m) [XPubUnspent]
-> ReaderT WebState m [XPubUnspent]
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (CacheT (DatabaseReaderT m) [XPubUnspent]
-> ReaderT WebState m [XPubUnspent])
-> (Limits -> CacheT (DatabaseReaderT m) [XPubUnspent])
-> Limits
-> ReaderT WebState m [XPubUnspent]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubSpec
-> [XPubBal] -> Limits -> CacheT (DatabaseReaderT m) [XPubUnspent]
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> Limits -> m [XPubUnspent]
xPubUnspents XPubSpec
xpub [XPubBal]
xbals
xPubTxs :: XPubSpec -> [XPubBal] -> Limits -> ReaderT WebState m [TxRef]
xPubTxs xpub :: XPubSpec
xpub xbals :: [XPubBal]
xbals = CacheT (DatabaseReaderT m) [TxRef] -> ReaderT WebState m [TxRef]
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (CacheT (DatabaseReaderT m) [TxRef] -> ReaderT WebState m [TxRef])
-> (Limits -> CacheT (DatabaseReaderT m) [TxRef])
-> Limits
-> ReaderT WebState m [TxRef]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubSpec
-> [XPubBal] -> Limits -> CacheT (DatabaseReaderT m) [TxRef]
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> Limits -> m [TxRef]
xPubTxs XPubSpec
xpub [XPubBal]
xbals
xPubTxCount :: XPubSpec -> [XPubBal] -> ReaderT WebState m Word32
xPubTxCount xpub :: XPubSpec
xpub = CacheT (DatabaseReaderT m) Word32 -> ReaderT WebState m Word32
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (CacheT (DatabaseReaderT m) Word32 -> ReaderT WebState m Word32)
-> ([XPubBal] -> CacheT (DatabaseReaderT m) Word32)
-> [XPubBal]
-> ReaderT WebState m Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubSpec -> [XPubBal] -> CacheT (DatabaseReaderT m) Word32
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> m Word32
xPubTxCount XPubSpec
xpub
getNumTxData :: Word64 -> ReaderT WebState m [TxData]
getNumTxData = CacheT (DatabaseReaderT m) [TxData] -> ReaderT WebState m [TxData]
forall (m :: * -> *) a.
MonadIO m =>
CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader (CacheT (DatabaseReaderT m) [TxData]
-> ReaderT WebState m [TxData])
-> (Word64 -> CacheT (DatabaseReaderT m) [TxData])
-> Word64
-> ReaderT WebState m [TxData]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> CacheT (DatabaseReaderT m) [TxData]
forall (m :: * -> *). StoreReadExtra m => Word64 -> m [TxData]
getNumTxData
instance (MonadUnliftIO m, MonadLoggerIO m) => StoreReadBase (WebT m) where
getNetwork :: WebT m Network
getNetwork = ReaderT WebState m Network -> WebT m Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ReaderT WebState m Network
forall (m :: * -> *). StoreReadBase m => m Network
getNetwork
getBestBlock :: WebT m (Maybe BlockHash)
getBestBlock = ReaderT WebState m (Maybe BlockHash) -> WebT m (Maybe BlockHash)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ReaderT WebState m (Maybe BlockHash)
forall (m :: * -> *). StoreReadBase m => m (Maybe BlockHash)
getBestBlock
getBlocksAtHeight :: Word32 -> WebT m [BlockHash]
getBlocksAtHeight = ReaderT WebState m [BlockHash] -> WebT m [BlockHash]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [BlockHash] -> WebT m [BlockHash])
-> (Word32 -> ReaderT WebState m [BlockHash])
-> Word32
-> WebT m [BlockHash]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> ReaderT WebState m [BlockHash]
forall (m :: * -> *). StoreReadBase m => Word32 -> m [BlockHash]
getBlocksAtHeight
getBlock :: BlockHash -> WebT m (Maybe BlockData)
getBlock = ReaderT WebState m (Maybe BlockData) -> WebT m (Maybe BlockData)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m (Maybe BlockData) -> WebT m (Maybe BlockData))
-> (BlockHash -> ReaderT WebState m (Maybe BlockData))
-> BlockHash
-> WebT m (Maybe BlockData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockHash -> ReaderT WebState m (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock
getTxData :: TxHash -> WebT m (Maybe TxData)
getTxData = ReaderT WebState m (Maybe TxData) -> WebT m (Maybe TxData)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m (Maybe TxData) -> WebT m (Maybe TxData))
-> (TxHash -> ReaderT WebState m (Maybe TxData))
-> TxHash
-> WebT m (Maybe TxData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxHash -> ReaderT WebState m (Maybe TxData)
forall (m :: * -> *). StoreReadBase m => TxHash -> m (Maybe TxData)
getTxData
getSpender :: OutPoint -> WebT m (Maybe Spender)
getSpender = ReaderT WebState m (Maybe Spender) -> WebT m (Maybe Spender)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m (Maybe Spender) -> WebT m (Maybe Spender))
-> (OutPoint -> ReaderT WebState m (Maybe Spender))
-> OutPoint
-> WebT m (Maybe Spender)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OutPoint -> ReaderT WebState m (Maybe Spender)
forall (m :: * -> *).
StoreReadBase m =>
OutPoint -> m (Maybe Spender)
getSpender
getUnspent :: OutPoint -> WebT m (Maybe Unspent)
getUnspent = ReaderT WebState m (Maybe Unspent) -> WebT m (Maybe Unspent)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m (Maybe Unspent) -> WebT m (Maybe Unspent))
-> (OutPoint -> ReaderT WebState m (Maybe Unspent))
-> OutPoint
-> WebT m (Maybe Unspent)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OutPoint -> ReaderT WebState m (Maybe Unspent)
forall (m :: * -> *).
StoreReadBase m =>
OutPoint -> m (Maybe Unspent)
getUnspent
getBalance :: Address -> WebT m (Maybe Balance)
getBalance = ReaderT WebState m (Maybe Balance) -> WebT m (Maybe Balance)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m (Maybe Balance) -> WebT m (Maybe Balance))
-> (Address -> ReaderT WebState m (Maybe Balance))
-> Address
-> WebT m (Maybe Balance)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Address -> ReaderT WebState m (Maybe Balance)
forall (m :: * -> *).
StoreReadBase m =>
Address -> m (Maybe Balance)
getBalance
getMempool :: WebT m [(Word64, TxHash)]
getMempool = ReaderT WebState m [(Word64, TxHash)] -> WebT m [(Word64, TxHash)]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ReaderT WebState m [(Word64, TxHash)]
forall (m :: * -> *). StoreReadBase m => m [(Word64, TxHash)]
getMempool
instance (MonadUnliftIO m, MonadLoggerIO m) => StoreReadExtra (WebT m) where
getBalances :: [Address] -> WebT m [Balance]
getBalances = ReaderT WebState m [Balance] -> WebT m [Balance]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [Balance] -> WebT m [Balance])
-> ([Address] -> ReaderT WebState m [Balance])
-> [Address]
-> WebT m [Balance]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Address] -> ReaderT WebState m [Balance]
forall (m :: * -> *). StoreReadExtra m => [Address] -> m [Balance]
getBalances
getAddressesTxs :: [Address] -> Limits -> WebT m [TxRef]
getAddressesTxs as :: [Address]
as = ReaderT WebState m [TxRef] -> WebT m [TxRef]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [TxRef] -> WebT m [TxRef])
-> (Limits -> ReaderT WebState m [TxRef])
-> Limits
-> WebT m [TxRef]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Address] -> Limits -> ReaderT WebState m [TxRef]
forall (m :: * -> *).
StoreReadExtra m =>
[Address] -> Limits -> m [TxRef]
getAddressesTxs [Address]
as
getAddressesUnspents :: [Address] -> Limits -> WebT m [Unspent]
getAddressesUnspents as :: [Address]
as = ReaderT WebState m [Unspent] -> WebT m [Unspent]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [Unspent] -> WebT m [Unspent])
-> (Limits -> ReaderT WebState m [Unspent])
-> Limits
-> WebT m [Unspent]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Address] -> Limits -> ReaderT WebState m [Unspent]
forall (m :: * -> *).
StoreReadExtra m =>
[Address] -> Limits -> m [Unspent]
getAddressesUnspents [Address]
as
xPubBals :: XPubSpec -> WebT m [XPubBal]
xPubBals = ReaderT WebState m [XPubBal] -> WebT m [XPubBal]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [XPubBal] -> WebT m [XPubBal])
-> (XPubSpec -> ReaderT WebState m [XPubBal])
-> XPubSpec
-> WebT m [XPubBal]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubSpec -> ReaderT WebState m [XPubBal]
forall (m :: * -> *). StoreReadExtra m => XPubSpec -> m [XPubBal]
xPubBals
xPubSummary :: XPubSpec -> [XPubBal] -> WebT m XPubSummary
xPubSummary xpub :: XPubSpec
xpub = ReaderT WebState m XPubSummary -> WebT m XPubSummary
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m XPubSummary -> WebT m XPubSummary)
-> ([XPubBal] -> ReaderT WebState m XPubSummary)
-> [XPubBal]
-> WebT m XPubSummary
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubSpec -> [XPubBal] -> ReaderT WebState m XPubSummary
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> m XPubSummary
xPubSummary XPubSpec
xpub
xPubUnspents :: XPubSpec -> [XPubBal] -> Limits -> WebT m [XPubUnspent]
xPubUnspents xpub :: XPubSpec
xpub xbals :: [XPubBal]
xbals = ReaderT WebState m [XPubUnspent] -> WebT m [XPubUnspent]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [XPubUnspent] -> WebT m [XPubUnspent])
-> (Limits -> ReaderT WebState m [XPubUnspent])
-> Limits
-> WebT m [XPubUnspent]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubSpec -> [XPubBal] -> Limits -> ReaderT WebState m [XPubUnspent]
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> Limits -> m [XPubUnspent]
xPubUnspents XPubSpec
xpub [XPubBal]
xbals
xPubTxs :: XPubSpec -> [XPubBal] -> Limits -> WebT m [TxRef]
xPubTxs xpub :: XPubSpec
xpub xbals :: [XPubBal]
xbals = ReaderT WebState m [TxRef] -> WebT m [TxRef]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [TxRef] -> WebT m [TxRef])
-> (Limits -> ReaderT WebState m [TxRef])
-> Limits
-> WebT m [TxRef]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubSpec -> [XPubBal] -> Limits -> ReaderT WebState m [TxRef]
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> Limits -> m [TxRef]
xPubTxs XPubSpec
xpub [XPubBal]
xbals
xPubTxCount :: XPubSpec -> [XPubBal] -> WebT m Word32
xPubTxCount xpub :: XPubSpec
xpub = ReaderT WebState m Word32 -> WebT m Word32
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Word32 -> WebT m Word32)
-> ([XPubBal] -> ReaderT WebState m Word32)
-> [XPubBal]
-> WebT m Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubSpec -> [XPubBal] -> ReaderT WebState m Word32
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> m Word32
xPubTxCount XPubSpec
xpub
getMaxGap :: WebT m Word32
getMaxGap = ReaderT WebState m Word32 -> WebT m Word32
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ReaderT WebState m Word32
forall (m :: * -> *). StoreReadExtra m => m Word32
getMaxGap
getInitialGap :: WebT m Word32
getInitialGap = ReaderT WebState m Word32 -> WebT m Word32
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ReaderT WebState m Word32
forall (m :: * -> *). StoreReadExtra m => m Word32
getInitialGap
getNumTxData :: Word64 -> WebT m [TxData]
getNumTxData = ReaderT WebState m [TxData] -> WebT m [TxData]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [TxData] -> WebT m [TxData])
-> (Word64 -> ReaderT WebState m [TxData])
-> Word64
-> WebT m [TxData]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> ReaderT WebState m [TxData]
forall (m :: * -> *). StoreReadExtra m => Word64 -> m [TxData]
getNumTxData
runWeb :: (MonadUnliftIO m, MonadLoggerIO m) => WebConfig -> m ()
runWeb :: WebConfig -> m ()
runWeb cfg :: WebConfig
cfg@WebConfig{ webHost :: WebConfig -> String
webHost = String
host
, webPort :: WebConfig -> Int
webPort = Int
port
, webStore :: WebConfig -> Store
webStore = Store
store
, webStats :: WebConfig -> Maybe Store
webStats = Maybe Store
stats
, webPriceGet :: WebConfig -> Int
webPriceGet = Int
pget
} = do
TVar (HashMap Text BinfoTicker)
ticker <- HashMap Text BinfoTicker -> m (TVar (HashMap Text BinfoTicker))
forall (m :: * -> *) a. MonadIO m => a -> m (TVar a)
newTVarIO HashMap Text BinfoTicker
forall k v. HashMap k v
HashMap.empty
Maybe WebMetrics
metrics <- (Store -> m WebMetrics) -> Maybe Store -> m (Maybe WebMetrics)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Store -> m WebMetrics
forall (m :: * -> *). MonadIO m => Store -> m WebMetrics
createMetrics Maybe Store
stats
let st :: WebState
st = $WWebState :: WebConfig
-> TVar (HashMap Text BinfoTicker) -> Maybe WebMetrics -> WebState
WebState
{ webConfig :: WebConfig
webConfig = WebConfig
cfg
, webTicker :: TVar (HashMap Text BinfoTicker)
webTicker = TVar (HashMap Text BinfoTicker)
ticker
, webMetrics :: Maybe WebMetrics
webMetrics = Maybe WebMetrics
metrics
}
net :: Network
net = Store -> Network
storeNetwork Store
store
m () -> (Async () -> m ()) -> m ()
forall (m :: * -> *) a b.
MonadUnliftIO m =>
m a -> (Async a -> m b) -> m b
withAsync (Network -> Int -> TVar (HashMap Text BinfoTicker) -> m ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Network -> Int -> TVar (HashMap Text BinfoTicker) -> m ()
price Network
net Int
pget TVar (HashMap Text BinfoTicker)
ticker) ((Async () -> m ()) -> m ()) -> (Async () -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \_ -> do
Middleware
reqLogger <- Maybe WebMetrics -> m Middleware
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Maybe WebMetrics -> m Middleware
logIt Maybe WebMetrics
metrics
m Response -> IO Response
runner <- m (m Response -> IO Response)
forall (m :: * -> *) a. MonadUnliftIO m => m (m a -> IO a)
askRunInIO
Options
-> (ReaderT WebState m Response -> IO Response)
-> ScottyT Except (ReaderT WebState m) ()
-> m ()
forall (m :: * -> *) (n :: * -> *) e.
(Monad m, MonadIO n) =>
Options -> (m Response -> IO Response) -> ScottyT e m () -> n ()
S.scottyOptsT Options
opts (m Response -> IO Response
runner (m Response -> IO Response)
-> (ReaderT WebState m Response -> m Response)
-> ReaderT WebState m Response
-> IO Response
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ReaderT WebState m Response -> WebState -> m Response
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
`runReaderT` WebState
st)) (ScottyT Except (ReaderT WebState m) () -> m ())
-> ScottyT Except (ReaderT WebState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Middleware -> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *). Middleware -> ScottyT e m ()
S.middleware Middleware
reqLogger
Middleware -> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *). Middleware -> ScottyT e m ()
S.middleware Middleware
reqSizeLimit
(Except -> ActionT Except (ReaderT WebState m) ())
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, Monad m) =>
(e -> ActionT e m ()) -> ScottyT e m ()
S.defaultHandler Except -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *). Monad m => Except -> WebT m ()
defHandler
ScottyT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
ScottyT Except (ReaderT WebState m) ()
handlePaths
ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
ActionT e m () -> ScottyT e m ()
S.notFound (ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ())
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$ Except -> ActionT Except (ReaderT WebState m) ()
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
e -> ActionT e m a
S.raise Except
ThingNotFound
where
opts :: Options
opts = Options
forall a. Default a => a
def {settings :: Settings
S.settings = Settings -> Settings
settings Settings
defaultSettings}
settings :: Settings -> Settings
settings = Int -> Settings -> Settings
setPort Int
port (Settings -> Settings)
-> (Settings -> Settings) -> Settings -> Settings
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HostPreference -> Settings -> Settings
setHost (String -> HostPreference
forall a. IsString a => String -> a
fromString String
host)
price :: (MonadUnliftIO m, MonadLoggerIO m)
=> Network
-> Int
-> TVar (HashMap Text BinfoTicker)
-> m ()
price :: Network -> Int -> TVar (HashMap Text BinfoTicker) -> m ()
price net :: Network
net pget :: Int
pget v :: TVar (HashMap Text BinfoTicker)
v =
case Maybe String
code of
Nothing -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just s :: String
s -> String -> m ()
forall (f :: * -> *) b.
(MonadUnliftIO f, MonadLogger f) =>
String -> f b
go String
s
where
code :: Maybe String
code | Network
net Network -> Network -> Bool
forall a. Eq a => a -> a -> Bool
== Network
btc = String -> Maybe String
forall a. a -> Maybe a
Just "btc"
| Network
net Network -> Network -> Bool
forall a. Eq a => a -> a -> Bool
== Network
bch = String -> Maybe String
forall a. a -> Maybe a
Just "bch"
| Bool
otherwise = Maybe String
forall a. Maybe a
Nothing
go :: String -> f b
go s :: String
s = f () -> f b
forall (f :: * -> *) a b. Applicative f => f a -> f b
forever (f () -> f b) -> f () -> f b
forall a b. (a -> b) -> a -> b
$ do
let err :: a -> m ()
err e :: a
e = $(Text
LogLevel
String -> String -> String -> CharPos -> CharPos -> Loc
Loc -> Text -> LogLevel -> Text -> m ()
forall (m :: * -> *) msg.
(MonadLogger m, ToLogStr msg) =>
Loc -> Text -> LogLevel -> msg -> m ()
monadLoggerLog :: forall (m :: * -> *) msg.
(MonadLogger m, ToLogStr msg) =>
Loc -> Text -> LogLevel -> msg -> m ()
b :: Text
a :: Text
logErrorS) "Price" (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$ String -> Text
forall a b. ConvertibleStrings a b => a -> b
cs (a -> String
forall a. Show a => a -> String
show a
e)
url :: String
url = "https://api.blockchain.info/ticker" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> "?" String -> ShowS
forall a. Semigroup a => a -> a -> a
<>
"base" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> "=" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
s
(SomeException -> f ()) -> f () -> f ()
forall (m :: * -> *) a.
MonadUnliftIO m =>
(SomeException -> m a) -> m a -> m a
handleAny SomeException -> f ()
forall (m :: * -> *) a. (MonadLogger m, Show a) => a -> m ()
err (f () -> f ()) -> f () -> f ()
forall a b. (a -> b) -> a -> b
$ do
Response (HashMap Text BinfoTicker)
r <- IO (Response (HashMap Text BinfoTicker))
-> f (Response (HashMap Text BinfoTicker))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Response (HashMap Text BinfoTicker))
-> f (Response (HashMap Text BinfoTicker)))
-> IO (Response (HashMap Text BinfoTicker))
-> f (Response (HashMap Text BinfoTicker))
forall a b. (a -> b) -> a -> b
$ Response ByteString -> IO (Response (HashMap Text BinfoTicker))
forall (m :: * -> *) a.
(MonadThrow m, FromJSON a) =>
Response ByteString -> m (Response a)
Wreq.asJSON (Response ByteString -> IO (Response (HashMap Text BinfoTicker)))
-> IO (Response ByteString)
-> IO (Response (HashMap Text BinfoTicker))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< String -> IO (Response ByteString)
Wreq.get String
url
STM () -> f ()
forall (m :: * -> *) a. MonadIO m => STM a -> m a
atomically (STM () -> f ())
-> (HashMap Text BinfoTicker -> STM ())
-> HashMap Text BinfoTicker
-> f ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TVar (HashMap Text BinfoTicker)
-> HashMap Text BinfoTicker -> STM ()
forall a. TVar a -> a -> STM ()
writeTVar TVar (HashMap Text BinfoTicker)
v (HashMap Text BinfoTicker -> f ())
-> HashMap Text BinfoTicker -> f ()
forall a b. (a -> b) -> a -> b
$ Response (HashMap Text BinfoTicker)
r Response (HashMap Text BinfoTicker)
-> Getting
(HashMap Text BinfoTicker)
(Response (HashMap Text BinfoTicker))
(HashMap Text BinfoTicker)
-> HashMap Text BinfoTicker
forall s a. s -> Getting a s a -> a
^. Getting
(HashMap Text BinfoTicker)
(Response (HashMap Text BinfoTicker))
(HashMap Text BinfoTicker)
forall body0 body1.
Lens (Response body0) (Response body1) body0 body1
Wreq.responseBody
Int -> f ()
forall (m :: * -> *). MonadIO m => Int -> m ()
threadDelay Int
pget
raise_ :: MonadIO m => Except -> WebT m a
raise_ :: Except -> WebT m a
raise_ err :: Except
err =
ReaderT WebState m (Maybe WebMetrics)
-> ActionT Except (ReaderT WebState m) (Maybe WebMetrics)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> Maybe WebMetrics)
-> ReaderT WebState m (Maybe WebMetrics)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WebState -> Maybe WebMetrics
webMetrics) ActionT Except (ReaderT WebState m) (Maybe WebMetrics)
-> (Maybe WebMetrics -> WebT m a) -> WebT m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> Except -> WebT m a
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
e -> ActionT e m a
S.raise Except
err
Just metrics :: WebMetrics
metrics -> do
let status :: Status
status = Except -> Status
errStatus Except
err
if | Status -> Bool
statusIsClientError Status
status ->
IO () -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ActionT Except (ReaderT WebState m) ())
-> IO () -> ActionT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$ StatDist -> IO ()
forall (m :: * -> *). MonadIO m => StatDist -> m ()
addClientError (WebMetrics -> StatDist
everyStat WebMetrics
metrics)
| Status -> Bool
statusIsServerError Status
status ->
IO () -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ActionT Except (ReaderT WebState m) ())
-> IO () -> ActionT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$ StatDist -> IO ()
forall (m :: * -> *). MonadIO m => StatDist -> m ()
addServerError (WebMetrics -> StatDist
everyStat WebMetrics
metrics)
| Bool
otherwise ->
() -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Except -> WebT m a
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
e -> ActionT e m a
S.raise Except
err
raise :: MonadIO m => (WebMetrics -> StatDist) -> Except -> WebT m a
raise :: (WebMetrics -> StatDist) -> Except -> WebT m a
raise metric :: WebMetrics -> StatDist
metric err :: Except
err =
ReaderT WebState m (Maybe WebMetrics)
-> ActionT Except (ReaderT WebState m) (Maybe WebMetrics)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> Maybe WebMetrics)
-> ReaderT WebState m (Maybe WebMetrics)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WebState -> Maybe WebMetrics
webMetrics) ActionT Except (ReaderT WebState m) (Maybe WebMetrics)
-> (Maybe WebMetrics -> WebT m a) -> WebT m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> Except -> WebT m a
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
e -> ActionT e m a
S.raise Except
err
Just metrics :: WebMetrics
metrics -> do
let status :: Status
status = Except -> Status
errStatus Except
err
if | Status -> Bool
statusIsClientError Status
status ->
IO () -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ActionT Except (ReaderT WebState m) ())
-> IO () -> ActionT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$ do
StatDist -> IO ()
forall (m :: * -> *). MonadIO m => StatDist -> m ()
addClientError (WebMetrics -> StatDist
everyStat WebMetrics
metrics)
StatDist -> IO ()
forall (m :: * -> *). MonadIO m => StatDist -> m ()
addClientError (WebMetrics -> StatDist
metric WebMetrics
metrics)
| Status -> Bool
statusIsServerError Status
status ->
IO () -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ActionT Except (ReaderT WebState m) ())
-> IO () -> ActionT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$ do
StatDist -> IO ()
forall (m :: * -> *). MonadIO m => StatDist -> m ()
addServerError (WebMetrics -> StatDist
everyStat WebMetrics
metrics)
StatDist -> IO ()
forall (m :: * -> *). MonadIO m => StatDist -> m ()
addServerError (WebMetrics -> StatDist
metric WebMetrics
metrics)
| Bool
otherwise ->
() -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Except -> WebT m a
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
e -> ActionT e m a
S.raise Except
err
errStatus :: Except -> Status
errStatus :: Except -> Status
errStatus ThingNotFound = Status
status404
errStatus BadRequest = Status
status400
errStatus UserError{} = Status
status400
errStatus StringError{} = Status
status400
errStatus ServerError = Status
status500
errStatus TxIndexConflict{} = Status
status409
errStatus ServerTimeout = Status
status500
defHandler :: Monad m => Except -> WebT m ()
defHandler :: Except -> WebT m ()
defHandler e :: Except
e = do
Status -> WebT m ()
forall (m :: * -> *) e. Monad m => Status -> ActionT e m ()
S.status (Status -> WebT m ()) -> Status -> WebT m ()
forall a b. (a -> b) -> a -> b
$ Except -> Status
errStatus Except
e
Except -> WebT m ()
forall a e (m :: * -> *).
(ToJSON a, ScottyError e, Monad m) =>
a -> ActionT e m ()
S.json Except
e
handlePaths :: (MonadUnliftIO m, MonadLoggerIO m)
=> S.ScottyT Except (ReaderT WebState m) ()
handlePaths :: ScottyT Except (ReaderT WebState m) ()
handlePaths = do
WebT m GetBlock
-> (GetBlock -> WebT m BlockData)
-> (Network -> BlockData -> Encoding)
-> (Network -> BlockData -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(BlockHash -> NoTx -> GetBlock
GetBlock (BlockHash -> NoTx -> GetBlock)
-> ActionT Except (ReaderT WebState m) BlockHash
-> ActionT Except (ReaderT WebState m) (NoTx -> GetBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) BlockHash
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT Except (ReaderT WebState m) (NoTx -> GetBlock)
-> ActionT Except (ReaderT WebState m) NoTx -> WebT m GetBlock
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) NoTx
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
GetBlock -> WebT m BlockData
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlock -> WebT m BlockData
scottyBlock
Network -> BlockData -> Encoding
blockDataToEncoding
Network -> BlockData -> Value
blockDataToJSON
WebT m GetBlocks
-> (GetBlocks -> WebT m (SerialList BlockData))
-> (Network -> SerialList BlockData -> Encoding)
-> (Network -> SerialList BlockData -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
([BlockHash] -> NoTx -> GetBlocks
GetBlocks ([BlockHash] -> NoTx -> GetBlocks)
-> ActionT Except (ReaderT WebState m) [BlockHash]
-> ActionT Except (ReaderT WebState m) (NoTx -> GetBlocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) [BlockHash]
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
param ActionT Except (ReaderT WebState m) (NoTx -> GetBlocks)
-> ActionT Except (ReaderT WebState m) NoTx -> WebT m GetBlocks
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) NoTx
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
(([BlockData] -> SerialList BlockData)
-> ActionT Except (ReaderT WebState m) [BlockData]
-> WebT m (SerialList BlockData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [BlockData] -> SerialList BlockData
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [BlockData]
-> WebT m (SerialList BlockData))
-> (GetBlocks -> ActionT Except (ReaderT WebState m) [BlockData])
-> GetBlocks
-> WebT m (SerialList BlockData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetBlocks -> ActionT Except (ReaderT WebState m) [BlockData]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlocks -> WebT m [BlockData]
scottyBlocks)
(\n :: Network
n -> (BlockData -> Encoding) -> [BlockData] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> BlockData -> Encoding
blockDataToEncoding Network
n) ([BlockData] -> Encoding)
-> (SerialList BlockData -> [BlockData])
-> SerialList BlockData
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList BlockData -> [BlockData]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> BlockData -> Value) -> Network -> [BlockData] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> BlockData -> Value
blockDataToJSON Network
n ([BlockData] -> Value)
-> (SerialList BlockData -> [BlockData])
-> SerialList BlockData
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList BlockData -> [BlockData]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetBlockRaw
-> (GetBlockRaw -> WebT m (RawResult Block))
-> (Network -> RawResult Block -> Encoding)
-> (Network -> RawResult Block -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(BlockHash -> GetBlockRaw
GetBlockRaw (BlockHash -> GetBlockRaw)
-> ActionT Except (ReaderT WebState m) BlockHash
-> WebT m GetBlockRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) BlockHash
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy)
GetBlockRaw -> WebT m (RawResult Block)
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlockRaw -> WebT m (RawResult Block)
scottyBlockRaw
((RawResult Block -> Encoding)
-> Network -> RawResult Block -> Encoding
forall a b. a -> b -> a
const RawResult Block -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((RawResult Block -> Value) -> Network -> RawResult Block -> Value
forall a b. a -> b -> a
const RawResult Block -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetBlockBest
-> (GetBlockBest -> WebT m BlockData)
-> (Network -> BlockData -> Encoding)
-> (Network -> BlockData -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(NoTx -> GetBlockBest
GetBlockBest (NoTx -> GetBlockBest)
-> ActionT Except (ReaderT WebState m) NoTx -> WebT m GetBlockBest
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) NoTx
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
GetBlockBest -> WebT m BlockData
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlockBest -> WebT m BlockData
scottyBlockBest
Network -> BlockData -> Encoding
blockDataToEncoding
Network -> BlockData -> Value
blockDataToJSON
WebT m GetBlockBestRaw
-> (GetBlockBestRaw -> WebT m (RawResult Block))
-> (Network -> RawResult Block -> Encoding)
-> (Network -> RawResult Block -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(GetBlockBestRaw
GetBlockBestRaw GetBlockBestRaw
-> (GetBlockBestRaw -> WebT m GetBlockBestRaw)
-> WebT m GetBlockBestRaw
forall a b. a -> (a -> b) -> b
& GetBlockBestRaw -> WebT m GetBlockBestRaw
forall (m :: * -> *) a. Monad m => a -> m a
return)
GetBlockBestRaw -> WebT m (RawResult Block)
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlockBestRaw -> WebT m (RawResult Block)
scottyBlockBestRaw
((RawResult Block -> Encoding)
-> Network -> RawResult Block -> Encoding
forall a b. a -> b -> a
const RawResult Block -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((RawResult Block -> Value) -> Network -> RawResult Block -> Value
forall a b. a -> b -> a
const RawResult Block -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetBlockLatest
-> (GetBlockLatest -> WebT m (SerialList BlockData))
-> (Network -> SerialList BlockData -> Encoding)
-> (Network -> SerialList BlockData -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(NoTx -> GetBlockLatest
GetBlockLatest (NoTx -> GetBlockLatest)
-> ActionT Except (ReaderT WebState m) NoTx
-> WebT m GetBlockLatest
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) NoTx
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
(([BlockData] -> SerialList BlockData)
-> ActionT Except (ReaderT WebState m) [BlockData]
-> WebT m (SerialList BlockData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [BlockData] -> SerialList BlockData
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [BlockData]
-> WebT m (SerialList BlockData))
-> (GetBlockLatest
-> ActionT Except (ReaderT WebState m) [BlockData])
-> GetBlockLatest
-> WebT m (SerialList BlockData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetBlockLatest -> ActionT Except (ReaderT WebState m) [BlockData]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlockLatest -> WebT m [BlockData]
scottyBlockLatest)
(\n :: Network
n -> (BlockData -> Encoding) -> [BlockData] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> BlockData -> Encoding
blockDataToEncoding Network
n) ([BlockData] -> Encoding)
-> (SerialList BlockData -> [BlockData])
-> SerialList BlockData
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList BlockData -> [BlockData]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> BlockData -> Value) -> Network -> [BlockData] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> BlockData -> Value
blockDataToJSON Network
n ([BlockData] -> Value)
-> (SerialList BlockData -> [BlockData])
-> SerialList BlockData
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList BlockData -> [BlockData]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetBlockHeight
-> (GetBlockHeight -> WebT m (SerialList BlockData))
-> (Network -> SerialList BlockData -> Encoding)
-> (Network -> SerialList BlockData -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(HeightParam -> NoTx -> GetBlockHeight
GetBlockHeight (HeightParam -> NoTx -> GetBlockHeight)
-> ActionT Except (ReaderT WebState m) HeightParam
-> ActionT Except (ReaderT WebState m) (NoTx -> GetBlockHeight)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) HeightParam
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT Except (ReaderT WebState m) (NoTx -> GetBlockHeight)
-> ActionT Except (ReaderT WebState m) NoTx
-> WebT m GetBlockHeight
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) NoTx
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
(([BlockData] -> SerialList BlockData)
-> ActionT Except (ReaderT WebState m) [BlockData]
-> WebT m (SerialList BlockData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [BlockData] -> SerialList BlockData
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [BlockData]
-> WebT m (SerialList BlockData))
-> (GetBlockHeight
-> ActionT Except (ReaderT WebState m) [BlockData])
-> GetBlockHeight
-> WebT m (SerialList BlockData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetBlockHeight -> ActionT Except (ReaderT WebState m) [BlockData]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlockHeight -> WebT m [BlockData]
scottyBlockHeight)
(\n :: Network
n -> (BlockData -> Encoding) -> [BlockData] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> BlockData -> Encoding
blockDataToEncoding Network
n) ([BlockData] -> Encoding)
-> (SerialList BlockData -> [BlockData])
-> SerialList BlockData
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList BlockData -> [BlockData]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> BlockData -> Value) -> Network -> [BlockData] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> BlockData -> Value
blockDataToJSON Network
n ([BlockData] -> Value)
-> (SerialList BlockData -> [BlockData])
-> SerialList BlockData
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList BlockData -> [BlockData]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetBlockHeights
-> (GetBlockHeights -> WebT m (SerialList BlockData))
-> (Network -> SerialList BlockData -> Encoding)
-> (Network -> SerialList BlockData -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(HeightsParam -> NoTx -> GetBlockHeights
GetBlockHeights (HeightsParam -> NoTx -> GetBlockHeights)
-> ActionT Except (ReaderT WebState m) HeightsParam
-> ActionT Except (ReaderT WebState m) (NoTx -> GetBlockHeights)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) HeightsParam
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
param ActionT Except (ReaderT WebState m) (NoTx -> GetBlockHeights)
-> ActionT Except (ReaderT WebState m) NoTx
-> WebT m GetBlockHeights
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) NoTx
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
(([BlockData] -> SerialList BlockData)
-> ActionT Except (ReaderT WebState m) [BlockData]
-> WebT m (SerialList BlockData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [BlockData] -> SerialList BlockData
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [BlockData]
-> WebT m (SerialList BlockData))
-> (GetBlockHeights
-> ActionT Except (ReaderT WebState m) [BlockData])
-> GetBlockHeights
-> WebT m (SerialList BlockData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetBlockHeights -> ActionT Except (ReaderT WebState m) [BlockData]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlockHeights -> WebT m [BlockData]
scottyBlockHeights)
(\n :: Network
n -> (BlockData -> Encoding) -> [BlockData] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> BlockData -> Encoding
blockDataToEncoding Network
n) ([BlockData] -> Encoding)
-> (SerialList BlockData -> [BlockData])
-> SerialList BlockData
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList BlockData -> [BlockData]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> BlockData -> Value) -> Network -> [BlockData] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> BlockData -> Value
blockDataToJSON Network
n ([BlockData] -> Value)
-> (SerialList BlockData -> [BlockData])
-> SerialList BlockData
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList BlockData -> [BlockData]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetBlockHeightRaw
-> (GetBlockHeightRaw -> WebT m (RawResultList Block))
-> (Network -> RawResultList Block -> Encoding)
-> (Network -> RawResultList Block -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(HeightParam -> GetBlockHeightRaw
GetBlockHeightRaw (HeightParam -> GetBlockHeightRaw)
-> ActionT Except (ReaderT WebState m) HeightParam
-> WebT m GetBlockHeightRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) HeightParam
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy)
GetBlockHeightRaw -> WebT m (RawResultList Block)
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlockHeightRaw -> WebT m (RawResultList Block)
scottyBlockHeightRaw
((RawResultList Block -> Encoding)
-> Network -> RawResultList Block -> Encoding
forall a b. a -> b -> a
const RawResultList Block -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((RawResultList Block -> Value)
-> Network -> RawResultList Block -> Value
forall a b. a -> b -> a
const RawResultList Block -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetBlockTime
-> (GetBlockTime -> WebT m BlockData)
-> (Network -> BlockData -> Encoding)
-> (Network -> BlockData -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(TimeParam -> NoTx -> GetBlockTime
GetBlockTime (TimeParam -> NoTx -> GetBlockTime)
-> ActionT Except (ReaderT WebState m) TimeParam
-> ActionT Except (ReaderT WebState m) (NoTx -> GetBlockTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) TimeParam
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT Except (ReaderT WebState m) (NoTx -> GetBlockTime)
-> ActionT Except (ReaderT WebState m) NoTx -> WebT m GetBlockTime
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) NoTx
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
GetBlockTime -> WebT m BlockData
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlockTime -> WebT m BlockData
scottyBlockTime
Network -> BlockData -> Encoding
blockDataToEncoding
Network -> BlockData -> Value
blockDataToJSON
WebT m GetBlockTimeRaw
-> (GetBlockTimeRaw -> WebT m (RawResult Block))
-> (Network -> RawResult Block -> Encoding)
-> (Network -> RawResult Block -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(TimeParam -> GetBlockTimeRaw
GetBlockTimeRaw (TimeParam -> GetBlockTimeRaw)
-> ActionT Except (ReaderT WebState m) TimeParam
-> WebT m GetBlockTimeRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) TimeParam
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy)
GetBlockTimeRaw -> WebT m (RawResult Block)
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlockTimeRaw -> WebT m (RawResult Block)
scottyBlockTimeRaw
((RawResult Block -> Encoding)
-> Network -> RawResult Block -> Encoding
forall a b. a -> b -> a
const RawResult Block -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((RawResult Block -> Value) -> Network -> RawResult Block -> Value
forall a b. a -> b -> a
const RawResult Block -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetBlockMTP
-> (GetBlockMTP -> WebT m BlockData)
-> (Network -> BlockData -> Encoding)
-> (Network -> BlockData -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(TimeParam -> NoTx -> GetBlockMTP
GetBlockMTP (TimeParam -> NoTx -> GetBlockMTP)
-> ActionT Except (ReaderT WebState m) TimeParam
-> ActionT Except (ReaderT WebState m) (NoTx -> GetBlockMTP)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) TimeParam
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT Except (ReaderT WebState m) (NoTx -> GetBlockMTP)
-> ActionT Except (ReaderT WebState m) NoTx -> WebT m GetBlockMTP
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) NoTx
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
GetBlockMTP -> WebT m BlockData
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlockMTP -> WebT m BlockData
scottyBlockMTP
Network -> BlockData -> Encoding
blockDataToEncoding
Network -> BlockData -> Value
blockDataToJSON
WebT m GetBlockMTPRaw
-> (GetBlockMTPRaw -> WebT m (RawResult Block))
-> (Network -> RawResult Block -> Encoding)
-> (Network -> RawResult Block -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(TimeParam -> GetBlockMTPRaw
GetBlockMTPRaw (TimeParam -> GetBlockMTPRaw)
-> ActionT Except (ReaderT WebState m) TimeParam
-> WebT m GetBlockMTPRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) TimeParam
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy)
GetBlockMTPRaw -> WebT m (RawResult Block)
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetBlockMTPRaw -> WebT m (RawResult Block)
scottyBlockMTPRaw
((RawResult Block -> Encoding)
-> Network -> RawResult Block -> Encoding
forall a b. a -> b -> a
const RawResult Block -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((RawResult Block -> Value) -> Network -> RawResult Block -> Value
forall a b. a -> b -> a
const RawResult Block -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetTx
-> (GetTx -> WebT m Transaction)
-> (Network -> Transaction -> Encoding)
-> (Network -> Transaction -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(TxHash -> GetTx
GetTx (TxHash -> GetTx)
-> ActionT Except (ReaderT WebState m) TxHash -> WebT m GetTx
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) TxHash
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy)
GetTx -> WebT m Transaction
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetTx -> WebT m Transaction
scottyTx
Network -> Transaction -> Encoding
transactionToEncoding
Network -> Transaction -> Value
transactionToJSON
WebT m GetTxs
-> (GetTxs -> WebT m (SerialList Transaction))
-> (Network -> SerialList Transaction -> Encoding)
-> (Network -> SerialList Transaction -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
([TxHash] -> GetTxs
GetTxs ([TxHash] -> GetTxs)
-> ActionT Except (ReaderT WebState m) [TxHash] -> WebT m GetTxs
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) [TxHash]
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
param)
(([Transaction] -> SerialList Transaction)
-> ActionT Except (ReaderT WebState m) [Transaction]
-> WebT m (SerialList Transaction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Transaction] -> SerialList Transaction
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [Transaction]
-> WebT m (SerialList Transaction))
-> (GetTxs -> ActionT Except (ReaderT WebState m) [Transaction])
-> GetTxs
-> WebT m (SerialList Transaction)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetTxs -> ActionT Except (ReaderT WebState m) [Transaction]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetTxs -> WebT m [Transaction]
scottyTxs)
(\n :: Network
n -> (Transaction -> Encoding) -> [Transaction] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> Transaction -> Encoding
transactionToEncoding Network
n) ([Transaction] -> Encoding)
-> (SerialList Transaction -> [Transaction])
-> SerialList Transaction
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Transaction -> [Transaction]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> Transaction -> Value)
-> Network -> [Transaction] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> Transaction -> Value
transactionToJSON Network
n ([Transaction] -> Value)
-> (SerialList Transaction -> [Transaction])
-> SerialList Transaction
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Transaction -> [Transaction]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetTxRaw
-> (GetTxRaw -> WebT m (RawResult Tx))
-> (Network -> RawResult Tx -> Encoding)
-> (Network -> RawResult Tx -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(TxHash -> GetTxRaw
GetTxRaw (TxHash -> GetTxRaw)
-> ActionT Except (ReaderT WebState m) TxHash -> WebT m GetTxRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) TxHash
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy)
GetTxRaw -> WebT m (RawResult Tx)
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetTxRaw -> WebT m (RawResult Tx)
scottyTxRaw
((RawResult Tx -> Encoding) -> Network -> RawResult Tx -> Encoding
forall a b. a -> b -> a
const RawResult Tx -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((RawResult Tx -> Value) -> Network -> RawResult Tx -> Value
forall a b. a -> b -> a
const RawResult Tx -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetTxsRaw
-> (GetTxsRaw -> WebT m (RawResultList Tx))
-> (Network -> RawResultList Tx -> Encoding)
-> (Network -> RawResultList Tx -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
([TxHash] -> GetTxsRaw
GetTxsRaw ([TxHash] -> GetTxsRaw)
-> ActionT Except (ReaderT WebState m) [TxHash] -> WebT m GetTxsRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) [TxHash]
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
param)
GetTxsRaw -> WebT m (RawResultList Tx)
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetTxsRaw -> WebT m (RawResultList Tx)
scottyTxsRaw
((RawResultList Tx -> Encoding)
-> Network -> RawResultList Tx -> Encoding
forall a b. a -> b -> a
const RawResultList Tx -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((RawResultList Tx -> Value) -> Network -> RawResultList Tx -> Value
forall a b. a -> b -> a
const RawResultList Tx -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetTxsBlock
-> (GetTxsBlock -> WebT m (SerialList Transaction))
-> (Network -> SerialList Transaction -> Encoding)
-> (Network -> SerialList Transaction -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(BlockHash -> GetTxsBlock
GetTxsBlock (BlockHash -> GetTxsBlock)
-> ActionT Except (ReaderT WebState m) BlockHash
-> WebT m GetTxsBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) BlockHash
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy)
(([Transaction] -> SerialList Transaction)
-> ActionT Except (ReaderT WebState m) [Transaction]
-> WebT m (SerialList Transaction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Transaction] -> SerialList Transaction
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [Transaction]
-> WebT m (SerialList Transaction))
-> (GetTxsBlock
-> ActionT Except (ReaderT WebState m) [Transaction])
-> GetTxsBlock
-> WebT m (SerialList Transaction)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetTxsBlock -> ActionT Except (ReaderT WebState m) [Transaction]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetTxsBlock -> WebT m [Transaction]
scottyTxsBlock)
(\n :: Network
n -> (Transaction -> Encoding) -> [Transaction] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> Transaction -> Encoding
transactionToEncoding Network
n) ([Transaction] -> Encoding)
-> (SerialList Transaction -> [Transaction])
-> SerialList Transaction
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Transaction -> [Transaction]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> Transaction -> Value)
-> Network -> [Transaction] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> Transaction -> Value
transactionToJSON Network
n ([Transaction] -> Value)
-> (SerialList Transaction -> [Transaction])
-> SerialList Transaction
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Transaction -> [Transaction]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetTxsBlockRaw
-> (GetTxsBlockRaw -> WebT m (RawResultList Tx))
-> (Network -> RawResultList Tx -> Encoding)
-> (Network -> RawResultList Tx -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(BlockHash -> GetTxsBlockRaw
GetTxsBlockRaw (BlockHash -> GetTxsBlockRaw)
-> ActionT Except (ReaderT WebState m) BlockHash
-> WebT m GetTxsBlockRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) BlockHash
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy)
GetTxsBlockRaw -> WebT m (RawResultList Tx)
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetTxsBlockRaw -> WebT m (RawResultList Tx)
scottyTxsBlockRaw
((RawResultList Tx -> Encoding)
-> Network -> RawResultList Tx -> Encoding
forall a b. a -> b -> a
const RawResultList Tx -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((RawResultList Tx -> Value) -> Network -> RawResultList Tx -> Value
forall a b. a -> b -> a
const RawResultList Tx -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetTxAfter
-> (GetTxAfter -> WebT m (GenericResult (Maybe Bool)))
-> (Network -> GenericResult (Maybe Bool) -> Encoding)
-> (Network -> GenericResult (Maybe Bool) -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(TxHash -> HeightParam -> GetTxAfter
GetTxAfter (TxHash -> HeightParam -> GetTxAfter)
-> ActionT Except (ReaderT WebState m) TxHash
-> ActionT Except (ReaderT WebState m) (HeightParam -> GetTxAfter)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) TxHash
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT Except (ReaderT WebState m) (HeightParam -> GetTxAfter)
-> ActionT Except (ReaderT WebState m) HeightParam
-> WebT m GetTxAfter
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) HeightParam
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy)
GetTxAfter -> WebT m (GenericResult (Maybe Bool))
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetTxAfter -> WebT m (GenericResult (Maybe Bool))
scottyTxAfter
((GenericResult (Maybe Bool) -> Encoding)
-> Network -> GenericResult (Maybe Bool) -> Encoding
forall a b. a -> b -> a
const GenericResult (Maybe Bool) -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((GenericResult (Maybe Bool) -> Value)
-> Network -> GenericResult (Maybe Bool) -> Value
forall a b. a -> b -> a
const GenericResult (Maybe Bool) -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m PostTx
-> (PostTx -> WebT m TxId)
-> (Network -> TxId -> Encoding)
-> (Network -> TxId -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(Tx -> PostTx
PostTx (Tx -> PostTx)
-> ActionT Except (ReaderT WebState m) Tx -> WebT m PostTx
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) Tx
forall (m :: * -> *) a. (MonadIO m, Serial a) => WebT m a
parseBody)
PostTx -> WebT m TxId
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
PostTx -> WebT m TxId
scottyPostTx
((TxId -> Encoding) -> Network -> TxId -> Encoding
forall a b. a -> b -> a
const TxId -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((TxId -> Value) -> Network -> TxId -> Value
forall a b. a -> b -> a
const TxId -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetMempool
-> (GetMempool -> WebT m (SerialList TxHash))
-> (Network -> SerialList TxHash -> Encoding)
-> (Network -> SerialList TxHash -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(Maybe LimitParam -> OffsetParam -> GetMempool
GetMempool (Maybe LimitParam -> OffsetParam -> GetMempool)
-> ActionT Except (ReaderT WebState m) (Maybe LimitParam)
-> ActionT Except (ReaderT WebState m) (OffsetParam -> GetMempool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) (Maybe LimitParam)
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m (Maybe a)
paramOptional ActionT Except (ReaderT WebState m) (OffsetParam -> GetMempool)
-> ActionT Except (ReaderT WebState m) OffsetParam
-> WebT m GetMempool
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) OffsetParam
forall (m :: * -> *). MonadIO m => WebT m OffsetParam
parseOffset)
(([TxHash] -> SerialList TxHash)
-> ActionT Except (ReaderT WebState m) [TxHash]
-> WebT m (SerialList TxHash)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [TxHash] -> SerialList TxHash
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [TxHash]
-> WebT m (SerialList TxHash))
-> (GetMempool -> ActionT Except (ReaderT WebState m) [TxHash])
-> GetMempool
-> WebT m (SerialList TxHash)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetMempool -> ActionT Except (ReaderT WebState m) [TxHash]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetMempool -> WebT m [TxHash]
scottyMempool)
((SerialList TxHash -> Encoding)
-> Network -> SerialList TxHash -> Encoding
forall a b. a -> b -> a
const SerialList TxHash -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((SerialList TxHash -> Value)
-> Network -> SerialList TxHash -> Value
forall a b. a -> b -> a
const SerialList TxHash -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetAddrTxs
-> (GetAddrTxs -> WebT m (SerialList TxRef))
-> (Network -> SerialList TxRef -> Encoding)
-> (Network -> SerialList TxRef -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(Address -> LimitsParam -> GetAddrTxs
GetAddrTxs (Address -> LimitsParam -> GetAddrTxs)
-> ActionT Except (ReaderT WebState m) Address
-> ActionT Except (ReaderT WebState m) (LimitsParam -> GetAddrTxs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) Address
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT Except (ReaderT WebState m) (LimitsParam -> GetAddrTxs)
-> ActionT Except (ReaderT WebState m) LimitsParam
-> WebT m GetAddrTxs
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) LimitsParam
forall (m :: * -> *). MonadIO m => WebT m LimitsParam
parseLimits)
(([TxRef] -> SerialList TxRef)
-> ActionT Except (ReaderT WebState m) [TxRef]
-> WebT m (SerialList TxRef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [TxRef] -> SerialList TxRef
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [TxRef]
-> WebT m (SerialList TxRef))
-> (GetAddrTxs -> ActionT Except (ReaderT WebState m) [TxRef])
-> GetAddrTxs
-> WebT m (SerialList TxRef)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetAddrTxs -> ActionT Except (ReaderT WebState m) [TxRef]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetAddrTxs -> WebT m [TxRef]
scottyAddrTxs)
((SerialList TxRef -> Encoding)
-> Network -> SerialList TxRef -> Encoding
forall a b. a -> b -> a
const SerialList TxRef -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((SerialList TxRef -> Value) -> Network -> SerialList TxRef -> Value
forall a b. a -> b -> a
const SerialList TxRef -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetAddrsTxs
-> (GetAddrsTxs -> WebT m (SerialList TxRef))
-> (Network -> SerialList TxRef -> Encoding)
-> (Network -> SerialList TxRef -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
([Address] -> LimitsParam -> GetAddrsTxs
GetAddrsTxs ([Address] -> LimitsParam -> GetAddrsTxs)
-> ActionT Except (ReaderT WebState m) [Address]
-> ActionT Except (ReaderT WebState m) (LimitsParam -> GetAddrsTxs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) [Address]
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
param ActionT Except (ReaderT WebState m) (LimitsParam -> GetAddrsTxs)
-> ActionT Except (ReaderT WebState m) LimitsParam
-> WebT m GetAddrsTxs
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) LimitsParam
forall (m :: * -> *). MonadIO m => WebT m LimitsParam
parseLimits)
(([TxRef] -> SerialList TxRef)
-> ActionT Except (ReaderT WebState m) [TxRef]
-> WebT m (SerialList TxRef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [TxRef] -> SerialList TxRef
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [TxRef]
-> WebT m (SerialList TxRef))
-> (GetAddrsTxs -> ActionT Except (ReaderT WebState m) [TxRef])
-> GetAddrsTxs
-> WebT m (SerialList TxRef)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetAddrsTxs -> ActionT Except (ReaderT WebState m) [TxRef]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetAddrsTxs -> WebT m [TxRef]
scottyAddrsTxs)
((SerialList TxRef -> Encoding)
-> Network -> SerialList TxRef -> Encoding
forall a b. a -> b -> a
const SerialList TxRef -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((SerialList TxRef -> Value) -> Network -> SerialList TxRef -> Value
forall a b. a -> b -> a
const SerialList TxRef -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetAddrTxsFull
-> (GetAddrTxsFull -> WebT m (SerialList Transaction))
-> (Network -> SerialList Transaction -> Encoding)
-> (Network -> SerialList Transaction -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(Address -> LimitsParam -> GetAddrTxsFull
GetAddrTxsFull (Address -> LimitsParam -> GetAddrTxsFull)
-> ActionT Except (ReaderT WebState m) Address
-> ActionT
Except (ReaderT WebState m) (LimitsParam -> GetAddrTxsFull)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) Address
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT Except (ReaderT WebState m) (LimitsParam -> GetAddrTxsFull)
-> ActionT Except (ReaderT WebState m) LimitsParam
-> WebT m GetAddrTxsFull
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) LimitsParam
forall (m :: * -> *). MonadIO m => WebT m LimitsParam
parseLimits)
(([Transaction] -> SerialList Transaction)
-> ActionT Except (ReaderT WebState m) [Transaction]
-> WebT m (SerialList Transaction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Transaction] -> SerialList Transaction
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [Transaction]
-> WebT m (SerialList Transaction))
-> (GetAddrTxsFull
-> ActionT Except (ReaderT WebState m) [Transaction])
-> GetAddrTxsFull
-> WebT m (SerialList Transaction)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetAddrTxsFull -> ActionT Except (ReaderT WebState m) [Transaction]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetAddrTxsFull -> WebT m [Transaction]
scottyAddrTxsFull)
(\n :: Network
n -> (Transaction -> Encoding) -> [Transaction] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> Transaction -> Encoding
transactionToEncoding Network
n) ([Transaction] -> Encoding)
-> (SerialList Transaction -> [Transaction])
-> SerialList Transaction
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Transaction -> [Transaction]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> Transaction -> Value)
-> Network -> [Transaction] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> Transaction -> Value
transactionToJSON Network
n ([Transaction] -> Value)
-> (SerialList Transaction -> [Transaction])
-> SerialList Transaction
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Transaction -> [Transaction]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetAddrsTxsFull
-> (GetAddrsTxsFull -> WebT m (SerialList Transaction))
-> (Network -> SerialList Transaction -> Encoding)
-> (Network -> SerialList Transaction -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
([Address] -> LimitsParam -> GetAddrsTxsFull
GetAddrsTxsFull ([Address] -> LimitsParam -> GetAddrsTxsFull)
-> ActionT Except (ReaderT WebState m) [Address]
-> ActionT
Except (ReaderT WebState m) (LimitsParam -> GetAddrsTxsFull)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) [Address]
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
param ActionT
Except (ReaderT WebState m) (LimitsParam -> GetAddrsTxsFull)
-> ActionT Except (ReaderT WebState m) LimitsParam
-> WebT m GetAddrsTxsFull
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) LimitsParam
forall (m :: * -> *). MonadIO m => WebT m LimitsParam
parseLimits)
(([Transaction] -> SerialList Transaction)
-> ActionT Except (ReaderT WebState m) [Transaction]
-> WebT m (SerialList Transaction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Transaction] -> SerialList Transaction
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [Transaction]
-> WebT m (SerialList Transaction))
-> (GetAddrsTxsFull
-> ActionT Except (ReaderT WebState m) [Transaction])
-> GetAddrsTxsFull
-> WebT m (SerialList Transaction)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetAddrsTxsFull
-> ActionT Except (ReaderT WebState m) [Transaction]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetAddrsTxsFull -> WebT m [Transaction]
scottyAddrsTxsFull)
(\n :: Network
n -> (Transaction -> Encoding) -> [Transaction] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> Transaction -> Encoding
transactionToEncoding Network
n) ([Transaction] -> Encoding)
-> (SerialList Transaction -> [Transaction])
-> SerialList Transaction
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Transaction -> [Transaction]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> Transaction -> Value)
-> Network -> [Transaction] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> Transaction -> Value
transactionToJSON Network
n ([Transaction] -> Value)
-> (SerialList Transaction -> [Transaction])
-> SerialList Transaction
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Transaction -> [Transaction]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetAddrBalance
-> (GetAddrBalance -> WebT m Balance)
-> (Network -> Balance -> Encoding)
-> (Network -> Balance -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(Address -> GetAddrBalance
GetAddrBalance (Address -> GetAddrBalance)
-> ActionT Except (ReaderT WebState m) Address
-> WebT m GetAddrBalance
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) Address
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy)
GetAddrBalance -> WebT m Balance
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetAddrBalance -> WebT m Balance
scottyAddrBalance
Network -> Balance -> Encoding
balanceToEncoding
Network -> Balance -> Value
balanceToJSON
WebT m GetAddrsBalance
-> (GetAddrsBalance -> WebT m (SerialList Balance))
-> (Network -> SerialList Balance -> Encoding)
-> (Network -> SerialList Balance -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
([Address] -> GetAddrsBalance
GetAddrsBalance ([Address] -> GetAddrsBalance)
-> ActionT Except (ReaderT WebState m) [Address]
-> WebT m GetAddrsBalance
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) [Address]
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
param)
(([Balance] -> SerialList Balance)
-> ActionT Except (ReaderT WebState m) [Balance]
-> WebT m (SerialList Balance)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Balance] -> SerialList Balance
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [Balance]
-> WebT m (SerialList Balance))
-> (GetAddrsBalance
-> ActionT Except (ReaderT WebState m) [Balance])
-> GetAddrsBalance
-> WebT m (SerialList Balance)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetAddrsBalance -> ActionT Except (ReaderT WebState m) [Balance]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetAddrsBalance -> WebT m [Balance]
scottyAddrsBalance)
(\n :: Network
n -> (Balance -> Encoding) -> [Balance] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> Balance -> Encoding
balanceToEncoding Network
n) ([Balance] -> Encoding)
-> (SerialList Balance -> [Balance])
-> SerialList Balance
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Balance -> [Balance]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> Balance -> Value) -> Network -> [Balance] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> Balance -> Value
balanceToJSON Network
n ([Balance] -> Value)
-> (SerialList Balance -> [Balance]) -> SerialList Balance -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Balance -> [Balance]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetAddrUnspent
-> (GetAddrUnspent -> WebT m (SerialList Unspent))
-> (Network -> SerialList Unspent -> Encoding)
-> (Network -> SerialList Unspent -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(Address -> LimitsParam -> GetAddrUnspent
GetAddrUnspent (Address -> LimitsParam -> GetAddrUnspent)
-> ActionT Except (ReaderT WebState m) Address
-> ActionT
Except (ReaderT WebState m) (LimitsParam -> GetAddrUnspent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) Address
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT Except (ReaderT WebState m) (LimitsParam -> GetAddrUnspent)
-> ActionT Except (ReaderT WebState m) LimitsParam
-> WebT m GetAddrUnspent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) LimitsParam
forall (m :: * -> *). MonadIO m => WebT m LimitsParam
parseLimits)
(([Unspent] -> SerialList Unspent)
-> ActionT Except (ReaderT WebState m) [Unspent]
-> WebT m (SerialList Unspent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Unspent] -> SerialList Unspent
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [Unspent]
-> WebT m (SerialList Unspent))
-> (GetAddrUnspent
-> ActionT Except (ReaderT WebState m) [Unspent])
-> GetAddrUnspent
-> WebT m (SerialList Unspent)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetAddrUnspent -> ActionT Except (ReaderT WebState m) [Unspent]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetAddrUnspent -> WebT m [Unspent]
scottyAddrUnspent)
(\n :: Network
n -> (Unspent -> Encoding) -> [Unspent] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> Unspent -> Encoding
unspentToEncoding Network
n) ([Unspent] -> Encoding)
-> (SerialList Unspent -> [Unspent])
-> SerialList Unspent
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Unspent -> [Unspent]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> Unspent -> Value) -> Network -> [Unspent] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> Unspent -> Value
unspentToJSON Network
n ([Unspent] -> Value)
-> (SerialList Unspent -> [Unspent]) -> SerialList Unspent -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Unspent -> [Unspent]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetAddrsUnspent
-> (GetAddrsUnspent -> WebT m (SerialList Unspent))
-> (Network -> SerialList Unspent -> Encoding)
-> (Network -> SerialList Unspent -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
([Address] -> LimitsParam -> GetAddrsUnspent
GetAddrsUnspent ([Address] -> LimitsParam -> GetAddrsUnspent)
-> ActionT Except (ReaderT WebState m) [Address]
-> ActionT
Except (ReaderT WebState m) (LimitsParam -> GetAddrsUnspent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) [Address]
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
param ActionT
Except (ReaderT WebState m) (LimitsParam -> GetAddrsUnspent)
-> ActionT Except (ReaderT WebState m) LimitsParam
-> WebT m GetAddrsUnspent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) LimitsParam
forall (m :: * -> *). MonadIO m => WebT m LimitsParam
parseLimits)
(([Unspent] -> SerialList Unspent)
-> ActionT Except (ReaderT WebState m) [Unspent]
-> WebT m (SerialList Unspent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Unspent] -> SerialList Unspent
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [Unspent]
-> WebT m (SerialList Unspent))
-> (GetAddrsUnspent
-> ActionT Except (ReaderT WebState m) [Unspent])
-> GetAddrsUnspent
-> WebT m (SerialList Unspent)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetAddrsUnspent -> ActionT Except (ReaderT WebState m) [Unspent]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetAddrsUnspent -> WebT m [Unspent]
scottyAddrsUnspent)
(\n :: Network
n -> (Unspent -> Encoding) -> [Unspent] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> Unspent -> Encoding
unspentToEncoding Network
n) ([Unspent] -> Encoding)
-> (SerialList Unspent -> [Unspent])
-> SerialList Unspent
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Unspent -> [Unspent]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> Unspent -> Value) -> Network -> [Unspent] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> Unspent -> Value
unspentToJSON Network
n ([Unspent] -> Value)
-> (SerialList Unspent -> [Unspent]) -> SerialList Unspent -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Unspent -> [Unspent]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetXPub
-> (GetXPub -> WebT m XPubSummary)
-> (Network -> XPubSummary -> Encoding)
-> (Network -> XPubSummary -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(XPubKey -> DeriveType -> NoCache -> GetXPub
GetXPub (XPubKey -> DeriveType -> NoCache -> GetXPub)
-> ActionT Except (ReaderT WebState m) XPubKey
-> ActionT
Except (ReaderT WebState m) (DeriveType -> NoCache -> GetXPub)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) XPubKey
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT
Except (ReaderT WebState m) (DeriveType -> NoCache -> GetXPub)
-> ActionT Except (ReaderT WebState m) DeriveType
-> ActionT Except (ReaderT WebState m) (NoCache -> GetXPub)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) DeriveType
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef ActionT Except (ReaderT WebState m) (NoCache -> GetXPub)
-> ActionT Except (ReaderT WebState m) NoCache -> WebT m GetXPub
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) NoCache
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
GetXPub -> WebT m XPubSummary
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetXPub -> WebT m XPubSummary
scottyXPub
((XPubSummary -> Encoding) -> Network -> XPubSummary -> Encoding
forall a b. a -> b -> a
const XPubSummary -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((XPubSummary -> Value) -> Network -> XPubSummary -> Value
forall a b. a -> b -> a
const XPubSummary -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetXPubTxs
-> (GetXPubTxs -> WebT m (SerialList TxRef))
-> (Network -> SerialList TxRef -> Encoding)
-> (Network -> SerialList TxRef -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(XPubKey -> DeriveType -> LimitsParam -> NoCache -> GetXPubTxs
GetXPubTxs (XPubKey -> DeriveType -> LimitsParam -> NoCache -> GetXPubTxs)
-> ActionT Except (ReaderT WebState m) XPubKey
-> ActionT
Except
(ReaderT WebState m)
(DeriveType -> LimitsParam -> NoCache -> GetXPubTxs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) XPubKey
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT
Except
(ReaderT WebState m)
(DeriveType -> LimitsParam -> NoCache -> GetXPubTxs)
-> ActionT Except (ReaderT WebState m) DeriveType
-> ActionT
Except (ReaderT WebState m) (LimitsParam -> NoCache -> GetXPubTxs)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) DeriveType
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef ActionT
Except (ReaderT WebState m) (LimitsParam -> NoCache -> GetXPubTxs)
-> ActionT Except (ReaderT WebState m) LimitsParam
-> ActionT Except (ReaderT WebState m) (NoCache -> GetXPubTxs)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) LimitsParam
forall (m :: * -> *). MonadIO m => WebT m LimitsParam
parseLimits ActionT Except (ReaderT WebState m) (NoCache -> GetXPubTxs)
-> ActionT Except (ReaderT WebState m) NoCache -> WebT m GetXPubTxs
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) NoCache
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
(([TxRef] -> SerialList TxRef)
-> ActionT Except (ReaderT WebState m) [TxRef]
-> WebT m (SerialList TxRef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [TxRef] -> SerialList TxRef
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [TxRef]
-> WebT m (SerialList TxRef))
-> (GetXPubTxs -> ActionT Except (ReaderT WebState m) [TxRef])
-> GetXPubTxs
-> WebT m (SerialList TxRef)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetXPubTxs -> ActionT Except (ReaderT WebState m) [TxRef]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetXPubTxs -> WebT m [TxRef]
scottyXPubTxs)
((SerialList TxRef -> Encoding)
-> Network -> SerialList TxRef -> Encoding
forall a b. a -> b -> a
const SerialList TxRef -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((SerialList TxRef -> Value) -> Network -> SerialList TxRef -> Value
forall a b. a -> b -> a
const SerialList TxRef -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetXPubTxsFull
-> (GetXPubTxsFull -> WebT m (SerialList Transaction))
-> (Network -> SerialList Transaction -> Encoding)
-> (Network -> SerialList Transaction -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(XPubKey -> DeriveType -> LimitsParam -> NoCache -> GetXPubTxsFull
GetXPubTxsFull (XPubKey -> DeriveType -> LimitsParam -> NoCache -> GetXPubTxsFull)
-> ActionT Except (ReaderT WebState m) XPubKey
-> ActionT
Except
(ReaderT WebState m)
(DeriveType -> LimitsParam -> NoCache -> GetXPubTxsFull)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) XPubKey
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT
Except
(ReaderT WebState m)
(DeriveType -> LimitsParam -> NoCache -> GetXPubTxsFull)
-> ActionT Except (ReaderT WebState m) DeriveType
-> ActionT
Except
(ReaderT WebState m)
(LimitsParam -> NoCache -> GetXPubTxsFull)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) DeriveType
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef ActionT
Except
(ReaderT WebState m)
(LimitsParam -> NoCache -> GetXPubTxsFull)
-> ActionT Except (ReaderT WebState m) LimitsParam
-> ActionT Except (ReaderT WebState m) (NoCache -> GetXPubTxsFull)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) LimitsParam
forall (m :: * -> *). MonadIO m => WebT m LimitsParam
parseLimits ActionT Except (ReaderT WebState m) (NoCache -> GetXPubTxsFull)
-> ActionT Except (ReaderT WebState m) NoCache
-> WebT m GetXPubTxsFull
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) NoCache
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
(([Transaction] -> SerialList Transaction)
-> ActionT Except (ReaderT WebState m) [Transaction]
-> WebT m (SerialList Transaction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Transaction] -> SerialList Transaction
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [Transaction]
-> WebT m (SerialList Transaction))
-> (GetXPubTxsFull
-> ActionT Except (ReaderT WebState m) [Transaction])
-> GetXPubTxsFull
-> WebT m (SerialList Transaction)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetXPubTxsFull -> ActionT Except (ReaderT WebState m) [Transaction]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetXPubTxsFull -> WebT m [Transaction]
scottyXPubTxsFull)
(\n :: Network
n -> (Transaction -> Encoding) -> [Transaction] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> Transaction -> Encoding
transactionToEncoding Network
n) ([Transaction] -> Encoding)
-> (SerialList Transaction -> [Transaction])
-> SerialList Transaction
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Transaction -> [Transaction]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> Transaction -> Value)
-> Network -> [Transaction] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> Transaction -> Value
transactionToJSON Network
n ([Transaction] -> Value)
-> (SerialList Transaction -> [Transaction])
-> SerialList Transaction
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList Transaction -> [Transaction]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetXPubBalances
-> (GetXPubBalances -> WebT m (SerialList XPubBal))
-> (Network -> SerialList XPubBal -> Encoding)
-> (Network -> SerialList XPubBal -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(XPubKey -> DeriveType -> NoCache -> GetXPubBalances
GetXPubBalances (XPubKey -> DeriveType -> NoCache -> GetXPubBalances)
-> ActionT Except (ReaderT WebState m) XPubKey
-> ActionT
Except
(ReaderT WebState m)
(DeriveType -> NoCache -> GetXPubBalances)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) XPubKey
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT
Except
(ReaderT WebState m)
(DeriveType -> NoCache -> GetXPubBalances)
-> ActionT Except (ReaderT WebState m) DeriveType
-> ActionT Except (ReaderT WebState m) (NoCache -> GetXPubBalances)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) DeriveType
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef ActionT Except (ReaderT WebState m) (NoCache -> GetXPubBalances)
-> ActionT Except (ReaderT WebState m) NoCache
-> WebT m GetXPubBalances
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) NoCache
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
(([XPubBal] -> SerialList XPubBal)
-> ActionT Except (ReaderT WebState m) [XPubBal]
-> WebT m (SerialList XPubBal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [XPubBal] -> SerialList XPubBal
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [XPubBal]
-> WebT m (SerialList XPubBal))
-> (GetXPubBalances
-> ActionT Except (ReaderT WebState m) [XPubBal])
-> GetXPubBalances
-> WebT m (SerialList XPubBal)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetXPubBalances -> ActionT Except (ReaderT WebState m) [XPubBal]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetXPubBalances -> WebT m [XPubBal]
scottyXPubBalances)
(\n :: Network
n -> (XPubBal -> Encoding) -> [XPubBal] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> XPubBal -> Encoding
xPubBalToEncoding Network
n) ([XPubBal] -> Encoding)
-> (SerialList XPubBal -> [XPubBal])
-> SerialList XPubBal
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList XPubBal -> [XPubBal]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> XPubBal -> Value) -> Network -> [XPubBal] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> XPubBal -> Value
xPubBalToJSON Network
n ([XPubBal] -> Value)
-> (SerialList XPubBal -> [XPubBal]) -> SerialList XPubBal -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList XPubBal -> [XPubBal]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetXPubUnspent
-> (GetXPubUnspent -> WebT m (SerialList XPubUnspent))
-> (Network -> SerialList XPubUnspent -> Encoding)
-> (Network -> SerialList XPubUnspent -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(XPubKey -> DeriveType -> LimitsParam -> NoCache -> GetXPubUnspent
GetXPubUnspent (XPubKey -> DeriveType -> LimitsParam -> NoCache -> GetXPubUnspent)
-> ActionT Except (ReaderT WebState m) XPubKey
-> ActionT
Except
(ReaderT WebState m)
(DeriveType -> LimitsParam -> NoCache -> GetXPubUnspent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) XPubKey
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m a
paramLazy ActionT
Except
(ReaderT WebState m)
(DeriveType -> LimitsParam -> NoCache -> GetXPubUnspent)
-> ActionT Except (ReaderT WebState m) DeriveType
-> ActionT
Except
(ReaderT WebState m)
(LimitsParam -> NoCache -> GetXPubUnspent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) DeriveType
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef ActionT
Except
(ReaderT WebState m)
(LimitsParam -> NoCache -> GetXPubUnspent)
-> ActionT Except (ReaderT WebState m) LimitsParam
-> ActionT Except (ReaderT WebState m) (NoCache -> GetXPubUnspent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) LimitsParam
forall (m :: * -> *). MonadIO m => WebT m LimitsParam
parseLimits ActionT Except (ReaderT WebState m) (NoCache -> GetXPubUnspent)
-> ActionT Except (ReaderT WebState m) NoCache
-> WebT m GetXPubUnspent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) NoCache
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef)
(([XPubUnspent] -> SerialList XPubUnspent)
-> ActionT Except (ReaderT WebState m) [XPubUnspent]
-> WebT m (SerialList XPubUnspent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [XPubUnspent] -> SerialList XPubUnspent
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [XPubUnspent]
-> WebT m (SerialList XPubUnspent))
-> (GetXPubUnspent
-> ActionT Except (ReaderT WebState m) [XPubUnspent])
-> GetXPubUnspent
-> WebT m (SerialList XPubUnspent)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetXPubUnspent -> ActionT Except (ReaderT WebState m) [XPubUnspent]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetXPubUnspent -> WebT m [XPubUnspent]
scottyXPubUnspent)
(\n :: Network
n -> (XPubUnspent -> Encoding) -> [XPubUnspent] -> Encoding
forall a. (a -> Encoding) -> [a] -> Encoding
list (Network -> XPubUnspent -> Encoding
xPubUnspentToEncoding Network
n) ([XPubUnspent] -> Encoding)
-> (SerialList XPubUnspent -> [XPubUnspent])
-> SerialList XPubUnspent
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList XPubUnspent -> [XPubUnspent]
forall a. SerialList a -> [a]
getSerialList)
(\n :: Network
n -> (Network -> XPubUnspent -> Value)
-> Network -> [XPubUnspent] -> Value
forall a t a. ToJSON a => (t -> a -> a) -> t -> [a] -> Value
json_list Network -> XPubUnspent -> Value
xPubUnspentToJSON Network
n ([XPubUnspent] -> Value)
-> (SerialList XPubUnspent -> [XPubUnspent])
-> SerialList XPubUnspent
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialList XPubUnspent -> [XPubUnspent]
forall a. SerialList a -> [a]
getSerialList)
WebT m GetPeers
-> (GetPeers -> WebT m (SerialList PeerInformation))
-> (Network -> SerialList PeerInformation -> Encoding)
-> (Network -> SerialList PeerInformation -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(GetPeers
GetPeers GetPeers -> (GetPeers -> WebT m GetPeers) -> WebT m GetPeers
forall a b. a -> (a -> b) -> b
& GetPeers -> WebT m GetPeers
forall (m :: * -> *) a. Monad m => a -> m a
return)
(([PeerInformation] -> SerialList PeerInformation)
-> ActionT Except (ReaderT WebState m) [PeerInformation]
-> WebT m (SerialList PeerInformation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [PeerInformation] -> SerialList PeerInformation
forall a. [a] -> SerialList a
SerialList (ActionT Except (ReaderT WebState m) [PeerInformation]
-> WebT m (SerialList PeerInformation))
-> (GetPeers
-> ActionT Except (ReaderT WebState m) [PeerInformation])
-> GetPeers
-> WebT m (SerialList PeerInformation)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GetPeers -> ActionT Except (ReaderT WebState m) [PeerInformation]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetPeers -> WebT m [PeerInformation]
scottyPeers)
((SerialList PeerInformation -> Encoding)
-> Network -> SerialList PeerInformation -> Encoding
forall a b. a -> b -> a
const SerialList PeerInformation -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((SerialList PeerInformation -> Value)
-> Network -> SerialList PeerInformation -> Value
forall a b. a -> b -> a
const SerialList PeerInformation -> Value
forall a. ToJSON a => a -> Value
toJSON)
WebT m GetHealth
-> (GetHealth -> WebT m HealthCheck)
-> (Network -> HealthCheck -> Encoding)
-> (Network -> HealthCheck -> Value)
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact
(GetHealth
GetHealth GetHealth -> (GetHealth -> WebT m GetHealth) -> WebT m GetHealth
forall a b. a -> (a -> b) -> b
& GetHealth -> WebT m GetHealth
forall (m :: * -> *) a. Monad m => a -> m a
return)
GetHealth -> WebT m HealthCheck
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
GetHealth -> WebT m HealthCheck
scottyHealth
((HealthCheck -> Encoding) -> Network -> HealthCheck -> Encoding
forall a b. a -> b -> a
const HealthCheck -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding)
((HealthCheck -> Value) -> Network -> HealthCheck -> Value
forall a b. a -> b -> a
const HealthCheck -> Value
forall a. ToJSON a => a -> Value
toJSON)
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.get "/events" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyEvents
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.get "/dbstats" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyDbStats
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.post "/blockchain/multiaddr" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyMultiAddr
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.get "/blockchain/multiaddr" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyMultiAddr
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.get "/blockchain/balance" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyShortBal
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.post "/blockchain/balance" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyShortBal
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.get "/blockchain/rawaddr/:addr" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyRawAddr
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.post "/blockchain/unspent" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyBinfoUnspent
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.get "/blockchain/unspent" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyBinfoUnspent
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.get "/blockchain/rawtx/:txid" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyBinfoTx
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.get "/blockchain/rawblock/:block" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyBinfoBlock
RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
RoutePattern -> ActionT e m () -> ScottyT e m ()
S.get "/blockchain/block-height/:height" ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m ()
scottyBinfoBlockHeight
where
json_list :: (t -> a -> a) -> t -> [a] -> Value
json_list f :: t -> a -> a
f net :: t
net = [a] -> Value
forall a. ToJSON a => [a] -> Value
toJSONList ([a] -> Value) -> ([a] -> [a]) -> [a] -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (t -> a -> a
f t
net)
pathPretty ::
(ApiResource a b, MonadIO m)
=> WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> S.ScottyT Except (ReaderT WebState m) ()
pathPretty :: WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathPretty parser :: WebT m a
parser action :: a -> WebT m b
action encJson :: Network -> b -> Encoding
encJson encValue :: Network -> b -> Value
encValue =
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> Bool
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> Bool
-> ScottyT Except (ReaderT WebState m) ()
pathCommon WebT m a
parser a -> WebT m b
action Network -> b -> Encoding
encJson Network -> b -> Value
encValue Bool
True
pathCompact ::
(ApiResource a b, MonadIO m)
=> WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> S.ScottyT Except (ReaderT WebState m) ()
pathCompact :: WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> ScottyT Except (ReaderT WebState m) ()
pathCompact parser :: WebT m a
parser action :: a -> WebT m b
action encJson :: Network -> b -> Encoding
encJson encValue :: Network -> b -> Value
encValue =
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> Bool
-> ScottyT Except (ReaderT WebState m) ()
forall a b (m :: * -> *).
(ApiResource a b, MonadIO m) =>
WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> Bool
-> ScottyT Except (ReaderT WebState m) ()
pathCommon WebT m a
parser a -> WebT m b
action Network -> b -> Encoding
encJson Network -> b -> Value
encValue Bool
False
pathCommon ::
(ApiResource a b, MonadIO m)
=> WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> Bool
-> S.ScottyT Except (ReaderT WebState m) ()
pathCommon :: WebT m a
-> (a -> WebT m b)
-> (Network -> b -> Encoding)
-> (Network -> b -> Value)
-> Bool
-> ScottyT Except (ReaderT WebState m) ()
pathCommon parser :: WebT m a
parser action :: a -> WebT m b
action encJson :: Network -> b -> Encoding
encJson encValue :: Network -> b -> Value
encValue pretty :: Bool
pretty =
StdMethod
-> RoutePattern
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
StdMethod -> RoutePattern -> ActionT e m () -> ScottyT e m ()
S.addroute (Proxy a -> StdMethod
forall a b. ApiResource a b => Proxy a -> StdMethod
resourceMethod Proxy a
proxy) (Proxy a -> RoutePattern
forall a b. ApiResource a b => Proxy a -> RoutePattern
capturePath Proxy a
proxy) (ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ())
-> ActionT Except (ReaderT WebState m) ()
-> ScottyT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$ do
ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
SerialAs
proto <- Bool -> ActionT Except (ReaderT WebState m) SerialAs
forall (m :: * -> *). Monad m => Bool -> ActionT Except m SerialAs
setupContentType Bool
pretty
Network
net <- ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network)
-> ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall a b. (a -> b) -> a -> b
$ (WebState -> Network) -> ReaderT WebState m Network
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Network
storeNetwork (Store -> Network) -> (WebState -> Store) -> WebState -> Network
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
a
apiRes <- WebT m a
parser
b
res <- a -> WebT m b
action a
apiRes
ByteString -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) e. Monad m => ByteString -> ActionT e m ()
S.raw (ByteString -> ActionT Except (ReaderT WebState m) ())
-> ByteString -> ActionT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$ SerialAs -> (b -> Encoding) -> (b -> Value) -> b -> ByteString
forall a.
Serial a =>
SerialAs -> (a -> Encoding) -> (a -> Value) -> a -> ByteString
protoSerial SerialAs
proto (Network -> b -> Encoding
encJson Network
net) (Network -> b -> Value
encValue Network
net) b
res
where
toProxy :: WebT m a -> Proxy a
toProxy :: WebT m a -> Proxy a
toProxy = Proxy a -> WebT m a -> Proxy a
forall a b. a -> b -> a
const Proxy a
forall k (t :: k). Proxy t
Proxy
proxy :: Proxy a
proxy = WebT m a -> Proxy a
forall (m :: * -> *) a. WebT m a -> Proxy a
toProxy WebT m a
parser
streamEncoding :: Monad m => Encoding -> WebT m ()
streamEncoding :: Encoding -> WebT m ()
streamEncoding e :: Encoding
e = do
Text -> Text -> WebT m ()
forall (m :: * -> *) e. Monad m => Text -> Text -> ActionT e m ()
S.setHeader "Content-Type" "application/json; charset=utf-8"
ByteString -> WebT m ()
forall (m :: * -> *) e. Monad m => ByteString -> ActionT e m ()
S.raw (Encoding -> ByteString
forall a. Encoding' a -> ByteString
encodingToLazyByteString Encoding
e)
protoSerial
:: Serial a
=> SerialAs
-> (a -> Encoding)
-> (a -> Value)
-> a
-> L.ByteString
protoSerial :: SerialAs -> (a -> Encoding) -> (a -> Value) -> a -> ByteString
protoSerial SerialAsBinary _ _ = Put -> ByteString
runPutL (Put -> ByteString) -> (a -> Put) -> a -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
serialize
protoSerial SerialAsJSON f :: a -> Encoding
f _ = Encoding -> ByteString
forall a. Encoding' a -> ByteString
encodingToLazyByteString (Encoding -> ByteString) -> (a -> Encoding) -> a -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Encoding
f
protoSerial SerialAsPrettyJSON _ g :: a -> Value
g =
Config -> Value -> ByteString
forall a. ToJSON a => Config -> a -> ByteString
encodePretty' Config
defConfig {confTrailingNewline :: Bool
confTrailingNewline = Bool
True} (Value -> ByteString) -> (a -> Value) -> a -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Value
g
setHeaders :: (Monad m, S.ScottyError e) => ActionT e m ()
= Text -> Text -> ActionT e m ()
forall (m :: * -> *) e. Monad m => Text -> Text -> ActionT e m ()
S.setHeader "Access-Control-Allow-Origin" "*"
waiExcept :: Status -> Except -> Response
waiExcept :: Status -> Except -> Response
waiExcept s :: Status
s e :: Except
e =
Status -> ResponseHeaders -> ByteString -> Response
responseLBS Status
s ResponseHeaders
hs ByteString
e'
where
hs :: ResponseHeaders
hs = [ ("Access-Control-Allow-Origin", "*")
, ("Content-Type", "application/json")
]
e' :: ByteString
e' = Except -> ByteString
forall a. ToJSON a => a -> ByteString
A.encode Except
e
setupJSON :: Monad m => Bool -> ActionT Except m SerialAs
setupJSON :: Bool -> ActionT Except m SerialAs
setupJSON pretty :: Bool
pretty = do
Text -> Text -> ActionT Except m ()
forall (m :: * -> *) e. Monad m => Text -> Text -> ActionT e m ()
S.setHeader "Content-Type" "application/json"
Bool
p <- Text -> ActionT Except m Bool
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "pretty" ActionT Except m Bool
-> (Except -> ActionT Except m Bool) -> ActionT Except m Bool
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT Except m Bool -> Except -> ActionT Except m Bool
forall a b. a -> b -> a
const (Bool -> ActionT Except m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
pretty)
SerialAs -> ActionT Except m SerialAs
forall (m :: * -> *) a. Monad m => a -> m a
return (SerialAs -> ActionT Except m SerialAs)
-> SerialAs -> ActionT Except m SerialAs
forall a b. (a -> b) -> a -> b
$ if Bool
p then SerialAs
SerialAsPrettyJSON else SerialAs
SerialAsJSON
setupBinary :: Monad m => ActionT Except m SerialAs
setupBinary :: ActionT Except m SerialAs
setupBinary = do
Text -> Text -> ActionT Except m ()
forall (m :: * -> *) e. Monad m => Text -> Text -> ActionT e m ()
S.setHeader "Content-Type" "application/octet-stream"
SerialAs -> ActionT Except m SerialAs
forall (m :: * -> *) a. Monad m => a -> m a
return SerialAs
SerialAsBinary
setupContentType :: Monad m => Bool -> ActionT Except m SerialAs
setupContentType :: Bool -> ActionT Except m SerialAs
setupContentType pretty :: Bool
pretty = do
Maybe Text
accept <- Text -> ActionT Except m (Maybe Text)
forall e (m :: * -> *).
(ScottyError e, Monad m) =>
Text -> ActionT e m (Maybe Text)
S.header "accept"
ActionT Except m SerialAs
-> (Text -> ActionT Except m SerialAs)
-> Maybe Text
-> ActionT Except m SerialAs
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> ActionT Except m SerialAs
forall (m :: * -> *). Monad m => Bool -> ActionT Except m SerialAs
setupJSON Bool
pretty) Text -> ActionT Except m SerialAs
forall a (m :: * -> *).
(Eq a, IsString a, Monad m) =>
a -> ActionT Except m SerialAs
setType Maybe Text
accept
where
setType :: a -> ActionT Except m SerialAs
setType "application/octet-stream" = ActionT Except m SerialAs
forall (m :: * -> *). Monad m => ActionT Except m SerialAs
setupBinary
setType _ = Bool -> ActionT Except m SerialAs
forall (m :: * -> *). Monad m => Bool -> ActionT Except m SerialAs
setupJSON Bool
pretty
scottyBlock ::
(MonadUnliftIO m, MonadLoggerIO m) => GetBlock -> WebT m BlockData
scottyBlock :: GetBlock -> WebT m BlockData
scottyBlock (GetBlock h :: BlockHash
h (NoTx noTx :: Bool
noTx)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
blockStat 1
BlockHash -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock BlockHash
h ActionT Except (ReaderT WebState m) (Maybe BlockData)
-> (Maybe BlockData -> WebT m BlockData) -> WebT m BlockData
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= WebT m BlockData
-> (BlockData -> WebT m BlockData)
-> Maybe BlockData
-> WebT m BlockData
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
((WebMetrics -> StatDist) -> Except -> WebT m BlockData
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
blockStat Except
ThingNotFound)
(BlockData -> WebT m BlockData
forall (m :: * -> *) a. Monad m => a -> m a
return (BlockData -> WebT m BlockData)
-> (BlockData -> BlockData) -> BlockData -> WebT m BlockData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> BlockData -> BlockData
pruneTx Bool
noTx)
getBlocks :: (MonadUnliftIO m, MonadLoggerIO m)
=> [H.BlockHash]
-> Bool
-> WebT m [BlockData]
getBlocks :: [BlockHash] -> Bool -> WebT m [BlockData]
getBlocks hs :: [BlockHash]
hs notx :: Bool
notx =
(Bool -> BlockData -> BlockData
pruneTx Bool
notx (BlockData -> BlockData) -> [BlockData] -> [BlockData]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) ([BlockData] -> [BlockData])
-> ([Maybe BlockData] -> [BlockData])
-> [Maybe BlockData]
-> [BlockData]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe BlockData] -> [BlockData]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe BlockData] -> [BlockData])
-> ActionT Except (ReaderT WebState m) [Maybe BlockData]
-> WebT m [BlockData]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (BlockHash
-> ActionT Except (ReaderT WebState m) (Maybe BlockData))
-> [BlockHash]
-> ActionT Except (ReaderT WebState m) [Maybe BlockData]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM BlockHash -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock ([BlockHash] -> [BlockHash]
forall a. Eq a => [a] -> [a]
nub [BlockHash]
hs)
scottyBlocks ::
(MonadUnliftIO m, MonadLoggerIO m) => GetBlocks -> WebT m [BlockData]
scottyBlocks :: GetBlocks -> WebT m [BlockData]
scottyBlocks (GetBlocks hs :: [BlockHash]
hs (NoTx notx :: Bool
notx)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
blockStat ([BlockHash] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [BlockHash]
hs)
[BlockHash] -> Bool -> WebT m [BlockData]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
[BlockHash] -> Bool -> WebT m [BlockData]
getBlocks [BlockHash]
hs Bool
notx
pruneTx :: Bool -> BlockData -> BlockData
pruneTx :: Bool -> BlockData -> BlockData
pruneTx False b :: BlockData
b = BlockData
b
pruneTx True b :: BlockData
b = BlockData
b {blockDataTxs :: [TxHash]
blockDataTxs = Int -> [TxHash] -> [TxHash]
forall a. Int -> [a] -> [a]
take 1 (BlockData -> [TxHash]
blockDataTxs BlockData
b)}
scottyBlockRaw :: (MonadUnliftIO m, MonadLoggerIO m)
=> GetBlockRaw -> WebT m (RawResult H.Block)
scottyBlockRaw :: GetBlockRaw -> WebT m (RawResult Block)
scottyBlockRaw (GetBlockRaw h :: BlockHash
h) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
rawBlockStat 1
Block -> RawResult Block
forall a. a -> RawResult a
RawResult (Block -> RawResult Block)
-> ActionT Except (ReaderT WebState m) Block
-> WebT m (RawResult Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BlockHash -> ActionT Except (ReaderT WebState m) Block
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
BlockHash -> WebT m Block
getRawBlock BlockHash
h
getRawBlock :: (MonadUnliftIO m, MonadLoggerIO m)
=> H.BlockHash -> WebT m H.Block
getRawBlock :: BlockHash -> WebT m Block
getRawBlock h :: BlockHash
h = do
BlockData
b <- BlockHash -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock BlockHash
h ActionT Except (ReaderT WebState m) (Maybe BlockData)
-> (Maybe BlockData
-> ActionT Except (ReaderT WebState m) BlockData)
-> ActionT Except (ReaderT WebState m) BlockData
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ActionT Except (ReaderT WebState m) BlockData
-> (BlockData -> ActionT Except (ReaderT WebState m) BlockData)
-> Maybe BlockData
-> ActionT Except (ReaderT WebState m) BlockData
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
((WebMetrics -> StatDist)
-> Except -> ActionT Except (ReaderT WebState m) BlockData
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
rawBlockStat Except
ThingNotFound)
BlockData -> ActionT Except (ReaderT WebState m) BlockData
forall (m :: * -> *) a. Monad m => a -> m a
return
ReaderT WebState m Block -> WebT m Block
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (BlockData -> ReaderT WebState m Block
forall (m :: * -> *).
(MonadUnliftIO m, StoreReadBase m) =>
BlockData -> m Block
toRawBlock BlockData
b)
toRawBlock :: (MonadUnliftIO m, StoreReadBase m) => BlockData -> m H.Block
toRawBlock :: BlockData -> m Block
toRawBlock b :: BlockData
b = do
let ths :: [TxHash]
ths = BlockData -> [TxHash]
blockDataTxs BlockData
b
[Tx]
txs <- (TxHash -> m Tx) -> [TxHash] -> m [Tx]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TxHash -> m Tx
forall (m :: * -> *).
(MonadUnliftIO m, StoreReadBase m) =>
TxHash -> m Tx
f [TxHash]
ths
Block -> m Block
forall (m :: * -> *) a. Monad m => a -> m a
return $WBlock :: BlockHeader -> [Tx] -> Block
H.Block {blockHeader :: BlockHeader
H.blockHeader = BlockData -> BlockHeader
blockDataHeader BlockData
b, blockTxns :: [Tx]
H.blockTxns = [Tx]
txs}
where
f :: TxHash -> m Tx
f x :: TxHash
x = ((forall a. m a -> IO a) -> IO Tx) -> m Tx
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (((forall a. m a -> IO a) -> IO Tx) -> m Tx)
-> ((forall a. m a -> IO a) -> IO Tx) -> m Tx
forall a b. (a -> b) -> a -> b
$ \run :: forall a. m a -> IO a
run ->
IO Tx -> IO Tx
forall a. IO a -> IO a
unsafeInterleaveIO (IO Tx -> IO Tx) -> (m Tx -> IO Tx) -> m Tx -> IO Tx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m Tx -> IO Tx
forall a. m a -> IO a
run (m Tx -> IO Tx) -> m Tx -> IO Tx
forall a b. (a -> b) -> a -> b
$
TxHash -> m (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction TxHash
x m (Maybe Transaction) -> (Maybe Transaction -> m Tx) -> m Tx
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> m Tx
forall a. HasCallStack => a
undefined
Just t :: Transaction
t -> Tx -> m Tx
forall (m :: * -> *) a. Monad m => a -> m a
return (Tx -> m Tx) -> Tx -> m Tx
forall a b. (a -> b) -> a -> b
$ Transaction -> Tx
transactionData Transaction
t
scottyBlockBest ::
(MonadUnliftIO m, MonadLoggerIO m) => GetBlockBest -> WebT m BlockData
scottyBlockBest :: GetBlockBest -> WebT m BlockData
scottyBlockBest (GetBlockBest (NoTx notx :: Bool
notx)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
blockStat 1
ActionT Except (ReaderT WebState m) (Maybe BlockHash)
forall (m :: * -> *). StoreReadBase m => m (Maybe BlockHash)
getBestBlock ActionT Except (ReaderT WebState m) (Maybe BlockHash)
-> (Maybe BlockHash -> WebT m BlockData) -> WebT m BlockData
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> (WebMetrics -> StatDist) -> Except -> WebT m BlockData
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
blockStat Except
ThingNotFound
Just bb :: BlockHash
bb -> BlockHash -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock BlockHash
bb ActionT Except (ReaderT WebState m) (Maybe BlockData)
-> (Maybe BlockData -> WebT m BlockData) -> WebT m BlockData
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> (WebMetrics -> StatDist) -> Except -> WebT m BlockData
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
blockStat Except
ThingNotFound
Just b :: BlockData
b -> BlockData -> WebT m BlockData
forall (m :: * -> *) a. Monad m => a -> m a
return (BlockData -> WebT m BlockData) -> BlockData -> WebT m BlockData
forall a b. (a -> b) -> a -> b
$ Bool -> BlockData -> BlockData
pruneTx Bool
notx BlockData
b
scottyBlockBestRaw ::
(MonadUnliftIO m, MonadLoggerIO m)
=> GetBlockBestRaw
-> WebT m (RawResult H.Block)
scottyBlockBestRaw :: GetBlockBestRaw -> WebT m (RawResult Block)
scottyBlockBestRaw _ = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
rawBlockStat 1
Maybe BlockHash
bb <- ActionT Except (ReaderT WebState m) (Maybe BlockHash)
forall (m :: * -> *). StoreReadBase m => m (Maybe BlockHash)
getBestBlock
Block -> RawResult Block
forall a. a -> RawResult a
RawResult (Block -> RawResult Block)
-> ActionT Except (ReaderT WebState m) Block
-> WebT m (RawResult Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) Block
-> (BlockHash -> ActionT Except (ReaderT WebState m) Block)
-> Maybe BlockHash
-> ActionT Except (ReaderT WebState m) Block
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
((WebMetrics -> StatDist)
-> Except -> ActionT Except (ReaderT WebState m) Block
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
rawBlockStat Except
ThingNotFound)
BlockHash -> ActionT Except (ReaderT WebState m) Block
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
BlockHash -> WebT m Block
getRawBlock
Maybe BlockHash
bb
scottyBlockLatest ::
(MonadUnliftIO m, MonadLoggerIO m)
=> GetBlockLatest
-> WebT m [BlockData]
scottyBlockLatest :: GetBlockLatest -> WebT m [BlockData]
scottyBlockLatest (GetBlockLatest (NoTx noTx :: Bool
noTx)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
blockStat 100
ActionT Except (ReaderT WebState m) (Maybe BlockHash)
forall (m :: * -> *). StoreReadBase m => m (Maybe BlockHash)
getBestBlock ActionT Except (ReaderT WebState m) (Maybe BlockHash)
-> (Maybe BlockHash -> WebT m [BlockData]) -> WebT m [BlockData]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= WebT m [BlockData]
-> (BlockHash -> WebT m [BlockData])
-> Maybe BlockHash
-> WebT m [BlockData]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
((WebMetrics -> StatDist) -> Except -> WebT m [BlockData]
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
blockStat Except
ThingNotFound)
([BlockData] -> Maybe BlockData -> WebT m [BlockData]
forall (m :: * -> *).
StoreReadBase m =>
[BlockData] -> Maybe BlockData -> m [BlockData]
go [] (Maybe BlockData -> WebT m [BlockData])
-> (BlockHash
-> ActionT Except (ReaderT WebState m) (Maybe BlockData))
-> BlockHash
-> WebT m [BlockData]
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< BlockHash -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock)
where
go :: [BlockData] -> Maybe BlockData -> m [BlockData]
go acc :: [BlockData]
acc Nothing = [BlockData] -> m [BlockData]
forall (m :: * -> *) a. Monad m => a -> m a
return [BlockData]
acc
go acc :: [BlockData]
acc (Just b :: BlockData
b)
| BlockData -> Word32
blockDataHeight BlockData
b Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0 = [BlockData] -> m [BlockData]
forall (m :: * -> *) a. Monad m => a -> m a
return [BlockData]
acc
| [BlockData] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [BlockData]
acc Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 99 = [BlockData] -> m [BlockData]
forall (m :: * -> *) a. Monad m => a -> m a
return (BlockData
bBlockData -> [BlockData] -> [BlockData]
forall a. a -> [a] -> [a]
:[BlockData]
acc)
| Bool
otherwise = do
let prev :: BlockHash
prev = BlockHeader -> BlockHash
H.prevBlock (BlockData -> BlockHeader
blockDataHeader BlockData
b)
[BlockData] -> Maybe BlockData -> m [BlockData]
go (Bool -> BlockData -> BlockData
pruneTx Bool
noTx BlockData
b BlockData -> [BlockData] -> [BlockData]
forall a. a -> [a] -> [a]
: [BlockData]
acc) (Maybe BlockData -> m [BlockData])
-> m (Maybe BlockData) -> m [BlockData]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< BlockHash -> m (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock BlockHash
prev
scottyBlockHeight ::
(MonadUnliftIO m, MonadLoggerIO m) => GetBlockHeight -> WebT m [BlockData]
scottyBlockHeight :: GetBlockHeight -> WebT m [BlockData]
scottyBlockHeight (GetBlockHeight h :: HeightParam
h (NoTx notx :: Bool
notx)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
blockStat 1
([BlockHash] -> Bool -> WebT m [BlockData]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
[BlockHash] -> Bool -> WebT m [BlockData]
`getBlocks` Bool
notx) ([BlockHash] -> WebT m [BlockData])
-> ActionT Except (ReaderT WebState m) [BlockHash]
-> WebT m [BlockData]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Word32 -> ActionT Except (ReaderT WebState m) [BlockHash]
forall (m :: * -> *). StoreReadBase m => Word32 -> m [BlockHash]
getBlocksAtHeight (HeightParam -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral HeightParam
h)
scottyBlockHeights ::
(MonadUnliftIO m, MonadLoggerIO m)
=> GetBlockHeights
-> WebT m [BlockData]
scottyBlockHeights :: GetBlockHeights -> WebT m [BlockData]
scottyBlockHeights (GetBlockHeights (HeightsParam heights :: [Natural]
heights) (NoTx notx :: Bool
notx)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
blockStat ([Natural] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Natural]
heights)
[BlockHash]
bhs <- [[BlockHash]] -> [BlockHash]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[BlockHash]] -> [BlockHash])
-> ActionT Except (ReaderT WebState m) [[BlockHash]]
-> ActionT Except (ReaderT WebState m) [BlockHash]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Word32 -> ActionT Except (ReaderT WebState m) [BlockHash])
-> [Word32] -> ActionT Except (ReaderT WebState m) [[BlockHash]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Word32 -> ActionT Except (ReaderT WebState m) [BlockHash]
forall (m :: * -> *). StoreReadBase m => Word32 -> m [BlockHash]
getBlocksAtHeight (Natural -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Natural -> Word32) -> [Natural] -> [Word32]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Natural]
heights)
[BlockHash] -> Bool -> WebT m [BlockData]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
[BlockHash] -> Bool -> WebT m [BlockData]
getBlocks [BlockHash]
bhs Bool
notx
scottyBlockHeightRaw ::
(MonadUnliftIO m, MonadLoggerIO m)
=> GetBlockHeightRaw
-> WebT m (RawResultList H.Block)
scottyBlockHeightRaw :: GetBlockHeightRaw -> WebT m (RawResultList Block)
scottyBlockHeightRaw (GetBlockHeightRaw h :: HeightParam
h) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
rawBlockStat 1
[Block] -> RawResultList Block
forall a. [a] -> RawResultList a
RawResultList ([Block] -> RawResultList Block)
-> ActionT Except (ReaderT WebState m) [Block]
-> WebT m (RawResultList Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((BlockHash -> ActionT Except (ReaderT WebState m) Block)
-> [BlockHash] -> ActionT Except (ReaderT WebState m) [Block]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM BlockHash -> ActionT Except (ReaderT WebState m) Block
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
BlockHash -> WebT m Block
getRawBlock ([BlockHash] -> ActionT Except (ReaderT WebState m) [Block])
-> ActionT Except (ReaderT WebState m) [BlockHash]
-> ActionT Except (ReaderT WebState m) [Block]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Word32 -> ActionT Except (ReaderT WebState m) [BlockHash]
forall (m :: * -> *). StoreReadBase m => Word32 -> m [BlockHash]
getBlocksAtHeight (HeightParam -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral HeightParam
h))
scottyBlockTime :: (MonadUnliftIO m, MonadLoggerIO m)
=> GetBlockTime -> WebT m BlockData
scottyBlockTime :: GetBlockTime -> WebT m BlockData
scottyBlockTime (GetBlockTime (TimeParam t :: Word64
t) (NoTx notx :: Bool
notx)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
blockStat 1
Chain
ch <- ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain)
-> ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain
forall a b. (a -> b) -> a -> b
$ (WebState -> Chain) -> ReaderT WebState m Chain
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Chain
storeChain (Store -> Chain) -> (WebState -> Store) -> WebState -> Chain
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Maybe BlockData
m <- Chain
-> Word64 -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
(MonadIO m, StoreReadExtra m) =>
Chain -> Word64 -> m (Maybe BlockData)
blockAtOrBefore Chain
ch Word64
t
WebT m BlockData
-> (BlockData -> WebT m BlockData)
-> Maybe BlockData
-> WebT m BlockData
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((WebMetrics -> StatDist) -> Except -> WebT m BlockData
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
blockStat Except
ThingNotFound) (BlockData -> WebT m BlockData
forall (m :: * -> *) a. Monad m => a -> m a
return (BlockData -> WebT m BlockData)
-> (BlockData -> BlockData) -> BlockData -> WebT m BlockData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> BlockData -> BlockData
pruneTx Bool
notx) Maybe BlockData
m
scottyBlockMTP :: (MonadUnliftIO m, MonadLoggerIO m)
=> GetBlockMTP -> WebT m BlockData
scottyBlockMTP :: GetBlockMTP -> WebT m BlockData
scottyBlockMTP (GetBlockMTP (TimeParam t :: Word64
t) (NoTx noTx :: Bool
noTx)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
blockStat 1
Chain
ch <- ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain)
-> ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain
forall a b. (a -> b) -> a -> b
$ (WebState -> Chain) -> ReaderT WebState m Chain
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Chain
storeChain (Store -> Chain) -> (WebState -> Store) -> WebState -> Chain
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Maybe BlockData
m <- Chain
-> Word64 -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
(MonadIO m, StoreReadExtra m) =>
Chain -> Word64 -> m (Maybe BlockData)
blockAtOrAfterMTP Chain
ch Word64
t
WebT m BlockData
-> (BlockData -> WebT m BlockData)
-> Maybe BlockData
-> WebT m BlockData
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((WebMetrics -> StatDist) -> Except -> WebT m BlockData
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
blockStat Except
ThingNotFound) (BlockData -> WebT m BlockData
forall (m :: * -> *) a. Monad m => a -> m a
return (BlockData -> WebT m BlockData)
-> (BlockData -> BlockData) -> BlockData -> WebT m BlockData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> BlockData -> BlockData
pruneTx Bool
noTx) Maybe BlockData
m
scottyBlockTimeRaw :: (MonadUnliftIO m, MonadLoggerIO m)
=> GetBlockTimeRaw -> WebT m (RawResult H.Block)
scottyBlockTimeRaw :: GetBlockTimeRaw -> WebT m (RawResult Block)
scottyBlockTimeRaw (GetBlockTimeRaw (TimeParam t :: Word64
t)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
rawBlockStat 1
Chain
ch <- ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain)
-> ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain
forall a b. (a -> b) -> a -> b
$ (WebState -> Chain) -> ReaderT WebState m Chain
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Chain
storeChain (Store -> Chain) -> (WebState -> Store) -> WebState -> Chain
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Maybe BlockData
m <- Chain
-> Word64 -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
(MonadIO m, StoreReadExtra m) =>
Chain -> Word64 -> m (Maybe BlockData)
blockAtOrBefore Chain
ch Word64
t
BlockData
b <- WebT m BlockData
-> (BlockData -> WebT m BlockData)
-> Maybe BlockData
-> WebT m BlockData
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((WebMetrics -> StatDist) -> Except -> WebT m BlockData
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
rawBlockStat Except
ThingNotFound) BlockData -> WebT m BlockData
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe BlockData
m
Block -> RawResult Block
forall a. a -> RawResult a
RawResult (Block -> RawResult Block)
-> ActionT Except (ReaderT WebState m) Block
-> WebT m (RawResult Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT WebState m Block
-> ActionT Except (ReaderT WebState m) Block
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (BlockData -> ReaderT WebState m Block
forall (m :: * -> *).
(MonadUnliftIO m, StoreReadBase m) =>
BlockData -> m Block
toRawBlock BlockData
b)
scottyBlockMTPRaw :: (MonadUnliftIO m, MonadLoggerIO m)
=> GetBlockMTPRaw -> WebT m (RawResult H.Block)
scottyBlockMTPRaw :: GetBlockMTPRaw -> WebT m (RawResult Block)
scottyBlockMTPRaw (GetBlockMTPRaw (TimeParam t :: Word64
t)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
rawBlockStat 1
Chain
ch <- ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain)
-> ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain
forall a b. (a -> b) -> a -> b
$ (WebState -> Chain) -> ReaderT WebState m Chain
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Chain
storeChain (Store -> Chain) -> (WebState -> Store) -> WebState -> Chain
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Maybe BlockData
m <- Chain
-> Word64 -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
(MonadIO m, StoreReadExtra m) =>
Chain -> Word64 -> m (Maybe BlockData)
blockAtOrAfterMTP Chain
ch Word64
t
BlockData
b <- WebT m BlockData
-> (BlockData -> WebT m BlockData)
-> Maybe BlockData
-> WebT m BlockData
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((WebMetrics -> StatDist) -> Except -> WebT m BlockData
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
rawBlockStat Except
ThingNotFound) BlockData -> WebT m BlockData
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe BlockData
m
Block -> RawResult Block
forall a. a -> RawResult a
RawResult (Block -> RawResult Block)
-> ActionT Except (ReaderT WebState m) Block
-> WebT m (RawResult Block)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT WebState m Block
-> ActionT Except (ReaderT WebState m) Block
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (BlockData -> ReaderT WebState m Block
forall (m :: * -> *).
(MonadUnliftIO m, StoreReadBase m) =>
BlockData -> m Block
toRawBlock BlockData
b)
scottyTx :: (MonadUnliftIO m, MonadLoggerIO m) => GetTx -> WebT m Transaction
scottyTx :: GetTx -> WebT m Transaction
scottyTx (GetTx txid :: TxHash
txid) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
txStat 1
WebT m Transaction
-> (Transaction -> WebT m Transaction)
-> Maybe Transaction
-> WebT m Transaction
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((WebMetrics -> StatDist) -> Except -> WebT m Transaction
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
txStat Except
ThingNotFound) Transaction -> WebT m Transaction
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Transaction -> WebT m Transaction)
-> ActionT Except (ReaderT WebState m) (Maybe Transaction)
-> WebT m Transaction
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TxHash -> ActionT Except (ReaderT WebState m) (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction TxHash
txid
scottyTxs ::
(MonadUnliftIO m, MonadLoggerIO m) => GetTxs -> WebT m [Transaction]
scottyTxs :: GetTxs -> WebT m [Transaction]
scottyTxs (GetTxs txids :: [TxHash]
txids) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
txStat ([TxHash] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TxHash]
txids)
[Maybe Transaction] -> [Transaction]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Transaction] -> [Transaction])
-> ActionT Except (ReaderT WebState m) [Maybe Transaction]
-> WebT m [Transaction]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TxHash -> ActionT Except (ReaderT WebState m) (Maybe Transaction))
-> [TxHash]
-> ActionT Except (ReaderT WebState m) [Maybe Transaction]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TxHash -> ActionT Except (ReaderT WebState m) (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction ([TxHash] -> [TxHash]
forall a. Eq a => [a] -> [a]
nub [TxHash]
txids)
scottyTxRaw ::
(MonadUnliftIO m, MonadLoggerIO m) => GetTxRaw -> WebT m (RawResult Tx)
scottyTxRaw :: GetTxRaw -> WebT m (RawResult Tx)
scottyTxRaw (GetTxRaw txid :: TxHash
txid) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
txStat 1
Transaction
tx <- WebT m Transaction
-> (Transaction -> WebT m Transaction)
-> Maybe Transaction
-> WebT m Transaction
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((WebMetrics -> StatDist) -> Except -> WebT m Transaction
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
txStat Except
ThingNotFound) Transaction -> WebT m Transaction
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Transaction -> WebT m Transaction)
-> ActionT Except (ReaderT WebState m) (Maybe Transaction)
-> WebT m Transaction
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TxHash -> ActionT Except (ReaderT WebState m) (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction TxHash
txid
RawResult Tx -> WebT m (RawResult Tx)
forall (m :: * -> *) a. Monad m => a -> m a
return (RawResult Tx -> WebT m (RawResult Tx))
-> RawResult Tx -> WebT m (RawResult Tx)
forall a b. (a -> b) -> a -> b
$ Tx -> RawResult Tx
forall a. a -> RawResult a
RawResult (Tx -> RawResult Tx) -> Tx -> RawResult Tx
forall a b. (a -> b) -> a -> b
$ Transaction -> Tx
transactionData Transaction
tx
scottyTxsRaw ::
(MonadUnliftIO m, MonadLoggerIO m)
=> GetTxsRaw
-> WebT m (RawResultList Tx)
scottyTxsRaw :: GetTxsRaw -> WebT m (RawResultList Tx)
scottyTxsRaw (GetTxsRaw txids :: [TxHash]
txids) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
txStat ([TxHash] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TxHash]
txids)
[Transaction]
txs <- [Maybe Transaction] -> [Transaction]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Transaction] -> [Transaction])
-> ActionT Except (ReaderT WebState m) [Maybe Transaction]
-> ActionT Except (ReaderT WebState m) [Transaction]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TxHash -> ActionT Except (ReaderT WebState m) (Maybe Transaction))
-> [TxHash]
-> ActionT Except (ReaderT WebState m) [Maybe Transaction]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TxHash -> ActionT Except (ReaderT WebState m) (Maybe Transaction)
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(MonadTrans t, MonadUnliftIO m, StoreReadBase m) =>
TxHash -> t m (Maybe Transaction)
f ([TxHash] -> [TxHash]
forall a. Eq a => [a] -> [a]
nub [TxHash]
txids)
RawResultList Tx -> WebT m (RawResultList Tx)
forall (m :: * -> *) a. Monad m => a -> m a
return (RawResultList Tx -> WebT m (RawResultList Tx))
-> RawResultList Tx -> WebT m (RawResultList Tx)
forall a b. (a -> b) -> a -> b
$ [Tx] -> RawResultList Tx
forall a. [a] -> RawResultList a
RawResultList ([Tx] -> RawResultList Tx) -> [Tx] -> RawResultList Tx
forall a b. (a -> b) -> a -> b
$ Transaction -> Tx
transactionData (Transaction -> Tx) -> [Transaction] -> [Tx]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Transaction]
txs
where
f :: TxHash -> t m (Maybe Transaction)
f x :: TxHash
x = m (Maybe Transaction) -> t m (Maybe Transaction)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Maybe Transaction) -> t m (Maybe Transaction))
-> m (Maybe Transaction) -> t m (Maybe Transaction)
forall a b. (a -> b) -> a -> b
$ ((forall a. m a -> IO a) -> IO (Maybe Transaction))
-> m (Maybe Transaction)
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (((forall a. m a -> IO a) -> IO (Maybe Transaction))
-> m (Maybe Transaction))
-> ((forall a. m a -> IO a) -> IO (Maybe Transaction))
-> m (Maybe Transaction)
forall a b. (a -> b) -> a -> b
$ \run :: forall a. m a -> IO a
run ->
IO (Maybe Transaction) -> IO (Maybe Transaction)
forall a. IO a -> IO a
unsafeInterleaveIO (IO (Maybe Transaction) -> IO (Maybe Transaction))
-> (m (Maybe Transaction) -> IO (Maybe Transaction))
-> m (Maybe Transaction)
-> IO (Maybe Transaction)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Maybe Transaction) -> IO (Maybe Transaction)
forall a. m a -> IO a
run (m (Maybe Transaction) -> IO (Maybe Transaction))
-> m (Maybe Transaction) -> IO (Maybe Transaction)
forall a b. (a -> b) -> a -> b
$
TxHash -> m (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction TxHash
x
getTxsBlock :: (MonadUnliftIO m, MonadLoggerIO m)
=> H.BlockHash
-> WebT m [Transaction]
getTxsBlock :: BlockHash -> WebT m [Transaction]
getTxsBlock h :: BlockHash
h = do
BlockData
b <- WebT m BlockData
-> (BlockData -> WebT m BlockData)
-> Maybe BlockData
-> WebT m BlockData
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((WebMetrics -> StatDist) -> Except -> WebT m BlockData
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
txsBlockStat Except
ThingNotFound) BlockData -> WebT m BlockData
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe BlockData -> WebT m BlockData)
-> ActionT Except (ReaderT WebState m) (Maybe BlockData)
-> WebT m BlockData
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< BlockHash -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock BlockHash
h
(TxHash -> ActionT Except (ReaderT WebState m) Transaction)
-> [TxHash] -> WebT m [Transaction]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TxHash -> ActionT Except (ReaderT WebState m) Transaction
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(MonadTrans t, MonadUnliftIO m, StoreReadBase m) =>
TxHash -> t m Transaction
f (BlockData -> [TxHash]
blockDataTxs BlockData
b)
where
f :: TxHash -> t m Transaction
f x :: TxHash
x = m Transaction -> t m Transaction
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Transaction -> t m Transaction)
-> m Transaction -> t m Transaction
forall a b. (a -> b) -> a -> b
$ ((forall a. m a -> IO a) -> IO Transaction) -> m Transaction
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (((forall a. m a -> IO a) -> IO Transaction) -> m Transaction)
-> ((forall a. m a -> IO a) -> IO Transaction) -> m Transaction
forall a b. (a -> b) -> a -> b
$ \run :: forall a. m a -> IO a
run ->
IO Transaction -> IO Transaction
forall a. IO a -> IO a
unsafeInterleaveIO (IO Transaction -> IO Transaction)
-> (m Transaction -> IO Transaction)
-> m Transaction
-> IO Transaction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m Transaction -> IO Transaction
forall a. m a -> IO a
run (m Transaction -> IO Transaction)
-> m Transaction -> IO Transaction
forall a b. (a -> b) -> a -> b
$
TxHash -> m (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction TxHash
x m (Maybe Transaction)
-> (Maybe Transaction -> m Transaction) -> m Transaction
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> m Transaction
forall a. HasCallStack => a
undefined
Just t :: Transaction
t -> Transaction -> m Transaction
forall (m :: * -> *) a. Monad m => a -> m a
return Transaction
t
scottyTxsBlock ::
(MonadUnliftIO m, MonadLoggerIO m) => GetTxsBlock -> WebT m [Transaction]
scottyTxsBlock :: GetTxsBlock -> WebT m [Transaction]
scottyTxsBlock (GetTxsBlock h :: BlockHash
h) =
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
txsBlockStat 1 WebT m () -> WebT m [Transaction] -> WebT m [Transaction]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BlockHash -> WebT m [Transaction]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
BlockHash -> WebT m [Transaction]
getTxsBlock BlockHash
h
scottyTxsBlockRaw ::
(MonadUnliftIO m, MonadLoggerIO m)
=> GetTxsBlockRaw
-> WebT m (RawResultList Tx)
scottyTxsBlockRaw :: GetTxsBlockRaw -> WebT m (RawResultList Tx)
scottyTxsBlockRaw (GetTxsBlockRaw h :: BlockHash
h) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
txsBlockStat 1
[Tx] -> RawResultList Tx
forall a. [a] -> RawResultList a
RawResultList ([Tx] -> RawResultList Tx)
-> ([Transaction] -> [Tx]) -> [Transaction] -> RawResultList Tx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Transaction -> Tx) -> [Transaction] -> [Tx]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Transaction -> Tx
transactionData ([Transaction] -> RawResultList Tx)
-> ActionT Except (ReaderT WebState m) [Transaction]
-> WebT m (RawResultList Tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BlockHash -> ActionT Except (ReaderT WebState m) [Transaction]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
BlockHash -> WebT m [Transaction]
getTxsBlock BlockHash
h
scottyTxAfter ::
(MonadUnliftIO m, MonadLoggerIO m)
=> GetTxAfter
-> WebT m (GenericResult (Maybe Bool))
scottyTxAfter :: GetTxAfter -> WebT m (GenericResult (Maybe Bool))
scottyTxAfter (GetTxAfter txid :: TxHash
txid height :: HeightParam
height) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
txAfterStat 1
Maybe Bool -> GenericResult (Maybe Bool)
forall a. a -> GenericResult a
GenericResult (Maybe Bool -> GenericResult (Maybe Bool))
-> ActionT Except (ReaderT WebState m) (Maybe Bool)
-> WebT m (GenericResult (Maybe Bool))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word32
-> TxHash -> ActionT Except (ReaderT WebState m) (Maybe Bool)
forall (m :: * -> *).
(MonadIO m, StoreReadBase m) =>
Word32 -> TxHash -> m (Maybe Bool)
cbAfterHeight (HeightParam -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral HeightParam
height) TxHash
txid
cbAfterHeight ::
(MonadIO m, StoreReadBase m)
=> H.BlockHeight
-> TxHash
-> m (Maybe Bool)
cbAfterHeight :: Word32 -> TxHash -> m (Maybe Bool)
cbAfterHeight height :: Word32
height txid :: TxHash
txid =
Integer
-> HashSet TxHash -> HashSet TxHash -> [TxHash] -> m (Maybe Bool)
forall a (m :: * -> *).
(Eq a, Num a, StoreReadBase m) =>
a -> HashSet TxHash -> HashSet TxHash -> [TxHash] -> m (Maybe Bool)
inputs 10000 HashSet TxHash
forall a. HashSet a
HashSet.empty HashSet TxHash
forall a. HashSet a
HashSet.empty [TxHash
txid]
where
inputs :: a -> HashSet TxHash -> HashSet TxHash -> [TxHash] -> m (Maybe Bool)
inputs 0 _ _ [] = Maybe Bool -> m (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Bool
forall a. Maybe a
Nothing
inputs i :: a
i is :: HashSet TxHash
is ns :: HashSet TxHash
ns [] =
let is' :: HashSet TxHash
is' = HashSet TxHash -> HashSet TxHash -> HashSet TxHash
forall a. (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a
HashSet.union HashSet TxHash
is HashSet TxHash
ns
ns' :: HashSet a
ns' = HashSet a
forall a. HashSet a
HashSet.empty
ts :: [TxHash]
ts = HashSet TxHash -> [TxHash]
forall a. HashSet a -> [a]
HashSet.toList (HashSet TxHash -> HashSet TxHash -> HashSet TxHash
forall a. (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a
HashSet.difference HashSet TxHash
ns HashSet TxHash
is)
in case [TxHash]
ts of
[] -> Maybe Bool -> m (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
_ -> a -> HashSet TxHash -> HashSet TxHash -> [TxHash] -> m (Maybe Bool)
inputs a
i HashSet TxHash
is' HashSet TxHash
forall a. HashSet a
ns' [TxHash]
ts
inputs i :: a
i is :: HashSet TxHash
is ns :: HashSet TxHash
ns (t :: TxHash
t:ts :: [TxHash]
ts) = TxHash -> m (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction TxHash
t m (Maybe Transaction)
-> (Maybe Transaction -> m (Maybe Bool)) -> m (Maybe Bool)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> Maybe Bool -> m (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Bool
forall a. Maybe a
Nothing
Just tx :: Transaction
tx | Transaction -> Bool
height_check Transaction
tx ->
if Transaction -> Bool
cb_check Transaction
tx
then Maybe Bool -> m (Maybe Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True)
else let ns' :: HashSet TxHash
ns' = HashSet TxHash -> HashSet TxHash -> HashSet TxHash
forall a. (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a
HashSet.union (Transaction -> HashSet TxHash
ins Transaction
tx) HashSet TxHash
ns
in a -> HashSet TxHash -> HashSet TxHash -> [TxHash] -> m (Maybe Bool)
inputs (a
i a -> a -> a
forall a. Num a => a -> a -> a
- 1) HashSet TxHash
is HashSet TxHash
ns' [TxHash]
ts
| Bool
otherwise -> a -> HashSet TxHash -> HashSet TxHash -> [TxHash] -> m (Maybe Bool)
inputs (a
i a -> a -> a
forall a. Num a => a -> a -> a
- 1) HashSet TxHash
is HashSet TxHash
ns [TxHash]
ts
cb_check :: Transaction -> Bool
cb_check = (StoreInput -> Bool) -> [StoreInput] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any StoreInput -> Bool
isCoinbase ([StoreInput] -> Bool)
-> (Transaction -> [StoreInput]) -> Transaction -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transaction -> [StoreInput]
transactionInputs
ins :: Transaction -> HashSet TxHash
ins = [TxHash] -> HashSet TxHash
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList ([TxHash] -> HashSet TxHash)
-> (Transaction -> [TxHash]) -> Transaction -> HashSet TxHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StoreInput -> TxHash) -> [StoreInput] -> [TxHash]
forall a b. (a -> b) -> [a] -> [b]
map (OutPoint -> TxHash
outPointHash (OutPoint -> TxHash)
-> (StoreInput -> OutPoint) -> StoreInput -> TxHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StoreInput -> OutPoint
inputPoint) ([StoreInput] -> [TxHash])
-> (Transaction -> [StoreInput]) -> Transaction -> [TxHash]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transaction -> [StoreInput]
transactionInputs
height_check :: Transaction -> Bool
height_check tx :: Transaction
tx =
case Transaction -> BlockRef
transactionBlock Transaction
tx of
BlockRef h :: Word32
h _ -> Word32
h Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
> Word32
height
_ -> Bool
True
scottyPostTx :: (MonadUnliftIO m, MonadLoggerIO m) => PostTx -> WebT m TxId
scottyPostTx :: PostTx -> WebT m TxId
scottyPostTx (PostTx tx :: Tx
tx) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
postTxStat 1
ReaderT WebState m WebConfig
-> ActionT Except (ReaderT WebState m) WebConfig
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> WebConfig) -> ReaderT WebState m WebConfig
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WebState -> WebConfig
webConfig) ActionT Except (ReaderT WebState m) WebConfig
-> (WebConfig -> WebT m TxId) -> WebT m TxId
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \cfg :: WebConfig
cfg -> ReaderT WebState m (Either PubExcept ())
-> ActionT Except (ReaderT WebState m) (Either PubExcept ())
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (WebConfig -> Tx -> ReaderT WebState m (Either PubExcept ())
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m) =>
WebConfig -> Tx -> m (Either PubExcept ())
publishTx WebConfig
cfg Tx
tx) ActionT Except (ReaderT WebState m) (Either PubExcept ())
-> (Either PubExcept () -> WebT m TxId) -> WebT m TxId
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Right () -> TxId -> WebT m TxId
forall (m :: * -> *) a. Monad m => a -> m a
return (TxId -> WebT m TxId) -> TxId -> WebT m TxId
forall a b. (a -> b) -> a -> b
$ TxHash -> TxId
TxId (Tx -> TxHash
txHash Tx
tx)
Left e :: PubExcept
e@(PubReject _) -> (WebMetrics -> StatDist) -> Except -> WebT m TxId
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
postTxStat (Except -> WebT m TxId) -> Except -> WebT m TxId
forall a b. (a -> b) -> a -> b
$ String -> Except
UserError (String -> Except) -> String -> Except
forall a b. (a -> b) -> a -> b
$ PubExcept -> String
forall a. Show a => a -> String
show PubExcept
e
_ -> (WebMetrics -> StatDist) -> Except -> WebT m TxId
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
postTxStat Except
ServerError
publishTx ::
(MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m)
=> WebConfig
-> Tx
-> m (Either PubExcept ())
publishTx :: WebConfig -> Tx -> m (Either PubExcept ())
publishTx cfg :: WebConfig
cfg tx :: Tx
tx =
Publisher StoreEvent
-> (Inbox StoreEvent -> m (Either PubExcept ()))
-> m (Either PubExcept ())
forall (m :: * -> *) msg a.
MonadUnliftIO m =>
Publisher msg -> (Inbox msg -> m a) -> m a
withSubscription Publisher StoreEvent
pub ((Inbox StoreEvent -> m (Either PubExcept ()))
-> m (Either PubExcept ()))
-> (Inbox StoreEvent -> m (Either PubExcept ()))
-> m (Either PubExcept ())
forall a b. (a -> b) -> a -> b
$ \s :: Inbox StoreEvent
s ->
TxHash -> m (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction (Tx -> TxHash
txHash Tx
tx) m (Maybe Transaction)
-> (Maybe Transaction -> m (Either PubExcept ()))
-> m (Either PubExcept ())
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just _ -> Either PubExcept () -> m (Either PubExcept ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Either PubExcept () -> m (Either PubExcept ()))
-> Either PubExcept () -> m (Either PubExcept ())
forall a b. (a -> b) -> a -> b
$ () -> Either PubExcept ()
forall a b. b -> Either a b
Right ()
Nothing -> Inbox StoreEvent -> m (Either PubExcept ())
forall (m :: * -> *) (mbox :: * -> *).
(MonadIO m, InChan mbox) =>
mbox StoreEvent -> m (Either PubExcept ())
go Inbox StoreEvent
s
where
pub :: Publisher StoreEvent
pub = Store -> Publisher StoreEvent
storePublisher (WebConfig -> Store
webStore WebConfig
cfg)
mgr :: PeerManager
mgr = Store -> PeerManager
storeManager (WebConfig -> Store
webStore WebConfig
cfg)
net :: Network
net = Store -> Network
storeNetwork (WebConfig -> Store
webStore WebConfig
cfg)
go :: mbox StoreEvent -> m (Either PubExcept ())
go s :: mbox StoreEvent
s =
PeerManager -> m [OnlinePeer]
forall (m :: * -> *). MonadIO m => PeerManager -> m [OnlinePeer]
getPeers PeerManager
mgr m [OnlinePeer]
-> ([OnlinePeer] -> m (Either PubExcept ()))
-> m (Either PubExcept ())
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
[] -> Either PubExcept () -> m (Either PubExcept ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Either PubExcept () -> m (Either PubExcept ()))
-> Either PubExcept () -> m (Either PubExcept ())
forall a b. (a -> b) -> a -> b
$ PubExcept -> Either PubExcept ()
forall a b. a -> Either a b
Left PubExcept
PubNoPeers
OnlinePeer {onlinePeerMailbox :: OnlinePeer -> Peer
onlinePeerMailbox = Peer
p}:_ -> do
Tx -> Message
MTx Tx
tx Message -> Peer -> m ()
forall (m :: * -> *). MonadIO m => Message -> Peer -> m ()
`sendMessage` Peer
p
let v :: InvType
v =
if Network -> Bool
getSegWit Network
net
then InvType
InvWitnessTx
else InvType
InvTx
Message -> Peer -> m ()
forall (m :: * -> *). MonadIO m => Message -> Peer -> m ()
sendMessage
(GetData -> Message
MGetData ([InvVector] -> GetData
GetData [InvType -> Hash256 -> InvVector
InvVector InvType
v (TxHash -> Hash256
getTxHash (Tx -> TxHash
txHash Tx
tx))]))
Peer
p
Peer -> mbox StoreEvent -> m (Either PubExcept ())
forall (m :: * -> *) (mbox :: * -> *).
(MonadIO m, InChan mbox) =>
Peer -> mbox StoreEvent -> m (Either PubExcept ())
f Peer
p mbox StoreEvent
s
t :: Int
t = 5 Int -> Int -> Int
forall a. Num a => a -> a -> a
* 1000 Int -> Int -> Int
forall a. Num a => a -> a -> a
* 1000
f :: Peer -> mbox StoreEvent -> m (Either PubExcept ())
f p :: Peer
p s :: mbox StoreEvent
s
| WebConfig -> Bool
webNoMempool WebConfig
cfg = Either PubExcept () -> m (Either PubExcept ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Either PubExcept () -> m (Either PubExcept ()))
-> Either PubExcept () -> m (Either PubExcept ())
forall a b. (a -> b) -> a -> b
$ () -> Either PubExcept ()
forall a b. b -> Either a b
Right ()
| Bool
otherwise =
IO (Maybe (Either PubExcept ())) -> m (Maybe (Either PubExcept ()))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Int -> IO (Either PubExcept ()) -> IO (Maybe (Either PubExcept ()))
forall (m :: * -> *) a.
MonadUnliftIO m =>
Int -> m a -> m (Maybe a)
timeout Int
t (Peer -> mbox StoreEvent -> IO (Either PubExcept ())
forall (m :: * -> *) (mbox :: * -> *).
(InChan mbox, MonadIO m) =>
Peer -> mbox StoreEvent -> m (Either PubExcept ())
g Peer
p mbox StoreEvent
s)) m (Maybe (Either PubExcept ()))
-> (Maybe (Either PubExcept ()) -> m (Either PubExcept ()))
-> m (Either PubExcept ())
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> Either PubExcept () -> m (Either PubExcept ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Either PubExcept () -> m (Either PubExcept ()))
-> Either PubExcept () -> m (Either PubExcept ())
forall a b. (a -> b) -> a -> b
$ PubExcept -> Either PubExcept ()
forall a b. a -> Either a b
Left PubExcept
PubTimeout
Just (Left e :: PubExcept
e) -> Either PubExcept () -> m (Either PubExcept ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Either PubExcept () -> m (Either PubExcept ()))
-> Either PubExcept () -> m (Either PubExcept ())
forall a b. (a -> b) -> a -> b
$ PubExcept -> Either PubExcept ()
forall a b. a -> Either a b
Left PubExcept
e
Just (Right ()) -> Either PubExcept () -> m (Either PubExcept ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Either PubExcept () -> m (Either PubExcept ()))
-> Either PubExcept () -> m (Either PubExcept ())
forall a b. (a -> b) -> a -> b
$ () -> Either PubExcept ()
forall a b. b -> Either a b
Right ()
g :: Peer -> mbox StoreEvent -> m (Either PubExcept ())
g p :: Peer
p s :: mbox StoreEvent
s =
mbox StoreEvent -> m StoreEvent
forall (mbox :: * -> *) (m :: * -> *) msg.
(InChan mbox, MonadIO m) =>
mbox msg -> m msg
receive mbox StoreEvent
s m StoreEvent
-> (StoreEvent -> m (Either PubExcept ()))
-> m (Either PubExcept ())
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
StoreTxReject p' :: Peer
p' h' :: TxHash
h' c :: RejectCode
c _
| Peer
p Peer -> Peer -> Bool
forall a. Eq a => a -> a -> Bool
== Peer
p' Bool -> Bool -> Bool
&& TxHash
h' TxHash -> TxHash -> Bool
forall a. Eq a => a -> a -> Bool
== Tx -> TxHash
txHash Tx
tx -> Either PubExcept () -> m (Either PubExcept ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Either PubExcept () -> m (Either PubExcept ()))
-> (PubExcept -> Either PubExcept ())
-> PubExcept
-> m (Either PubExcept ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PubExcept -> Either PubExcept ()
forall a b. a -> Either a b
Left (PubExcept -> m (Either PubExcept ()))
-> PubExcept -> m (Either PubExcept ())
forall a b. (a -> b) -> a -> b
$ RejectCode -> PubExcept
PubReject RejectCode
c
StorePeerDisconnected p' :: Peer
p'
| Peer
p Peer -> Peer -> Bool
forall a. Eq a => a -> a -> Bool
== Peer
p' -> Either PubExcept () -> m (Either PubExcept ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Either PubExcept () -> m (Either PubExcept ()))
-> Either PubExcept () -> m (Either PubExcept ())
forall a b. (a -> b) -> a -> b
$ PubExcept -> Either PubExcept ()
forall a b. a -> Either a b
Left PubExcept
PubPeerDisconnected
StoreMempoolNew h' :: TxHash
h'
| TxHash
h' TxHash -> TxHash -> Bool
forall a. Eq a => a -> a -> Bool
== Tx -> TxHash
txHash Tx
tx -> Either PubExcept () -> m (Either PubExcept ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Either PubExcept () -> m (Either PubExcept ()))
-> Either PubExcept () -> m (Either PubExcept ())
forall a b. (a -> b) -> a -> b
$ () -> Either PubExcept ()
forall a b. b -> Either a b
Right ()
_ -> Peer -> mbox StoreEvent -> m (Either PubExcept ())
g Peer
p mbox StoreEvent
s
scottyMempool ::
(MonadUnliftIO m, MonadLoggerIO m) => GetMempool -> WebT m [TxHash]
scottyMempool :: GetMempool -> WebT m [TxHash]
scottyMempool (GetMempool limitM :: Maybe LimitParam
limitM (OffsetParam o :: Natural
o)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
mempoolStat 1
WebLimits
wl <- ReaderT WebState m WebLimits
-> ActionT Except (ReaderT WebState m) WebLimits
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m WebLimits
-> ActionT Except (ReaderT WebState m) WebLimits)
-> ReaderT WebState m WebLimits
-> ActionT Except (ReaderT WebState m) WebLimits
forall a b. (a -> b) -> a -> b
$ (WebState -> WebLimits) -> ReaderT WebState m WebLimits
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (WebConfig -> WebLimits
webMaxLimits (WebConfig -> WebLimits)
-> (WebState -> WebConfig) -> WebState -> WebLimits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
let wl' :: WebLimits
wl' = WebLimits
wl { maxLimitCount :: Word32
maxLimitCount = 0 }
l :: Limits
l = Word32 -> Word32 -> Maybe Start -> Limits
Limits (WebLimits -> Bool -> Maybe LimitParam -> Word32
validateLimit WebLimits
wl' Bool
False Maybe LimitParam
limitM) (Natural -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
o) Maybe Start
forall a. Maybe a
Nothing
((Word64, TxHash) -> TxHash) -> [(Word64, TxHash)] -> [TxHash]
forall a b. (a -> b) -> [a] -> [b]
map (Word64, TxHash) -> TxHash
forall a b. (a, b) -> b
snd ([(Word64, TxHash)] -> [TxHash])
-> ([(Word64, TxHash)] -> [(Word64, TxHash)])
-> [(Word64, TxHash)]
-> [TxHash]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Limits -> [(Word64, TxHash)] -> [(Word64, TxHash)]
forall a. Limits -> [a] -> [a]
applyLimits Limits
l ([(Word64, TxHash)] -> [TxHash])
-> ActionT Except (ReaderT WebState m) [(Word64, TxHash)]
-> WebT m [TxHash]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) [(Word64, TxHash)]
forall (m :: * -> *). StoreReadBase m => m [(Word64, TxHash)]
getMempool
scottyEvents :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()
scottyEvents :: WebT m ()
scottyEvents =
(WebMetrics -> Gauge) -> WebT m () -> WebT m ()
forall (m :: * -> *) a.
MonadUnliftIO m =>
(WebMetrics -> Gauge) -> WebT m a -> WebT m a
withGaugeIncrease WebMetrics -> Gauge
eventsConnected (WebT m () -> WebT m ()) -> WebT m () -> WebT m ()
forall a b. (a -> b) -> a -> b
$ do
WebT m ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
SerialAs
proto <- Bool -> ActionT Except (ReaderT WebState m) SerialAs
forall (m :: * -> *). Monad m => Bool -> ActionT Except m SerialAs
setupContentType Bool
False
Publisher StoreEvent
pub <- ReaderT WebState m (Publisher StoreEvent)
-> ActionT Except (ReaderT WebState m) (Publisher StoreEvent)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m (Publisher StoreEvent)
-> ActionT Except (ReaderT WebState m) (Publisher StoreEvent))
-> ReaderT WebState m (Publisher StoreEvent)
-> ActionT Except (ReaderT WebState m) (Publisher StoreEvent)
forall a b. (a -> b) -> a -> b
$ (WebState -> Publisher StoreEvent)
-> ReaderT WebState m (Publisher StoreEvent)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Publisher StoreEvent
storePublisher (Store -> Publisher StoreEvent)
-> (WebState -> Store) -> WebState -> Publisher StoreEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
StreamingBody -> WebT m ()
forall (m :: * -> *) e. Monad m => StreamingBody -> ActionT e m ()
S.stream (StreamingBody -> WebT m ()) -> StreamingBody -> WebT m ()
forall a b. (a -> b) -> a -> b
$ \io :: Builder -> IO ()
io flush' :: IO ()
flush' ->
Publisher StoreEvent -> (Inbox StoreEvent -> IO ()) -> IO ()
forall (m :: * -> *) msg a.
MonadUnliftIO m =>
Publisher msg -> (Inbox msg -> m a) -> m a
withSubscription Publisher StoreEvent
pub ((Inbox StoreEvent -> IO ()) -> IO ())
-> (Inbox StoreEvent -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \sub :: Inbox StoreEvent
sub ->
IO () -> IO ()
forall (f :: * -> *) a b. Applicative f => f a -> f b
forever (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
IO ()
flush' IO () -> IO (Maybe Event) -> IO (Maybe Event)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inbox StoreEvent -> IO (Maybe Event)
receiveEvent Inbox StoreEvent
sub IO (Maybe Event) -> (Maybe Event -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IO () -> (Event -> IO ()) -> Maybe Event -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (Builder -> IO ()
io (Builder -> IO ()) -> (Event -> Builder) -> Event -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialAs -> Event -> Builder
forall a. (Serial a, ToJSON a) => SerialAs -> a -> Builder
serial SerialAs
proto)
where
serial :: SerialAs -> a -> Builder
serial proto :: SerialAs
proto e :: a
e =
ByteString -> Builder
lazyByteString (ByteString -> Builder) -> ByteString -> Builder
forall a b. (a -> b) -> a -> b
$ SerialAs -> (a -> Encoding) -> (a -> Value) -> a -> ByteString
forall a.
Serial a =>
SerialAs -> (a -> Encoding) -> (a -> Value) -> a -> ByteString
protoSerial SerialAs
proto a -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding a -> Value
forall a. ToJSON a => a -> Value
toJSON a
e ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> SerialAs -> ByteString
forall p. (Monoid p, IsString p) => SerialAs -> p
newLine SerialAs
proto
newLine :: SerialAs -> p
newLine SerialAsBinary = p
forall a. Monoid a => a
mempty
newLine SerialAsJSON = "\n"
newLine SerialAsPrettyJSON = p
forall a. Monoid a => a
mempty
receiveEvent :: Inbox StoreEvent -> IO (Maybe Event)
receiveEvent :: Inbox StoreEvent -> IO (Maybe Event)
receiveEvent sub :: Inbox StoreEvent
sub = do
StoreEvent
se <- Inbox StoreEvent -> IO StoreEvent
forall (mbox :: * -> *) (m :: * -> *) msg.
(InChan mbox, MonadIO m) =>
mbox msg -> m msg
receive Inbox StoreEvent
sub
Maybe Event -> IO (Maybe Event)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Event -> IO (Maybe Event))
-> Maybe Event -> IO (Maybe Event)
forall a b. (a -> b) -> a -> b
$
case StoreEvent
se of
StoreBestBlock b :: BlockHash
b -> Event -> Maybe Event
forall a. a -> Maybe a
Just (BlockHash -> Event
EventBlock BlockHash
b)
StoreMempoolNew t :: TxHash
t -> Event -> Maybe Event
forall a. a -> Maybe a
Just (TxHash -> Event
EventTx TxHash
t)
_ -> Maybe Event
forall a. Maybe a
Nothing
scottyAddrTxs ::
(MonadUnliftIO m, MonadLoggerIO m) => GetAddrTxs -> WebT m [TxRef]
scottyAddrTxs :: GetAddrTxs -> WebT m [TxRef]
scottyAddrTxs (GetAddrTxs addr :: Address
addr pLimits :: LimitsParam
pLimits) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
addrTxStat 1
Address -> Limits -> WebT m [TxRef]
forall (m :: * -> *).
StoreReadExtra m =>
Address -> Limits -> m [TxRef]
getAddressTxs Address
addr (Limits -> WebT m [TxRef])
-> ActionT Except (ReaderT WebState m) Limits -> WebT m [TxRef]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bool -> LimitsParam -> ActionT Except (ReaderT WebState m) Limits
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Bool -> LimitsParam -> WebT m Limits
paramToLimits Bool
False LimitsParam
pLimits
scottyAddrsTxs ::
(MonadUnliftIO m, MonadLoggerIO m) => GetAddrsTxs -> WebT m [TxRef]
scottyAddrsTxs :: GetAddrsTxs -> WebT m [TxRef]
scottyAddrsTxs (GetAddrsTxs addrs :: [Address]
addrs pLimits :: LimitsParam
pLimits) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
addrTxStat ([Address] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Address]
addrs)
[Address] -> Limits -> WebT m [TxRef]
forall (m :: * -> *).
StoreReadExtra m =>
[Address] -> Limits -> m [TxRef]
getAddressesTxs [Address]
addrs (Limits -> WebT m [TxRef])
-> ActionT Except (ReaderT WebState m) Limits -> WebT m [TxRef]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bool -> LimitsParam -> ActionT Except (ReaderT WebState m) Limits
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Bool -> LimitsParam -> WebT m Limits
paramToLimits Bool
False LimitsParam
pLimits
scottyAddrTxsFull ::
(MonadUnliftIO m, MonadLoggerIO m)
=> GetAddrTxsFull
-> WebT m [Transaction]
scottyAddrTxsFull :: GetAddrTxsFull -> WebT m [Transaction]
scottyAddrTxsFull (GetAddrTxsFull addr :: Address
addr pLimits :: LimitsParam
pLimits) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
addrTxFullStat 1
[TxRef]
txs <- Address -> Limits -> ActionT Except (ReaderT WebState m) [TxRef]
forall (m :: * -> *).
StoreReadExtra m =>
Address -> Limits -> m [TxRef]
getAddressTxs Address
addr (Limits -> ActionT Except (ReaderT WebState m) [TxRef])
-> ActionT Except (ReaderT WebState m) Limits
-> ActionT Except (ReaderT WebState m) [TxRef]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bool -> LimitsParam -> ActionT Except (ReaderT WebState m) Limits
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Bool -> LimitsParam -> WebT m Limits
paramToLimits Bool
True LimitsParam
pLimits
[Maybe Transaction] -> [Transaction]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Transaction] -> [Transaction])
-> ActionT Except (ReaderT WebState m) [Maybe Transaction]
-> WebT m [Transaction]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TxRef -> ActionT Except (ReaderT WebState m) (Maybe Transaction))
-> [TxRef]
-> ActionT Except (ReaderT WebState m) [Maybe Transaction]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (TxHash -> ActionT Except (ReaderT WebState m) (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction (TxHash -> ActionT Except (ReaderT WebState m) (Maybe Transaction))
-> (TxRef -> TxHash)
-> TxRef
-> ActionT Except (ReaderT WebState m) (Maybe Transaction)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxRef -> TxHash
txRefHash) [TxRef]
txs
scottyAddrsTxsFull :: (MonadUnliftIO m, MonadLoggerIO m)
=> GetAddrsTxsFull -> WebT m [Transaction]
scottyAddrsTxsFull :: GetAddrsTxsFull -> WebT m [Transaction]
scottyAddrsTxsFull (GetAddrsTxsFull addrs :: [Address]
addrs pLimits :: LimitsParam
pLimits) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
addrTxFullStat ([Address] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Address]
addrs)
[TxRef]
txs <- [Address] -> Limits -> ActionT Except (ReaderT WebState m) [TxRef]
forall (m :: * -> *).
StoreReadExtra m =>
[Address] -> Limits -> m [TxRef]
getAddressesTxs [Address]
addrs (Limits -> ActionT Except (ReaderT WebState m) [TxRef])
-> ActionT Except (ReaderT WebState m) Limits
-> ActionT Except (ReaderT WebState m) [TxRef]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bool -> LimitsParam -> ActionT Except (ReaderT WebState m) Limits
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Bool -> LimitsParam -> WebT m Limits
paramToLimits Bool
True LimitsParam
pLimits
[Maybe Transaction] -> [Transaction]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Transaction] -> [Transaction])
-> ActionT Except (ReaderT WebState m) [Maybe Transaction]
-> WebT m [Transaction]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TxRef -> ActionT Except (ReaderT WebState m) (Maybe Transaction))
-> [TxRef]
-> ActionT Except (ReaderT WebState m) [Maybe Transaction]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (TxHash -> ActionT Except (ReaderT WebState m) (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction (TxHash -> ActionT Except (ReaderT WebState m) (Maybe Transaction))
-> (TxRef -> TxHash)
-> TxRef
-> ActionT Except (ReaderT WebState m) (Maybe Transaction)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxRef -> TxHash
txRefHash) [TxRef]
txs
scottyAddrBalance :: (MonadUnliftIO m, MonadLoggerIO m)
=> GetAddrBalance -> WebT m Balance
scottyAddrBalance :: GetAddrBalance -> WebT m Balance
scottyAddrBalance (GetAddrBalance addr :: Address
addr) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
addrBalanceStat 1
Address -> WebT m Balance
forall (m :: * -> *). StoreReadBase m => Address -> m Balance
getDefaultBalance Address
addr
scottyAddrsBalance ::
(MonadUnliftIO m, MonadLoggerIO m) => GetAddrsBalance -> WebT m [Balance]
scottyAddrsBalance :: GetAddrsBalance -> WebT m [Balance]
scottyAddrsBalance (GetAddrsBalance addrs :: [Address]
addrs) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
addrBalanceStat ([Address] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Address]
addrs)
[Address] -> WebT m [Balance]
forall (m :: * -> *). StoreReadExtra m => [Address] -> m [Balance]
getBalances [Address]
addrs
scottyAddrUnspent ::
(MonadUnliftIO m, MonadLoggerIO m) => GetAddrUnspent -> WebT m [Unspent]
scottyAddrUnspent :: GetAddrUnspent -> WebT m [Unspent]
scottyAddrUnspent (GetAddrUnspent addr :: Address
addr pLimits :: LimitsParam
pLimits) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
addrUnspentStat 1
Address -> Limits -> WebT m [Unspent]
forall (m :: * -> *).
StoreReadExtra m =>
Address -> Limits -> m [Unspent]
getAddressUnspents Address
addr (Limits -> WebT m [Unspent])
-> ActionT Except (ReaderT WebState m) Limits -> WebT m [Unspent]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bool -> LimitsParam -> ActionT Except (ReaderT WebState m) Limits
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Bool -> LimitsParam -> WebT m Limits
paramToLimits Bool
False LimitsParam
pLimits
scottyAddrsUnspent ::
(MonadUnliftIO m, MonadLoggerIO m) => GetAddrsUnspent -> WebT m [Unspent]
scottyAddrsUnspent :: GetAddrsUnspent -> WebT m [Unspent]
scottyAddrsUnspent (GetAddrsUnspent addrs :: [Address]
addrs pLimits :: LimitsParam
pLimits) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
addrUnspentStat ([Address] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Address]
addrs)
[Address] -> Limits -> WebT m [Unspent]
forall (m :: * -> *).
StoreReadExtra m =>
[Address] -> Limits -> m [Unspent]
getAddressesUnspents [Address]
addrs (Limits -> WebT m [Unspent])
-> ActionT Except (ReaderT WebState m) Limits -> WebT m [Unspent]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bool -> LimitsParam -> ActionT Except (ReaderT WebState m) Limits
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Bool -> LimitsParam -> WebT m Limits
paramToLimits Bool
False LimitsParam
pLimits
scottyXPub ::
(MonadUnliftIO m, MonadLoggerIO m) => GetXPub -> WebT m XPubSummary
scottyXPub :: GetXPub -> WebT m XPubSummary
scottyXPub (GetXPub xpub :: XPubKey
xpub deriv :: DeriveType
deriv (NoCache noCache :: Bool
noCache)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
xPubStat 1
let xspec :: XPubSpec
xspec = XPubKey -> DeriveType -> XPubSpec
XPubSpec XPubKey
xpub DeriveType
deriv
[XPubBal]
xbals <- XPubSpec -> ActionT Except (ReaderT WebState m) [XPubBal]
forall (m :: * -> *). StoreReadExtra m => XPubSpec -> m [XPubBal]
xPubBals XPubSpec
xspec
ReaderT WebState m XPubSummary -> WebT m XPubSummary
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m XPubSummary -> WebT m XPubSummary)
-> (ReaderT WebState m XPubSummary
-> ReaderT WebState m XPubSummary)
-> ReaderT WebState m XPubSummary
-> WebT m XPubSummary
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool
-> ReaderT WebState m XPubSummary -> ReaderT WebState m XPubSummary
forall (m :: * -> *) a.
MonadIO m =>
Bool -> ReaderT WebState m a -> ReaderT WebState m a
runNoCache Bool
noCache (ReaderT WebState m XPubSummary -> WebT m XPubSummary)
-> ReaderT WebState m XPubSummary -> WebT m XPubSummary
forall a b. (a -> b) -> a -> b
$ XPubSpec -> [XPubBal] -> ReaderT WebState m XPubSummary
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> m XPubSummary
xPubSummary XPubSpec
xspec [XPubBal]
xbals
getXPubTxs :: (MonadUnliftIO m, MonadLoggerIO m)
=> XPubKey -> DeriveType -> LimitsParam -> Bool -> WebT m [TxRef]
getXPubTxs :: XPubKey -> DeriveType -> LimitsParam -> Bool -> WebT m [TxRef]
getXPubTxs xpub :: XPubKey
xpub deriv :: DeriveType
deriv plimits :: LimitsParam
plimits nocache :: Bool
nocache = do
Limits
limits <- Bool -> LimitsParam -> WebT m Limits
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Bool -> LimitsParam -> WebT m Limits
paramToLimits Bool
False LimitsParam
plimits
let xspec :: XPubSpec
xspec = XPubKey -> DeriveType -> XPubSpec
XPubSpec XPubKey
xpub DeriveType
deriv
[XPubBal]
xbals <- XPubSpec -> ActionT Except (ReaderT WebState m) [XPubBal]
forall (m :: * -> *). StoreReadExtra m => XPubSpec -> m [XPubBal]
xPubBals XPubSpec
xspec
ReaderT WebState m [TxRef] -> WebT m [TxRef]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [TxRef] -> WebT m [TxRef])
-> (ReaderT WebState m [TxRef] -> ReaderT WebState m [TxRef])
-> ReaderT WebState m [TxRef]
-> WebT m [TxRef]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> ReaderT WebState m [TxRef] -> ReaderT WebState m [TxRef]
forall (m :: * -> *) a.
MonadIO m =>
Bool -> ReaderT WebState m a -> ReaderT WebState m a
runNoCache Bool
nocache (ReaderT WebState m [TxRef] -> WebT m [TxRef])
-> ReaderT WebState m [TxRef] -> WebT m [TxRef]
forall a b. (a -> b) -> a -> b
$ XPubSpec -> [XPubBal] -> Limits -> ReaderT WebState m [TxRef]
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> Limits -> m [TxRef]
xPubTxs XPubSpec
xspec [XPubBal]
xbals Limits
limits
scottyXPubTxs ::
(MonadUnliftIO m, MonadLoggerIO m) => GetXPubTxs -> WebT m [TxRef]
scottyXPubTxs :: GetXPubTxs -> WebT m [TxRef]
scottyXPubTxs (GetXPubTxs xpub :: XPubKey
xpub deriv :: DeriveType
deriv plimits :: LimitsParam
plimits (NoCache nocache :: Bool
nocache)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
xPubTxStat 1
XPubKey -> DeriveType -> LimitsParam -> Bool -> WebT m [TxRef]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
XPubKey -> DeriveType -> LimitsParam -> Bool -> WebT m [TxRef]
getXPubTxs XPubKey
xpub DeriveType
deriv LimitsParam
plimits Bool
nocache
scottyXPubTxsFull ::
(MonadUnliftIO m, MonadLoggerIO m)
=> GetXPubTxsFull
-> WebT m [Transaction]
scottyXPubTxsFull :: GetXPubTxsFull -> WebT m [Transaction]
scottyXPubTxsFull (GetXPubTxsFull xpub :: XPubKey
xpub deriv :: DeriveType
deriv plimits :: LimitsParam
plimits (NoCache nocache :: Bool
nocache)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
xPubTxFullStat 1
[TxRef]
refs <- XPubKey -> DeriveType -> LimitsParam -> Bool -> WebT m [TxRef]
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
XPubKey -> DeriveType -> LimitsParam -> Bool -> WebT m [TxRef]
getXPubTxs XPubKey
xpub DeriveType
deriv LimitsParam
plimits Bool
nocache
[Maybe Transaction]
txs <- ReaderT WebState m [Maybe Transaction]
-> ActionT Except (ReaderT WebState m) [Maybe Transaction]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [Maybe Transaction]
-> ActionT Except (ReaderT WebState m) [Maybe Transaction])
-> (ReaderT WebState m [Maybe Transaction]
-> ReaderT WebState m [Maybe Transaction])
-> ReaderT WebState m [Maybe Transaction]
-> ActionT Except (ReaderT WebState m) [Maybe Transaction]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool
-> ReaderT WebState m [Maybe Transaction]
-> ReaderT WebState m [Maybe Transaction]
forall (m :: * -> *) a.
MonadIO m =>
Bool -> ReaderT WebState m a -> ReaderT WebState m a
runNoCache Bool
nocache (ReaderT WebState m [Maybe Transaction]
-> ActionT Except (ReaderT WebState m) [Maybe Transaction])
-> ReaderT WebState m [Maybe Transaction]
-> ActionT Except (ReaderT WebState m) [Maybe Transaction]
forall a b. (a -> b) -> a -> b
$ (TxRef -> ReaderT WebState m (Maybe Transaction))
-> [TxRef] -> ReaderT WebState m [Maybe Transaction]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (TxHash -> ReaderT WebState m (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction (TxHash -> ReaderT WebState m (Maybe Transaction))
-> (TxRef -> TxHash)
-> TxRef
-> ReaderT WebState m (Maybe Transaction)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxRef -> TxHash
txRefHash) [TxRef]
refs
[Transaction] -> WebT m [Transaction]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Transaction] -> WebT m [Transaction])
-> [Transaction] -> WebT m [Transaction]
forall a b. (a -> b) -> a -> b
$ [Maybe Transaction] -> [Transaction]
forall a. [Maybe a] -> [a]
catMaybes [Maybe Transaction]
txs
scottyXPubBalances ::
(MonadUnliftIO m, MonadLoggerIO m) => GetXPubBalances -> WebT m [XPubBal]
scottyXPubBalances :: GetXPubBalances -> WebT m [XPubBal]
scottyXPubBalances (GetXPubBalances xpub :: XPubKey
xpub deriv :: DeriveType
deriv (NoCache noCache :: Bool
noCache)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
xPubStat 1
(XPubBal -> Bool) -> [XPubBal] -> [XPubBal]
forall a. (a -> Bool) -> [a] -> [a]
filter XPubBal -> Bool
f ([XPubBal] -> [XPubBal]) -> WebT m [XPubBal] -> WebT m [XPubBal]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT WebState m [XPubBal] -> WebT m [XPubBal]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Bool
-> ReaderT WebState m [XPubBal] -> ReaderT WebState m [XPubBal]
forall (m :: * -> *) a.
MonadIO m =>
Bool -> ReaderT WebState m a -> ReaderT WebState m a
runNoCache Bool
noCache (XPubSpec -> ReaderT WebState m [XPubBal]
forall (m :: * -> *). StoreReadExtra m => XPubSpec -> m [XPubBal]
xPubBals XPubSpec
spec))
where
spec :: XPubSpec
spec = XPubKey -> DeriveType -> XPubSpec
XPubSpec XPubKey
xpub DeriveType
deriv
f :: XPubBal -> Bool
f = Bool -> Bool
not (Bool -> Bool) -> (XPubBal -> Bool) -> XPubBal -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Balance -> Bool
nullBalance (Balance -> Bool) -> (XPubBal -> Balance) -> XPubBal -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubBal -> Balance
xPubBal
scottyXPubUnspent ::
(MonadUnliftIO m, MonadLoggerIO m)
=> GetXPubUnspent
-> WebT m [XPubUnspent]
scottyXPubUnspent :: GetXPubUnspent -> WebT m [XPubUnspent]
scottyXPubUnspent (GetXPubUnspent xpub :: XPubKey
xpub deriv :: DeriveType
deriv pLimits :: LimitsParam
pLimits (NoCache noCache :: Bool
noCache)) = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
xPubUnspentStat 1
Limits
limits <- Bool -> LimitsParam -> WebT m Limits
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Bool -> LimitsParam -> WebT m Limits
paramToLimits Bool
False LimitsParam
pLimits
let xspec :: XPubSpec
xspec = XPubKey -> DeriveType -> XPubSpec
XPubSpec XPubKey
xpub DeriveType
deriv
[XPubBal]
xbals <- XPubSpec -> ActionT Except (ReaderT WebState m) [XPubBal]
forall (m :: * -> *). StoreReadExtra m => XPubSpec -> m [XPubBal]
xPubBals XPubSpec
xspec
ReaderT WebState m [XPubUnspent] -> WebT m [XPubUnspent]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [XPubUnspent] -> WebT m [XPubUnspent])
-> (ReaderT WebState m [XPubUnspent]
-> ReaderT WebState m [XPubUnspent])
-> ReaderT WebState m [XPubUnspent]
-> WebT m [XPubUnspent]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool
-> ReaderT WebState m [XPubUnspent]
-> ReaderT WebState m [XPubUnspent]
forall (m :: * -> *) a.
MonadIO m =>
Bool -> ReaderT WebState m a -> ReaderT WebState m a
runNoCache Bool
noCache (ReaderT WebState m [XPubUnspent] -> WebT m [XPubUnspent])
-> ReaderT WebState m [XPubUnspent] -> WebT m [XPubUnspent]
forall a b. (a -> b) -> a -> b
$ XPubSpec -> [XPubBal] -> Limits -> ReaderT WebState m [XPubUnspent]
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> Limits -> m [XPubUnspent]
xPubUnspents XPubSpec
xspec [XPubBal]
xbals Limits
limits
netBinfoSymbol :: Network -> BinfoSymbol
netBinfoSymbol :: Network -> BinfoSymbol
netBinfoSymbol net :: Network
net
| Network
net Network -> Network -> Bool
forall a. Eq a => a -> a -> Bool
== Network
btc =
$WBinfoSymbol :: Text -> Text -> Text -> Double -> Bool -> Bool -> BinfoSymbol
BinfoSymbol{ getBinfoSymbolCode :: Text
getBinfoSymbolCode = "BTC"
, getBinfoSymbolString :: Text
getBinfoSymbolString = "BTC"
, getBinfoSymbolName :: Text
getBinfoSymbolName = "Bitcoin"
, getBinfoSymbolConversion :: Double
getBinfoSymbolConversion = 100 Double -> Double -> Double
forall a. Num a => a -> a -> a
* 1000 Double -> Double -> Double
forall a. Num a => a -> a -> a
* 1000
, getBinfoSymbolAfter :: Bool
getBinfoSymbolAfter = Bool
True
, getBinfoSymbolLocal :: Bool
getBinfoSymbolLocal = Bool
False
}
| Network
net Network -> Network -> Bool
forall a. Eq a => a -> a -> Bool
== Network
bch =
$WBinfoSymbol :: Text -> Text -> Text -> Double -> Bool -> Bool -> BinfoSymbol
BinfoSymbol{ getBinfoSymbolCode :: Text
getBinfoSymbolCode = "BCH"
, getBinfoSymbolString :: Text
getBinfoSymbolString = "BCH"
, getBinfoSymbolName :: Text
getBinfoSymbolName = "Bitcoin Cash"
, getBinfoSymbolConversion :: Double
getBinfoSymbolConversion = 100 Double -> Double -> Double
forall a. Num a => a -> a -> a
* 1000 Double -> Double -> Double
forall a. Num a => a -> a -> a
* 1000
, getBinfoSymbolAfter :: Bool
getBinfoSymbolAfter = Bool
True
, getBinfoSymbolLocal :: Bool
getBinfoSymbolLocal = Bool
False
}
| Bool
otherwise =
$WBinfoSymbol :: Text -> Text -> Text -> Double -> Bool -> Bool -> BinfoSymbol
BinfoSymbol{ getBinfoSymbolCode :: Text
getBinfoSymbolCode = "XTS"
, getBinfoSymbolString :: Text
getBinfoSymbolString = "¤"
, getBinfoSymbolName :: Text
getBinfoSymbolName = "Test"
, getBinfoSymbolConversion :: Double
getBinfoSymbolConversion = 100 Double -> Double -> Double
forall a. Num a => a -> a -> a
* 1000 Double -> Double -> Double
forall a. Num a => a -> a -> a
* 1000
, getBinfoSymbolAfter :: Bool
getBinfoSymbolAfter = Bool
False
, getBinfoSymbolLocal :: Bool
getBinfoSymbolLocal = Bool
False
}
binfoTickerToSymbol :: Text -> BinfoTicker -> BinfoSymbol
binfoTickerToSymbol :: Text -> BinfoTicker -> BinfoSymbol
binfoTickerToSymbol code :: Text
code BinfoTicker{..} =
$WBinfoSymbol :: Text -> Text -> Text -> Double -> Bool -> Bool -> BinfoSymbol
BinfoSymbol{ getBinfoSymbolCode :: Text
getBinfoSymbolCode = Text
code
, getBinfoSymbolString :: Text
getBinfoSymbolString = Text
binfoTickerSymbol
, getBinfoSymbolName :: Text
getBinfoSymbolName = Text
name
, getBinfoSymbolConversion :: Double
getBinfoSymbolConversion =
100 Double -> Double -> Double
forall a. Num a => a -> a -> a
* 1000 Double -> Double -> Double
forall a. Num a => a -> a -> a
* 1000 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
binfoTicker15m
, getBinfoSymbolAfter :: Bool
getBinfoSymbolAfter = Bool
False
, getBinfoSymbolLocal :: Bool
getBinfoSymbolLocal = Bool
True
}
where
name :: Text
name = case Text
code of
"EUR" -> "Euro"
"USD" -> "U.S. dollar"
"GBP" -> "British pound"
x :: Text
x -> Text
x
getBinfoAddrsParam :: MonadIO m
=> (WebMetrics -> StatDist)
-> Text
-> WebT m (HashSet BinfoAddr)
getBinfoAddrsParam :: (WebMetrics -> StatDist) -> Text -> WebT m (HashSet BinfoAddr)
getBinfoAddrsParam metric :: WebMetrics -> StatDist
metric name :: Text
name = do
Network
net <- ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> Network) -> ReaderT WebState m Network
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Network
storeNetwork (Store -> Network) -> (WebState -> Store) -> WebState -> Network
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig))
Text
p <- Text -> ActionT Except (ReaderT WebState m) Text
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param (Text -> Text
forall a b. ConvertibleStrings a b => a -> b
cs Text
name) ActionT Except (ReaderT WebState m) Text
-> (Except -> ActionT Except (ReaderT WebState m) Text)
-> ActionT Except (ReaderT WebState m) Text
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT Except (ReaderT WebState m) Text
-> Except -> ActionT Except (ReaderT WebState m) Text
forall a b. a -> b -> a
const (Text -> ActionT Except (ReaderT WebState m) Text
forall (m :: * -> *) a. Monad m => a -> m a
return "")
case Network -> Text -> Maybe [BinfoAddr]
parseBinfoAddr Network
net Text
p of
Nothing -> (WebMetrics -> StatDist) -> Except -> WebT m (HashSet BinfoAddr)
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
metric (String -> Except
UserError "invalid active address")
Just xs :: [BinfoAddr]
xs -> HashSet BinfoAddr -> WebT m (HashSet BinfoAddr)
forall (m :: * -> *) a. Monad m => a -> m a
return (HashSet BinfoAddr -> WebT m (HashSet BinfoAddr))
-> HashSet BinfoAddr -> WebT m (HashSet BinfoAddr)
forall a b. (a -> b) -> a -> b
$ [BinfoAddr] -> HashSet BinfoAddr
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList [BinfoAddr]
xs
getBinfoActive :: MonadIO m
=> (WebMetrics -> StatDist)
-> WebT m (HashMap XPubKey XPubSpec, HashSet Address)
getBinfoActive :: (WebMetrics -> StatDist)
-> WebT m (HashMap XPubKey XPubSpec, HashSet Address)
getBinfoActive metric :: WebMetrics -> StatDist
metric = do
HashSet BinfoAddr
active <- (WebMetrics -> StatDist) -> Text -> WebT m (HashSet BinfoAddr)
forall (m :: * -> *).
MonadIO m =>
(WebMetrics -> StatDist) -> Text -> WebT m (HashSet BinfoAddr)
getBinfoAddrsParam WebMetrics -> StatDist
metric "active"
HashSet BinfoAddr
p2sh <- (WebMetrics -> StatDist) -> Text -> WebT m (HashSet BinfoAddr)
forall (m :: * -> *).
MonadIO m =>
(WebMetrics -> StatDist) -> Text -> WebT m (HashSet BinfoAddr)
getBinfoAddrsParam WebMetrics -> StatDist
metric "activeP2SH"
HashSet BinfoAddr
bech32 <- (WebMetrics -> StatDist) -> Text -> WebT m (HashSet BinfoAddr)
forall (m :: * -> *).
MonadIO m =>
(WebMetrics -> StatDist) -> Text -> WebT m (HashSet BinfoAddr)
getBinfoAddrsParam WebMetrics -> StatDist
metric "activeBech32"
let xspec :: DeriveType -> BinfoAddr -> Maybe (XPubKey, XPubSpec)
xspec d :: DeriveType
d b :: BinfoAddr
b = (\x :: XPubKey
x -> (XPubKey
x, XPubKey -> DeriveType -> XPubSpec
XPubSpec XPubKey
x DeriveType
d)) (XPubKey -> (XPubKey, XPubSpec))
-> Maybe XPubKey -> Maybe (XPubKey, XPubSpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BinfoAddr -> Maybe XPubKey
xpub BinfoAddr
b
xspecs :: HashMap XPubKey XPubSpec
xspecs = [(XPubKey, XPubSpec)] -> HashMap XPubKey XPubSpec
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(XPubKey, XPubSpec)] -> HashMap XPubKey XPubSpec)
-> [(XPubKey, XPubSpec)] -> HashMap XPubKey XPubSpec
forall a b. (a -> b) -> a -> b
$ [[(XPubKey, XPubSpec)]] -> [(XPubKey, XPubSpec)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ (BinfoAddr -> Maybe (XPubKey, XPubSpec))
-> [BinfoAddr] -> [(XPubKey, XPubSpec)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (DeriveType -> BinfoAddr -> Maybe (XPubKey, XPubSpec)
xspec DeriveType
DeriveNormal) (HashSet BinfoAddr -> [BinfoAddr]
forall a. HashSet a -> [a]
HashSet.toList HashSet BinfoAddr
active)
, (BinfoAddr -> Maybe (XPubKey, XPubSpec))
-> [BinfoAddr] -> [(XPubKey, XPubSpec)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (DeriveType -> BinfoAddr -> Maybe (XPubKey, XPubSpec)
xspec DeriveType
DeriveP2SH) (HashSet BinfoAddr -> [BinfoAddr]
forall a. HashSet a -> [a]
HashSet.toList HashSet BinfoAddr
p2sh)
, (BinfoAddr -> Maybe (XPubKey, XPubSpec))
-> [BinfoAddr] -> [(XPubKey, XPubSpec)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (DeriveType -> BinfoAddr -> Maybe (XPubKey, XPubSpec)
xspec DeriveType
DeriveP2WPKH) (HashSet BinfoAddr -> [BinfoAddr]
forall a. HashSet a -> [a]
HashSet.toList HashSet BinfoAddr
bech32)
]
addrs :: HashSet Address
addrs = [Address] -> HashSet Address
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList ([Address] -> HashSet Address)
-> ([BinfoAddr] -> [Address]) -> [BinfoAddr] -> HashSet Address
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BinfoAddr -> Maybe Address) -> [BinfoAddr] -> [Address]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe BinfoAddr -> Maybe Address
addr ([BinfoAddr] -> HashSet Address) -> [BinfoAddr] -> HashSet Address
forall a b. (a -> b) -> a -> b
$ HashSet BinfoAddr -> [BinfoAddr]
forall a. HashSet a -> [a]
HashSet.toList HashSet BinfoAddr
active
(HashMap XPubKey XPubSpec, HashSet Address)
-> WebT m (HashMap XPubKey XPubSpec, HashSet Address)
forall (m :: * -> *) a. Monad m => a -> m a
return (HashMap XPubKey XPubSpec
xspecs, HashSet Address
addrs)
where
addr :: BinfoAddr -> Maybe Address
addr (BinfoAddr a :: Address
a) = Address -> Maybe Address
forall a. a -> Maybe a
Just Address
a
addr (BinfoXpub x :: XPubKey
x) = Maybe Address
forall a. Maybe a
Nothing
xpub :: BinfoAddr -> Maybe XPubKey
xpub (BinfoXpub x :: XPubKey
x) = XPubKey -> Maybe XPubKey
forall a. a -> Maybe a
Just XPubKey
x
xpub (BinfoAddr _) = Maybe XPubKey
forall a. Maybe a
Nothing
getNumTxId :: MonadIO m => WebT m Bool
getNumTxId :: WebT m Bool
getNumTxId = (Bool -> Bool) -> WebT m Bool -> WebT m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Bool -> Bool
not (WebT m Bool -> WebT m Bool) -> WebT m Bool -> WebT m Bool
forall a b. (a -> b) -> a -> b
$ Text -> WebT m Bool
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "txidindex" WebT m Bool -> (Except -> WebT m Bool) -> WebT m Bool
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` WebT m Bool -> Except -> WebT m Bool
forall a b. a -> b -> a
const (Bool -> WebT m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False)
getChainHeight :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m H.BlockHeight
getChainHeight :: WebT m Word32
getChainHeight =
(BlockNode -> Word32)
-> ActionT Except (ReaderT WebState m) BlockNode -> WebT m Word32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BlockNode -> Word32
H.nodeHeight (ActionT Except (ReaderT WebState m) BlockNode -> WebT m Word32)
-> ActionT Except (ReaderT WebState m) BlockNode -> WebT m Word32
forall a b. (a -> b) -> a -> b
$ Chain -> ActionT Except (ReaderT WebState m) BlockNode
forall (m :: * -> *). MonadIO m => Chain -> m BlockNode
chainGetBest (Chain -> ActionT Except (ReaderT WebState m) BlockNode)
-> ActionT Except (ReaderT WebState m) Chain
-> ActionT Except (ReaderT WebState m) BlockNode
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ReaderT WebState m Chain
-> ActionT Except (ReaderT WebState m) Chain
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> Chain) -> ReaderT WebState m Chain
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Chain
storeChain (Store -> Chain) -> (WebState -> Store) -> WebState -> Chain
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig))
scottyBinfoUnspent :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()
scottyBinfoUnspent :: WebT m ()
scottyBinfoUnspent =
(WebMetrics -> StatDist)
-> WebT m (HashMap XPubKey XPubSpec, HashSet Address)
forall (m :: * -> *).
MonadIO m =>
(WebMetrics -> StatDist)
-> WebT m (HashMap XPubKey XPubSpec, HashSet Address)
getBinfoActive WebMetrics -> StatDist
unspentStat WebT m (HashMap XPubKey XPubSpec, HashSet Address)
-> ((HashMap XPubKey XPubSpec, HashSet Address) -> WebT m ())
-> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(xspecs :: HashMap XPubKey XPubSpec
xspecs, addrs :: HashSet Address
addrs) ->
WebT m Bool
forall (m :: * -> *). MonadIO m => WebT m Bool
getNumTxId WebT m Bool -> (Bool -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \numtxid :: Bool
numtxid ->
ActionT Except (ReaderT WebState m) Int
get_limit ActionT Except (ReaderT WebState m) Int
-> (Int -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \limit :: Int
limit ->
ActionT Except (ReaderT WebState m) Int32
get_min_conf ActionT Except (ReaderT WebState m) Int32
-> (Int32 -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \min_conf :: Int32
min_conf -> do
let len :: Int
len = HashSet Address -> Int
forall a. HashSet a -> Int
HashSet.size HashSet Address
addrs Int -> Int -> Int
forall a. Num a => a -> a -> a
+ HashMap XPubKey XPubSpec -> Int
forall k v. HashMap k v -> Int
HashMap.size HashMap XPubKey XPubSpec
xspecs
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
unspentStat Int
len
Network
net <- ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network)
-> ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall a b. (a -> b) -> a -> b
$ (WebState -> Network) -> ReaderT WebState m Network
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Network
storeNetwork (Store -> Network) -> (WebState -> Store) -> WebState -> Network
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Word32
height <- WebT m Word32
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
WebT m Word32
getChainHeight
let mn :: BinfoUnspent -> Bool
mn BinfoUnspent{..} = Int32
min_conf Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
> Int32
getBinfoUnspentConfirmations
xspecs' :: HashSet XPubSpec
xspecs' = [XPubSpec] -> HashSet XPubSpec
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList ([XPubSpec] -> HashSet XPubSpec) -> [XPubSpec] -> HashSet XPubSpec
forall a b. (a -> b) -> a -> b
$ HashMap XPubKey XPubSpec -> [XPubSpec]
forall k v. HashMap k v -> [v]
HashMap.elems HashMap XPubKey XPubSpec
xspecs
[BinfoUnspent]
bus <- ReaderT WebState m [BinfoUnspent]
-> ActionT Except (ReaderT WebState m) [BinfoUnspent]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [BinfoUnspent]
-> ActionT Except (ReaderT WebState m) [BinfoUnspent])
-> (ConduitT () Void (ReaderT WebState m) [BinfoUnspent]
-> ReaderT WebState m [BinfoUnspent])
-> ConduitT () Void (ReaderT WebState m) [BinfoUnspent]
-> ActionT Except (ReaderT WebState m) [BinfoUnspent]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConduitT () Void (ReaderT WebState m) [BinfoUnspent]
-> ReaderT WebState m [BinfoUnspent]
forall (m :: * -> *) r. Monad m => ConduitT () Void m r -> m r
runConduit (ConduitT () Void (ReaderT WebState m) [BinfoUnspent]
-> ActionT Except (ReaderT WebState m) [BinfoUnspent])
-> ConduitT () Void (ReaderT WebState m) [BinfoUnspent]
-> ActionT Except (ReaderT WebState m) [BinfoUnspent]
forall a b. (a -> b) -> a -> b
$
Bool
-> Word32
-> HashSet XPubSpec
-> HashSet Address
-> ConduitT () BinfoUnspent (ReaderT WebState m) ()
forall (m :: * -> *).
(StoreReadExtra m, MonadIO m) =>
Bool
-> Word32
-> HashSet XPubSpec
-> HashSet Address
-> ConduitT () BinfoUnspent m ()
getBinfoUnspents Bool
numtxid Word32
height HashSet XPubSpec
xspecs' HashSet Address
addrs ConduitT () BinfoUnspent (ReaderT WebState m) ()
-> ConduitM BinfoUnspent Void (ReaderT WebState m) [BinfoUnspent]
-> ConduitT () Void (ReaderT WebState m) [BinfoUnspent]
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.|
((BinfoUnspent -> Bool)
-> ConduitT BinfoUnspent Void (ReaderT WebState m) ()
forall (m :: * -> *) a o.
Monad m =>
(a -> Bool) -> ConduitT a o m ()
dropWhileC BinfoUnspent -> Bool
mn ConduitT BinfoUnspent Void (ReaderT WebState m) ()
-> ConduitM BinfoUnspent Void (ReaderT WebState m) [BinfoUnspent]
-> ConduitM BinfoUnspent Void (ReaderT WebState m) [BinfoUnspent]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> ConduitT BinfoUnspent BinfoUnspent (ReaderT WebState m) ()
forall (m :: * -> *) a. Monad m => Int -> ConduitT a a m ()
takeC Int
limit ConduitT BinfoUnspent BinfoUnspent (ReaderT WebState m) ()
-> ConduitM BinfoUnspent Void (ReaderT WebState m) [BinfoUnspent]
-> ConduitM BinfoUnspent Void (ReaderT WebState m) [BinfoUnspent]
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.| ConduitM BinfoUnspent Void (ReaderT WebState m) [BinfoUnspent]
forall (m :: * -> *) a o. Monad m => ConduitT a o m [a]
sinkList)
WebT m ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
Encoding -> WebT m ()
forall (m :: * -> *). Monad m => Encoding -> WebT m ()
streamEncoding (Network -> BinfoUnspents -> Encoding
binfoUnspentsToEncoding Network
net ([BinfoUnspent] -> BinfoUnspents
BinfoUnspents [BinfoUnspent]
bus))
where
get_limit :: ActionT Except (ReaderT WebState m) Int
get_limit = (Int -> Int)
-> ActionT Except (ReaderT WebState m) Int
-> ActionT Except (ReaderT WebState m) Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Int -> Int
forall a. Ord a => a -> a -> a
min 1000) (ActionT Except (ReaderT WebState m) Int
-> ActionT Except (ReaderT WebState m) Int)
-> ActionT Except (ReaderT WebState m) Int
-> ActionT Except (ReaderT WebState m) Int
forall a b. (a -> b) -> a -> b
$ Text -> ActionT Except (ReaderT WebState m) Int
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "limit" ActionT Except (ReaderT WebState m) Int
-> (Except -> ActionT Except (ReaderT WebState m) Int)
-> ActionT Except (ReaderT WebState m) Int
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT Except (ReaderT WebState m) Int
-> Except -> ActionT Except (ReaderT WebState m) Int
forall a b. a -> b -> a
const (Int -> ActionT Except (ReaderT WebState m) Int
forall (m :: * -> *) a. Monad m => a -> m a
return 250)
get_min_conf :: ActionT Except (ReaderT WebState m) Int32
get_min_conf = Text -> ActionT Except (ReaderT WebState m) Int32
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "confirmations" ActionT Except (ReaderT WebState m) Int32
-> (Except -> ActionT Except (ReaderT WebState m) Int32)
-> ActionT Except (ReaderT WebState m) Int32
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT Except (ReaderT WebState m) Int32
-> Except -> ActionT Except (ReaderT WebState m) Int32
forall a b. a -> b -> a
const (Int32 -> ActionT Except (ReaderT WebState m) Int32
forall (m :: * -> *) a. Monad m => a -> m a
return 0)
getBinfoUnspents :: (StoreReadExtra m, MonadIO m)
=> Bool
-> H.BlockHeight
-> HashSet XPubSpec
-> HashSet Address
-> ConduitT () BinfoUnspent m ()
getBinfoUnspents :: Bool
-> Word32
-> HashSet XPubSpec
-> HashSet Address
-> ConduitT () BinfoUnspent m ()
getBinfoUnspents numtxid :: Bool
numtxid height :: Word32
height xspecs :: HashSet XPubSpec
xspecs addrs :: HashSet Address
addrs = do
[ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
cs <- ConduitT
() BinfoUnspent m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
conduits
[ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> ConduitM () (Unspent, Maybe BinfoXPubPath) m ()
forall (m :: * -> *) a.
(Monad m, Ord a) =>
[ConduitT () a m ()] -> ConduitT () a m ()
joinDescStreams [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
cs ConduitM () (Unspent, Maybe BinfoXPubPath) m ()
-> ConduitM (Unspent, Maybe BinfoXPubPath) BinfoUnspent m ()
-> ConduitT () BinfoUnspent m ()
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.| ((Unspent, Maybe BinfoXPubPath) -> BinfoUnspent)
-> ConduitM (Unspent, Maybe BinfoXPubPath) BinfoUnspent m ()
forall (m :: * -> *) a b. Monad m => (a -> b) -> ConduitT a b m ()
mapC ((Unspent -> Maybe BinfoXPubPath -> BinfoUnspent)
-> (Unspent, Maybe BinfoXPubPath) -> BinfoUnspent
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Unspent -> Maybe BinfoXPubPath -> BinfoUnspent
binfo)
where
binfo :: Unspent -> Maybe BinfoXPubPath -> BinfoUnspent
binfo Unspent{..} xp :: Maybe BinfoXPubPath
xp =
let conf :: Word32
conf = case BlockRef
unspentBlock of
MemRef{} -> 0
BlockRef h :: Word32
h _ -> Word32
height Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
h Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ 1
hash :: TxHash
hash = OutPoint -> TxHash
outPointHash OutPoint
unspentPoint
idx :: Word32
idx = OutPoint -> Word32
outPointIndex OutPoint
unspentPoint
val :: Word64
val = Word64
unspentAmount
script :: ByteString
script = ByteString
unspentScript
txi :: BinfoTxId
txi = Bool -> TxHash -> BinfoTxId
encodeBinfoTxId Bool
numtxid TxHash
hash
in $WBinfoUnspent :: TxHash
-> Word32
-> ByteString
-> Word64
-> Int32
-> BinfoTxId
-> Maybe BinfoXPubPath
-> BinfoUnspent
BinfoUnspent
{ getBinfoUnspentHash :: TxHash
getBinfoUnspentHash = TxHash
hash
, getBinfoUnspentOutputIndex :: Word32
getBinfoUnspentOutputIndex = Word32
idx
, getBinfoUnspentScript :: ByteString
getBinfoUnspentScript = ByteString
script
, getBinfoUnspentValue :: Word64
getBinfoUnspentValue = Word64
val
, getBinfoUnspentConfirmations :: Int32
getBinfoUnspentConfirmations = Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
conf
, getBinfoUnspentTxIndex :: BinfoTxId
getBinfoUnspentTxIndex = BinfoTxId
txi
, getBinfoUnspentXPub :: Maybe BinfoXPubPath
getBinfoUnspentXPub = Maybe BinfoXPubPath
xp
}
point_hash :: Unspent -> TxHash
point_hash = OutPoint -> TxHash
outPointHash (OutPoint -> TxHash) -> (Unspent -> OutPoint) -> Unspent -> TxHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Unspent -> OutPoint
unspentPoint
conduits :: ConduitT
() BinfoUnspent m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
conduits = [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
forall a. Semigroup a => a -> a -> a
(<>) ([ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()])
-> ConduitT
() BinfoUnspent m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> ConduitT
()
BinfoUnspent
m
([ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ConduitT
() BinfoUnspent m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
xconduits ConduitT
()
BinfoUnspent
m
([ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()])
-> ConduitT
() BinfoUnspent m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> ConduitT
() BinfoUnspent m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> ConduitT
() BinfoUnspent m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
forall a. [ConduitM () (Unspent, Maybe a) m ()]
acounduits
xconduits :: ConduitT
() BinfoUnspent m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
xconduits = m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> ConduitT
() BinfoUnspent m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> ConduitT
()
BinfoUnspent
m
[ConduitM () (Unspent, Maybe BinfoXPubPath) m ()])
-> m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
-> ConduitT
() BinfoUnspent m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
forall a b. (a -> b) -> a -> b
$ do
let f :: XPubSpec -> XPubUnspent -> (Unspent, Maybe BinfoXPubPath)
f x :: XPubSpec
x (XPubUnspent u :: Unspent
u p :: [Word32]
p) =
let path :: Maybe SoftPath
path = DerivPathI AnyDeriv -> Maybe SoftPath
forall t. DerivPathI t -> Maybe SoftPath
toSoft ([Word32] -> DerivPathI AnyDeriv
listToPath [Word32]
p)
xp :: Maybe BinfoXPubPath
xp = XPubKey -> SoftPath -> BinfoXPubPath
BinfoXPubPath (XPubSpec -> XPubKey
xPubSpecKey XPubSpec
x) (SoftPath -> BinfoXPubPath)
-> Maybe SoftPath -> Maybe BinfoXPubPath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe SoftPath
path
in (Unspent
u, Maybe BinfoXPubPath
xp)
g :: XPubSpec -> m (ConduitM () (Unspent, Maybe BinfoXPubPath) m ())
g x :: XPubSpec
x = do
[XPubBal]
bs <- XPubSpec -> m [XPubBal]
forall (m :: * -> *). StoreReadExtra m => XPubSpec -> m [XPubBal]
xPubBals XPubSpec
x
ConduitM () (Unspent, Maybe BinfoXPubPath) m ()
-> m (ConduitM () (Unspent, Maybe BinfoXPubPath) m ())
forall (m :: * -> *) a. Monad m => a -> m a
return (ConduitM () (Unspent, Maybe BinfoXPubPath) m ()
-> m (ConduitM () (Unspent, Maybe BinfoXPubPath) m ()))
-> ConduitM () (Unspent, Maybe BinfoXPubPath) m ()
-> m (ConduitM () (Unspent, Maybe BinfoXPubPath) m ())
forall a b. (a -> b) -> a -> b
$
(Limits -> m [XPubUnspent])
-> Maybe (XPubUnspent -> TxHash)
-> Limits
-> ConduitT () XPubUnspent m ()
forall (m :: * -> *) a.
Monad m =>
(Limits -> m [a])
-> Maybe (a -> TxHash) -> Limits -> ConduitT () a m ()
streamThings
(XPubSpec -> [XPubBal] -> Limits -> m [XPubUnspent]
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> Limits -> m [XPubUnspent]
xPubUnspents XPubSpec
x [XPubBal]
bs)
Maybe (XPubUnspent -> TxHash)
forall a. Maybe a
Nothing
Limits
forall a. Default a => a
def{limit :: Word32
limit = 250} ConduitT () XPubUnspent m ()
-> ConduitM XPubUnspent (Unspent, Maybe BinfoXPubPath) m ()
-> ConduitM () (Unspent, Maybe BinfoXPubPath) m ()
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.|
(XPubUnspent -> (Unspent, Maybe BinfoXPubPath))
-> ConduitM XPubUnspent (Unspent, Maybe BinfoXPubPath) m ()
forall (m :: * -> *) a b. Monad m => (a -> b) -> ConduitT a b m ()
mapC (XPubSpec -> XPubUnspent -> (Unspent, Maybe BinfoXPubPath)
f XPubSpec
x)
(XPubSpec -> m (ConduitM () (Unspent, Maybe BinfoXPubPath) m ()))
-> [XPubSpec]
-> m [ConduitM () (Unspent, Maybe BinfoXPubPath) m ()]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM XPubSpec -> m (ConduitM () (Unspent, Maybe BinfoXPubPath) m ())
forall (m :: * -> *) (m :: * -> *).
(StoreReadExtra m, StoreReadExtra m) =>
XPubSpec -> m (ConduitM () (Unspent, Maybe BinfoXPubPath) m ())
g (HashSet XPubSpec -> [XPubSpec]
forall a. HashSet a -> [a]
HashSet.toList HashSet XPubSpec
xspecs)
acounduits :: [ConduitM () (Unspent, Maybe a) m ()]
acounduits =
let f :: a -> (a, Maybe a)
f u :: a
u = (a
u, Maybe a
forall a. Maybe a
Nothing)
g :: Address -> ConduitM () (Unspent, Maybe a) m ()
g a :: Address
a = (Limits -> m [Unspent])
-> Maybe (Unspent -> TxHash) -> Limits -> ConduitT () Unspent m ()
forall (m :: * -> *) a.
Monad m =>
(Limits -> m [a])
-> Maybe (a -> TxHash) -> Limits -> ConduitT () a m ()
streamThings
(Address -> Limits -> m [Unspent]
forall (m :: * -> *).
StoreReadExtra m =>
Address -> Limits -> m [Unspent]
getAddressUnspents Address
a)
Maybe (Unspent -> TxHash)
forall a. Maybe a
Nothing
Limits
forall a. Default a => a
def{limit :: Word32
limit = 250} ConduitT () Unspent m ()
-> ConduitM Unspent (Unspent, Maybe a) m ()
-> ConduitM () (Unspent, Maybe a) m ()
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.|
(Unspent -> (Unspent, Maybe a))
-> ConduitM Unspent (Unspent, Maybe a) m ()
forall (m :: * -> *) a b. Monad m => (a -> b) -> ConduitT a b m ()
mapC Unspent -> (Unspent, Maybe a)
forall a a. a -> (a, Maybe a)
f
in (Address -> ConduitM () (Unspent, Maybe a) m ())
-> [Address] -> [ConduitM () (Unspent, Maybe a) m ()]
forall a b. (a -> b) -> [a] -> [b]
map Address -> ConduitM () (Unspent, Maybe a) m ()
forall (m :: * -> *) a.
StoreReadExtra m =>
Address -> ConduitM () (Unspent, Maybe a) m ()
g (HashSet Address -> [Address]
forall a. HashSet a -> [a]
HashSet.toList HashSet Address
addrs)
getBinfoTxs :: (StoreReadExtra m, MonadIO m)
=> HashMap Address (Maybe BinfoXPubPath)
-> HashSet XPubSpec
-> HashSet Address
-> HashSet Address
-> BinfoFilter
-> Bool
-> Bool
-> Int64
-> ConduitT () BinfoTx m ()
getBinfoTxs :: HashMap Address (Maybe BinfoXPubPath)
-> HashSet XPubSpec
-> HashSet Address
-> HashSet Address
-> BinfoFilter
-> Bool
-> Bool
-> Int64
-> ConduitT () BinfoTx m ()
getBinfoTxs abook :: HashMap Address (Maybe BinfoXPubPath)
abook sxspecs :: HashSet XPubSpec
sxspecs saddrs :: HashSet Address
saddrs baddrs :: HashSet Address
baddrs bfilter :: BinfoFilter
bfilter numtxid :: Bool
numtxid prune :: Bool
prune bal :: Int64
bal = do
[ConduitT () TxRef m ()]
cs <- ConduitT () BinfoTx m [ConduitT () TxRef m ()]
conduits
[ConduitT () TxRef m ()] -> ConduitT () TxRef m ()
forall (m :: * -> *) a.
(Monad m, Ord a) =>
[ConduitT () a m ()] -> ConduitT () a m ()
joinDescStreams [ConduitT () TxRef m ()]
cs ConduitT () TxRef m ()
-> ConduitM TxRef BinfoTx m () -> ConduitT () BinfoTx m ()
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.| Int64 -> ConduitM TxRef BinfoTx m ()
forall (m :: * -> *).
StoreReadBase m =>
Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
bal
where
sxspecs_ls :: [XPubSpec]
sxspecs_ls = HashSet XPubSpec -> [XPubSpec]
forall a. HashSet a -> [a]
HashSet.toList HashSet XPubSpec
sxspecs
saddrs_ls :: [Address]
saddrs_ls = HashSet Address -> [Address]
forall a. HashSet a -> [a]
HashSet.toList HashSet Address
saddrs
conduits :: ConduitT () BinfoTx m [ConduitT () TxRef m ()]
conduits = [ConduitT () TxRef m ()]
-> [ConduitT () TxRef m ()] -> [ConduitT () TxRef m ()]
forall a. Semigroup a => a -> a -> a
(<>) ([ConduitT () TxRef m ()]
-> [ConduitT () TxRef m ()] -> [ConduitT () TxRef m ()])
-> ConduitT () BinfoTx m [ConduitT () TxRef m ()]
-> ConduitT
() BinfoTx m ([ConduitT () TxRef m ()] -> [ConduitT () TxRef m ()])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (XPubSpec -> ConduitT () BinfoTx m (ConduitT () TxRef m ()))
-> [XPubSpec] -> ConduitT () BinfoTx m [ConduitT () TxRef m ()]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM XPubSpec -> ConduitT () BinfoTx m (ConduitT () TxRef m ())
forall (t :: (* -> *) -> * -> *) (m :: * -> *) (m :: * -> *).
(MonadTrans t, StoreReadExtra m, StoreReadExtra m) =>
XPubSpec -> t m (ConduitT () TxRef m ())
xpub_c [XPubSpec]
sxspecs_ls ConduitT
() BinfoTx m ([ConduitT () TxRef m ()] -> [ConduitT () TxRef m ()])
-> ConduitT () BinfoTx m [ConduitT () TxRef m ()]
-> ConduitT () BinfoTx m [ConduitT () TxRef m ()]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [ConduitT () TxRef m ()]
-> ConduitT () BinfoTx m [ConduitT () TxRef m ()]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Address -> ConduitT () TxRef m ())
-> [Address] -> [ConduitT () TxRef m ()]
forall a b. (a -> b) -> [a] -> [b]
map Address -> ConduitT () TxRef m ()
forall (m :: * -> *).
StoreReadExtra m =>
Address -> ConduitT () TxRef m ()
addr_c [Address]
saddrs_ls)
xpub_c :: XPubSpec -> t m (ConduitT () TxRef m ())
xpub_c x :: XPubSpec
x = m (ConduitT () TxRef m ()) -> t m (ConduitT () TxRef m ())
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (ConduitT () TxRef m ()) -> t m (ConduitT () TxRef m ()))
-> m (ConduitT () TxRef m ()) -> t m (ConduitT () TxRef m ())
forall a b. (a -> b) -> a -> b
$ do
[XPubBal]
bs <- XPubSpec -> m [XPubBal]
forall (m :: * -> *). StoreReadExtra m => XPubSpec -> m [XPubBal]
xPubBals XPubSpec
x
ConduitT () TxRef m () -> m (ConduitT () TxRef m ())
forall (m :: * -> *) a. Monad m => a -> m a
return (ConduitT () TxRef m () -> m (ConduitT () TxRef m ()))
-> ConduitT () TxRef m () -> m (ConduitT () TxRef m ())
forall a b. (a -> b) -> a -> b
$ (Limits -> m [TxRef])
-> Maybe (TxRef -> TxHash) -> Limits -> ConduitT () TxRef m ()
forall (m :: * -> *) a.
Monad m =>
(Limits -> m [a])
-> Maybe (a -> TxHash) -> Limits -> ConduitT () a m ()
streamThings (XPubSpec -> [XPubBal] -> Limits -> m [TxRef]
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> Limits -> m [TxRef]
xPubTxs XPubSpec
x [XPubBal]
bs) ((TxRef -> TxHash) -> Maybe (TxRef -> TxHash)
forall a. a -> Maybe a
Just TxRef -> TxHash
txRefHash) Limits
forall a. Default a => a
def{limit :: Word32
limit = 50}
addr_c :: Address -> ConduitT () TxRef m ()
addr_c a :: Address
a = (Limits -> m [TxRef])
-> Maybe (TxRef -> TxHash) -> Limits -> ConduitT () TxRef m ()
forall (m :: * -> *) a.
Monad m =>
(Limits -> m [a])
-> Maybe (a -> TxHash) -> Limits -> ConduitT () a m ()
streamThings (Address -> Limits -> m [TxRef]
forall (m :: * -> *).
StoreReadExtra m =>
Address -> Limits -> m [TxRef]
getAddressTxs Address
a) ((TxRef -> TxHash) -> Maybe (TxRef -> TxHash)
forall a. a -> Maybe a
Just TxRef -> TxHash
txRefHash) Limits
forall a. Default a => a
def{limit :: Word32
limit = 50}
binfo_tx :: Int64 -> Transaction -> BinfoTx
binfo_tx b :: Int64
b = Bool
-> HashMap Address (Maybe BinfoXPubPath)
-> Bool
-> Int64
-> Transaction
-> BinfoTx
toBinfoTx Bool
numtxid HashMap Address (Maybe BinfoXPubPath)
abook Bool
prune Int64
b
compute_bal_change :: BinfoTx -> a
compute_bal_change BinfoTx{..} =
let ins :: [BinfoTxOutput]
ins = (BinfoTxInput -> Maybe BinfoTxOutput)
-> [BinfoTxInput] -> [BinfoTxOutput]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe BinfoTxInput -> Maybe BinfoTxOutput
getBinfoTxInputPrevOut [BinfoTxInput]
getBinfoTxInputs
out :: [BinfoTxOutput]
out = [BinfoTxOutput]
getBinfoTxOutputs
f :: Bool -> BinfoTxOutput -> a
f b :: Bool
b BinfoTxOutput{..} =
let val :: a
val = Word64 -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
getBinfoTxOutputValue
in case Maybe Address
getBinfoTxOutputAddress of
Nothing -> 0
Just a :: Address
a | Address
a Address -> HashSet Address -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
`HashSet.member` HashSet Address
baddrs ->
if Bool
b then a
val else a -> a
forall a. Num a => a -> a
negate a
val
| Bool
otherwise -> 0
in [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([a] -> a) -> [a] -> a
forall a b. (a -> b) -> a -> b
$ (BinfoTxOutput -> a) -> [BinfoTxOutput] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> BinfoTxOutput -> a
forall a. Num a => Bool -> BinfoTxOutput -> a
f Bool
False) [BinfoTxOutput]
ins [a] -> [a] -> [a]
forall a. Semigroup a => a -> a -> a
<> (BinfoTxOutput -> a) -> [BinfoTxOutput] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> BinfoTxOutput -> a
forall a. Num a => Bool -> BinfoTxOutput -> a
f Bool
True) [BinfoTxOutput]
out
go :: Int64 -> ConduitT TxRef BinfoTx m ()
go b :: Int64
b = ConduitT TxRef BinfoTx m (Maybe TxRef)
forall (m :: * -> *) i. Monad m => Consumer i m (Maybe i)
await ConduitT TxRef BinfoTx m (Maybe TxRef)
-> (Maybe TxRef -> ConduitT TxRef BinfoTx m ())
-> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> () -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just (TxRef _ t :: TxHash
t) -> m (Maybe Transaction)
-> ConduitT TxRef BinfoTx m (Maybe Transaction)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TxHash -> m (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction TxHash
t) ConduitT TxRef BinfoTx m (Maybe Transaction)
-> (Maybe Transaction -> ConduitT TxRef BinfoTx m ())
-> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
b
Just x :: Transaction
x -> do
let a :: BinfoTx
a = Int64 -> Transaction -> BinfoTx
binfo_tx Int64
b Transaction
x
b' :: Int64
b' = Int64
b Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- BinfoTx -> Int64
forall a. Num a => BinfoTx -> a
compute_bal_change BinfoTx
a
c :: Bool
c = Maybe Word32 -> Bool
forall a. Maybe a -> Bool
isJust (BinfoTx -> Maybe Word32
getBinfoTxBlockHeight BinfoTx
a)
Just (d :: Int64
d, _) = BinfoTx -> Maybe (Int64, Int64)
getBinfoTxResultBal BinfoTx
a
r :: Int64
r = Int64
d Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ Word64 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (BinfoTx -> Word64
getBinfoTxFee BinfoTx
a)
case BinfoFilter
bfilter of
BinfoFilterAll ->
BinfoTx -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield BinfoTx
a ConduitT TxRef BinfoTx m ()
-> ConduitT TxRef BinfoTx m () -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
b'
BinfoFilterSent
| 0 Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
> Int64
r -> BinfoTx -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield BinfoTx
a ConduitT TxRef BinfoTx m ()
-> ConduitT TxRef BinfoTx m () -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
b'
| Bool
otherwise -> Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
b'
BinfoFilterReceived
| Int64
r Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
> 0 -> BinfoTx -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield BinfoTx
a ConduitT TxRef BinfoTx m ()
-> ConduitT TxRef BinfoTx m () -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
b'
| Bool
otherwise -> Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
b'
BinfoFilterMoved
| Int64
r Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== 0 -> BinfoTx -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield BinfoTx
a ConduitT TxRef BinfoTx m ()
-> ConduitT TxRef BinfoTx m () -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
b'
| Bool
otherwise -> Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
b'
BinfoFilterConfirmed
| Bool
c -> BinfoTx -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield BinfoTx
a ConduitT TxRef BinfoTx m ()
-> ConduitT TxRef BinfoTx m () -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
b'
| Bool
otherwise -> Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
b'
BinfoFilterMempool
| Bool
c -> () -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise -> BinfoTx -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield BinfoTx
a ConduitT TxRef BinfoTx m ()
-> ConduitT TxRef BinfoTx m () -> ConduitT TxRef BinfoTx m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int64 -> ConduitT TxRef BinfoTx m ()
go Int64
b'
scottyMultiAddr :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()
scottyMultiAddr :: WebT m ()
scottyMultiAddr =
ActionT
Except
(ReaderT WebState m)
(HashSet Address, HashSet XPubKey, HashSet Address,
HashSet XPubKey, HashMap XPubKey XPubSpec)
get_addrs ActionT
Except
(ReaderT WebState m)
(HashSet Address, HashSet XPubKey, HashSet Address,
HashSet XPubKey, HashMap XPubKey XPubSpec)
-> ((HashSet Address, HashSet XPubKey, HashSet Address,
HashSet XPubKey, HashMap XPubKey XPubSpec)
-> WebT m ())
-> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(addrs' :: HashSet Address
addrs', xpubs :: HashSet XPubKey
xpubs, saddrs :: HashSet Address
saddrs, sxpubs :: HashSet XPubKey
sxpubs, xspecs :: HashMap XPubKey XPubSpec
xspecs) ->
WebT m Bool
forall (m :: * -> *). MonadIO m => WebT m Bool
getNumTxId WebT m Bool -> (Bool -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \numtxid :: Bool
numtxid ->
ReaderT WebState m (TVar (HashMap Text BinfoTicker))
-> ActionT
Except (ReaderT WebState m) (TVar (HashMap Text BinfoTicker))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> TVar (HashMap Text BinfoTicker))
-> ReaderT WebState m (TVar (HashMap Text BinfoTicker))
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WebState -> TVar (HashMap Text BinfoTicker)
webTicker) ActionT
Except (ReaderT WebState m) (TVar (HashMap Text BinfoTicker))
-> (TVar (HashMap Text BinfoTicker) -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ticker :: TVar (HashMap Text BinfoTicker)
ticker ->
TVar (HashMap Text BinfoTicker)
-> ActionT Except (ReaderT WebState m) BinfoSymbol
forall (m :: * -> *) b.
(ScottyError b, MonadIO m) =>
TVar (HashMap Text BinfoTicker) -> ActionT b m BinfoSymbol
get_price TVar (HashMap Text BinfoTicker)
ticker ActionT Except (ReaderT WebState m) BinfoSymbol
-> (BinfoSymbol -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \local :: BinfoSymbol
local ->
WebT m Bool
get_cashaddr WebT m Bool -> (Bool -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \cashaddr :: Bool
cashaddr ->
ActionT Except (ReaderT WebState m) Int
get_offset ActionT Except (ReaderT WebState m) Int
-> (Int -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \offset :: Int
offset ->
ActionT Except (ReaderT WebState m) Int
get_count ActionT Except (ReaderT WebState m) Int
-> (Int -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \n :: Int
n ->
WebT m Bool
get_prune WebT m Bool -> (Bool -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \prune :: Bool
prune ->
ActionT Except (ReaderT WebState m) BinfoFilter
get_filter ActionT Except (ReaderT WebState m) BinfoFilter
-> (BinfoFilter -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \fltr :: BinfoFilter
fltr ->
let len :: Int
len = HashSet Address -> Int
forall a. HashSet a -> Int
HashSet.size HashSet Address
addrs' Int -> Int -> Int
forall a. Num a => a -> a -> a
+ HashSet XPubKey -> Int
forall a. HashSet a -> Int
HashSet.size HashSet XPubKey
xpubs
in do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
multiaddrStat Int
len
HashMap XPubKey [XPubBal]
xbals <- HashMap XPubKey XPubSpec
-> ActionT Except (ReaderT WebState m) (HashMap XPubKey [XPubBal])
get_xbals HashMap XPubKey XPubSpec
xspecs
HashMap XPubKey Int
xtxns <- HashMap XPubKey [XPubBal]
-> HashMap XPubKey XPubSpec
-> ActionT Except (ReaderT WebState m) (HashMap XPubKey Int)
forall (f :: * -> *) k v.
(Num v, StoreReadExtra f, Eq k, Hashable k) =>
HashMap k [XPubBal] -> HashMap k XPubSpec -> f (HashMap k v)
get_xpub_tx_count HashMap XPubKey [XPubBal]
xbals HashMap XPubKey XPubSpec
xspecs
let sxbals :: HashMap XPubKey [XPubBal]
sxbals = HashSet XPubKey
-> HashMap XPubKey [XPubBal] -> HashMap XPubKey [XPubBal]
forall a v.
(Eq a, Hashable a) =>
HashSet a -> HashMap a v -> HashMap a v
subset HashSet XPubKey
sxpubs HashMap XPubKey [XPubBal]
xbals
xabals :: HashMap Address Balance
xabals = HashMap XPubKey [XPubBal] -> HashMap Address Balance
forall k. HashMap k [XPubBal] -> HashMap Address Balance
compute_xabals HashMap XPubKey [XPubBal]
xbals
addrs :: HashSet Address
addrs = HashSet Address
addrs' HashSet Address -> HashSet Address -> HashSet Address
forall a. (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a
`HashSet.difference` HashMap Address Balance -> HashSet Address
forall k a. HashMap k a -> HashSet k
HashMap.keysSet HashMap Address Balance
xabals
HashMap Address Balance
abals <- HashSet Address
-> ActionT Except (ReaderT WebState m) (HashMap Address Balance)
get_abals HashSet Address
addrs
let sxspecs :: HashSet XPubSpec
sxspecs = HashSet XPubKey -> HashMap XPubKey XPubSpec -> HashSet XPubSpec
forall a k.
(Eq a, Eq k, Hashable a, Hashable k) =>
HashSet k -> HashMap k a -> HashSet a
compute_sxspecs HashSet XPubKey
sxpubs HashMap XPubKey XPubSpec
xspecs
sxabals :: HashMap Address Balance
sxabals = HashMap XPubKey [XPubBal] -> HashMap Address Balance
forall k. HashMap k [XPubBal] -> HashMap Address Balance
compute_xabals HashMap XPubKey [XPubBal]
sxbals
sabals :: HashMap Address Balance
sabals = HashSet Address
-> HashMap Address Balance -> HashMap Address Balance
forall a v.
(Eq a, Hashable a) =>
HashSet a -> HashMap a v -> HashMap a v
subset HashSet Address
saddrs HashMap Address Balance
abals
sallbals :: HashMap Address Balance
sallbals = HashMap Address Balance
sabals HashMap Address Balance
-> HashMap Address Balance -> HashMap Address Balance
forall a. Semigroup a => a -> a -> a
<> HashMap Address Balance
sxabals
sbal :: Word64
sbal = HashMap Address Balance -> Word64
forall k. HashMap k Balance -> Word64
compute_bal HashMap Address Balance
sallbals
allbals :: HashMap Address Balance
allbals = HashMap Address Balance
abals HashMap Address Balance
-> HashMap Address Balance -> HashMap Address Balance
forall a. Semigroup a => a -> a -> a
<> HashMap Address Balance
xabals
abook :: HashMap Address (Maybe BinfoXPubPath)
abook = HashSet Address
-> HashMap XPubKey [XPubBal]
-> HashMap Address (Maybe BinfoXPubPath)
compute_abook HashSet Address
addrs HashMap XPubKey [XPubBal]
xbals
sxaddrs :: HashSet Address
sxaddrs = HashMap XPubKey [XPubBal] -> HashSet Address
forall k. HashMap k [XPubBal] -> HashSet Address
compute_xaddrs HashMap XPubKey [XPubBal]
sxbals
salladdrs :: HashSet Address
salladdrs = HashSet Address
saddrs HashSet Address -> HashSet Address -> HashSet Address
forall a. Semigroup a => a -> a -> a
<> HashSet Address
sxaddrs
bal :: Word64
bal = HashMap Address Balance -> Word64
forall k. HashMap k Balance -> Word64
compute_bal HashMap Address Balance
allbals
let ibal :: Int64
ibal = Word64 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
sbal
[BinfoTx]
ftxs <-
ReaderT WebState m [BinfoTx]
-> ActionT Except (ReaderT WebState m) [BinfoTx]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [BinfoTx]
-> ActionT Except (ReaderT WebState m) [BinfoTx])
-> (ConduitT () Void (ReaderT WebState m) [BinfoTx]
-> ReaderT WebState m [BinfoTx])
-> ConduitT () Void (ReaderT WebState m) [BinfoTx]
-> ActionT Except (ReaderT WebState m) [BinfoTx]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConduitT () Void (ReaderT WebState m) [BinfoTx]
-> ReaderT WebState m [BinfoTx]
forall (m :: * -> *) r. Monad m => ConduitT () Void m r -> m r
runConduit (ConduitT () Void (ReaderT WebState m) [BinfoTx]
-> ActionT Except (ReaderT WebState m) [BinfoTx])
-> ConduitT () Void (ReaderT WebState m) [BinfoTx]
-> ActionT Except (ReaderT WebState m) [BinfoTx]
forall a b. (a -> b) -> a -> b
$
HashMap Address (Maybe BinfoXPubPath)
-> HashSet XPubSpec
-> HashSet Address
-> HashSet Address
-> BinfoFilter
-> Bool
-> Bool
-> Int64
-> ConduitT () BinfoTx (ReaderT WebState m) ()
forall (m :: * -> *).
(StoreReadExtra m, MonadIO m) =>
HashMap Address (Maybe BinfoXPubPath)
-> HashSet XPubSpec
-> HashSet Address
-> HashSet Address
-> BinfoFilter
-> Bool
-> Bool
-> Int64
-> ConduitT () BinfoTx m ()
getBinfoTxs HashMap Address (Maybe BinfoXPubPath)
abook HashSet XPubSpec
sxspecs HashSet Address
saddrs HashSet Address
salladdrs BinfoFilter
fltr Bool
numtxid Bool
prune Int64
ibal ConduitT () BinfoTx (ReaderT WebState m) ()
-> ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
-> ConduitT () Void (ReaderT WebState m) [BinfoTx]
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.|
(Int -> ConduitT BinfoTx Void (ReaderT WebState m) ()
forall (m :: * -> *) a o. Monad m => Int -> ConduitT a o m ()
dropC Int
offset ConduitT BinfoTx Void (ReaderT WebState m) ()
-> ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
-> ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> ConduitT BinfoTx BinfoTx (ReaderT WebState m) ()
forall (m :: * -> *) a. Monad m => Int -> ConduitT a a m ()
takeC Int
n ConduitT BinfoTx BinfoTx (ReaderT WebState m) ()
-> ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
-> ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.| ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
forall (m :: * -> *) a o. Monad m => ConduitT a o m [a]
sinkList)
BlockData
best <- ActionT Except (ReaderT WebState m) BlockData
get_best_block
Word32
peers <- ActionT Except (ReaderT WebState m) Word32
get_peers
Network
net <- ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network)
-> ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall a b. (a -> b) -> a -> b
$ (WebState -> Network) -> ReaderT WebState m Network
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Network
storeNetwork (Store -> Network) -> (WebState -> Store) -> WebState -> Network
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
let baddrs :: [BinfoBalance]
baddrs = HashMap Address Balance
-> HashMap XPubKey [XPubBal]
-> HashMap XPubKey Int
-> [BinfoBalance]
toBinfoAddrs HashMap Address Balance
sabals HashMap XPubKey [XPubBal]
sxbals HashMap XPubKey Int
xtxns
abaddrs :: [BinfoBalance]
abaddrs = HashMap Address Balance
-> HashMap XPubKey [XPubBal]
-> HashMap XPubKey Int
-> [BinfoBalance]
toBinfoAddrs HashMap Address Balance
abals HashMap XPubKey [XPubBal]
xbals HashMap XPubKey Int
xtxns
recv :: Word64
recv = [Word64] -> Word64
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Word64] -> Word64) -> [Word64] -> Word64
forall a b. (a -> b) -> a -> b
$ (BinfoBalance -> Word64) -> [BinfoBalance] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map BinfoBalance -> Word64
getBinfoAddrReceived [BinfoBalance]
abaddrs
sent :: Word64
sent = [Word64] -> Word64
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Word64] -> Word64) -> [Word64] -> Word64
forall a b. (a -> b) -> a -> b
$ (BinfoBalance -> Word64) -> [BinfoBalance] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map BinfoBalance -> Word64
getBinfoAddrSent [BinfoBalance]
abaddrs
txn :: Word64
txn = Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word64) -> Int -> Word64
forall a b. (a -> b) -> a -> b
$ [BinfoTx] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [BinfoTx]
ftxs
wallet :: BinfoWallet
wallet =
$WBinfoWallet :: Word64 -> Word64 -> Word64 -> Word64 -> Word64 -> BinfoWallet
BinfoWallet
{ getBinfoWalletBalance :: Word64
getBinfoWalletBalance = Word64
bal
, getBinfoWalletTxCount :: Word64
getBinfoWalletTxCount = Word64
txn
, getBinfoWalletFilteredCount :: Word64
getBinfoWalletFilteredCount = Word64
txn
, getBinfoWalletTotalReceived :: Word64
getBinfoWalletTotalReceived = Word64
recv
, getBinfoWalletTotalSent :: Word64
getBinfoWalletTotalSent = Word64
sent
}
coin :: BinfoSymbol
coin = Network -> BinfoSymbol
netBinfoSymbol Network
net
block :: BinfoBlockInfo
block =
$WBinfoBlockInfo :: BlockHash -> Word32 -> Word32 -> Word32 -> BinfoBlockInfo
BinfoBlockInfo
{ getBinfoBlockInfoHash :: BlockHash
getBinfoBlockInfoHash = BlockHeader -> BlockHash
H.headerHash (BlockData -> BlockHeader
blockDataHeader BlockData
best)
, getBinfoBlockInfoHeight :: Word32
getBinfoBlockInfoHeight = BlockData -> Word32
blockDataHeight BlockData
best
, getBinfoBlockInfoTime :: Word32
getBinfoBlockInfoTime = BlockHeader -> Word32
H.blockTimestamp (BlockData -> BlockHeader
blockDataHeader BlockData
best)
, getBinfoBlockInfoIndex :: Word32
getBinfoBlockInfoIndex = BlockData -> Word32
blockDataHeight BlockData
best
}
info :: BinfoInfo
info =
$WBinfoInfo :: Word32
-> Double
-> BinfoSymbol
-> BinfoSymbol
-> BinfoBlockInfo
-> BinfoInfo
BinfoInfo
{ getBinfoConnected :: Word32
getBinfoConnected = Word32
peers
, getBinfoConversion :: Double
getBinfoConversion = 100 Double -> Double -> Double
forall a. Num a => a -> a -> a
* 1000 Double -> Double -> Double
forall a. Num a => a -> a -> a
* 1000
, getBinfoLocal :: BinfoSymbol
getBinfoLocal = BinfoSymbol
local
, getBinfoBTC :: BinfoSymbol
getBinfoBTC = BinfoSymbol
coin
, getBinfoLatestBlock :: BinfoBlockInfo
getBinfoLatestBlock = BinfoBlockInfo
block
}
WebT m ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
Encoding -> WebT m ()
forall (m :: * -> *). Monad m => Encoding -> WebT m ()
streamEncoding (Encoding -> WebT m ()) -> Encoding -> WebT m ()
forall a b. (a -> b) -> a -> b
$ Network -> BinfoMultiAddr -> Encoding
binfoMultiAddrToEncoding Network
net
$WBinfoMultiAddr :: [BinfoBalance]
-> BinfoWallet
-> [BinfoTx]
-> BinfoInfo
-> Bool
-> Bool
-> BinfoMultiAddr
BinfoMultiAddr
{ getBinfoMultiAddrAddresses :: [BinfoBalance]
getBinfoMultiAddrAddresses = [BinfoBalance]
baddrs
, getBinfoMultiAddrWallet :: BinfoWallet
getBinfoMultiAddrWallet = BinfoWallet
wallet
, getBinfoMultiAddrTxs :: [BinfoTx]
getBinfoMultiAddrTxs = [BinfoTx]
ftxs
, getBinfoMultiAddrInfo :: BinfoInfo
getBinfoMultiAddrInfo = BinfoInfo
info
, getBinfoMultiAddrRecommendFee :: Bool
getBinfoMultiAddrRecommendFee = Bool
True
, getBinfoMultiAddrCashAddr :: Bool
getBinfoMultiAddrCashAddr = Bool
cashaddr
}
where
get_xpub_tx_count :: HashMap k [XPubBal] -> HashMap k XPubSpec -> f (HashMap k v)
get_xpub_tx_count xbals :: HashMap k [XPubBal]
xbals =
let f :: (k, XPubSpec) -> m (k, b)
f (k :: k
k, s :: XPubSpec
s) =
case k -> HashMap k [XPubBal] -> Maybe [XPubBal]
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup k
k HashMap k [XPubBal]
xbals of
Nothing -> (k, b) -> m (k, b)
forall (m :: * -> *) a. Monad m => a -> m a
return (k
k, 0)
Just bs :: [XPubBal]
bs -> do
Word32
n <- XPubSpec -> [XPubBal] -> m Word32
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> m Word32
xPubTxCount XPubSpec
s [XPubBal]
bs
(k, b) -> m (k, b)
forall (m :: * -> *) a. Monad m => a -> m a
return (k
k, Word32 -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
n)
in ([(k, v)] -> HashMap k v) -> f [(k, v)] -> f (HashMap k v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(k, v)] -> HashMap k v
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList (f [(k, v)] -> f (HashMap k v))
-> (HashMap k XPubSpec -> f [(k, v)])
-> HashMap k XPubSpec
-> f (HashMap k v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((k, XPubSpec) -> f (k, v)) -> [(k, XPubSpec)] -> f [(k, v)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (k, XPubSpec) -> f (k, v)
forall (m :: * -> *) b.
(Num b, StoreReadExtra m) =>
(k, XPubSpec) -> m (k, b)
f ([(k, XPubSpec)] -> f [(k, v)])
-> (HashMap k XPubSpec -> [(k, XPubSpec)])
-> HashMap k XPubSpec
-> f [(k, v)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap k XPubSpec -> [(k, XPubSpec)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList
get_filter :: ActionT Except (ReaderT WebState m) BinfoFilter
get_filter = Text -> ActionT Except (ReaderT WebState m) BinfoFilter
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "filter" ActionT Except (ReaderT WebState m) BinfoFilter
-> (Except -> ActionT Except (ReaderT WebState m) BinfoFilter)
-> ActionT Except (ReaderT WebState m) BinfoFilter
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT Except (ReaderT WebState m) BinfoFilter
-> Except -> ActionT Except (ReaderT WebState m) BinfoFilter
forall a b. a -> b -> a
const (BinfoFilter -> ActionT Except (ReaderT WebState m) BinfoFilter
forall (m :: * -> *) a. Monad m => a -> m a
return BinfoFilter
BinfoFilterAll)
get_best_block :: ActionT Except (ReaderT WebState m) BlockData
get_best_block =
ActionT Except (ReaderT WebState m) (Maybe BlockHash)
forall (m :: * -> *). StoreReadBase m => m (Maybe BlockHash)
getBestBlock ActionT Except (ReaderT WebState m) (Maybe BlockHash)
-> (Maybe BlockHash
-> ActionT Except (ReaderT WebState m) BlockData)
-> ActionT Except (ReaderT WebState m) BlockData
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> (WebMetrics -> StatDist)
-> Except -> ActionT Except (ReaderT WebState m) BlockData
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
multiaddrStat Except
ThingNotFound
Just bh :: BlockHash
bh -> BlockHash -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock BlockHash
bh ActionT Except (ReaderT WebState m) (Maybe BlockData)
-> (Maybe BlockData
-> ActionT Except (ReaderT WebState m) BlockData)
-> ActionT Except (ReaderT WebState m) BlockData
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> (WebMetrics -> StatDist)
-> Except -> ActionT Except (ReaderT WebState m) BlockData
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
multiaddrStat Except
ThingNotFound
Just b :: BlockData
b -> BlockData -> ActionT Except (ReaderT WebState m) BlockData
forall (m :: * -> *) a. Monad m => a -> m a
return BlockData
b
get_price :: TVar (HashMap Text BinfoTicker) -> ActionT b m BinfoSymbol
get_price ticker :: TVar (HashMap Text BinfoTicker)
ticker = do
Text
code <- Text -> Text
T.toUpper (Text -> Text) -> ActionT b m Text -> ActionT b m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ActionT b m Text
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "currency" ActionT b m Text -> (b -> ActionT b m Text) -> ActionT b m Text
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT b m Text -> b -> ActionT b m Text
forall a b. a -> b -> a
const (Text -> ActionT b m Text
forall (m :: * -> *) a. Monad m => a -> m a
return "USD")
HashMap Text BinfoTicker
prices <- TVar (HashMap Text BinfoTicker)
-> ActionT b m (HashMap Text BinfoTicker)
forall (m :: * -> *) a. MonadIO m => TVar a -> m a
readTVarIO TVar (HashMap Text BinfoTicker)
ticker
case Text -> HashMap Text BinfoTicker -> Maybe BinfoTicker
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup Text
code HashMap Text BinfoTicker
prices of
Nothing -> BinfoSymbol -> ActionT b m BinfoSymbol
forall (m :: * -> *) a. Monad m => a -> m a
return BinfoSymbol
forall a. Default a => a
def
Just p :: BinfoTicker
p -> BinfoSymbol -> ActionT b m BinfoSymbol
forall (m :: * -> *) a. Monad m => a -> m a
return (BinfoSymbol -> ActionT b m BinfoSymbol)
-> BinfoSymbol -> ActionT b m BinfoSymbol
forall a b. (a -> b) -> a -> b
$ Text -> BinfoTicker -> BinfoSymbol
binfoTickerToSymbol Text
code BinfoTicker
p
get_prune :: WebT m Bool
get_prune = (Bool -> Bool) -> WebT m Bool -> WebT m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Bool -> Bool
not (WebT m Bool -> WebT m Bool) -> WebT m Bool -> WebT m Bool
forall a b. (a -> b) -> a -> b
$ Text -> WebT m Bool
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "no_compact"
WebT m Bool -> (Except -> WebT m Bool) -> WebT m Bool
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` WebT m Bool -> Except -> WebT m Bool
forall a b. a -> b -> a
const (Bool -> WebT m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False)
get_cashaddr :: WebT m Bool
get_cashaddr = Text -> WebT m Bool
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "cashaddr"
WebT m Bool -> (Except -> WebT m Bool) -> WebT m Bool
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` WebT m Bool -> Except -> WebT m Bool
forall a b. a -> b -> a
const (Bool -> WebT m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False)
get_count :: ActionT Except (ReaderT WebState m) Int
get_count = do
Word32
d <- ReaderT WebState m Word32
-> ActionT Except (ReaderT WebState m) Word32
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> Word32) -> ReaderT WebState m Word32
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (WebLimits -> Word32
maxLimitDefault (WebLimits -> Word32)
-> (WebState -> WebLimits) -> WebState -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> WebLimits
webMaxLimits (WebConfig -> WebLimits)
-> (WebState -> WebConfig) -> WebState -> WebLimits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig))
Word32
x <- ReaderT WebState m Word32
-> ActionT Except (ReaderT WebState m) Word32
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> Word32) -> ReaderT WebState m Word32
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (WebLimits -> Word32
maxLimitFull (WebLimits -> Word32)
-> (WebState -> WebLimits) -> WebState -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> WebLimits
webMaxLimits (WebConfig -> WebLimits)
-> (WebState -> WebConfig) -> WebState -> WebLimits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig))
Word32
i <- Word32 -> Word32 -> Word32
forall a. Ord a => a -> a -> a
min Word32
x (Word32 -> Word32)
-> ActionT Except (ReaderT WebState m) Word32
-> ActionT Except (ReaderT WebState m) Word32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> ActionT Except (ReaderT WebState m) Word32
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "n" ActionT Except (ReaderT WebState m) Word32
-> (Except -> ActionT Except (ReaderT WebState m) Word32)
-> ActionT Except (ReaderT WebState m) Word32
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT Except (ReaderT WebState m) Word32
-> Except -> ActionT Except (ReaderT WebState m) Word32
forall a b. a -> b -> a
const (Word32 -> ActionT Except (ReaderT WebState m) Word32
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
d))
Int -> ActionT Except (ReaderT WebState m) Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
i :: Int)
get_offset :: ActionT Except (ReaderT WebState m) Int
get_offset = do
Word32
x <- ReaderT WebState m Word32
-> ActionT Except (ReaderT WebState m) Word32
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> Word32) -> ReaderT WebState m Word32
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (WebLimits -> Word32
maxLimitOffset (WebLimits -> Word32)
-> (WebState -> WebLimits) -> WebState -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> WebLimits
webMaxLimits (WebConfig -> WebLimits)
-> (WebState -> WebConfig) -> WebState -> WebLimits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig))
Word32
o <- Text -> ActionT Except (ReaderT WebState m) Word32
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "offset" ActionT Except (ReaderT WebState m) Word32
-> (Except -> ActionT Except (ReaderT WebState m) Word32)
-> ActionT Except (ReaderT WebState m) Word32
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT Except (ReaderT WebState m) Word32
-> Except -> ActionT Except (ReaderT WebState m) Word32
forall a b. a -> b -> a
const (Word32 -> ActionT Except (ReaderT WebState m) Word32
forall (m :: * -> *) a. Monad m => a -> m a
return 0)
Bool -> WebT m () -> WebT m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Word32
o Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
> Word32
x) (WebT m () -> WebT m ()) -> WebT m () -> WebT m ()
forall a b. (a -> b) -> a -> b
$
(WebMetrics -> StatDist) -> Except -> WebT m ()
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
multiaddrStat (Except -> WebT m ()) -> Except -> WebT m ()
forall a b. (a -> b) -> a -> b
$
String -> Except
UserError (String -> Except) -> String -> Except
forall a b. (a -> b) -> a -> b
$ "offset exceeded: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word32 -> String
forall a. Show a => a -> String
show Word32
o String -> ShowS
forall a. Semigroup a => a -> a -> a
<> " > " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word32 -> String
forall a. Show a => a -> String
show Word32
x
Int -> ActionT Except (ReaderT WebState m) Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
o :: Int)
subset :: HashSet a -> HashMap a v -> HashMap a v
subset ks :: HashSet a
ks =
(a -> v -> Bool) -> HashMap a v -> HashMap a v
forall k v. (k -> v -> Bool) -> HashMap k v -> HashMap k v
HashMap.filterWithKey (\k :: a
k _ -> a
k a -> HashSet a -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
`HashSet.member` HashSet a
ks)
compute_sxspecs :: HashSet k -> HashMap k a -> HashSet a
compute_sxspecs sxpubs :: HashSet k
sxpubs =
[a] -> HashSet a
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList ([a] -> HashSet a)
-> (HashMap k a -> [a]) -> HashMap k a -> HashSet a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap k a -> [a]
forall k v. HashMap k v -> [v]
HashMap.elems (HashMap k a -> [a])
-> (HashMap k a -> HashMap k a) -> HashMap k a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashSet k -> HashMap k a -> HashMap k a
forall a v.
(Eq a, Hashable a) =>
HashSet a -> HashMap a v -> HashMap a v
subset HashSet k
sxpubs
addr :: BinfoAddr -> Maybe Address
addr (BinfoAddr a :: Address
a) = Address -> Maybe Address
forall a. a -> Maybe a
Just Address
a
addr (BinfoXpub x :: XPubKey
x) = Maybe Address
forall a. Maybe a
Nothing
xpub :: BinfoAddr -> Maybe XPubKey
xpub (BinfoXpub x :: XPubKey
x) = XPubKey -> Maybe XPubKey
forall a. a -> Maybe a
Just XPubKey
x
xpub (BinfoAddr _) = Maybe XPubKey
forall a. Maybe a
Nothing
get_addrs :: ActionT
Except
(ReaderT WebState m)
(HashSet Address, HashSet XPubKey, HashSet Address,
HashSet XPubKey, HashMap XPubKey XPubSpec)
get_addrs = do
(xspecs :: HashMap XPubKey XPubSpec
xspecs, addrs :: HashSet Address
addrs) <- (WebMetrics -> StatDist)
-> WebT m (HashMap XPubKey XPubSpec, HashSet Address)
forall (m :: * -> *).
MonadIO m =>
(WebMetrics -> StatDist)
-> WebT m (HashMap XPubKey XPubSpec, HashSet Address)
getBinfoActive WebMetrics -> StatDist
multiaddrStat
HashSet BinfoAddr
sh <- (WebMetrics -> StatDist) -> Text -> WebT m (HashSet BinfoAddr)
forall (m :: * -> *).
MonadIO m =>
(WebMetrics -> StatDist) -> Text -> WebT m (HashSet BinfoAddr)
getBinfoAddrsParam WebMetrics -> StatDist
multiaddrStat "onlyShow"
let xpubs :: HashSet XPubKey
xpubs = HashMap XPubKey XPubSpec -> HashSet XPubKey
forall k a. HashMap k a -> HashSet k
HashMap.keysSet HashMap XPubKey XPubSpec
xspecs
actives :: HashSet BinfoAddr
actives = (Address -> BinfoAddr) -> HashSet Address -> HashSet BinfoAddr
forall b a.
(Hashable b, Eq b) =>
(a -> b) -> HashSet a -> HashSet b
HashSet.map Address -> BinfoAddr
BinfoAddr HashSet Address
addrs HashSet BinfoAddr -> HashSet BinfoAddr -> HashSet BinfoAddr
forall a. Semigroup a => a -> a -> a
<>
(XPubKey -> BinfoAddr) -> HashSet XPubKey -> HashSet BinfoAddr
forall b a.
(Hashable b, Eq b) =>
(a -> b) -> HashSet a -> HashSet b
HashSet.map XPubKey -> BinfoAddr
BinfoXpub HashSet XPubKey
xpubs
sh' :: HashSet BinfoAddr
sh' = if HashSet BinfoAddr -> Bool
forall a. HashSet a -> Bool
HashSet.null HashSet BinfoAddr
sh then HashSet BinfoAddr
actives else HashSet BinfoAddr
sh
saddrs :: HashSet Address
saddrs = [Address] -> HashSet Address
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList ([Address] -> HashSet Address)
-> ([BinfoAddr] -> [Address]) -> [BinfoAddr] -> HashSet Address
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BinfoAddr -> Maybe Address) -> [BinfoAddr] -> [Address]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe BinfoAddr -> Maybe Address
addr ([BinfoAddr] -> HashSet Address) -> [BinfoAddr] -> HashSet Address
forall a b. (a -> b) -> a -> b
$ HashSet BinfoAddr -> [BinfoAddr]
forall a. HashSet a -> [a]
HashSet.toList HashSet BinfoAddr
sh'
sxpubs :: HashSet XPubKey
sxpubs = [XPubKey] -> HashSet XPubKey
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList ([XPubKey] -> HashSet XPubKey)
-> ([BinfoAddr] -> [XPubKey]) -> [BinfoAddr] -> HashSet XPubKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BinfoAddr -> Maybe XPubKey) -> [BinfoAddr] -> [XPubKey]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe BinfoAddr -> Maybe XPubKey
xpub ([BinfoAddr] -> HashSet XPubKey) -> [BinfoAddr] -> HashSet XPubKey
forall a b. (a -> b) -> a -> b
$ HashSet BinfoAddr -> [BinfoAddr]
forall a. HashSet a -> [a]
HashSet.toList HashSet BinfoAddr
sh'
(HashSet Address, HashSet XPubKey, HashSet Address,
HashSet XPubKey, HashMap XPubKey XPubSpec)
-> ActionT
Except
(ReaderT WebState m)
(HashSet Address, HashSet XPubKey, HashSet Address,
HashSet XPubKey, HashMap XPubKey XPubSpec)
forall (m :: * -> *) a. Monad m => a -> m a
return (HashSet Address
addrs, HashSet XPubKey
xpubs, HashSet Address
saddrs, HashSet XPubKey
sxpubs, HashMap XPubKey XPubSpec
xspecs)
get_xbals :: HashMap XPubKey XPubSpec
-> ActionT Except (ReaderT WebState m) (HashMap XPubKey [XPubBal])
get_xbals =
let f :: XPubBal -> Bool
f = Bool -> Bool
not (Bool -> Bool) -> (XPubBal -> Bool) -> XPubBal -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Balance -> Bool
nullBalance (Balance -> Bool) -> (XPubBal -> Balance) -> XPubBal -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubBal -> Balance
xPubBal
g :: [(XPubKey, [XPubBal])] -> HashMap XPubKey [XPubBal]
g = [(XPubKey, [XPubBal])] -> HashMap XPubKey [XPubBal]
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(XPubKey, [XPubBal])] -> HashMap XPubKey [XPubBal])
-> ([(XPubKey, [XPubBal])] -> [(XPubKey, [XPubBal])])
-> [(XPubKey, [XPubBal])]
-> HashMap XPubKey [XPubBal]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((XPubKey, [XPubBal]) -> (XPubKey, [XPubBal]))
-> [(XPubKey, [XPubBal])] -> [(XPubKey, [XPubBal])]
forall a b. (a -> b) -> [a] -> [b]
map (([XPubBal] -> [XPubBal])
-> (XPubKey, [XPubBal]) -> (XPubKey, [XPubBal])
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ((XPubBal -> Bool) -> [XPubBal] -> [XPubBal]
forall a. (a -> Bool) -> [a] -> [a]
filter XPubBal -> Bool
f))
h :: (a, XPubSpec) -> f (a, [XPubBal])
h (k :: a
k, s :: XPubSpec
s) = (,) a
k ([XPubBal] -> (a, [XPubBal])) -> f [XPubBal] -> f (a, [XPubBal])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> XPubSpec -> f [XPubBal]
forall (m :: * -> *). StoreReadExtra m => XPubSpec -> m [XPubBal]
xPubBals XPubSpec
s
in ([(XPubKey, [XPubBal])] -> HashMap XPubKey [XPubBal])
-> ActionT Except (ReaderT WebState m) [(XPubKey, [XPubBal])]
-> ActionT Except (ReaderT WebState m) (HashMap XPubKey [XPubBal])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(XPubKey, [XPubBal])] -> HashMap XPubKey [XPubBal]
g (ActionT Except (ReaderT WebState m) [(XPubKey, [XPubBal])]
-> ActionT Except (ReaderT WebState m) (HashMap XPubKey [XPubBal]))
-> (HashMap XPubKey XPubSpec
-> ActionT Except (ReaderT WebState m) [(XPubKey, [XPubBal])])
-> HashMap XPubKey XPubSpec
-> ActionT Except (ReaderT WebState m) (HashMap XPubKey [XPubBal])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((XPubKey, XPubSpec)
-> ActionT Except (ReaderT WebState m) (XPubKey, [XPubBal]))
-> [(XPubKey, XPubSpec)]
-> ActionT Except (ReaderT WebState m) [(XPubKey, [XPubBal])]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (XPubKey, XPubSpec)
-> ActionT Except (ReaderT WebState m) (XPubKey, [XPubBal])
forall (f :: * -> *) a.
StoreReadExtra f =>
(a, XPubSpec) -> f (a, [XPubBal])
h ([(XPubKey, XPubSpec)]
-> ActionT Except (ReaderT WebState m) [(XPubKey, [XPubBal])])
-> (HashMap XPubKey XPubSpec -> [(XPubKey, XPubSpec)])
-> HashMap XPubKey XPubSpec
-> ActionT Except (ReaderT WebState m) [(XPubKey, [XPubBal])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap XPubKey XPubSpec -> [(XPubKey, XPubSpec)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList
get_abals :: HashSet Address
-> ActionT Except (ReaderT WebState m) (HashMap Address Balance)
get_abals =
let f :: Balance -> (Address, Balance)
f b :: Balance
b = (Balance -> Address
balanceAddress Balance
b, Balance
b)
g :: [Balance] -> HashMap Address Balance
g = [(Address, Balance)] -> HashMap Address Balance
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(Address, Balance)] -> HashMap Address Balance)
-> ([Balance] -> [(Address, Balance)])
-> [Balance]
-> HashMap Address Balance
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Balance -> (Address, Balance))
-> [Balance] -> [(Address, Balance)]
forall a b. (a -> b) -> [a] -> [b]
map Balance -> (Address, Balance)
f
in ([Balance] -> HashMap Address Balance)
-> ActionT Except (ReaderT WebState m) [Balance]
-> ActionT Except (ReaderT WebState m) (HashMap Address Balance)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Balance] -> HashMap Address Balance
g (ActionT Except (ReaderT WebState m) [Balance]
-> ActionT Except (ReaderT WebState m) (HashMap Address Balance))
-> (HashSet Address
-> ActionT Except (ReaderT WebState m) [Balance])
-> HashSet Address
-> ActionT Except (ReaderT WebState m) (HashMap Address Balance)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Address] -> ActionT Except (ReaderT WebState m) [Balance]
forall (m :: * -> *). StoreReadExtra m => [Address] -> m [Balance]
getBalances ([Address] -> ActionT Except (ReaderT WebState m) [Balance])
-> (HashSet Address -> [Address])
-> HashSet Address
-> ActionT Except (ReaderT WebState m) [Balance]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashSet Address -> [Address]
forall a. HashSet a -> [a]
HashSet.toList
addr_in_set :: HashSet Address -> Transaction -> Bool
addr_in_set s :: HashSet Address
s t :: Transaction
t =
let f :: StoreInput -> Bool
f StoreCoinbase{} = Bool
False
f StoreInput{inputAddress :: StoreInput -> Maybe Address
inputAddress = Maybe Address
Nothing} = Bool
False
f StoreInput{inputAddress :: StoreInput -> Maybe Address
inputAddress = Just a :: Address
a} = Address
a Address -> HashSet Address -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
`HashSet.member` HashSet Address
s
g :: StoreOutput -> Bool
g StoreOutput{outputAddr :: StoreOutput -> Maybe Address
outputAddr = Maybe Address
m} = case Maybe Address
m of
Nothing -> Bool
False
Just a :: Address
a -> Address
a Address -> HashSet Address -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
`HashSet.member` HashSet Address
s
i :: Bool
i = (StoreInput -> Bool) -> [StoreInput] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any StoreInput -> Bool
f (Transaction -> [StoreInput]
transactionInputs Transaction
t)
o :: Bool
o = (StoreOutput -> Bool) -> [StoreOutput] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any StoreOutput -> Bool
g (Transaction -> [StoreOutput]
transactionOutputs Transaction
t)
in Bool
i Bool -> Bool -> Bool
|| Bool
o
get_peers :: ActionT Except (ReaderT WebState m) Word32
get_peers = do
[PeerInformation]
ps <- ReaderT WebState m [PeerInformation]
-> ActionT Except (ReaderT WebState m) [PeerInformation]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [PeerInformation]
-> ActionT Except (ReaderT WebState m) [PeerInformation])
-> ReaderT WebState m [PeerInformation]
-> ActionT Except (ReaderT WebState m) [PeerInformation]
forall a b. (a -> b) -> a -> b
$ PeerManager -> ReaderT WebState m [PeerInformation]
forall (m :: * -> *).
MonadLoggerIO m =>
PeerManager -> m [PeerInformation]
getPeersInformation (PeerManager -> ReaderT WebState m [PeerInformation])
-> ReaderT WebState m PeerManager
-> ReaderT WebState m [PeerInformation]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
(WebState -> PeerManager) -> ReaderT WebState m PeerManager
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> PeerManager
storeManager (Store -> PeerManager)
-> (WebState -> Store) -> WebState -> PeerManager
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Word32 -> ActionT Except (ReaderT WebState m) Word32
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([PeerInformation] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [PeerInformation]
ps))
compute_txids :: Set TxRef -> [TxHash]
compute_txids = (TxRef -> TxHash) -> [TxRef] -> [TxHash]
forall a b. (a -> b) -> [a] -> [b]
map TxRef -> TxHash
txRefHash ([TxRef] -> [TxHash])
-> (Set TxRef -> [TxRef]) -> Set TxRef -> [TxHash]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set TxRef -> [TxRef]
forall a. Set a -> [a]
Set.toDescList
compute_etxids :: Bool -> HashMap Address a -> [Transaction] -> [TxHash]
compute_etxids prune :: Bool
prune abook :: HashMap Address a
abook =
let f :: Transaction -> HashSet TxHash
f = HashSet Address -> Bool -> Transaction -> HashSet TxHash
relevantTxs (HashMap Address a -> HashSet Address
forall k a. HashMap k a -> HashSet k
HashMap.keysSet HashMap Address a
abook) Bool
prune
in HashSet TxHash -> [TxHash]
forall a. HashSet a -> [a]
HashSet.toList (HashSet TxHash -> [TxHash])
-> ([Transaction] -> HashSet TxHash) -> [Transaction] -> [TxHash]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (HashSet TxHash -> HashSet TxHash -> HashSet TxHash)
-> HashSet TxHash -> [HashSet TxHash] -> HashSet TxHash
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl HashSet TxHash -> HashSet TxHash -> HashSet TxHash
forall a. (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a
HashSet.union HashSet TxHash
forall a. HashSet a
HashSet.empty ([HashSet TxHash] -> HashSet TxHash)
-> ([Transaction] -> [HashSet TxHash])
-> [Transaction]
-> HashSet TxHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Transaction -> HashSet TxHash)
-> [Transaction] -> [HashSet TxHash]
forall a b. (a -> b) -> [a] -> [b]
map Transaction -> HashSet TxHash
f
compute_xabals :: HashMap k [XPubBal] -> HashMap Address Balance
compute_xabals =
let f :: XPubBal -> (Address, Balance)
f b :: XPubBal
b = (Balance -> Address
balanceAddress (XPubBal -> Balance
xPubBal XPubBal
b), XPubBal -> Balance
xPubBal XPubBal
b)
in [(Address, Balance)] -> HashMap Address Balance
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(Address, Balance)] -> HashMap Address Balance)
-> (HashMap k [XPubBal] -> [(Address, Balance)])
-> HashMap k [XPubBal]
-> HashMap Address Balance
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([XPubBal] -> [(Address, Balance)])
-> [[XPubBal]] -> [(Address, Balance)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((XPubBal -> (Address, Balance))
-> [XPubBal] -> [(Address, Balance)]
forall a b. (a -> b) -> [a] -> [b]
map XPubBal -> (Address, Balance)
f) ([[XPubBal]] -> [(Address, Balance)])
-> (HashMap k [XPubBal] -> [[XPubBal]])
-> HashMap k [XPubBal]
-> [(Address, Balance)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap k [XPubBal] -> [[XPubBal]]
forall k v. HashMap k v -> [v]
HashMap.elems
compute_bal :: HashMap k Balance -> Word64
compute_bal =
let f :: Balance -> Word64
f b :: Balance
b = Balance -> Word64
balanceAmount Balance
b Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Balance -> Word64
balanceZero Balance
b
in [Word64] -> Word64
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Word64] -> Word64)
-> (HashMap k Balance -> [Word64]) -> HashMap k Balance -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Balance -> Word64) -> [Balance] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map Balance -> Word64
f ([Balance] -> [Word64])
-> (HashMap k Balance -> [Balance])
-> HashMap k Balance
-> [Word64]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap k Balance -> [Balance]
forall k v. HashMap k v -> [v]
HashMap.elems
compute_abook :: HashSet Address
-> HashMap XPubKey [XPubBal]
-> HashMap Address (Maybe BinfoXPubPath)
compute_abook addrs :: HashSet Address
addrs xbals :: HashMap XPubKey [XPubBal]
xbals =
let f :: XPubKey -> XPubBal -> (Address, Maybe BinfoXPubPath)
f k :: XPubKey
k XPubBal{..} =
let a :: Address
a = Balance -> Address
balanceAddress Balance
xPubBal
e :: a
e = String -> a
forall a. HasCallStack => String -> a
error "lions and tigers and bears"
s :: Maybe SoftPath
s = DerivPathI AnyDeriv -> Maybe SoftPath
forall t. DerivPathI t -> Maybe SoftPath
toSoft ([Word32] -> DerivPathI AnyDeriv
listToPath [Word32]
xPubBalPath)
m :: SoftPath
m = SoftPath -> Maybe SoftPath -> SoftPath
forall a. a -> Maybe a -> a
fromMaybe SoftPath
forall a. a
e Maybe SoftPath
s
in (Address
a, BinfoXPubPath -> Maybe BinfoXPubPath
forall a. a -> Maybe a
Just (XPubKey -> SoftPath -> BinfoXPubPath
BinfoXPubPath XPubKey
k SoftPath
m))
g :: XPubKey -> [XPubBal] -> [(Address, Maybe BinfoXPubPath)]
g k :: XPubKey
k = (XPubBal -> (Address, Maybe BinfoXPubPath))
-> [XPubBal] -> [(Address, Maybe BinfoXPubPath)]
forall a b. (a -> b) -> [a] -> [b]
map (XPubKey -> XPubBal -> (Address, Maybe BinfoXPubPath)
f XPubKey
k)
amap :: HashMap Address (Maybe a)
amap = (() -> Maybe a) -> HashMap Address () -> HashMap Address (Maybe a)
forall v1 v2 k. (v1 -> v2) -> HashMap k v1 -> HashMap k v2
HashMap.map (Maybe a -> () -> Maybe a
forall a b. a -> b -> a
const Maybe a
forall a. Maybe a
Nothing) (HashMap Address () -> HashMap Address (Maybe a))
-> HashMap Address () -> HashMap Address (Maybe a)
forall a b. (a -> b) -> a -> b
$
HashSet Address -> HashMap Address ()
forall a. HashSet a -> HashMap a ()
HashSet.toMap HashSet Address
addrs
xmap :: HashMap Address (Maybe BinfoXPubPath)
xmap = [(Address, Maybe BinfoXPubPath)]
-> HashMap Address (Maybe BinfoXPubPath)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(Address, Maybe BinfoXPubPath)]
-> HashMap Address (Maybe BinfoXPubPath))
-> ([(XPubKey, [XPubBal])] -> [(Address, Maybe BinfoXPubPath)])
-> [(XPubKey, [XPubBal])]
-> HashMap Address (Maybe BinfoXPubPath)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
((XPubKey, [XPubBal]) -> [(Address, Maybe BinfoXPubPath)])
-> [(XPubKey, [XPubBal])] -> [(Address, Maybe BinfoXPubPath)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((XPubKey -> [XPubBal] -> [(Address, Maybe BinfoXPubPath)])
-> (XPubKey, [XPubBal]) -> [(Address, Maybe BinfoXPubPath)]
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry XPubKey -> [XPubBal] -> [(Address, Maybe BinfoXPubPath)]
g) ([(XPubKey, [XPubBal])] -> HashMap Address (Maybe BinfoXPubPath))
-> [(XPubKey, [XPubBal])] -> HashMap Address (Maybe BinfoXPubPath)
forall a b. (a -> b) -> a -> b
$
HashMap XPubKey [XPubBal] -> [(XPubKey, [XPubBal])]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList HashMap XPubKey [XPubBal]
xbals
in HashMap Address (Maybe BinfoXPubPath)
forall a. HashMap Address (Maybe a)
amap HashMap Address (Maybe BinfoXPubPath)
-> HashMap Address (Maybe BinfoXPubPath)
-> HashMap Address (Maybe BinfoXPubPath)
forall a. Semigroup a => a -> a -> a
<> HashMap Address (Maybe BinfoXPubPath)
xmap
compute_xaddrs :: HashMap k [XPubBal] -> HashSet Address
compute_xaddrs =
let f :: [XPubBal] -> [Address]
f = (XPubBal -> Address) -> [XPubBal] -> [Address]
forall a b. (a -> b) -> [a] -> [b]
map (Balance -> Address
balanceAddress (Balance -> Address) -> (XPubBal -> Balance) -> XPubBal -> Address
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPubBal -> Balance
xPubBal)
in [Address] -> HashSet Address
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList ([Address] -> HashSet Address)
-> (HashMap k [XPubBal] -> [Address])
-> HashMap k [XPubBal]
-> HashSet Address
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([XPubBal] -> [Address]) -> [[XPubBal]] -> [Address]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap [XPubBal] -> [Address]
f ([[XPubBal]] -> [Address])
-> (HashMap k [XPubBal] -> [[XPubBal]])
-> HashMap k [XPubBal]
-> [Address]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap k [XPubBal] -> [[XPubBal]]
forall k v. HashMap k v -> [v]
HashMap.elems
sent :: BinfoTx -> p
sent BinfoTx{getBinfoTxResultBal :: BinfoTx -> Maybe (Int64, Int64)
getBinfoTxResultBal = Just (r :: Int64
r, _)}
| Int64
r Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = Int64 -> p
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Int64
forall a. Num a => a -> a
negate Int64
r)
| Bool
otherwise = 0
sent _ = 0
received :: BinfoTx -> p
received BinfoTx{getBinfoTxResultBal :: BinfoTx -> Maybe (Int64, Int64)
getBinfoTxResultBal = Just (r :: Int64
r, _)}
| Int64
r Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = Int64 -> p
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
r
| Bool
otherwise = 0
received _ = 0
scottyRawAddr :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()
scottyRawAddr :: WebT m ()
scottyRawAddr =
ActionT Except (ReaderT WebState m) Address
get_addr ActionT Except (ReaderT WebState m) Address
-> (Address -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \addr :: Address
addr ->
WebT m Bool
forall (m :: * -> *). MonadIO m => WebT m Bool
getNumTxId WebT m Bool -> (Bool -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \numtxid :: Bool
numtxid ->
ActionT Except (ReaderT WebState m) Int
get_offset ActionT Except (ReaderT WebState m) Int
-> (Int -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \off :: Int
off ->
ActionT Except (ReaderT WebState m) Int
get_count ActionT Except (ReaderT WebState m) Int
-> (Int -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \n :: Int
n -> do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
rawaddrStat 1
Balance
bal <- Balance -> Maybe Balance -> Balance
forall a. a -> Maybe a -> a
fromMaybe (Address -> Balance
zeroBalance Address
addr) (Maybe Balance -> Balance)
-> ActionT Except (ReaderT WebState m) (Maybe Balance)
-> ActionT Except (ReaderT WebState m) Balance
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Address -> ActionT Except (ReaderT WebState m) (Maybe Balance)
forall (m :: * -> *).
StoreReadBase m =>
Address -> m (Maybe Balance)
getBalance Address
addr
Network
net <- ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network)
-> ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall a b. (a -> b) -> a -> b
$ (WebState -> Network) -> ReaderT WebState m Network
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Network
storeNetwork (Store -> Network) -> (WebState -> Store) -> WebState -> Network
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
let abook :: HashMap Address (Maybe a)
abook = Address -> Maybe a -> HashMap Address (Maybe a)
forall k v. Hashable k => k -> v -> HashMap k v
HashMap.singleton Address
addr Maybe a
forall a. Maybe a
Nothing
xspecs :: HashSet a
xspecs = HashSet a
forall a. HashSet a
HashSet.empty
saddrs :: HashSet Address
saddrs = Address -> HashSet Address
forall a. Hashable a => a -> HashSet a
HashSet.singleton Address
addr
bfilter :: BinfoFilter
bfilter = BinfoFilter
BinfoFilterAll
b :: Int64
b = Word64 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Int64) -> Word64 -> Int64
forall a b. (a -> b) -> a -> b
$ Balance -> Word64
balanceAmount Balance
bal Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Balance -> Word64
balanceZero Balance
bal
[BinfoTx]
txs <- ReaderT WebState m [BinfoTx]
-> ActionT Except (ReaderT WebState m) [BinfoTx]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [BinfoTx]
-> ActionT Except (ReaderT WebState m) [BinfoTx])
-> (ConduitT () Void (ReaderT WebState m) [BinfoTx]
-> ReaderT WebState m [BinfoTx])
-> ConduitT () Void (ReaderT WebState m) [BinfoTx]
-> ActionT Except (ReaderT WebState m) [BinfoTx]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConduitT () Void (ReaderT WebState m) [BinfoTx]
-> ReaderT WebState m [BinfoTx]
forall (m :: * -> *) r. Monad m => ConduitT () Void m r -> m r
runConduit (ConduitT () Void (ReaderT WebState m) [BinfoTx]
-> ActionT Except (ReaderT WebState m) [BinfoTx])
-> ConduitT () Void (ReaderT WebState m) [BinfoTx]
-> ActionT Except (ReaderT WebState m) [BinfoTx]
forall a b. (a -> b) -> a -> b
$
HashMap Address (Maybe BinfoXPubPath)
-> HashSet XPubSpec
-> HashSet Address
-> HashSet Address
-> BinfoFilter
-> Bool
-> Bool
-> Int64
-> ConduitT () BinfoTx (ReaderT WebState m) ()
forall (m :: * -> *).
(StoreReadExtra m, MonadIO m) =>
HashMap Address (Maybe BinfoXPubPath)
-> HashSet XPubSpec
-> HashSet Address
-> HashSet Address
-> BinfoFilter
-> Bool
-> Bool
-> Int64
-> ConduitT () BinfoTx m ()
getBinfoTxs HashMap Address (Maybe BinfoXPubPath)
forall a. HashMap Address (Maybe a)
abook HashSet XPubSpec
forall a. HashSet a
xspecs HashSet Address
saddrs HashSet Address
saddrs BinfoFilter
bfilter Bool
numtxid Bool
False Int64
b ConduitT () BinfoTx (ReaderT WebState m) ()
-> ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
-> ConduitT () Void (ReaderT WebState m) [BinfoTx]
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.|
(Int -> ConduitT BinfoTx Void (ReaderT WebState m) ()
forall (m :: * -> *) a o. Monad m => Int -> ConduitT a o m ()
dropC Int
off ConduitT BinfoTx Void (ReaderT WebState m) ()
-> ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
-> ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> ConduitT BinfoTx BinfoTx (ReaderT WebState m) ()
forall (m :: * -> *) a. Monad m => Int -> ConduitT a a m ()
takeC Int
n ConduitT BinfoTx BinfoTx (ReaderT WebState m) ()
-> ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
-> ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.| ConduitM BinfoTx Void (ReaderT WebState m) [BinfoTx]
forall (m :: * -> *) a o. Monad m => ConduitT a o m [a]
sinkList)
WebT m ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
Encoding -> WebT m ()
forall (m :: * -> *). Monad m => Encoding -> WebT m ()
streamEncoding (Encoding -> WebT m ()) -> Encoding -> WebT m ()
forall a b. (a -> b) -> a -> b
$ Network -> BinfoRawAddr -> Encoding
binfoRawAddrToEncoding Network
net (BinfoRawAddr -> Encoding) -> BinfoRawAddr -> Encoding
forall a b. (a -> b) -> a -> b
$ Balance -> [BinfoTx] -> BinfoRawAddr
BinfoRawAddr Balance
bal [BinfoTx]
txs
where
get_addr :: ActionT Except (ReaderT WebState m) Address
get_addr = do
Text
txt <- Text -> ActionT Except (ReaderT WebState m) Text
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "addr"
Network
net <- ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network)
-> ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall a b. (a -> b) -> a -> b
$ (WebState -> Network) -> ReaderT WebState m Network
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Network
storeNetwork (Store -> Network) -> (WebState -> Store) -> WebState -> Network
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
case Network -> Text -> Maybe Address
textToAddr Network
net Text
txt of
Nothing -> (WebMetrics -> StatDist)
-> Except -> ActionT Except (ReaderT WebState m) Address
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
rawaddrStat Except
ThingNotFound
Just a :: Address
a -> Address -> ActionT Except (ReaderT WebState m) Address
forall (m :: * -> *) a. Monad m => a -> m a
return Address
a
get_count :: ActionT Except (ReaderT WebState m) Int
get_count = do
Word32
d <- ReaderT WebState m Word32
-> ActionT Except (ReaderT WebState m) Word32
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> Word32) -> ReaderT WebState m Word32
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (WebLimits -> Word32
maxLimitDefault (WebLimits -> Word32)
-> (WebState -> WebLimits) -> WebState -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> WebLimits
webMaxLimits (WebConfig -> WebLimits)
-> (WebState -> WebConfig) -> WebState -> WebLimits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig))
Word32
x <- ReaderT WebState m Word32
-> ActionT Except (ReaderT WebState m) Word32
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> Word32) -> ReaderT WebState m Word32
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (WebLimits -> Word32
maxLimitFull (WebLimits -> Word32)
-> (WebState -> WebLimits) -> WebState -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> WebLimits
webMaxLimits (WebConfig -> WebLimits)
-> (WebState -> WebConfig) -> WebState -> WebLimits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig))
Word32
i <- Word32 -> Word32 -> Word32
forall a. Ord a => a -> a -> a
min Word32
x (Word32 -> Word32)
-> ActionT Except (ReaderT WebState m) Word32
-> ActionT Except (ReaderT WebState m) Word32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> ActionT Except (ReaderT WebState m) Word32
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "n" ActionT Except (ReaderT WebState m) Word32
-> (Except -> ActionT Except (ReaderT WebState m) Word32)
-> ActionT Except (ReaderT WebState m) Word32
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT Except (ReaderT WebState m) Word32
-> Except -> ActionT Except (ReaderT WebState m) Word32
forall a b. a -> b -> a
const (Word32 -> ActionT Except (ReaderT WebState m) Word32
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
d))
Int -> ActionT Except (ReaderT WebState m) Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> ActionT Except (ReaderT WebState m) Int)
-> Int -> ActionT Except (ReaderT WebState m) Int
forall a b. (a -> b) -> a -> b
$ Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
i
get_offset :: ActionT Except (ReaderT WebState m) Int
get_offset = do
Word32
x <- ReaderT WebState m Word32
-> ActionT Except (ReaderT WebState m) Word32
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((WebState -> Word32) -> ReaderT WebState m Word32
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (WebLimits -> Word32
maxLimitOffset (WebLimits -> Word32)
-> (WebState -> WebLimits) -> WebState -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> WebLimits
webMaxLimits (WebConfig -> WebLimits)
-> (WebState -> WebConfig) -> WebState -> WebLimits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig))
Word32
o <- Text -> ActionT Except (ReaderT WebState m) Word32
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "offset" ActionT Except (ReaderT WebState m) Word32
-> (Except -> ActionT Except (ReaderT WebState m) Word32)
-> ActionT Except (ReaderT WebState m) Word32
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT Except (ReaderT WebState m) Word32
-> Except -> ActionT Except (ReaderT WebState m) Word32
forall a b. a -> b -> a
const (Word32 -> ActionT Except (ReaderT WebState m) Word32
forall (m :: * -> *) a. Monad m => a -> m a
return 0)
Bool -> WebT m () -> WebT m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Word32
o Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
> Word32
x) (WebT m () -> WebT m ()) -> WebT m () -> WebT m ()
forall a b. (a -> b) -> a -> b
$
(WebMetrics -> StatDist) -> Except -> WebT m ()
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
rawaddrStat (Except -> WebT m ()) -> Except -> WebT m ()
forall a b. (a -> b) -> a -> b
$
String -> Except
UserError (String -> Except) -> String -> Except
forall a b. (a -> b) -> a -> b
$ "offset exceeded: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word32 -> String
forall a. Show a => a -> String
show Word32
o String -> ShowS
forall a. Semigroup a => a -> a -> a
<> " > " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word32 -> String
forall a. Show a => a -> String
show Word32
x
Int -> ActionT Except (ReaderT WebState m) Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> ActionT Except (ReaderT WebState m) Int)
-> Int -> ActionT Except (ReaderT WebState m) Int
forall a b. (a -> b) -> a -> b
$ Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
o
scottyShortBal :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()
scottyShortBal :: WebT m ()
scottyShortBal =
(WebMetrics -> StatDist)
-> WebT m (HashMap XPubKey XPubSpec, HashSet Address)
forall (m :: * -> *).
MonadIO m =>
(WebMetrics -> StatDist)
-> WebT m (HashMap XPubKey XPubSpec, HashSet Address)
getBinfoActive WebMetrics -> StatDist
balanceStat WebT m (HashMap XPubKey XPubSpec, HashSet Address)
-> ((HashMap XPubKey XPubSpec, HashSet Address) -> WebT m ())
-> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(xspecs :: HashMap XPubKey XPubSpec
xspecs, addrs :: HashSet Address
addrs) ->
WebT m Bool
forall (m :: * -> *). MonadIO m => WebT m Bool
getNumTxId WebT m Bool -> (Bool -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \numtxid :: Bool
numtxid -> do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
balanceStat (HashSet Address -> Int
forall a. HashSet a -> Int
hl HashSet Address
addrs Int -> Int -> Int
forall a. Num a => a -> a -> a
+ HashMap XPubKey XPubSpec -> Int
forall k v. HashMap k v -> Int
ml HashMap XPubKey XPubSpec
xspecs)
Network
net <- ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network)
-> ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall a b. (a -> b) -> a -> b
$ (WebState -> Network) -> ReaderT WebState m Network
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Network
storeNetwork (Store -> Network) -> (WebState -> Store) -> WebState -> Network
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
[(Text, BinfoShortBal)]
abals <- [Maybe (Text, BinfoShortBal)] -> [(Text, BinfoShortBal)]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe (Text, BinfoShortBal)] -> [(Text, BinfoShortBal)])
-> ActionT
Except (ReaderT WebState m) [Maybe (Text, BinfoShortBal)]
-> ActionT Except (ReaderT WebState m) [(Text, BinfoShortBal)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Address
-> ActionT
Except (ReaderT WebState m) (Maybe (Text, BinfoShortBal)))
-> [Address]
-> ActionT
Except (ReaderT WebState m) [Maybe (Text, BinfoShortBal)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Network
-> Address
-> ActionT
Except (ReaderT WebState m) (Maybe (Text, BinfoShortBal))
forall (m :: * -> *).
StoreReadBase m =>
Network -> Address -> m (Maybe (Text, BinfoShortBal))
get_addr_balance Network
net) (HashSet Address -> [Address]
forall a. HashSet a -> [a]
HashSet.toList HashSet Address
addrs)
[(Text, BinfoShortBal)]
xbals <- (XPubSpec
-> ActionT Except (ReaderT WebState m) (Text, BinfoShortBal))
-> [XPubSpec]
-> ActionT Except (ReaderT WebState m) [(Text, BinfoShortBal)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Network
-> XPubSpec
-> ActionT Except (ReaderT WebState m) (Text, BinfoShortBal)
forall (m :: * -> *).
StoreReadExtra m =>
Network -> XPubSpec -> m (Text, BinfoShortBal)
get_xspec_balance Network
net) (HashMap XPubKey XPubSpec -> [XPubSpec]
forall k v. HashMap k v -> [v]
HashMap.elems HashMap XPubKey XPubSpec
xspecs)
let res :: HashMap Text BinfoShortBal
res = [(Text, BinfoShortBal)] -> HashMap Text BinfoShortBal
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(Text, BinfoShortBal)]
abals [(Text, BinfoShortBal)]
-> [(Text, BinfoShortBal)] -> [(Text, BinfoShortBal)]
forall a. Semigroup a => a -> a -> a
<> [(Text, BinfoShortBal)]
xbals)
WebT m ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
Encoding -> WebT m ()
forall (m :: * -> *). Monad m => Encoding -> WebT m ()
streamEncoding (Encoding -> WebT m ()) -> Encoding -> WebT m ()
forall a b. (a -> b) -> a -> b
$ HashMap Text BinfoShortBal -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding HashMap Text BinfoShortBal
res
where
hl :: HashSet a -> Int
hl = HashSet a -> Int
forall a. HashSet a -> Int
HashSet.size
ml :: HashMap k v -> Int
ml = HashMap k v -> Int
forall k v. HashMap k v -> Int
HashMap.size
to_short_bal :: Balance -> BinfoShortBal
to_short_bal Balance{..} =
$WBinfoShortBal :: Word64 -> Word64 -> Word64 -> BinfoShortBal
BinfoShortBal
{
binfoShortBalFinal :: Word64
binfoShortBalFinal = Word64
balanceAmount Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
balanceZero,
binfoShortBalTxCount :: Word64
binfoShortBalTxCount = Word64
balanceTxCount,
binfoShortBalReceived :: Word64
binfoShortBalReceived = Word64
balanceTotalReceived
}
get_addr_balance :: Network -> Address -> m (Maybe (Text, BinfoShortBal))
get_addr_balance net :: Network
net a :: Address
a =
case Network -> Address -> Maybe Text
addrToText Network
net Address
a of
Nothing -> Maybe (Text, BinfoShortBal) -> m (Maybe (Text, BinfoShortBal))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Text, BinfoShortBal)
forall a. Maybe a
Nothing
Just a' :: Text
a' -> Address -> m (Maybe Balance)
forall (m :: * -> *).
StoreReadBase m =>
Address -> m (Maybe Balance)
getBalance Address
a m (Maybe Balance)
-> (Maybe Balance -> m (Maybe (Text, BinfoShortBal)))
-> m (Maybe (Text, BinfoShortBal))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> Maybe (Text, BinfoShortBal) -> m (Maybe (Text, BinfoShortBal))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Text, BinfoShortBal) -> m (Maybe (Text, BinfoShortBal)))
-> Maybe (Text, BinfoShortBal) -> m (Maybe (Text, BinfoShortBal))
forall a b. (a -> b) -> a -> b
$ (Text, BinfoShortBal) -> Maybe (Text, BinfoShortBal)
forall a. a -> Maybe a
Just (Text
a', Balance -> BinfoShortBal
to_short_bal (Address -> Balance
zeroBalance Address
a))
Just b :: Balance
b -> Maybe (Text, BinfoShortBal) -> m (Maybe (Text, BinfoShortBal))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Text, BinfoShortBal) -> m (Maybe (Text, BinfoShortBal)))
-> Maybe (Text, BinfoShortBal) -> m (Maybe (Text, BinfoShortBal))
forall a b. (a -> b) -> a -> b
$ (Text, BinfoShortBal) -> Maybe (Text, BinfoShortBal)
forall a. a -> Maybe a
Just (Text
a', Balance -> BinfoShortBal
to_short_bal Balance
b)
is_ext :: XPubBal -> Bool
is_ext XPubBal{xPubBalPath :: XPubBal -> [Word32]
xPubBalPath = 0:_} = Bool
True
is_ext _ = Bool
False
get_xspec_balance :: Network -> XPubSpec -> m (Text, BinfoShortBal)
get_xspec_balance net :: Network
net xpub :: XPubSpec
xpub = do
[XPubBal]
xbals <- XPubSpec -> m [XPubBal]
forall (m :: * -> *). StoreReadExtra m => XPubSpec -> m [XPubBal]
xPubBals XPubSpec
xpub
Word32
xts <- XPubSpec -> [XPubBal] -> m Word32
forall (m :: * -> *).
StoreReadExtra m =>
XPubSpec -> [XPubBal] -> m Word32
xPubTxCount XPubSpec
xpub [XPubBal]
xbals
let val :: Word64
val = [Word64] -> Word64
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Word64] -> Word64) -> [Word64] -> Word64
forall a b. (a -> b) -> a -> b
$ (Balance -> Word64) -> [Balance] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map Balance -> Word64
balanceAmount ([Balance] -> [Word64]) -> [Balance] -> [Word64]
forall a b. (a -> b) -> a -> b
$ (XPubBal -> Balance) -> [XPubBal] -> [Balance]
forall a b. (a -> b) -> [a] -> [b]
map XPubBal -> Balance
xPubBal [XPubBal]
xbals
zro :: Word64
zro = [Word64] -> Word64
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Word64] -> Word64) -> [Word64] -> Word64
forall a b. (a -> b) -> a -> b
$ (Balance -> Word64) -> [Balance] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map Balance -> Word64
balanceZero ([Balance] -> [Word64]) -> [Balance] -> [Word64]
forall a b. (a -> b) -> a -> b
$ (XPubBal -> Balance) -> [XPubBal] -> [Balance]
forall a b. (a -> b) -> [a] -> [b]
map XPubBal -> Balance
xPubBal [XPubBal]
xbals
exs :: [XPubBal]
exs = (XPubBal -> Bool) -> [XPubBal] -> [XPubBal]
forall a. (a -> Bool) -> [a] -> [a]
filter XPubBal -> Bool
is_ext [XPubBal]
xbals
rcv :: Word64
rcv = [Word64] -> Word64
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Word64] -> Word64) -> [Word64] -> Word64
forall a b. (a -> b) -> a -> b
$ (Balance -> Word64) -> [Balance] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map Balance -> Word64
balanceTotalReceived ([Balance] -> [Word64]) -> [Balance] -> [Word64]
forall a b. (a -> b) -> a -> b
$ (XPubBal -> Balance) -> [XPubBal] -> [Balance]
forall a b. (a -> b) -> [a] -> [b]
map XPubBal -> Balance
xPubBal [XPubBal]
exs
sbl :: BinfoShortBal
sbl =
$WBinfoShortBal :: Word64 -> Word64 -> Word64 -> BinfoShortBal
BinfoShortBal
{
binfoShortBalFinal :: Word64
binfoShortBalFinal = Word64
val Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
zro,
binfoShortBalTxCount :: Word64
binfoShortBalTxCount = Word32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
xts,
binfoShortBalReceived :: Word64
binfoShortBalReceived = Word64
rcv
}
(Text, BinfoShortBal) -> m (Text, BinfoShortBal)
forall (m :: * -> *) a. Monad m => a -> m a
return (Network -> XPubKey -> Text
xPubExport Network
net (XPubSpec -> XPubKey
xPubSpecKey XPubSpec
xpub), BinfoShortBal
sbl)
getBinfoHex :: Monad m => WebT m Bool
getBinfoHex :: WebT m Bool
getBinfoHex =
(Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== ("hex" :: Text)) (Text -> Bool)
-> ActionT Except (ReaderT WebState m) Text -> WebT m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Text -> ActionT Except (ReaderT WebState m) Text
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "format" ActionT Except (ReaderT WebState m) Text
-> (Except -> ActionT Except (ReaderT WebState m) Text)
-> ActionT Except (ReaderT WebState m) Text
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT Except (ReaderT WebState m) Text
-> Except -> ActionT Except (ReaderT WebState m) Text
forall a b. a -> b -> a
const (Text -> ActionT Except (ReaderT WebState m) Text
forall (m :: * -> *) a. Monad m => a -> m a
return "json")
scottyBinfoBlockHeight :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()
scottyBinfoBlockHeight :: WebT m ()
scottyBinfoBlockHeight =
WebT m Bool
forall (m :: * -> *). MonadIO m => WebT m Bool
getNumTxId WebT m Bool -> (Bool -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \numtxid :: Bool
numtxid ->
Text -> ActionT Except (ReaderT WebState m) Word32
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "height" ActionT Except (ReaderT WebState m) Word32
-> (Word32 -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \height :: Word32
height ->
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
rawBlockStat 1 WebT m ()
-> ActionT Except (ReaderT WebState m) [BlockHash]
-> ActionT Except (ReaderT WebState m) [BlockHash]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Word32 -> ActionT Except (ReaderT WebState m) [BlockHash]
forall (m :: * -> *). StoreReadBase m => Word32 -> m [BlockHash]
getBlocksAtHeight Word32
height ActionT Except (ReaderT WebState m) [BlockHash]
-> ([BlockHash] -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \block_hashes :: [BlockHash]
block_hashes -> do
[BlockData]
block_headers <- [Maybe BlockData] -> [BlockData]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe BlockData] -> [BlockData])
-> ActionT Except (ReaderT WebState m) [Maybe BlockData]
-> ActionT Except (ReaderT WebState m) [BlockData]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (BlockHash
-> ActionT Except (ReaderT WebState m) (Maybe BlockData))
-> [BlockHash]
-> ActionT Except (ReaderT WebState m) [Maybe BlockData]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM BlockHash -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock [BlockHash]
block_hashes
[BlockHash]
next_block_hashes <- Word32 -> ActionT Except (ReaderT WebState m) [BlockHash]
forall (m :: * -> *). StoreReadBase m => Word32 -> m [BlockHash]
getBlocksAtHeight (Word32
height Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ 1)
[BlockData]
next_block_headers <- [Maybe BlockData] -> [BlockData]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe BlockData] -> [BlockData])
-> ActionT Except (ReaderT WebState m) [Maybe BlockData]
-> ActionT Except (ReaderT WebState m) [BlockData]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (BlockHash
-> ActionT Except (ReaderT WebState m) (Maybe BlockData))
-> [BlockHash]
-> ActionT Except (ReaderT WebState m) [Maybe BlockData]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM BlockHash -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock [BlockHash]
next_block_hashes
[BinfoBlock]
binfo_blocks <-
(BlockData -> ActionT Except (ReaderT WebState m) BinfoBlock)
-> [BlockData] -> ActionT Except (ReaderT WebState m) [BinfoBlock]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Bool
-> [BlockData]
-> BlockData
-> ActionT Except (ReaderT WebState m) BinfoBlock
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(MonadTrans t, Monad (t m), MonadUnliftIO m, StoreReadBase m) =>
Bool -> [BlockData] -> BlockData -> t m BinfoBlock
get_binfo_blocks Bool
numtxid [BlockData]
next_block_headers) [BlockData]
block_headers
WebT m ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
Network
net <- ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network)
-> ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall a b. (a -> b) -> a -> b
$ (WebState -> Network) -> ReaderT WebState m Network
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Network
storeNetwork (Store -> Network) -> (WebState -> Store) -> WebState -> Network
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Encoding -> WebT m ()
forall (m :: * -> *). Monad m => Encoding -> WebT m ()
streamEncoding (Encoding -> WebT m ()) -> Encoding -> WebT m ()
forall a b. (a -> b) -> a -> b
$ Network -> [BinfoBlock] -> Encoding
binfoBlocksToEncoding Network
net [BinfoBlock]
binfo_blocks
where
get_tx :: TxHash -> m Transaction
get_tx th :: TxHash
th =
((forall a. m a -> IO a) -> IO Transaction) -> m Transaction
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (((forall a. m a -> IO a) -> IO Transaction) -> m Transaction)
-> ((forall a. m a -> IO a) -> IO Transaction) -> m Transaction
forall a b. (a -> b) -> a -> b
$ \run :: forall a. m a -> IO a
run ->
IO Transaction -> IO Transaction
forall a. IO a -> IO a
unsafeInterleaveIO (IO Transaction -> IO Transaction)
-> IO Transaction -> IO Transaction
forall a b. (a -> b) -> a -> b
$
m Transaction -> IO Transaction
forall a. m a -> IO a
run (m Transaction -> IO Transaction)
-> m Transaction -> IO Transaction
forall a b. (a -> b) -> a -> b
$ Maybe Transaction -> Transaction
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Transaction -> Transaction)
-> m (Maybe Transaction) -> m Transaction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TxHash -> m (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction TxHash
th
get_binfo_blocks :: Bool -> [BlockData] -> BlockData -> t m BinfoBlock
get_binfo_blocks numtxid :: Bool
numtxid next_block_headers :: [BlockData]
next_block_headers block_header :: BlockData
block_header = do
let my_hash :: BlockHash
my_hash = BlockHeader -> BlockHash
H.headerHash (BlockData -> BlockHeader
blockDataHeader BlockData
block_header)
get_prev :: BlockData -> BlockHash
get_prev = BlockHeader -> BlockHash
H.prevBlock (BlockHeader -> BlockHash)
-> (BlockData -> BlockHeader) -> BlockData -> BlockHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockData -> BlockHeader
blockDataHeader
get_hash :: BlockData -> BlockHash
get_hash = BlockHeader -> BlockHash
H.headerHash (BlockHeader -> BlockHash)
-> (BlockData -> BlockHeader) -> BlockData -> BlockHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockData -> BlockHeader
blockDataHeader
[Transaction]
txs <- m [Transaction] -> t m [Transaction]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m [Transaction] -> t m [Transaction])
-> m [Transaction] -> t m [Transaction]
forall a b. (a -> b) -> a -> b
$ (TxHash -> m Transaction) -> [TxHash] -> m [Transaction]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TxHash -> m Transaction
forall (m :: * -> *).
(MonadUnliftIO m, StoreReadBase m) =>
TxHash -> m Transaction
get_tx (BlockData -> [TxHash]
blockDataTxs BlockData
block_header)
let next_blocks :: [BlockHash]
next_blocks = (BlockData -> BlockHash) -> [BlockData] -> [BlockHash]
forall a b. (a -> b) -> [a] -> [b]
map BlockData -> BlockHash
get_hash ([BlockData] -> [BlockHash]) -> [BlockData] -> [BlockHash]
forall a b. (a -> b) -> a -> b
$
(BlockData -> Bool) -> [BlockData] -> [BlockData]
forall a. (a -> Bool) -> [a] -> [a]
filter ((BlockHash -> BlockHash -> Bool
forall a. Eq a => a -> a -> Bool
== BlockHash
my_hash) (BlockHash -> Bool)
-> (BlockData -> BlockHash) -> BlockData -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockData -> BlockHash
get_prev)
[BlockData]
next_block_headers
let binfo_txs :: [BinfoTx]
binfo_txs = (Transaction -> BinfoTx) -> [Transaction] -> [BinfoTx]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> Transaction -> BinfoTx
toBinfoTxSimple Bool
numtxid) [Transaction]
txs
binfo_block :: BinfoBlock
binfo_block = BlockData -> [BinfoTx] -> [BlockHash] -> BinfoBlock
toBinfoBlock BlockData
block_header [BinfoTx]
binfo_txs [BlockHash]
next_blocks
BinfoBlock -> t m BinfoBlock
forall (m :: * -> *) a. Monad m => a -> m a
return BinfoBlock
binfo_block
scottyBinfoBlock :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()
scottyBinfoBlock :: WebT m ()
scottyBinfoBlock =
WebT m Bool
forall (m :: * -> *). MonadIO m => WebT m Bool
getNumTxId WebT m Bool -> (Bool -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \numtxid :: Bool
numtxid ->
WebT m Bool
forall (m :: * -> *). Monad m => WebT m Bool
getBinfoHex WebT m Bool -> (Bool -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \hex :: Bool
hex ->
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
rawBlockStat 1 WebT m ()
-> ActionT Except (ReaderT WebState m) BinfoBlockId
-> ActionT Except (ReaderT WebState m) BinfoBlockId
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Text -> ActionT Except (ReaderT WebState m) BinfoBlockId
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "block" ActionT Except (ReaderT WebState m) BinfoBlockId
-> (BinfoBlockId -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
BinfoBlockHash bh :: BlockHash
bh -> Bool -> Bool -> BlockHash -> WebT m ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Bool -> Bool -> BlockHash -> ActionT Except (ReaderT WebState m) ()
go Bool
numtxid Bool
hex BlockHash
bh
BinfoBlockIndex i :: Word32
i ->
Word32 -> ActionT Except (ReaderT WebState m) [BlockHash]
forall (m :: * -> *). StoreReadBase m => Word32 -> m [BlockHash]
getBlocksAtHeight Word32
i ActionT Except (ReaderT WebState m) [BlockHash]
-> ([BlockHash] -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
[] -> (WebMetrics -> StatDist) -> Except -> WebT m ()
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
rawBlockStat Except
ThingNotFound
bh :: BlockHash
bh:_ -> Bool -> Bool -> BlockHash -> WebT m ()
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Bool -> Bool -> BlockHash -> ActionT Except (ReaderT WebState m) ()
go Bool
numtxid Bool
hex BlockHash
bh
where
get_tx :: TxHash -> m Transaction
get_tx th :: TxHash
th =
((forall a. m a -> IO a) -> IO Transaction) -> m Transaction
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (((forall a. m a -> IO a) -> IO Transaction) -> m Transaction)
-> ((forall a. m a -> IO a) -> IO Transaction) -> m Transaction
forall a b. (a -> b) -> a -> b
$ \run :: forall a. m a -> IO a
run ->
IO Transaction -> IO Transaction
forall a. IO a -> IO a
unsafeInterleaveIO (IO Transaction -> IO Transaction)
-> IO Transaction -> IO Transaction
forall a b. (a -> b) -> a -> b
$
m Transaction -> IO Transaction
forall a. m a -> IO a
run (m Transaction -> IO Transaction)
-> m Transaction -> IO Transaction
forall a b. (a -> b) -> a -> b
$ Maybe Transaction -> Transaction
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Transaction -> Transaction)
-> m (Maybe Transaction) -> m Transaction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TxHash -> m (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction TxHash
th
go :: Bool -> Bool -> BlockHash -> ActionT Except (ReaderT WebState m) ()
go numtxid :: Bool
numtxid hex :: Bool
hex bh :: BlockHash
bh =
BlockHash -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock BlockHash
bh ActionT Except (ReaderT WebState m) (Maybe BlockData)
-> (Maybe BlockData -> ActionT Except (ReaderT WebState m) ())
-> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> (WebMetrics -> StatDist)
-> Except -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
rawBlockStat Except
ThingNotFound
Just b :: BlockData
b -> do
[Transaction]
txs <- ReaderT WebState m [Transaction]
-> ActionT Except (ReaderT WebState m) [Transaction]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [Transaction]
-> ActionT Except (ReaderT WebState m) [Transaction])
-> ReaderT WebState m [Transaction]
-> ActionT Except (ReaderT WebState m) [Transaction]
forall a b. (a -> b) -> a -> b
$ (TxHash -> ReaderT WebState m Transaction)
-> [TxHash] -> ReaderT WebState m [Transaction]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TxHash -> ReaderT WebState m Transaction
forall (m :: * -> *).
(MonadUnliftIO m, StoreReadBase m) =>
TxHash -> m Transaction
get_tx (BlockData -> [TxHash]
blockDataTxs BlockData
b)
let my_hash :: BlockHash
my_hash = BlockHeader -> BlockHash
H.headerHash (BlockData -> BlockHeader
blockDataHeader BlockData
b)
get_prev :: BlockData -> BlockHash
get_prev = BlockHeader -> BlockHash
H.prevBlock (BlockHeader -> BlockHash)
-> (BlockData -> BlockHeader) -> BlockData -> BlockHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockData -> BlockHeader
blockDataHeader
get_hash :: BlockData -> BlockHash
get_hash = BlockHeader -> BlockHash
H.headerHash (BlockHeader -> BlockHash)
-> (BlockData -> BlockHeader) -> BlockData -> BlockHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockData -> BlockHeader
blockDataHeader
[BlockData]
nxt_headers <-
([Maybe BlockData] -> [BlockData])
-> ActionT Except (ReaderT WebState m) [Maybe BlockData]
-> ActionT Except (ReaderT WebState m) [BlockData]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Maybe BlockData] -> [BlockData]
forall a. [Maybe a] -> [a]
catMaybes (ActionT Except (ReaderT WebState m) [Maybe BlockData]
-> ActionT Except (ReaderT WebState m) [BlockData])
-> ActionT Except (ReaderT WebState m) [Maybe BlockData]
-> ActionT Except (ReaderT WebState m) [BlockData]
forall a b. (a -> b) -> a -> b
$
(BlockHash
-> ActionT Except (ReaderT WebState m) (Maybe BlockData))
-> [BlockHash]
-> ActionT Except (ReaderT WebState m) [Maybe BlockData]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM BlockHash -> ActionT Except (ReaderT WebState m) (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock ([BlockHash]
-> ActionT Except (ReaderT WebState m) [Maybe BlockData])
-> ActionT Except (ReaderT WebState m) [BlockHash]
-> ActionT Except (ReaderT WebState m) [Maybe BlockData]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
Word32 -> ActionT Except (ReaderT WebState m) [BlockHash]
forall (m :: * -> *). StoreReadBase m => Word32 -> m [BlockHash]
getBlocksAtHeight (BlockData -> Word32
blockDataHeight BlockData
b Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ 1)
let nxt :: [BlockHash]
nxt = (BlockData -> BlockHash) -> [BlockData] -> [BlockHash]
forall a b. (a -> b) -> [a] -> [b]
map BlockData -> BlockHash
get_hash ([BlockData] -> [BlockHash]) -> [BlockData] -> [BlockHash]
forall a b. (a -> b) -> a -> b
$
(BlockData -> Bool) -> [BlockData] -> [BlockData]
forall a. (a -> Bool) -> [a] -> [a]
filter ((BlockHash -> BlockHash -> Bool
forall a. Eq a => a -> a -> Bool
== BlockHash
my_hash) (BlockHash -> Bool)
-> (BlockData -> BlockHash) -> BlockData -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockData -> BlockHash
get_prev)
[BlockData]
nxt_headers
if Bool
hex
then do
let x :: Block
x = BlockHeader -> [Tx] -> Block
H.Block (BlockData -> BlockHeader
blockDataHeader BlockData
b) ((Transaction -> Tx) -> [Transaction] -> [Tx]
forall a b. (a -> b) -> [a] -> [b]
map Transaction -> Tx
transactionData [Transaction]
txs)
ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
Text -> ActionT Except (ReaderT WebState m) ()
forall e (m :: * -> *).
(ScottyError e, Monad m) =>
Text -> ActionT e m ()
S.text (Text -> ActionT Except (ReaderT WebState m) ())
-> (Put -> Text) -> Put -> ActionT Except (ReaderT WebState m) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
encodeHexLazy (ByteString -> Text) -> (Put -> ByteString) -> Put -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Put -> ByteString
runPutL (Put -> ActionT Except (ReaderT WebState m) ())
-> Put -> ActionT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$ Block -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
serialize Block
x
else do
let btxs :: [BinfoTx]
btxs = (Transaction -> BinfoTx) -> [Transaction] -> [BinfoTx]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> Transaction -> BinfoTx
toBinfoTxSimple Bool
numtxid) [Transaction]
txs
y :: BinfoBlock
y = BlockData -> [BinfoTx] -> [BlockHash] -> BinfoBlock
toBinfoBlock BlockData
b [BinfoTx]
btxs [BlockHash]
nxt
ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
Network
net <- ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network)
-> ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall a b. (a -> b) -> a -> b
$ (WebState -> Network) -> ReaderT WebState m Network
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Network
storeNetwork (Store -> Network) -> (WebState -> Store) -> WebState -> Network
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Encoding -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *). Monad m => Encoding -> WebT m ()
streamEncoding (Encoding -> ActionT Except (ReaderT WebState m) ())
-> Encoding -> ActionT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$ Network -> BinfoBlock -> Encoding
binfoBlockToEncoding Network
net BinfoBlock
y
scottyBinfoTx :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()
scottyBinfoTx :: WebT m ()
scottyBinfoTx =
WebT m Bool
forall (m :: * -> *). MonadIO m => WebT m Bool
getNumTxId WebT m Bool -> (Bool -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \numtxid :: Bool
numtxid ->
WebT m Bool
forall (m :: * -> *). Monad m => WebT m Bool
getBinfoHex WebT m Bool -> (Bool -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \hex :: Bool
hex ->
Text -> ActionT Except (ReaderT WebState m) BinfoTxId
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param "txid" ActionT Except (ReaderT WebState m) BinfoTxId
-> (BinfoTxId -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \txid :: BinfoTxId
txid ->
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
rawtxStat 1 WebT m () -> WebT m () -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
let f :: BinfoTxId -> f [Transaction]
f (BinfoTxIdHash h :: TxHash
h) = Maybe Transaction -> [Transaction]
forall a. Maybe a -> [a]
maybeToList (Maybe Transaction -> [Transaction])
-> f (Maybe Transaction) -> f [Transaction]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TxHash -> f (Maybe Transaction)
forall (m :: * -> *).
(Monad m, StoreReadBase m) =>
TxHash -> m (Maybe Transaction)
getTransaction TxHash
h
f (BinfoTxIdIndex i :: Word64
i) = Word64 -> f [Transaction]
forall (m :: * -> *).
(Monad m, StoreReadExtra m) =>
Word64 -> m [Transaction]
getNumTransaction Word64
i
in BinfoTxId -> ActionT Except (ReaderT WebState m) [Transaction]
forall (f :: * -> *).
StoreReadExtra f =>
BinfoTxId -> f [Transaction]
f BinfoTxId
txid ActionT Except (ReaderT WebState m) [Transaction]
-> ([Transaction] -> WebT m ()) -> WebT m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
[] -> (WebMetrics -> StatDist) -> Except -> WebT m ()
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
rawtxStat Except
ThingNotFound
[t :: Transaction
t] -> if Bool
hex then Transaction -> WebT m ()
forall (m :: * -> *) e.
(Monad m, ScottyError e) =>
Transaction -> ActionT e m ()
hx Transaction
t else Bool -> Transaction -> WebT m ()
forall (m :: * -> *).
Monad m =>
Bool -> Transaction -> ActionT Except (ReaderT WebState m) ()
js Bool
numtxid Transaction
t
ts :: [Transaction]
ts ->
let tids :: [TxHash]
tids = (Transaction -> TxHash) -> [Transaction] -> [TxHash]
forall a b. (a -> b) -> [a] -> [b]
map (Tx -> TxHash
txHash (Tx -> TxHash) -> (Transaction -> Tx) -> Transaction -> TxHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transaction -> Tx
transactionData) [Transaction]
ts
in (WebMetrics -> StatDist) -> Except -> WebT m ()
forall (m :: * -> *) a.
MonadIO m =>
(WebMetrics -> StatDist) -> Except -> WebT m a
raise WebMetrics -> StatDist
rawtxStat ([TxHash] -> Except
TxIndexConflict [TxHash]
tids)
where
js :: Bool -> Transaction -> ActionT Except (ReaderT WebState m) ()
js numtxid :: Bool
numtxid t :: Transaction
t = do
Network
net <- ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network)
-> ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall a b. (a -> b) -> a -> b
$ (WebState -> Network) -> ReaderT WebState m Network
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Network
storeNetwork (Store -> Network) -> (WebState -> Store) -> WebState -> Network
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
Encoding -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *). Monad m => Encoding -> WebT m ()
streamEncoding (Encoding -> ActionT Except (ReaderT WebState m) ())
-> Encoding -> ActionT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$ Network -> BinfoTx -> Encoding
binfoTxToEncoding Network
net (BinfoTx -> Encoding) -> BinfoTx -> Encoding
forall a b. (a -> b) -> a -> b
$ Bool -> Transaction -> BinfoTx
toBinfoTxSimple Bool
numtxid Transaction
t
hx :: Transaction -> ActionT e m ()
hx t :: Transaction
t = do
ActionT e m ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
Text -> ActionT e m ()
forall e (m :: * -> *).
(ScottyError e, Monad m) =>
Text -> ActionT e m ()
S.text (Text -> ActionT e m ()) -> (Tx -> Text) -> Tx -> ActionT e m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
encodeHexLazy (ByteString -> Text) -> (Tx -> ByteString) -> Tx -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Put -> ByteString
runPutL (Put -> ByteString) -> (Tx -> Put) -> Tx -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx -> Put
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
serialize (Tx -> ActionT e m ()) -> Tx -> ActionT e m ()
forall a b. (a -> b) -> a -> b
$ Transaction -> Tx
transactionData Transaction
t
scottyPeers :: (MonadUnliftIO m, MonadLoggerIO m)
=> GetPeers
-> WebT m [PeerInformation]
scottyPeers :: GetPeers -> WebT m [PeerInformation]
scottyPeers _ = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
peerStat 1
ReaderT WebState m [PeerInformation] -> WebT m [PeerInformation]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m [PeerInformation] -> WebT m [PeerInformation])
-> ReaderT WebState m [PeerInformation] -> WebT m [PeerInformation]
forall a b. (a -> b) -> a -> b
$ PeerManager -> ReaderT WebState m [PeerInformation]
forall (m :: * -> *).
MonadLoggerIO m =>
PeerManager -> m [PeerInformation]
getPeersInformation (PeerManager -> ReaderT WebState m [PeerInformation])
-> ReaderT WebState m PeerManager
-> ReaderT WebState m [PeerInformation]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (WebState -> PeerManager) -> ReaderT WebState m PeerManager
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> PeerManager
storeManager (Store -> PeerManager)
-> (WebState -> Store) -> WebState -> PeerManager
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
getPeersInformation
:: MonadLoggerIO m => PeerManager -> m [PeerInformation]
getPeersInformation :: PeerManager -> m [PeerInformation]
getPeersInformation mgr :: PeerManager
mgr =
(OnlinePeer -> Maybe PeerInformation)
-> [OnlinePeer] -> [PeerInformation]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe OnlinePeer -> Maybe PeerInformation
toInfo ([OnlinePeer] -> [PeerInformation])
-> m [OnlinePeer] -> m [PeerInformation]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PeerManager -> m [OnlinePeer]
forall (m :: * -> *). MonadIO m => PeerManager -> m [OnlinePeer]
getPeers PeerManager
mgr
where
toInfo :: OnlinePeer -> Maybe PeerInformation
toInfo op :: OnlinePeer
op = do
Version
ver <- OnlinePeer -> Maybe Version
onlinePeerVersion OnlinePeer
op
let as :: SockAddr
as = OnlinePeer -> SockAddr
onlinePeerAddress OnlinePeer
op
ua :: ByteString
ua = VarString -> ByteString
getVarString (VarString -> ByteString) -> VarString -> ByteString
forall a b. (a -> b) -> a -> b
$ Version -> VarString
userAgent Version
ver
vs :: Word32
vs = Version -> Word32
version Version
ver
sv :: Word64
sv = Version -> Word64
services Version
ver
rl :: Bool
rl = Version -> Bool
relay Version
ver
PeerInformation -> Maybe PeerInformation
forall (m :: * -> *) a. Monad m => a -> m a
return
$WPeerInformation :: ByteString -> String -> Word32 -> Word64 -> Bool -> PeerInformation
PeerInformation
{ peerUserAgent :: ByteString
peerUserAgent = ByteString
ua
, peerAddress :: String
peerAddress = SockAddr -> String
forall a. Show a => a -> String
show SockAddr
as
, peerVersion :: Word32
peerVersion = Word32
vs
, peerServices :: Word64
peerServices = Word64
sv
, peerRelay :: Bool
peerRelay = Bool
rl
}
scottyHealth ::
(MonadUnliftIO m, MonadLoggerIO m) => GetHealth -> WebT m HealthCheck
scottyHealth :: GetHealth -> WebT m HealthCheck
scottyHealth _ = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
healthStat 1
HealthCheck
h <- ReaderT WebState m HealthCheck -> WebT m HealthCheck
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m HealthCheck -> WebT m HealthCheck)
-> ReaderT WebState m HealthCheck -> WebT m HealthCheck
forall a b. (a -> b) -> a -> b
$ (WebState -> WebConfig) -> ReaderT WebState m WebConfig
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WebState -> WebConfig
webConfig ReaderT WebState m WebConfig
-> (WebConfig -> ReaderT WebState m HealthCheck)
-> ReaderT WebState m HealthCheck
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= WebConfig -> ReaderT WebState m HealthCheck
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m) =>
WebConfig -> m HealthCheck
healthCheck
Bool -> WebT m () -> WebT m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (HealthCheck -> Bool
forall a. Healthy a => a -> Bool
isOK HealthCheck
h) (WebT m () -> WebT m ()) -> WebT m () -> WebT m ()
forall a b. (a -> b) -> a -> b
$ Status -> WebT m ()
forall (m :: * -> *) e. Monad m => Status -> ActionT e m ()
S.status Status
status503
HealthCheck -> WebT m HealthCheck
forall (m :: * -> *) a. Monad m => a -> m a
return HealthCheck
h
blockHealthCheck :: (MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m)
=> WebConfig -> m BlockHealth
blockHealthCheck :: WebConfig -> m BlockHealth
blockHealthCheck cfg :: WebConfig
cfg = do
let ch :: Chain
ch = Store -> Chain
storeChain (Store -> Chain) -> Store -> Chain
forall a b. (a -> b) -> a -> b
$ WebConfig -> Store
webStore WebConfig
cfg
blockHealthMaxDiff :: Int32
blockHealthMaxDiff = Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int32) -> Int -> Int32
forall a b. (a -> b) -> a -> b
$ WebConfig -> Int
webMaxDiff WebConfig
cfg
Word32
blockHealthHeaders <-
BlockNode -> Word32
H.nodeHeight (BlockNode -> Word32) -> m BlockNode -> m Word32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Chain -> m BlockNode
forall (m :: * -> *). MonadIO m => Chain -> m BlockNode
chainGetBest Chain
ch
Word32
blockHealthBlocks <-
Word32 -> (BlockData -> Word32) -> Maybe BlockData -> Word32
forall b a. b -> (a -> b) -> Maybe a -> b
maybe 0 BlockData -> Word32
blockDataHeight (Maybe BlockData -> Word32) -> m (Maybe BlockData) -> m Word32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
MaybeT m BlockData -> m (Maybe BlockData)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (m (Maybe BlockHash) -> MaybeT m BlockHash
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT m (Maybe BlockHash)
forall (m :: * -> *). StoreReadBase m => m (Maybe BlockHash)
getBestBlock MaybeT m BlockHash
-> (BlockHash -> MaybeT m BlockData) -> MaybeT m BlockData
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= m (Maybe BlockData) -> MaybeT m BlockData
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (m (Maybe BlockData) -> MaybeT m BlockData)
-> (BlockHash -> m (Maybe BlockData))
-> BlockHash
-> MaybeT m BlockData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockHash -> m (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock)
BlockHealth -> m BlockHealth
forall (m :: * -> *) a. Monad m => a -> m a
return $WBlockHealth :: Word32 -> Word32 -> Int32 -> BlockHealth
BlockHealth {..}
lastBlockHealthCheck :: (MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m)
=> Chain -> WebTimeouts -> m TimeHealth
lastBlockHealthCheck :: Chain -> WebTimeouts -> m TimeHealth
lastBlockHealthCheck ch :: Chain
ch tos :: WebTimeouts
tos = do
Int64
n <- Int64 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Int64) -> (SystemTime -> Int64) -> SystemTime -> Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SystemTime -> Int64
systemSeconds (SystemTime -> Int64) -> m SystemTime -> m Int64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO SystemTime -> m SystemTime
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO SystemTime
getSystemTime
Int64
t <- Word32 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Int64) -> (BlockNode -> Word32) -> BlockNode -> Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockHeader -> Word32
H.blockTimestamp (BlockHeader -> Word32)
-> (BlockNode -> BlockHeader) -> BlockNode -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockNode -> BlockHeader
H.nodeHeader (BlockNode -> Int64) -> m BlockNode -> m Int64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Chain -> m BlockNode
forall (m :: * -> *). MonadIO m => Chain -> m BlockNode
chainGetBest Chain
ch
let timeHealthAge :: Int64
timeHealthAge = Int64
n Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
t
timeHealthMax :: Int64
timeHealthMax = Word64 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Int64) -> Word64 -> Int64
forall a b. (a -> b) -> a -> b
$ WebTimeouts -> Word64
blockTimeout WebTimeouts
tos
TimeHealth -> m TimeHealth
forall (m :: * -> *) a. Monad m => a -> m a
return $WTimeHealth :: Int64 -> Int64 -> TimeHealth
TimeHealth {..}
lastTxHealthCheck :: (MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m)
=> WebConfig -> m TimeHealth
lastTxHealthCheck :: WebConfig -> m TimeHealth
lastTxHealthCheck WebConfig {..} = do
Int64
n <- Int64 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Int64) -> (SystemTime -> Int64) -> SystemTime -> Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SystemTime -> Int64
systemSeconds (SystemTime -> Int64) -> m SystemTime -> m Int64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO SystemTime -> m SystemTime
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO SystemTime
getSystemTime
Int64
b <- Word32 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Int64) -> (BlockNode -> Word32) -> BlockNode -> Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockHeader -> Word32
H.blockTimestamp (BlockHeader -> Word32)
-> (BlockNode -> BlockHeader) -> BlockNode -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockNode -> BlockHeader
H.nodeHeader (BlockNode -> Int64) -> m BlockNode -> m Int64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Chain -> m BlockNode
forall (m :: * -> *). MonadIO m => Chain -> m BlockNode
chainGetBest Chain
ch
Int64
t <- [(Word64, TxHash)] -> Maybe (Word64, TxHash)
forall a. [a] -> Maybe a
listToMaybe ([(Word64, TxHash)] -> Maybe (Word64, TxHash))
-> m [(Word64, TxHash)] -> m (Maybe (Word64, TxHash))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m [(Word64, TxHash)]
forall (m :: * -> *). StoreReadBase m => m [(Word64, TxHash)]
getMempool m (Maybe (Word64, TxHash))
-> (Maybe (Word64, TxHash) -> m Int64) -> m Int64
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just t :: (Word64, TxHash)
t -> let x :: Int64
x = Word64 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Int64) -> Word64 -> Int64
forall a b. (a -> b) -> a -> b
$ (Word64, TxHash) -> Word64
forall a b. (a, b) -> a
fst (Word64, TxHash)
t
in Int64 -> m Int64
forall (m :: * -> *) a. Monad m => a -> m a
return (Int64 -> m Int64) -> Int64 -> m Int64
forall a b. (a -> b) -> a -> b
$ Int64 -> Int64 -> Int64
forall a. Ord a => a -> a -> a
max Int64
x Int64
b
Nothing -> Int64 -> m Int64
forall (m :: * -> *) a. Monad m => a -> m a
return Int64
b
let timeHealthAge :: Int64
timeHealthAge = Int64
n Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
t
timeHealthMax :: Int64
timeHealthMax = Word64 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
to
TimeHealth -> m TimeHealth
forall (m :: * -> *) a. Monad m => a -> m a
return $WTimeHealth :: Int64 -> Int64 -> TimeHealth
TimeHealth {..}
where
ch :: Chain
ch = Store -> Chain
storeChain Store
webStore
to :: Word64
to = if Bool
webNoMempool then WebTimeouts -> Word64
blockTimeout WebTimeouts
webTimeouts else WebTimeouts -> Word64
txTimeout WebTimeouts
webTimeouts
pendingTxsHealthCheck :: (MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m)
=> WebConfig -> m MaxHealth
pendingTxsHealthCheck :: WebConfig -> m MaxHealth
pendingTxsHealthCheck cfg :: WebConfig
cfg = do
let maxHealthMax :: Int64
maxHealthMax = Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int64) -> Int -> Int64
forall a b. (a -> b) -> a -> b
$ WebConfig -> Int
webMaxPending WebConfig
cfg
Int64
maxHealthNum <-
Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int64) -> m Int -> m Int64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
BlockStore -> m Int
forall (m :: * -> *). MonadIO m => BlockStore -> m Int
blockStorePendingTxs (Store -> BlockStore
storeBlock (WebConfig -> Store
webStore WebConfig
cfg))
MaxHealth -> m MaxHealth
forall (m :: * -> *) a. Monad m => a -> m a
return $WMaxHealth :: Int64 -> Int64 -> MaxHealth
MaxHealth {..}
peerHealthCheck :: (MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m)
=> PeerManager -> m CountHealth
peerHealthCheck :: PeerManager -> m CountHealth
peerHealthCheck mgr :: PeerManager
mgr = do
let countHealthMin :: Int64
countHealthMin = 1
Int64
countHealthNum <- Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int64) -> ([OnlinePeer] -> Int) -> [OnlinePeer] -> Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [OnlinePeer] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([OnlinePeer] -> Int64) -> m [OnlinePeer] -> m Int64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PeerManager -> m [OnlinePeer]
forall (m :: * -> *). MonadIO m => PeerManager -> m [OnlinePeer]
getPeers PeerManager
mgr
CountHealth -> m CountHealth
forall (m :: * -> *) a. Monad m => a -> m a
return $WCountHealth :: Int64 -> Int64 -> CountHealth
CountHealth {..}
healthCheck :: (MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m)
=> WebConfig -> m HealthCheck
healthCheck :: WebConfig -> m HealthCheck
healthCheck cfg :: WebConfig
cfg@WebConfig {..} = do
BlockHealth
healthBlocks <- WebConfig -> m BlockHealth
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m) =>
WebConfig -> m BlockHealth
blockHealthCheck WebConfig
cfg
TimeHealth
healthLastBlock <- Chain -> WebTimeouts -> m TimeHealth
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m) =>
Chain -> WebTimeouts -> m TimeHealth
lastBlockHealthCheck (Store -> Chain
storeChain Store
webStore) WebTimeouts
webTimeouts
TimeHealth
healthLastTx <- WebConfig -> m TimeHealth
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m) =>
WebConfig -> m TimeHealth
lastTxHealthCheck WebConfig
cfg
MaxHealth
healthPendingTxs <- WebConfig -> m MaxHealth
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m) =>
WebConfig -> m MaxHealth
pendingTxsHealthCheck WebConfig
cfg
CountHealth
healthPeers <- PeerManager -> m CountHealth
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m, StoreReadBase m) =>
PeerManager -> m CountHealth
peerHealthCheck (Store -> PeerManager
storeManager Store
webStore)
let healthNetwork :: String
healthNetwork = Network -> String
getNetworkName (Store -> Network
storeNetwork Store
webStore)
healthVersion :: String
healthVersion = String
webVersion
hc :: HealthCheck
hc = $WHealthCheck :: BlockHealth
-> TimeHealth
-> TimeHealth
-> MaxHealth
-> CountHealth
-> String
-> String
-> HealthCheck
HealthCheck {..}
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (HealthCheck -> Bool
forall a. Healthy a => a -> Bool
isOK HealthCheck
hc) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
let t :: Text
t = Text -> Text
toStrict (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ HealthCheck -> Text
forall a. ToJSON a => a -> Text
encodeToLazyText HealthCheck
hc
$(Text
LogLevel
String -> String -> String -> CharPos -> CharPos -> Loc
Loc -> Text -> LogLevel -> Text -> m ()
forall (m :: * -> *) msg.
(MonadLogger m, ToLogStr msg) =>
Loc -> Text -> LogLevel -> msg -> m ()
b :: Text
a :: Text
monadLoggerLog :: forall (m :: * -> *) msg.
(MonadLogger m, ToLogStr msg) =>
Loc -> Text -> LogLevel -> msg -> m ()
logErrorS) "Web" (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$ "Health check failed: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t
HealthCheck -> m HealthCheck
forall (m :: * -> *) a. Monad m => a -> m a
return HealthCheck
hc
scottyDbStats :: (MonadUnliftIO m, MonadLoggerIO m) => WebT m ()
scottyDbStats :: WebT m ()
scottyDbStats = do
(WebMetrics -> StatDist) -> Int -> WebT m ()
forall (m :: * -> *).
MonadUnliftIO m =>
(WebMetrics -> StatDist) -> Int -> WebT m ()
setMetrics WebMetrics -> StatDist
dbStatsStat 1
WebT m ()
forall (m :: * -> *) e. (Monad m, ScottyError e) => ActionT e m ()
setHeaders
DB
db <- ReaderT WebState m DB -> ActionT Except (ReaderT WebState m) DB
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m DB -> ActionT Except (ReaderT WebState m) DB)
-> ReaderT WebState m DB -> ActionT Except (ReaderT WebState m) DB
forall a b. (a -> b) -> a -> b
$ (WebState -> DB) -> ReaderT WebState m DB
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (DatabaseReader -> DB
databaseHandle (DatabaseReader -> DB)
-> (WebState -> DatabaseReader) -> WebState -> DB
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Store -> DatabaseReader
storeDB (Store -> DatabaseReader)
-> (WebState -> Store) -> WebState -> DatabaseReader
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Maybe ByteString
statsM <- ReaderT WebState m (Maybe ByteString)
-> ActionT Except (ReaderT WebState m) (Maybe ByteString)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (DB -> Property -> ReaderT WebState m (Maybe ByteString)
forall (m :: * -> *).
MonadIO m =>
DB -> Property -> m (Maybe ByteString)
getProperty DB
db Property
Stats)
Text -> WebT m ()
forall e (m :: * -> *).
(ScottyError e, Monad m) =>
Text -> ActionT e m ()
S.text (Text -> WebT m ()) -> Text -> WebT m ()
forall a b. (a -> b) -> a -> b
$ Text -> (ByteString -> Text) -> Maybe ByteString -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe "Could not get stats" ByteString -> Text
forall a b. ConvertibleStrings a b => a -> b
cs Maybe ByteString
statsM
paramOptional :: (Param a, MonadIO m) => WebT m (Maybe a)
paramOptional :: WebT m (Maybe a)
paramOptional = Proxy a -> WebT m (Maybe a)
forall a (m :: * -> *).
(Param a, MonadIO m) =>
Proxy a -> WebT m (Maybe a)
go Proxy a
forall k (t :: k). Proxy t
Proxy
where
go :: (Param a, MonadIO m) => Proxy a -> WebT m (Maybe a)
go :: Proxy a -> WebT m (Maybe a)
go proxy :: Proxy a
proxy = do
Network
net <- ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network)
-> ReaderT WebState m Network
-> ActionT Except (ReaderT WebState m) Network
forall a b. (a -> b) -> a -> b
$ (WebState -> Network) -> ReaderT WebState m Network
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Network
storeNetwork (Store -> Network) -> (WebState -> Store) -> WebState -> Network
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Maybe [Text]
tsM :: Maybe [Text] <- ActionT Except (ReaderT WebState m) (Maybe [Text])
p ActionT Except (ReaderT WebState m) (Maybe [Text])
-> (Except -> ActionT Except (ReaderT WebState m) (Maybe [Text]))
-> ActionT Except (ReaderT WebState m) (Maybe [Text])
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` ActionT Except (ReaderT WebState m) (Maybe [Text])
-> Except -> ActionT Except (ReaderT WebState m) (Maybe [Text])
forall a b. a -> b -> a
const (Maybe [Text] -> ActionT Except (ReaderT WebState m) (Maybe [Text])
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe [Text]
forall a. Maybe a
Nothing)
case Maybe [Text]
tsM of
Nothing -> Maybe a -> WebT m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
Just ts :: [Text]
ts -> WebT m (Maybe a)
-> (a -> WebT m (Maybe a)) -> Maybe a -> WebT m (Maybe a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Except -> WebT m (Maybe a)
forall (m :: * -> *) a. MonadIO m => Except -> WebT m a
raise_ Except
err) (Maybe a -> WebT m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> WebT m (Maybe a))
-> (a -> Maybe a) -> a -> WebT m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe a
forall a. a -> Maybe a
Just) (Maybe a -> WebT m (Maybe a)) -> Maybe a -> WebT m (Maybe a)
forall a b. (a -> b) -> a -> b
$ Network -> [Text] -> Maybe a
forall a. Param a => Network -> [Text] -> Maybe a
parseParam Network
net [Text]
ts
where
l :: Text
l = Proxy a -> Text
forall a. Param a => Proxy a -> Text
proxyLabel Proxy a
proxy
p :: ActionT Except (ReaderT WebState m) (Maybe [Text])
p = [Text] -> Maybe [Text]
forall a. a -> Maybe a
Just ([Text] -> Maybe [Text])
-> ActionT Except (ReaderT WebState m) [Text]
-> ActionT Except (ReaderT WebState m) (Maybe [Text])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ActionT Except (ReaderT WebState m) [Text]
forall a e (m :: * -> *).
(Parsable a, ScottyError e, Monad m) =>
Text -> ActionT e m a
S.param (Text -> Text
forall a b. ConvertibleStrings a b => a -> b
cs Text
l)
err :: Except
err = String -> Except
UserError (String -> Except) -> String -> Except
forall a b. (a -> b) -> a -> b
$ "Unable to parse param " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a b. ConvertibleStrings a b => a -> b
cs Text
l
param :: (Param a, MonadIO m) => WebT m a
param :: WebT m a
param = Proxy a -> WebT m a
forall a (m :: * -> *). (Param a, MonadIO m) => Proxy a -> WebT m a
go Proxy a
forall k (t :: k). Proxy t
Proxy
where
go :: (Param a, MonadIO m) => Proxy a -> WebT m a
go :: Proxy a -> WebT m a
go proxy :: Proxy a
proxy = do
Maybe a
resM <- WebT m (Maybe a)
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m (Maybe a)
paramOptional
case Maybe a
resM of
Just res :: a
res -> a -> WebT m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
res
_ ->
Except -> WebT m a
forall (m :: * -> *) a. MonadIO m => Except -> WebT m a
raise_ (Except -> WebT m a) -> (String -> Except) -> String -> WebT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Except
UserError (String -> WebT m a) -> String -> WebT m a
forall a b. (a -> b) -> a -> b
$
"The param " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a b. ConvertibleStrings a b => a -> b
cs (Proxy a -> Text
forall a. Param a => Proxy a -> Text
proxyLabel Proxy a
proxy) String -> ShowS
forall a. Semigroup a => a -> a -> a
<> " was not defined"
paramDef :: (Default a, Param a, MonadIO m) => WebT m a
paramDef :: WebT m a
paramDef = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe a
forall a. Default a => a
def (Maybe a -> a)
-> ActionT Except (ReaderT WebState m) (Maybe a) -> WebT m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) (Maybe a)
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m (Maybe a)
paramOptional
paramLazy :: (Param a, MonadIO m) => WebT m a
paramLazy :: WebT m a
paramLazy = do
Maybe a
resM <- WebT m (Maybe a)
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m (Maybe a)
paramOptional WebT m (Maybe a)
-> (Except -> WebT m (Maybe a)) -> WebT m (Maybe a)
forall e (m :: * -> *) a.
(ScottyError e, Monad m) =>
ActionT e m a -> (e -> ActionT e m a) -> ActionT e m a
`S.rescue` WebT m (Maybe a) -> Except -> WebT m (Maybe a)
forall a b. a -> b -> a
const (Maybe a -> WebT m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing)
WebT m a -> (a -> WebT m a) -> Maybe a -> WebT m a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe WebT m a
forall e (m :: * -> *) a. (ScottyError e, Monad m) => ActionT e m a
S.next a -> WebT m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
resM
parseBody :: (MonadIO m, Serial a) => WebT m a
parseBody :: WebT m a
parseBody = do
ByteString
b <- ByteString -> ByteString
L.toStrict (ByteString -> ByteString)
-> ActionT Except (ReaderT WebState m) ByteString
-> ActionT Except (ReaderT WebState m) ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) ByteString
forall e (m :: * -> *).
(ScottyError e, MonadIO m) =>
ActionT e m ByteString
S.body
case ByteString -> Either String a
hex ByteString
b Either String a -> Either String a -> Either String a
forall a. Semigroup a => a -> a -> a
<> ByteString -> Either String a
bin ByteString
b of
Left _ -> Except -> WebT m a
forall (m :: * -> *) a. MonadIO m => Except -> WebT m a
raise_ (Except -> WebT m a) -> Except -> WebT m a
forall a b. (a -> b) -> a -> b
$ String -> Except
UserError "Failed to parse request body"
Right x :: a
x -> a -> WebT m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x
where
bin :: ByteString -> Either String a
bin = Get a -> ByteString -> Either String a
forall a. Get a -> ByteString -> Either String a
runGetS Get a
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
deserialize
hex :: ByteString -> Either String a
hex b :: ByteString
b = case ByteString -> Either Text ByteString
B16.decodeBase16 (ByteString -> Either Text ByteString)
-> ByteString -> Either Text ByteString
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> ByteString -> ByteString
C.filter (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isSpace) ByteString
b of
Right x :: ByteString
x -> ByteString -> Either String a
bin ByteString
x
Left s :: Text
s -> String -> Either String a
forall a b. a -> Either a b
Left (Text -> String
T.unpack Text
s)
parseOffset :: MonadIO m => WebT m OffsetParam
parseOffset :: WebT m OffsetParam
parseOffset = do
res :: OffsetParam
res@(OffsetParam o :: Natural
o) <- WebT m OffsetParam
forall a (m :: * -> *). (Default a, Param a, MonadIO m) => WebT m a
paramDef
WebLimits
limits <- ReaderT WebState m WebLimits
-> ActionT Except (ReaderT WebState m) WebLimits
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m WebLimits
-> ActionT Except (ReaderT WebState m) WebLimits)
-> ReaderT WebState m WebLimits
-> ActionT Except (ReaderT WebState m) WebLimits
forall a b. (a -> b) -> a -> b
$ (WebState -> WebLimits) -> ReaderT WebState m WebLimits
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (WebConfig -> WebLimits
webMaxLimits (WebConfig -> WebLimits)
-> (WebState -> WebConfig) -> WebState -> WebLimits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Bool
-> ActionT Except (ReaderT WebState m) ()
-> ActionT Except (ReaderT WebState m) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (WebLimits -> Word32
maxLimitOffset WebLimits
limits Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
> 0 Bool -> Bool -> Bool
&& Natural -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
o Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
> WebLimits -> Word32
maxLimitOffset WebLimits
limits) (ActionT Except (ReaderT WebState m) ()
-> ActionT Except (ReaderT WebState m) ())
-> ActionT Except (ReaderT WebState m) ()
-> ActionT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$
Except -> ActionT Except (ReaderT WebState m) ()
forall (m :: * -> *) a. MonadIO m => Except -> WebT m a
raise_ (Except -> ActionT Except (ReaderT WebState m) ())
-> (String -> Except)
-> String
-> ActionT Except (ReaderT WebState m) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Except
UserError (String -> ActionT Except (ReaderT WebState m) ())
-> String -> ActionT Except (ReaderT WebState m) ()
forall a b. (a -> b) -> a -> b
$
"offset exceeded: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Natural -> String
forall a. Show a => a -> String
show Natural
o String -> ShowS
forall a. Semigroup a => a -> a -> a
<> " > " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word32 -> String
forall a. Show a => a -> String
show (WebLimits -> Word32
maxLimitOffset WebLimits
limits)
OffsetParam -> WebT m OffsetParam
forall (m :: * -> *) a. Monad m => a -> m a
return OffsetParam
res
parseStart ::
(MonadUnliftIO m, MonadLoggerIO m)
=> Maybe StartParam
-> WebT m (Maybe Start)
parseStart :: Maybe StartParam -> WebT m (Maybe Start)
parseStart Nothing = Maybe Start -> WebT m (Maybe Start)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Start
forall a. Maybe a
Nothing
parseStart (Just s :: StartParam
s) =
MaybeT (ActionT Except (ReaderT WebState m)) Start
-> WebT m (Maybe Start)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT (ActionT Except (ReaderT WebState m)) Start
-> WebT m (Maybe Start))
-> MaybeT (ActionT Except (ReaderT WebState m)) Start
-> WebT m (Maybe Start)
forall a b. (a -> b) -> a -> b
$
case StartParam
s of
StartParamHash {startParamHash :: StartParam -> Hash256
startParamHash = Hash256
h} -> Hash256 -> MaybeT (ActionT Except (ReaderT WebState m)) Start
forall (m :: * -> *). StoreReadBase m => Hash256 -> MaybeT m Start
start_tx Hash256
h MaybeT (ActionT Except (ReaderT WebState m)) Start
-> MaybeT (ActionT Except (ReaderT WebState m)) Start
-> MaybeT (ActionT Except (ReaderT WebState m)) Start
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Hash256 -> MaybeT (ActionT Except (ReaderT WebState m)) Start
forall (m :: * -> *). StoreReadBase m => Hash256 -> MaybeT m Start
start_block Hash256
h
StartParamHeight {startParamHeight :: StartParam -> Natural
startParamHeight = Natural
h} -> Natural -> MaybeT (ActionT Except (ReaderT WebState m)) Start
forall (m :: * -> *) a. (Monad m, Integral a) => a -> m Start
start_height Natural
h
StartParamTime {startParamTime :: StartParam -> Word64
startParamTime = Word64
q} -> Word64 -> MaybeT (ActionT Except (ReaderT WebState m)) Start
forall (m :: * -> *).
(MonadReader WebState m, MonadIO m, StoreReadExtra m) =>
Word64 -> MaybeT m Start
start_time Word64
q
where
start_height :: a -> m Start
start_height h :: a
h = Start -> m Start
forall (m :: * -> *) a. Monad m => a -> m a
return (Start -> m Start) -> Start -> m Start
forall a b. (a -> b) -> a -> b
$ Word32 -> Start
AtBlock (Word32 -> Start) -> Word32 -> Start
forall a b. (a -> b) -> a -> b
$ a -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
h
start_block :: Hash256 -> MaybeT m Start
start_block h :: Hash256
h = do
BlockData
b <- m (Maybe BlockData) -> MaybeT m BlockData
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (m (Maybe BlockData) -> MaybeT m BlockData)
-> m (Maybe BlockData) -> MaybeT m BlockData
forall a b. (a -> b) -> a -> b
$ BlockHash -> m (Maybe BlockData)
forall (m :: * -> *).
StoreReadBase m =>
BlockHash -> m (Maybe BlockData)
getBlock (Hash256 -> BlockHash
H.BlockHash Hash256
h)
Start -> MaybeT m Start
forall (m :: * -> *) a. Monad m => a -> m a
return (Start -> MaybeT m Start) -> Start -> MaybeT m Start
forall a b. (a -> b) -> a -> b
$ Word32 -> Start
AtBlock (BlockData -> Word32
blockDataHeight BlockData
b)
start_tx :: Hash256 -> MaybeT m Start
start_tx h :: Hash256
h = do
TxData
_ <- m (Maybe TxData) -> MaybeT m TxData
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (m (Maybe TxData) -> MaybeT m TxData)
-> m (Maybe TxData) -> MaybeT m TxData
forall a b. (a -> b) -> a -> b
$ TxHash -> m (Maybe TxData)
forall (m :: * -> *). StoreReadBase m => TxHash -> m (Maybe TxData)
getTxData (Hash256 -> TxHash
TxHash Hash256
h)
Start -> MaybeT m Start
forall (m :: * -> *) a. Monad m => a -> m a
return (Start -> MaybeT m Start) -> Start -> MaybeT m Start
forall a b. (a -> b) -> a -> b
$ TxHash -> Start
AtTx (Hash256 -> TxHash
TxHash Hash256
h)
start_time :: Word64 -> MaybeT m Start
start_time q :: Word64
q = do
Chain
ch <- m Chain -> MaybeT m Chain
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Chain -> MaybeT m Chain) -> m Chain -> MaybeT m Chain
forall a b. (a -> b) -> a -> b
$ (WebState -> Chain) -> m Chain
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Chain
storeChain (Store -> Chain) -> (WebState -> Store) -> WebState -> Chain
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
BlockData
b <- m (Maybe BlockData) -> MaybeT m BlockData
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (m (Maybe BlockData) -> MaybeT m BlockData)
-> m (Maybe BlockData) -> MaybeT m BlockData
forall a b. (a -> b) -> a -> b
$ Chain -> Word64 -> m (Maybe BlockData)
forall (m :: * -> *).
(MonadIO m, StoreReadExtra m) =>
Chain -> Word64 -> m (Maybe BlockData)
blockAtOrBefore Chain
ch Word64
q
let g :: Word32
g = BlockData -> Word32
blockDataHeight BlockData
b
Start -> MaybeT m Start
forall (m :: * -> *) a. Monad m => a -> m a
return (Start -> MaybeT m Start) -> Start -> MaybeT m Start
forall a b. (a -> b) -> a -> b
$ Word32 -> Start
AtBlock Word32
g
parseLimits :: MonadIO m => WebT m LimitsParam
parseLimits :: WebT m LimitsParam
parseLimits = Maybe LimitParam -> OffsetParam -> Maybe StartParam -> LimitsParam
LimitsParam (Maybe LimitParam
-> OffsetParam -> Maybe StartParam -> LimitsParam)
-> ActionT Except (ReaderT WebState m) (Maybe LimitParam)
-> ActionT
Except
(ReaderT WebState m)
(OffsetParam -> Maybe StartParam -> LimitsParam)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ActionT Except (ReaderT WebState m) (Maybe LimitParam)
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m (Maybe a)
paramOptional ActionT
Except
(ReaderT WebState m)
(OffsetParam -> Maybe StartParam -> LimitsParam)
-> ActionT Except (ReaderT WebState m) OffsetParam
-> ActionT
Except (ReaderT WebState m) (Maybe StartParam -> LimitsParam)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) OffsetParam
forall (m :: * -> *). MonadIO m => WebT m OffsetParam
parseOffset ActionT
Except (ReaderT WebState m) (Maybe StartParam -> LimitsParam)
-> ActionT Except (ReaderT WebState m) (Maybe StartParam)
-> WebT m LimitsParam
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ActionT Except (ReaderT WebState m) (Maybe StartParam)
forall a (m :: * -> *). (Param a, MonadIO m) => WebT m (Maybe a)
paramOptional
paramToLimits ::
(MonadUnliftIO m, MonadLoggerIO m)
=> Bool
-> LimitsParam
-> WebT m Limits
paramToLimits :: Bool -> LimitsParam -> WebT m Limits
paramToLimits full :: Bool
full (LimitsParam limitM :: Maybe LimitParam
limitM o :: OffsetParam
o startM :: Maybe StartParam
startM) = do
WebLimits
wl <- ReaderT WebState m WebLimits
-> ActionT Except (ReaderT WebState m) WebLimits
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT WebState m WebLimits
-> ActionT Except (ReaderT WebState m) WebLimits)
-> ReaderT WebState m WebLimits
-> ActionT Except (ReaderT WebState m) WebLimits
forall a b. (a -> b) -> a -> b
$ (WebState -> WebLimits) -> ReaderT WebState m WebLimits
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (WebConfig -> WebLimits
webMaxLimits (WebConfig -> WebLimits)
-> (WebState -> WebConfig) -> WebState -> WebLimits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Word32 -> Word32 -> Maybe Start -> Limits
Limits (WebLimits -> Bool -> Maybe LimitParam -> Word32
validateLimit WebLimits
wl Bool
full Maybe LimitParam
limitM) (OffsetParam -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral OffsetParam
o) (Maybe Start -> Limits)
-> ActionT Except (ReaderT WebState m) (Maybe Start)
-> WebT m Limits
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe StartParam
-> ActionT Except (ReaderT WebState m) (Maybe Start)
forall (m :: * -> *).
(MonadUnliftIO m, MonadLoggerIO m) =>
Maybe StartParam -> WebT m (Maybe Start)
parseStart Maybe StartParam
startM
validateLimit :: WebLimits -> Bool -> Maybe LimitParam -> Word32
validateLimit :: WebLimits -> Bool -> Maybe LimitParam -> Word32
validateLimit wl :: WebLimits
wl full :: Bool
full limitM :: Maybe LimitParam
limitM =
Word32 -> Word32 -> Word32
forall a. (Num a, Ord a) => a -> a -> a
f Word32
m (Word32 -> Word32) -> Word32 -> Word32
forall a b. (a -> b) -> a -> b
$ Word32 -> (LimitParam -> Word32) -> Maybe LimitParam -> Word32
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Word32
d (Natural -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Natural -> Word32)
-> (LimitParam -> Natural) -> LimitParam -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LimitParam -> Natural
getLimitParam) Maybe LimitParam
limitM
where
m :: Word32
m | Bool
full Bool -> Bool -> Bool
&& WebLimits -> Word32
maxLimitFull WebLimits
wl Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = WebLimits -> Word32
maxLimitFull WebLimits
wl
| Bool
otherwise = WebLimits -> Word32
maxLimitCount WebLimits
wl
d :: Word32
d = WebLimits -> Word32
maxLimitDefault WebLimits
wl
f :: a -> a -> a
f a :: a
a 0 = a
a
f 0 b :: a
b = a
b
f a :: a
a b :: a
b = a -> a -> a
forall a. Ord a => a -> a -> a
min a
a a
b
runInWebReader ::
MonadIO m
=> CacheT (DatabaseReaderT m) a
-> ReaderT WebState m a
runInWebReader :: CacheT (DatabaseReaderT m) a -> ReaderT WebState m a
runInWebReader f :: CacheT (DatabaseReaderT m) a
f = do
DatabaseReader
bdb <- (WebState -> DatabaseReader) -> ReaderT WebState m DatabaseReader
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> DatabaseReader
storeDB (Store -> DatabaseReader)
-> (WebState -> Store) -> WebState -> DatabaseReader
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
Maybe CacheConfig
mc <- (WebState -> Maybe CacheConfig)
-> ReaderT WebState m (Maybe CacheConfig)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (Store -> Maybe CacheConfig
storeCache (Store -> Maybe CacheConfig)
-> (WebState -> Store) -> WebState -> Maybe CacheConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebConfig -> Store
webStore (WebConfig -> Store)
-> (WebState -> WebConfig) -> WebState -> Store
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WebState -> WebConfig
webConfig)
m a -> ReaderT WebState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT WebState m a) -> m a -> ReaderT WebState m a
forall a b. (a -> b) -> a -> b
$ ReaderT DatabaseReader m a -> DatabaseReader -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (Maybe CacheConfig
-> CacheT (DatabaseReaderT m) a -> ReaderT DatabaseReader m a
forall (m :: * -> *) a.
StoreReadBase m =>
Maybe CacheConfig -> CacheT m a -> m a
withCache Maybe CacheConfig
mc CacheT (DatabaseReaderT m) a
f) DatabaseReader
bdb
runNoCache :: MonadIO m => Bool -> ReaderT WebState m a -> ReaderT WebState m a
runNoCache :: Bool -> ReaderT WebState m a -> ReaderT WebState m a
runNoCache False f :: ReaderT WebState m a
f = ReaderT WebState m a
f
runNoCache True f :: ReaderT WebState m a
f = (WebState -> WebState)
-> ReaderT WebState m a -> ReaderT WebState m a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local WebState -> WebState
g ReaderT WebState m a
f
where
g :: WebState -> WebState
g s :: WebState
s = WebState
s { webConfig :: WebConfig
webConfig = WebConfig -> WebConfig
h (WebState -> WebConfig
webConfig WebState
s) }
h :: WebConfig -> WebConfig
h c :: WebConfig
c = WebConfig
c { webStore :: Store
webStore = Store -> Store
i (WebConfig -> Store
webStore WebConfig
c) }
i :: Store -> Store
i s :: Store
s = Store
s { storeCache :: Maybe CacheConfig
storeCache = Maybe CacheConfig
forall a. Maybe a
Nothing }
logIt :: (MonadUnliftIO m, MonadLoggerIO m)
=> Maybe WebMetrics -> m Middleware
logIt :: Maybe WebMetrics -> m Middleware
logIt metrics :: Maybe WebMetrics
metrics = do
m () -> IO ()
runner <- m (m () -> IO ())
forall (m :: * -> *) a. MonadUnliftIO m => m (m a -> IO a)
askRunInIO
Middleware -> m Middleware
forall (m :: * -> *) a. Monad m => a -> m a
return (Middleware -> m Middleware) -> Middleware -> m Middleware
forall a b. (a -> b) -> a -> b
$ \app :: Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
app req :: Request
req respond :: Response -> IO ResponseReceived
respond -> do
TVar ByteString
var <- ByteString -> IO (TVar ByteString)
forall (m :: * -> *) a. MonadIO m => a -> m (TVar a)
newTVarIO ByteString
B.empty
Request
req' <-
let rb :: IO ByteString
rb = TVar ByteString -> IO ByteString -> IO ByteString
forall (m :: * -> *).
MonadIO m =>
TVar ByteString -> m ByteString -> m ByteString
req_body TVar ByteString
var (Request -> IO ByteString
getRequestBodyChunk Request
req)
rq :: Request
rq = Request
req{requestBody :: IO ByteString
requestBody = IO ByteString
rb}
in case Maybe WebMetrics
metrics of
Nothing -> Request -> IO Request
forall (m :: * -> *) a. Monad m => a -> m a
return Request
rq
Just m :: WebMetrics
m -> do
TVar (Maybe (WebMetrics -> StatDist))
stat_var <- Maybe (WebMetrics -> StatDist)
-> IO (TVar (Maybe (WebMetrics -> StatDist)))
forall (m :: * -> *) a. MonadIO m => a -> m (TVar a)
newTVarIO Maybe (WebMetrics -> StatDist)
forall a. Maybe a
Nothing
TVar Int
item_var <- Int -> IO (TVar Int)
forall (m :: * -> *) a. MonadIO m => a -> m (TVar a)
newTVarIO 0
let vt :: Vault
vt = Key (TVar (Maybe (WebMetrics -> StatDist)))
-> TVar (Maybe (WebMetrics -> StatDist)) -> Vault -> Vault
forall a. Key a -> a -> Vault -> Vault
V.insert (WebMetrics -> Key (TVar (Maybe (WebMetrics -> StatDist)))
statKey WebMetrics
m) TVar (Maybe (WebMetrics -> StatDist))
stat_var (Vault -> Vault) -> Vault -> Vault
forall a b. (a -> b) -> a -> b
$
Key (TVar Int) -> TVar Int -> Vault -> Vault
forall a. Key a -> a -> Vault -> Vault
V.insert (WebMetrics -> Key (TVar Int)
itemsKey WebMetrics
m) TVar Int
item_var (Vault -> Vault) -> Vault -> Vault
forall a b. (a -> b) -> a -> b
$
Request -> Vault
vault Request
rq
Request -> IO Request
forall (m :: * -> *) a. Monad m => a -> m a
return Request
rq{vault :: Vault
vault = Vault
vt}
IO UTCTime
-> (UTCTime -> IO ())
-> (UTCTime -> IO ResponseReceived)
-> IO ResponseReceived
forall (m :: * -> *) a b c.
MonadUnliftIO m =>
m a -> (a -> m b) -> (a -> m c) -> m c
bracket IO UTCTime
start (TVar ByteString -> (m () -> IO ()) -> Request -> UTCTime -> IO ()
forall (m :: * -> *).
MonadLogger m =>
TVar ByteString -> (m () -> IO ()) -> Request -> UTCTime -> IO ()
end TVar ByteString
var m () -> IO ()
runner Request
req') ((UTCTime -> IO ResponseReceived) -> IO ResponseReceived)
-> (UTCTime -> IO ResponseReceived) -> IO ResponseReceived
forall a b. (a -> b) -> a -> b
$ \t1 :: UTCTime
t1 ->
Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
app Request
req' ((Response -> IO ResponseReceived) -> IO ResponseReceived)
-> (Response -> IO ResponseReceived) -> IO ResponseReceived
forall a b. (a -> b) -> a -> b
$ \res :: Response
res -> do
UTCTime
t2 <- SystemTime -> UTCTime
systemToUTCTime (SystemTime -> UTCTime) -> IO SystemTime -> IO UTCTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO SystemTime
getSystemTime
ByteString
b <- TVar ByteString -> IO ByteString
forall (m :: * -> *) a. MonadIO m => TVar a -> m a
readTVarIO TVar ByteString
var
let s :: Status
s = Response -> Status
responseStatus Response
res
msg :: Text
msg = ByteString -> Request -> Text
fmtReq ByteString
b Request
req' Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ": " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Status -> Text
fmtStatus Status
s
if Status -> Bool
statusIsSuccessful Status
s
then m () -> IO ()
runner (m () -> IO ()) -> m () -> IO ()
forall a b. (a -> b) -> a -> b
$ $(Text
LogLevel
String -> String -> String -> CharPos -> CharPos -> Loc
Loc -> Text -> LogLevel -> Text -> m ()
forall (m :: * -> *) msg.
(MonadLogger m, ToLogStr msg) =>
Loc -> Text -> LogLevel -> msg -> m ()
b :: Text
a :: Text
monadLoggerLog :: forall (m :: * -> *) msg.
(MonadLogger m, ToLogStr msg) =>
Loc -> Text -> LogLevel -> msg -> m ()
logDebugS) "Web" Text
msg
else m () -> IO ()
runner (m () -> IO ()) -> m () -> IO ()
forall a b. (a -> b) -> a -> b
$ $(Text
LogLevel
String -> String -> String -> CharPos -> CharPos -> Loc
Loc -> Text -> LogLevel -> Text -> m ()
forall (m :: * -> *) msg.
(MonadLogger m, ToLogStr msg) =>
Loc -> Text -> LogLevel -> msg -> m ()
b :: Text
a :: Text
monadLoggerLog :: forall (m :: * -> *) msg.
(MonadLogger m, ToLogStr msg) =>
Loc -> Text -> LogLevel -> msg -> m ()
logErrorS) "Web" Text
msg
Response -> IO ResponseReceived
respond Response
res
where
start :: IO UTCTime
start = SystemTime -> UTCTime
systemToUTCTime (SystemTime -> UTCTime) -> IO SystemTime -> IO UTCTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO SystemTime
getSystemTime
req_body :: TVar ByteString -> m ByteString -> m ByteString
req_body var :: TVar ByteString
var old_body :: m ByteString
old_body = do
ByteString
b <- m ByteString
old_body
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (ByteString -> Bool
B.null ByteString
b) (m () -> m ()) -> (STM () -> m ()) -> STM () -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STM () -> m ()
forall (m :: * -> *) a. MonadIO m => STM a -> m a
atomically (STM () -> m ()) -> STM () -> m ()
forall a b. (a -> b) -> a -> b
$ TVar ByteString -> (ByteString -> ByteString) -> STM ()
forall a. TVar a -> (a -> a) -> STM ()
modifyTVar TVar ByteString
var (ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
b)
ByteString -> m ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
b
add_stat :: Int64 -> a -> StatDist -> m ()
add_stat d :: Int64
d i :: a
i s :: StatDist
s = do
StatDist -> m ()
forall (m :: * -> *). MonadIO m => StatDist -> m ()
addStatQuery StatDist
s
StatDist -> Int64 -> m ()
forall (m :: * -> *). MonadIO m => StatDist -> Int64 -> m ()
addStatTime StatDist
s Int64
d
StatDist -> Int64 -> m ()
forall (m :: * -> *). MonadIO m => StatDist -> Int64 -> m ()
addStatItems StatDist
s (a -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i)
end :: TVar ByteString -> (m () -> IO ()) -> Request -> UTCTime -> IO ()
end var :: TVar ByteString
var runner :: m () -> IO ()
runner req :: Request
req t1 :: UTCTime
t1 = do
UTCTime
t2 <- SystemTime -> UTCTime
systemToUTCTime (SystemTime -> UTCTime) -> IO SystemTime -> IO UTCTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO SystemTime
getSystemTime
let diff :: Int64
diff = NominalDiffTime -> Int64
forall a b. (RealFrac a, Integral b) => a -> b
round (NominalDiffTime -> Int64) -> NominalDiffTime -> Int64
forall a b. (a -> b) -> a -> b
$ UTCTime -> UTCTime -> NominalDiffTime
diffUTCTime UTCTime
t2 UTCTime
t1 NominalDiffTime -> NominalDiffTime -> NominalDiffTime
forall a. Num a => a -> a -> a
* 1000
case Maybe WebMetrics
metrics of
Nothing -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just m :: WebMetrics
m -> do
let m_stat_var :: Maybe (TVar (Maybe (WebMetrics -> StatDist)))
m_stat_var = Key (TVar (Maybe (WebMetrics -> StatDist)))
-> Vault -> Maybe (TVar (Maybe (WebMetrics -> StatDist)))
forall a. Key a -> Vault -> Maybe a
V.lookup (WebMetrics -> Key (TVar (Maybe (WebMetrics -> StatDist)))
statKey WebMetrics
m) (Request -> Vault
vault Request
req)
m_item_var :: Maybe (TVar Int)
m_item_var = Key (TVar Int) -> Vault -> Maybe (TVar Int)
forall a. Key a -> Vault -> Maybe a
V.lookup (WebMetrics -> Key (TVar Int)
itemsKey WebMetrics
m) (Request -> Vault
vault Request
req)
Int
i <- case Maybe (TVar Int)
m_item_var of
Nothing -> Int -> IO Int
forall (m :: * -> *) a. Monad m => a -> m a
return 0
Just item_var :: TVar Int
item_var -> TVar Int -> IO Int
forall (m :: * -> *) a. MonadIO m => TVar a -> m a
readTVarIO TVar Int
item_var
Int64 -> Int -> StatDist -> IO ()
forall (m :: * -> *) a.
(MonadIO m, Integral a) =>
Int64 -> a -> StatDist -> m ()
add_stat Int64
diff Int
i (WebMetrics -> StatDist
everyStat WebMetrics
m)
case Maybe (TVar (Maybe (WebMetrics -> StatDist)))
m_stat_var of
Nothing -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just stat_var :: TVar (Maybe (WebMetrics -> StatDist))
stat_var ->
TVar (Maybe (WebMetrics -> StatDist))
-> IO (Maybe (WebMetrics -> StatDist))
forall (m :: * -> *) a. MonadIO m => TVar a -> m a
readTVarIO TVar (Maybe (WebMetrics -> StatDist))
stat_var IO (Maybe (WebMetrics -> StatDist))
-> (Maybe (WebMetrics -> StatDist) -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Nothing -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just f :: WebMetrics -> StatDist
f -> Int64 -> Int -> StatDist -> IO ()
forall (m :: * -> *) a.
(MonadIO m, Integral a) =>
Int64 -> a -> StatDist -> m ()
add_stat Int64
diff Int
i (WebMetrics -> StatDist
f WebMetrics
m)
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int64
diff Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
> 10000) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
ByteString
b <- TVar ByteString -> IO ByteString
forall (m :: * -> *) a. MonadIO m => TVar a -> m a
readTVarIO TVar ByteString
var
m () -> IO ()
runner (m () -> IO ()) -> m () -> IO ()
forall a b. (a -> b) -> a -> b
$ $(Text
LogLevel
String -> String -> String -> CharPos -> CharPos -> Loc
Loc -> Text -> LogLevel -> Text -> m ()
forall (m :: * -> *) msg.
(MonadLogger m, ToLogStr msg) =>
Loc -> Text -> LogLevel -> msg -> m ()
b :: Text
a :: Text
monadLoggerLog :: forall (m :: * -> *) msg.
(MonadLogger m, ToLogStr msg) =>
Loc -> Text -> LogLevel -> msg -> m ()
logWarnS) "Web" (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$
"Slow [" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a b. ConvertibleStrings a b => a -> b
cs (Int64 -> String
forall a. Show a => a -> String
show Int64
diff) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> " ms]: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ByteString -> Request -> Text
fmtReq ByteString
b Request
req
reqSizeLimit :: Middleware
reqSizeLimit :: Middleware
reqSizeLimit = RequestSizeLimitSettings -> Middleware
requestSizeLimitMiddleware RequestSizeLimitSettings
lim
where
max_len :: p -> m (Maybe a)
max_len _req :: p
_req = Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> Maybe a
forall a. a -> Maybe a
Just (256 a -> a -> a
forall a. Num a => a -> a -> a
* 1024))
lim :: RequestSizeLimitSettings
lim = (Word64 -> Middleware)
-> RequestSizeLimitSettings -> RequestSizeLimitSettings
setOnLengthExceeded Word64 -> Middleware
forall p p p t. p -> p -> p -> (Response -> t) -> t
too_big (RequestSizeLimitSettings -> RequestSizeLimitSettings)
-> RequestSizeLimitSettings -> RequestSizeLimitSettings
forall a b. (a -> b) -> a -> b
$
(Request -> IO (Maybe Word64))
-> RequestSizeLimitSettings -> RequestSizeLimitSettings
setMaxLengthForRequest Request -> IO (Maybe Word64)
forall (m :: * -> *) a p. (Monad m, Num a) => p -> m (Maybe a)
max_len (RequestSizeLimitSettings -> RequestSizeLimitSettings)
-> RequestSizeLimitSettings -> RequestSizeLimitSettings
forall a b. (a -> b) -> a -> b
$
RequestSizeLimitSettings
defaultRequestSizeLimitSettings
too_big :: p -> p -> p -> (Response -> t) -> t
too_big w64 :: p
w64 = \_app :: p
_app _req :: p
_req send :: Response -> t
send -> Response -> t
send (Response -> t) -> Response -> t
forall a b. (a -> b) -> a -> b
$
Status -> Except -> Response
waiExcept Status
requestEntityTooLarge413 Except
RequestTooLarge
fmtReq :: ByteString -> Request -> Text
fmtReq :: ByteString -> Request -> Text
fmtReq bs :: ByteString
bs req :: Request
req =
let m :: ByteString
m = Request -> ByteString
requestMethod Request
req
v :: HttpVersion
v = Request -> HttpVersion
httpVersion Request
req
p :: ByteString
p = Request -> ByteString
rawPathInfo Request
req
q :: ByteString
q = Request -> ByteString
rawQueryString Request
req
txt :: Text
txt = case ByteString -> Either UnicodeException Text
T.decodeUtf8' ByteString
bs of
Left _ -> " {invalid utf8}"
Right "" -> ""
Right t :: Text
t -> " [" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "]"
in ByteString -> Text
T.decodeUtf8 (ByteString
m ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> " " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
p ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
q ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> " " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> String -> ByteString
forall a b. ConvertibleStrings a b => a -> b
cs (HttpVersion -> String
forall a. Show a => a -> String
show HttpVersion
v)) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
txt
fmtStatus :: Status -> Text
fmtStatus :: Status -> Text
fmtStatus s :: Status
s = String -> Text
forall a b. ConvertibleStrings a b => a -> b
cs (Int -> String
forall a. Show a => a -> String
show (Status -> Int
statusCode Status
s)) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> " " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ByteString -> Text
forall a b. ConvertibleStrings a b => a -> b
cs (Status -> ByteString
statusMessage Status
s)