Compare commits
No commits in common. "a79b86cc0505d40de042e11463a5cbc186a69453" and "b3e33b798bcafb772c0dc82644892f9d13353523" have entirely different histories.
a79b86cc05
...
b3e33b798b
6 changed files with 28 additions and 134 deletions
|
@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.4.4.3]
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
|
@ -15,7 +15,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Command line arguments to switch to legacy version
|
||||
- New configuration parameter for Zebra port
|
||||
- New functions to call `getinfo` and `getblockchaininfo` RPC methods
|
||||
- `Scanner` module
|
||||
|
||||
## [0.4.1]
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ import Zenith.Scanner (scanZebra)
|
|||
main :: IO ()
|
||||
main = do
|
||||
config <- load ["zenith.cfg"]
|
||||
--dbFilePath <- require config "dbFilePath"
|
||||
dataStorePath <- require config "dataStorePath"
|
||||
dbFilePath <- require config "dbFilePath"
|
||||
{-dataStorePath <- require config "dataStorePath"-}
|
||||
zebraPort <- require config "zebraPort"
|
||||
zebraHost <- require config "zebraHost"
|
||||
scanZebra 2781518 zebraHost zebraPort dataStorePath
|
||||
scanZebra 2772000 zebraHost zebraPort dbFilePath
|
||||
|
|
|
@ -17,27 +17,14 @@
|
|||
|
||||
module Zenith.DB where
|
||||
|
||||
import Control.Monad (when)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import qualified Data.ByteString as BS
|
||||
import Data.HexString
|
||||
import Data.Maybe (fromJust, isJust)
|
||||
import qualified Data.Text as T
|
||||
import Database.Persist
|
||||
import Database.Persist.Sqlite
|
||||
import Database.Persist.TH
|
||||
import Haskoin.Transaction.Common (TxOut(..))
|
||||
import ZcashHaskell.Types
|
||||
( OrchardAction(..)
|
||||
, OrchardBundle(..)
|
||||
, SaplingBundle(..)
|
||||
, Scope(..)
|
||||
, ShieldedOutput(..)
|
||||
, ShieldedSpend(..)
|
||||
, Transaction(..)
|
||||
, TransparentBundle(..)
|
||||
, ZcashNet
|
||||
)
|
||||
import ZcashHaskell.Types (Scope(..), ZcashNet)
|
||||
import Zenith.Types
|
||||
( HexStringDB(..)
|
||||
, OrchardSpendingKeyDB(..)
|
||||
|
@ -88,11 +75,8 @@ share
|
|||
txId HexStringDB
|
||||
conf Int
|
||||
time Int
|
||||
hex HexStringDB
|
||||
deriving Show Eq
|
||||
TransparentNote
|
||||
tx WalletTransactionId
|
||||
value Int
|
||||
script BS.ByteString
|
||||
OrchAction
|
||||
tx WalletTransactionId
|
||||
nf HexStringDB
|
||||
|
@ -210,65 +194,3 @@ saveAddress ::
|
|||
-> WalletAddress -- ^ The wallet to add to the database
|
||||
-> IO (Maybe (Entity WalletAddress))
|
||||
saveAddress dbFp w = runSqlite dbFp $ insertUniqueEntity w
|
||||
|
||||
-- | Save a transaction to the data model
|
||||
saveTransaction ::
|
||||
T.Text -- ^ the database path
|
||||
-> Int -- ^ block time
|
||||
-> Transaction -- ^ The transaction to save
|
||||
-> IO (Key WalletTransaction)
|
||||
saveTransaction dbFp t wt =
|
||||
runSqlite dbFp $ do
|
||||
w <-
|
||||
insert $
|
||||
WalletTransaction (tx_height wt) (HexStringDB $ tx_id wt) (tx_conf wt) t
|
||||
when (isJust $ tx_transpBundle wt) $
|
||||
insertMany_ $
|
||||
map (storeTxOut w) $ (tb_vout . fromJust . tx_transpBundle) wt
|
||||
when (isJust $ tx_saplingBundle wt) $ do
|
||||
_ <-
|
||||
insertMany_ $
|
||||
map (storeSapSpend w) $ (sbSpends . fromJust . tx_saplingBundle) wt
|
||||
_ <-
|
||||
insertMany_ $
|
||||
map (storeSapOutput w) $ (sbOutputs . fromJust . tx_saplingBundle) wt
|
||||
return ()
|
||||
when (isJust $ tx_orchardBundle wt) $
|
||||
insertMany_ $
|
||||
map (storeOrchAction w) $ (obActions . fromJust . tx_orchardBundle) wt
|
||||
return w
|
||||
where
|
||||
storeTxOut :: WalletTransactionId -> TxOut -> TransparentNote
|
||||
storeTxOut wid (TxOut v s) = TransparentNote wid (fromIntegral v) s
|
||||
storeSapSpend :: WalletTransactionId -> ShieldedSpend -> ShieldSpend
|
||||
storeSapSpend wid sp =
|
||||
ShieldSpend
|
||||
wid
|
||||
(HexStringDB $ sp_cv sp)
|
||||
(HexStringDB $ sp_anchor sp)
|
||||
(HexStringDB $ sp_nullifier sp)
|
||||
(HexStringDB $ sp_rk sp)
|
||||
(HexStringDB $ sp_proof sp)
|
||||
(HexStringDB $ sp_auth sp)
|
||||
storeSapOutput :: WalletTransactionId -> ShieldedOutput -> ShieldOutput
|
||||
storeSapOutput wid so =
|
||||
ShieldOutput
|
||||
wid
|
||||
(HexStringDB $ s_cv so)
|
||||
(HexStringDB $ s_cmu so)
|
||||
(HexStringDB $ s_ephKey so)
|
||||
(HexStringDB $ s_encCipherText so)
|
||||
(HexStringDB $ s_outCipherText so)
|
||||
(HexStringDB $ s_proof so)
|
||||
storeOrchAction :: WalletTransactionId -> OrchardAction -> OrchAction
|
||||
storeOrchAction wid oa =
|
||||
OrchAction
|
||||
wid
|
||||
(HexStringDB $ nf oa)
|
||||
(HexStringDB $ rk oa)
|
||||
(HexStringDB $ cmx oa)
|
||||
(HexStringDB $ eph_key oa)
|
||||
(HexStringDB $ enc_ciphertext oa)
|
||||
(HexStringDB $ out_ciphertext oa)
|
||||
(HexStringDB $ cv oa)
|
||||
(HexStringDB $ auth oa)
|
||||
|
|
|
@ -14,13 +14,11 @@ import ZcashHaskell.Types
|
|||
, Transaction(..)
|
||||
, ZebraGetBlockChainInfo(..)
|
||||
, ZebraTxResponse(..)
|
||||
, fromRawOBundle
|
||||
, fromRawSBundle
|
||||
, fromRawTBundle
|
||||
)
|
||||
import ZcashHaskell.Utils (getBlockTime, makeZebraCall, readZebraTransaction)
|
||||
import ZcashHaskell.Utils (makeZebraCall, readZebraTransaction)
|
||||
import Zenith.Core (checkBlockChain)
|
||||
import Zenith.DB (initRawStore, saveTransaction)
|
||||
import Zenith.DB (initRawStore)
|
||||
import Zenith.Utils (jsonNumber)
|
||||
|
||||
-- | Function to scan the Zcash blockchain through the Zebra node and populate the Zenith database
|
||||
|
@ -43,8 +41,8 @@ scanZebra b host port dbFilePath = do
|
|||
else do
|
||||
let bList = [b .. (zgb_blocks bStatus)]
|
||||
txList <-
|
||||
try $ mapM_ (processBlock host port dbFilePath) bList :: IO
|
||||
(Either IOError ())
|
||||
try $ concatMapM (processBlock host port) bList :: IO
|
||||
(Either IOError [Transaction])
|
||||
case txList of
|
||||
Left e1 -> print e1
|
||||
Right txList' -> print txList'
|
||||
|
@ -53,10 +51,9 @@ scanZebra b host port dbFilePath = do
|
|||
processBlock ::
|
||||
T.Text -- ^ Host name for `zebrad`
|
||||
-> Int -- ^ Port for `zebrad`
|
||||
-> T.Text -- ^ DB file path
|
||||
-> Int -- ^ The block number to process
|
||||
-> IO ()
|
||||
processBlock host port dbFp b = do
|
||||
-> IO [Transaction]
|
||||
processBlock host port b = do
|
||||
r <-
|
||||
makeZebraCall
|
||||
host
|
||||
|
@ -66,36 +63,16 @@ processBlock host port dbFp b = do
|
|||
case r of
|
||||
Left e -> throwIO $ userError e
|
||||
Right blk -> do
|
||||
r2 <-
|
||||
makeZebraCall
|
||||
host
|
||||
port
|
||||
"getblock"
|
||||
[Data.Aeson.String $ T.pack $ show b, jsonNumber 0]
|
||||
case r2 of
|
||||
Left e2 -> throwIO $ userError e2
|
||||
Right hb -> do
|
||||
let blockTime = getBlockTime hb
|
||||
mapM_ (processTx host port blockTime dbFp) $
|
||||
bl_txs $ addTime blk blockTime
|
||||
where
|
||||
addTime :: BlockResponse -> Int -> BlockResponse
|
||||
addTime bl t =
|
||||
BlockResponse
|
||||
(bl_confirmations bl)
|
||||
(bl_height bl)
|
||||
(fromIntegral t)
|
||||
(bl_txs bl)
|
||||
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`
|
||||
-> Int -- ^ Block time
|
||||
-> T.Text -- ^ DB file path
|
||||
-> HexString -- ^ transaction id
|
||||
-> IO ()
|
||||
processTx host port bt dbFp t = do
|
||||
-> IO (Maybe Transaction)
|
||||
processTx host port t = do
|
||||
r <-
|
||||
makeZebraCall
|
||||
host
|
||||
|
@ -106,16 +83,13 @@ processTx host port bt dbFp t = do
|
|||
Left e -> throwIO $ userError e
|
||||
Right rawTx -> do
|
||||
case readZebraTransaction (ztr_hex rawTx) of
|
||||
Nothing -> return ()
|
||||
Just rzt -> do
|
||||
k <-
|
||||
saveTransaction dbFp bt $
|
||||
Transaction
|
||||
t
|
||||
(ztr_blockheight rawTx)
|
||||
(ztr_conf rawTx)
|
||||
(fromIntegral $ zt_expiry rzt)
|
||||
(fromRawTBundle $ zt_tBundle rzt)
|
||||
(fromRawSBundle $ zt_sBundle rzt)
|
||||
(fromRawOBundle $ zt_oBundle rzt)
|
||||
print k
|
||||
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 938ccb4b9730fd8615513eb27bdbffacd62e29cc
|
||||
Subproject commit 4b064af4dece54fe51e3704aa95db18324167d36
|
|
@ -1,6 +1,6 @@
|
|||
cabal-version: 3.0
|
||||
name: zenith
|
||||
version: 0.4.4.3
|
||||
version: 0.4.4.2
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
author: Rene Vergara
|
||||
|
@ -44,7 +44,6 @@ library
|
|||
, brick
|
||||
, bytestring
|
||||
, ghc
|
||||
, haskoin-core
|
||||
, hexstring
|
||||
, http-client
|
||||
, http-conduit
|
||||
|
|
Loading…
Reference in a new issue