Compare commits
3 commits
0a2e585eb9
...
b3e33b798b
Author | SHA1 | Date | |
---|---|---|---|
b3e33b798b | |||
f386a6b974 | |||
de211d03b0 |
4 changed files with 42 additions and 9 deletions
|
@ -12,4 +12,4 @@ main = do
|
||||||
{-dataStorePath <- require config "dataStorePath"-}
|
{-dataStorePath <- require config "dataStorePath"-}
|
||||||
zebraPort <- require config "zebraPort"
|
zebraPort <- require config "zebraPort"
|
||||||
zebraHost <- require config "zebraHost"
|
zebraHost <- require config "zebraHost"
|
||||||
scanZebra 2764500 zebraHost zebraPort dbFilePath
|
scanZebra 2772000 zebraHost zebraPort dbFilePath
|
||||||
|
|
|
@ -5,15 +5,18 @@ module Zenith.Scanner where
|
||||||
import Control.Exception (throwIO, try)
|
import Control.Exception (throwIO, try)
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.HexString
|
import Data.HexString
|
||||||
|
import Data.Maybe
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import GHC.Utils.Monad (concatMapM)
|
import GHC.Utils.Monad (concatMapM)
|
||||||
import Network.HTTP.Simple (getResponseBody)
|
|
||||||
import ZcashHaskell.Types
|
import ZcashHaskell.Types
|
||||||
( BlockResponse(..)
|
( BlockResponse(..)
|
||||||
, RpcResponse(..)
|
, RawZebraTx(..)
|
||||||
|
, Transaction(..)
|
||||||
, ZebraGetBlockChainInfo(..)
|
, ZebraGetBlockChainInfo(..)
|
||||||
|
, ZebraTxResponse(..)
|
||||||
|
, fromRawTBundle
|
||||||
)
|
)
|
||||||
import ZcashHaskell.Utils (makeZebraCall)
|
import ZcashHaskell.Utils (makeZebraCall, readZebraTransaction)
|
||||||
import Zenith.Core (checkBlockChain)
|
import Zenith.Core (checkBlockChain)
|
||||||
import Zenith.DB (initRawStore)
|
import Zenith.DB (initRawStore)
|
||||||
import Zenith.Utils (jsonNumber)
|
import Zenith.Utils (jsonNumber)
|
||||||
|
@ -39,7 +42,7 @@ scanZebra b host port dbFilePath = do
|
||||||
let bList = [b .. (zgb_blocks bStatus)]
|
let bList = [b .. (zgb_blocks bStatus)]
|
||||||
txList <-
|
txList <-
|
||||||
try $ concatMapM (processBlock host port) bList :: IO
|
try $ concatMapM (processBlock host port) bList :: IO
|
||||||
(Either IOError [HexString])
|
(Either IOError [Transaction])
|
||||||
case txList of
|
case txList of
|
||||||
Left e1 -> print e1
|
Left e1 -> print e1
|
||||||
Right txList' -> print txList'
|
Right txList' -> print txList'
|
||||||
|
@ -49,7 +52,7 @@ processBlock ::
|
||||||
T.Text -- ^ Host name for `zebrad`
|
T.Text -- ^ Host name for `zebrad`
|
||||||
-> Int -- ^ Port for `zebrad`
|
-> Int -- ^ Port for `zebrad`
|
||||||
-> Int -- ^ The block number to process
|
-> Int -- ^ The block number to process
|
||||||
-> IO [HexString]
|
-> IO [Transaction]
|
||||||
processBlock host port b = do
|
processBlock host port b = do
|
||||||
r <-
|
r <-
|
||||||
makeZebraCall
|
makeZebraCall
|
||||||
|
@ -59,4 +62,34 @@ processBlock host port b = do
|
||||||
[Data.Aeson.String $ T.pack $ show b, jsonNumber 1]
|
[Data.Aeson.String $ T.pack $ show b, jsonNumber 1]
|
||||||
case r of
|
case r of
|
||||||
Left e -> throwIO $ userError e
|
Left e -> throwIO $ userError e
|
||||||
Right blk -> return $ bl_txs blk
|
Right blk -> do
|
||||||
|
x <- mapM (processTx host port) $ bl_txs blk
|
||||||
|
return $ catMaybes x
|
||||||
|
|
||||||
|
-- | Function to process a raw transaction
|
||||||
|
processTx ::
|
||||||
|
T.Text -- ^ Host name for `zebrad`
|
||||||
|
-> Int -- ^ Port for `zebrad`
|
||||||
|
-> HexString -- ^ transaction id
|
||||||
|
-> IO (Maybe Transaction)
|
||||||
|
processTx host port t = do
|
||||||
|
r <-
|
||||||
|
makeZebraCall
|
||||||
|
host
|
||||||
|
port
|
||||||
|
"getrawtransaction"
|
||||||
|
[Data.Aeson.String $ toText t, jsonNumber 1]
|
||||||
|
case r of
|
||||||
|
Left e -> throwIO $ userError e
|
||||||
|
Right rawTx -> do
|
||||||
|
case readZebraTransaction (ztr_hex rawTx) of
|
||||||
|
Nothing -> return Nothing
|
||||||
|
Just rzt ->
|
||||||
|
return $
|
||||||
|
Just $
|
||||||
|
Transaction
|
||||||
|
t
|
||||||
|
(ztr_blockheight rawTx)
|
||||||
|
(ztr_conf rawTx)
|
||||||
|
(fromIntegral $ zt_expiry rzt)
|
||||||
|
(fromRawTBundle $ zt_tBundle rzt)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit f0995441628381fee14ae1c655c3c4f8d96162e5
|
Subproject commit 4b064af4dece54fe51e3704aa95db18324167d36
|
|
@ -1,6 +1,6 @@
|
||||||
cabal-version: 3.0
|
cabal-version: 3.0
|
||||||
name: zenith
|
name: zenith
|
||||||
version: 0.4.4.1
|
version: 0.4.4.2
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Rene Vergara
|
author: Rene Vergara
|
||||||
|
|
Loading…
Reference in a new issue