Compare commits
No commits in common. "865f7241b1fcff64ba26b44a931385bde79685a4" and "a79b86cc0505d40de042e11463a5cbc186a69453" have entirely different histories.
865f7241b1
...
a79b86cc05
6 changed files with 38 additions and 96 deletions
|
@ -8,7 +8,8 @@ import Zenith.Scanner (scanZebra)
|
|||
main :: IO ()
|
||||
main = do
|
||||
config <- load ["zenith.cfg"]
|
||||
dbFilePath <- require config "dbFilePath"
|
||||
--dbFilePath <- require config "dbFilePath"
|
||||
dataStorePath <- require config "dataStorePath"
|
||||
zebraPort <- require config "zebraPort"
|
||||
zebraHost <- require config "zebraHost"
|
||||
scanZebra 2762066 zebraHost zebraPort dbFilePath
|
||||
scanZebra 2781518 zebraHost zebraPort dataStorePath
|
||||
|
|
|
@ -157,11 +157,3 @@ createWalletAddress n i zNet scope za = do
|
|||
(UnifiedAddressDB $
|
||||
encodeUnifiedAddress $ UnifiedAddress zNet oRec sRec (Just tRec))
|
||||
(ScopeDB scope)
|
||||
|
||||
-- * Wallet
|
||||
-- | Sync the wallet with the data store
|
||||
syncWallet ::
|
||||
T.Text -- ^ The database path
|
||||
-> Entity ZcashWallet
|
||||
-> IO ()
|
||||
syncWallet walletDb w = undefined
|
||||
|
|
|
@ -78,49 +78,23 @@ share
|
|||
UniqueAddress index scope accId
|
||||
UniqueAddName accId name
|
||||
deriving Show Eq
|
||||
|]
|
||||
|
||||
share
|
||||
[mkPersist sqlSettings, mkMigrate "rawStorage"]
|
||||
[persistLowerCase|
|
||||
WalletTransaction
|
||||
txId HexStringDB
|
||||
block Int
|
||||
conf Int
|
||||
time Int
|
||||
deriving Show Eq
|
||||
WalletTrNote
|
||||
tx WalletTransactionId
|
||||
addrId WalletAddressId
|
||||
value Int
|
||||
rawId TransparentNoteId
|
||||
spent Bool
|
||||
deriving Show Eq
|
||||
WalletSapNote
|
||||
tx WalletTransactionId
|
||||
addrId WalletAddressId
|
||||
value Int
|
||||
recipient BS.ByteString
|
||||
memo T.Text
|
||||
rawId ShieldOutputId
|
||||
spent Bool
|
||||
deriving Show Eq
|
||||
WalletOrchNote
|
||||
tx WalletTransactionId
|
||||
addrId WalletAddressId
|
||||
value Int
|
||||
recipient BS.ByteString
|
||||
memo T.Text
|
||||
rawId OrchActionId
|
||||
spent Bool
|
||||
deriving Show Eq
|
||||
ZcashTransaction
|
||||
block Int
|
||||
txId HexStringDB
|
||||
conf Int
|
||||
time Int
|
||||
deriving Show Eq
|
||||
TransparentNote
|
||||
tx ZcashTransactionId
|
||||
tx WalletTransactionId
|
||||
value Int
|
||||
script BS.ByteString
|
||||
OrchAction
|
||||
tx ZcashTransactionId
|
||||
tx WalletTransactionId
|
||||
nf HexStringDB
|
||||
rk HexStringDB
|
||||
cmx HexStringDB
|
||||
|
@ -131,7 +105,7 @@ share
|
|||
auth HexStringDB
|
||||
deriving Show Eq
|
||||
ShieldOutput
|
||||
tx ZcashTransactionId
|
||||
tx WalletTransactionId
|
||||
cv HexStringDB
|
||||
cmu HexStringDB
|
||||
ephKey HexStringDB
|
||||
|
@ -140,7 +114,7 @@ share
|
|||
proof HexStringDB
|
||||
deriving Show Eq
|
||||
ShieldSpend
|
||||
tx ZcashTransactionId
|
||||
tx WalletTransactionId
|
||||
cv HexStringDB
|
||||
anchor HexStringDB
|
||||
nullifier HexStringDB
|
||||
|
@ -158,6 +132,12 @@ initDb ::
|
|||
initDb dbName = do
|
||||
runSqlite dbName $ do runMigration migrateAll
|
||||
|
||||
-- | Initializes the raw data storage
|
||||
initRawStore ::
|
||||
T.Text -- ^ the database path
|
||||
-> IO ()
|
||||
initRawStore dbFilePath = runSqlite dbFilePath $ runMigration rawStorage
|
||||
|
||||
-- | Get existing wallets from database
|
||||
getWallets :: T.Text -> ZcashNet -> IO [Entity ZcashWallet]
|
||||
getWallets dbFp n =
|
||||
|
@ -197,30 +177,6 @@ saveAccount ::
|
|||
-> IO (Maybe (Entity ZcashAccount))
|
||||
saveAccount dbFp a = runSqlite dbFp $ insertUniqueEntity a
|
||||
|
||||
-- | Returns the largest block in storage
|
||||
getMaxBlock ::
|
||||
T.Text -- ^ The database path
|
||||
-> IO Int
|
||||
getMaxBlock dbPath = do
|
||||
b <-
|
||||
runSqlite dbPath $
|
||||
selectFirst [ZcashTransactionBlock >. 0] [Desc ZcashTransactionBlock]
|
||||
case b of
|
||||
Nothing -> return $ -1
|
||||
Just x -> return $ zcashTransactionBlock $ entityVal x
|
||||
|
||||
-- | Returns the largest block in the wallet
|
||||
getMaxWalletBlock ::
|
||||
T.Text -- ^ The database path
|
||||
-> IO Int
|
||||
getMaxWalletBlock dbPath = do
|
||||
b <-
|
||||
runSqlite dbPath $
|
||||
selectFirst [WalletTransactionBlock >. 0] [Desc WalletTransactionBlock]
|
||||
case b of
|
||||
Nothing -> return $ -1
|
||||
Just x -> return $ walletTransactionBlock $ entityVal x
|
||||
|
||||
-- | Returns a list of addresses associated with the given account
|
||||
getAddresses ::
|
||||
T.Text -- ^ The database path
|
||||
|
@ -260,12 +216,12 @@ saveTransaction ::
|
|||
T.Text -- ^ the database path
|
||||
-> Int -- ^ block time
|
||||
-> Transaction -- ^ The transaction to save
|
||||
-> IO (Key ZcashTransaction)
|
||||
-> IO (Key WalletTransaction)
|
||||
saveTransaction dbFp t wt =
|
||||
runSqlite dbFp $ do
|
||||
w <-
|
||||
insert $
|
||||
ZcashTransaction (tx_height wt) (HexStringDB $ tx_id wt) (tx_conf wt) t
|
||||
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
|
||||
|
@ -282,9 +238,9 @@ saveTransaction dbFp t wt =
|
|||
map (storeOrchAction w) $ (obActions . fromJust . tx_orchardBundle) wt
|
||||
return w
|
||||
where
|
||||
storeTxOut :: ZcashTransactionId -> TxOut -> TransparentNote
|
||||
storeTxOut :: WalletTransactionId -> TxOut -> TransparentNote
|
||||
storeTxOut wid (TxOut v s) = TransparentNote wid (fromIntegral v) s
|
||||
storeSapSpend :: ZcashTransactionId -> ShieldedSpend -> ShieldSpend
|
||||
storeSapSpend :: WalletTransactionId -> ShieldedSpend -> ShieldSpend
|
||||
storeSapSpend wid sp =
|
||||
ShieldSpend
|
||||
wid
|
||||
|
@ -294,7 +250,7 @@ saveTransaction dbFp t wt =
|
|||
(HexStringDB $ sp_rk sp)
|
||||
(HexStringDB $ sp_proof sp)
|
||||
(HexStringDB $ sp_auth sp)
|
||||
storeSapOutput :: ZcashTransactionId -> ShieldedOutput -> ShieldOutput
|
||||
storeSapOutput :: WalletTransactionId -> ShieldedOutput -> ShieldOutput
|
||||
storeSapOutput wid so =
|
||||
ShieldOutput
|
||||
wid
|
||||
|
@ -304,7 +260,7 @@ saveTransaction dbFp t wt =
|
|||
(HexStringDB $ s_encCipherText so)
|
||||
(HexStringDB $ s_outCipherText so)
|
||||
(HexStringDB $ s_proof so)
|
||||
storeOrchAction :: ZcashTransactionId -> OrchardAction -> OrchAction
|
||||
storeOrchAction :: WalletTransactionId -> OrchardAction -> OrchAction
|
||||
storeOrchAction wid oa =
|
||||
OrchAction
|
||||
wid
|
||||
|
|
|
@ -8,7 +8,6 @@ import Data.HexString
|
|||
import Data.Maybe
|
||||
import qualified Data.Text as T
|
||||
import GHC.Utils.Monad (concatMapM)
|
||||
import System.Console.AsciiProgress
|
||||
import ZcashHaskell.Types
|
||||
( BlockResponse(..)
|
||||
, RawZebraTx(..)
|
||||
|
@ -21,7 +20,7 @@ import ZcashHaskell.Types
|
|||
)
|
||||
import ZcashHaskell.Utils (getBlockTime, makeZebraCall, readZebraTransaction)
|
||||
import Zenith.Core (checkBlockChain)
|
||||
import Zenith.DB (getMaxBlock, initDb, saveTransaction)
|
||||
import Zenith.DB (initRawStore, saveTransaction)
|
||||
import Zenith.Utils (jsonNumber)
|
||||
|
||||
-- | Function to scan the Zcash blockchain through the Zebra node and populate the Zenith database
|
||||
|
@ -32,37 +31,32 @@ scanZebra ::
|
|||
-> T.Text -- ^ Path to database file
|
||||
-> IO ()
|
||||
scanZebra b host port dbFilePath = do
|
||||
_ <- initDb dbFilePath
|
||||
_ <- initRawStore dbFilePath
|
||||
bc <-
|
||||
try $ checkBlockChain host port :: IO
|
||||
(Either IOError ZebraGetBlockChainInfo)
|
||||
case bc of
|
||||
Left e -> print e
|
||||
Right bStatus -> do
|
||||
dbBlock <- getMaxBlock dbFilePath
|
||||
let sb = max dbBlock b
|
||||
if sb > zgb_blocks bStatus || sb < 1
|
||||
if b > zgb_blocks bStatus || b < 1
|
||||
then throwIO $ userError "Invalid starting block for scan"
|
||||
else do
|
||||
let bList = [sb .. (zgb_blocks bStatus)]
|
||||
displayConsoleRegions $ do
|
||||
pg <- newProgressBar def {pgTotal = fromIntegral $ length bList}
|
||||
txList <-
|
||||
try $ mapM_ (processBlock host port dbFilePath pg) bList :: IO
|
||||
(Either IOError ())
|
||||
case txList of
|
||||
Left e1 -> print e1
|
||||
Right txList' -> print txList'
|
||||
let bList = [b .. (zgb_blocks bStatus)]
|
||||
txList <-
|
||||
try $ mapM_ (processBlock host port dbFilePath) bList :: IO
|
||||
(Either IOError ())
|
||||
case txList of
|
||||
Left e1 -> print e1
|
||||
Right txList' -> print txList'
|
||||
|
||||
-- | Function to process a raw block and extract the transaction information
|
||||
processBlock ::
|
||||
T.Text -- ^ Host name for `zebrad`
|
||||
-> Int -- ^ Port for `zebrad`
|
||||
-> T.Text -- ^ DB file path
|
||||
-> ProgressBar -- ^ Progress bar
|
||||
-> Int -- ^ The block number to process
|
||||
-> IO ()
|
||||
processBlock host port dbFp pg b = do
|
||||
processBlock host port dbFp b = do
|
||||
r <-
|
||||
makeZebraCall
|
||||
host
|
||||
|
@ -84,7 +78,6 @@ processBlock host port dbFp pg b = do
|
|||
let blockTime = getBlockTime hb
|
||||
mapM_ (processTx host port blockTime dbFp) $
|
||||
bl_txs $ addTime blk blockTime
|
||||
tick pg
|
||||
where
|
||||
addTime :: BlockResponse -> Int -> BlockResponse
|
||||
addTime bl t =
|
||||
|
@ -115,7 +108,7 @@ processTx host port bt dbFp t = do
|
|||
case readZebraTransaction (ztr_hex rawTx) of
|
||||
Nothing -> return ()
|
||||
Just rzt -> do
|
||||
_ <-
|
||||
k <-
|
||||
saveTransaction dbFp bt $
|
||||
Transaction
|
||||
t
|
||||
|
@ -125,4 +118,4 @@ processTx host port bt dbFp t = do
|
|||
(fromRawTBundle $ zt_tBundle rzt)
|
||||
(fromRawSBundle $ zt_sBundle rzt)
|
||||
(fromRawOBundle $ zt_oBundle rzt)
|
||||
return ()
|
||||
print k
|
||||
|
|
|
@ -65,7 +65,6 @@ library
|
|||
, vector
|
||||
, vty
|
||||
, word-wrap
|
||||
, ascii-progress
|
||||
, zcash-haskell
|
||||
--pkgconfig-depends: rustzcash_wrapper
|
||||
default-language: Haskell2010
|
||||
|
|
|
@ -3,3 +3,4 @@ nodePwd = "superSecret"
|
|||
dbFilePath = "zenith.db"
|
||||
zebraHost = "127.0.0.1"
|
||||
zebraPort = 18232
|
||||
dataStorePath = "datastore.db"
|
||||
|
|
Loading…
Reference in a new issue