@@ -44,7 +44,8 @@ import Network.Wai.Middleware.RequestLogger (logStdoutDev)
44
44
45
45
import qualified Serokell.Util.Base64 as B64
46
46
import Servant.Generic (AsServerT , toServant )
47
- import Servant.Server (Server , ServerT , serve )
47
+ import Servant.Server (Server , ServerT , err405 , errReasonPhrase ,
48
+ serve )
48
49
import System.Wlog (logDebug )
49
50
50
51
import Pos.Crypto (WithHash (.. ), hash , redeemPkBuild , withHash )
@@ -65,10 +66,10 @@ import Pos.Core (AddrType (..), Address (..), Coin, EpochIndex,
65
66
import Pos.Core.Block (Block , HeaderHash , MainBlock , gbHeader ,
66
67
gbhConsensus , mainBlockSlot , mainBlockTxPayload , mcdSlot )
67
68
import Pos.Core.Chrono (NewestFirst (.. ))
68
- import Pos.Core.Txp (Tx (.. ), TxAux , TxId , TxOutAux (.. ), taTx ,
69
- txOutValue , txpTxs , _txOutputs )
70
- import Pos.DB.Txp (MonadTxpMem , getLocalTxs , getMemPool ,
71
- withTxpLocalData )
69
+ import Pos.Core.Txp (Tx (.. ), TxAux , TxId , TxIn (.. ), TxOutAux ( .. ) ,
70
+ taTx , txOutAddress , txOutValue , txpTxs , _txOutputs )
71
+ import Pos.DB.Txp (MonadTxpMem , getFilteredUtxo , getLocalTxs ,
72
+ getMemPool , withTxpLocalData )
72
73
import Pos.Infra.Slotting (MonadSlots (.. ), getSlotStart )
73
74
import Pos.Util (divRoundUp , maybeThrow )
74
75
import Pos.Web (serveImpl )
@@ -86,15 +87,18 @@ import Pos.Explorer.Web.Api (ExplorerApi, ExplorerApiRecord (..),
86
87
import Pos.Explorer.Web.ClientTypes (Byte , CAda (.. ), CAddress (.. ),
87
88
CAddressSummary (.. ), CAddressType (.. ),
88
89
CAddressesFilter (.. ), CBlockEntry (.. ),
89
- CBlockSummary (.. ), CGenesisAddressInfo (.. ),
90
- CGenesisSummary (.. ), CHash , CTxBrief (.. ), CTxEntry (.. ),
91
- CTxId (.. ), CTxSummary (.. ), TxInternal (.. ),
92
- convertTxOutputs , convertTxOutputsMB , fromCAddress ,
93
- fromCHash , fromCTxId , getEpochIndex , getSlotIndex ,
94
- mkCCoin , mkCCoinMB , tiToTxEntry , toBlockEntry ,
95
- toBlockSummary , toCAddress , toCHash , toCTxId , toTxBrief )
90
+ CBlockSummary (.. ), CByteString (.. ),
91
+ CGenesisAddressInfo (.. ), CGenesisSummary (.. ), CHash ,
92
+ CTxBrief (.. ), CTxEntry (.. ), CTxId (.. ), CTxSummary (.. ),
93
+ CUtxo (.. ), TxInternal (.. ), convertTxOutputs ,
94
+ convertTxOutputsMB , fromCAddress , fromCHash , fromCTxId ,
95
+ getEpochIndex , getSlotIndex , mkCCoin , mkCCoinMB ,
96
+ tiToTxEntry , toBlockEntry , toBlockSummary , toCAddress ,
97
+ toCHash , toCTxId , toTxBrief )
96
98
import Pos.Explorer.Web.Error (ExplorerError (.. ))
97
99
100
+ import qualified Data.Map as M
101
+ import Pos.Configuration (explorerExtendedApi )
98
102
99
103
100
104
----------------------------------------------------------------
@@ -132,6 +136,7 @@ explorerHandlers _diffusion =
132
136
, _txsLast = getLastTxs
133
137
, _txsSummary = getTxSummary
134
138
, _addressSummary = getAddressSummary
139
+ , _addressUtxoBulk = getAddressUtxoBulk
135
140
, _epochPages = getEpochPage
136
141
, _epochSlots = getEpochSlot
137
142
, _genesisSummary = getGenesisSummary
@@ -371,6 +376,42 @@ getAddressSummary cAddr = do
371
376
ATRedeem -> CRedeemAddress
372
377
ATUnknown {} -> CUnknownAddress
373
378
379
+
380
+ getAddressUtxoBulk
381
+ :: (ExplorerMode ctx m )
382
+ => [CAddress ]
383
+ -> m [CUtxo ]
384
+ getAddressUtxoBulk cAddrs = do
385
+ unless explorerExtendedApi $
386
+ throwM err405
387
+ { errReasonPhrase = " Explorer extended API is disabled by configuration!"
388
+ }
389
+
390
+ let nAddrs = length cAddrs
391
+
392
+ when (nAddrs > 10 ) $
393
+ throwM err405
394
+ { errReasonPhrase = " Maximum number of addresses you can send to fetch Utxo in bulk is 10!"
395
+ }
396
+
397
+ addrs <- mapM cAddrToAddr cAddrs
398
+ utxo <- getFilteredUtxo addrs
399
+
400
+ pure . map futxoToCUtxo . M. toList $ utxo
401
+ where
402
+ futxoToCUtxo :: (TxIn , TxOutAux ) -> CUtxo
403
+ futxoToCUtxo ((TxInUtxo txInHash txInIndex), txOutAux) = CUtxo {
404
+ cuId = toCTxId txInHash,
405
+ cuOutIndex = fromIntegral txInIndex,
406
+ cuAddress = toCAddress . txOutAddress . toaOut $ txOutAux,
407
+ cuCoins = mkCCoin . txOutValue . toaOut $ txOutAux
408
+ }
409
+ futxoToCUtxo ((TxInUnknown tag bs), _) = CUtxoUnknown {
410
+ cuTag = fromIntegral tag,
411
+ cuBs = CByteString bs
412
+ }
413
+
414
+
374
415
-- | Get transaction summary from transaction id. Looks at both the database
375
416
-- and the memory (mempool) for the transaction. What we have at the mempool
376
417
-- are transactions that have to be written in the blockchain.
0 commit comments