Refactor for new schema for ZcashTransaction
This commit is contained in:
parent
46b4969da5
commit
c68c504b53
5 changed files with 29 additions and 17 deletions
|
@ -717,10 +717,10 @@ abMBarAttr = A.attrName "menubar"
|
|||
|
||||
scanZebra ::
|
||||
T.Text -> T.Text -> Int -> Int -> BC.BChan Tick -> ZcashNet -> IO ()
|
||||
scanZebra dbP zHost zPort b eChan net = do
|
||||
scanZebra dbP zHost zPort b eChan znet = do
|
||||
bStatus <- liftIO $ checkBlockChain zHost zPort
|
||||
pool <- runNoLoggingT $ initPool dbP
|
||||
dbBlock <- runNoLoggingT $ getMaxBlock pool
|
||||
dbBlock <- getMaxBlock pool $ ZcashNetDB znet
|
||||
confUp <- try $ updateConfs zHost zPort pool :: IO (Either IOError ())
|
||||
case confUp of
|
||||
Left _e0 ->
|
||||
|
@ -765,7 +765,7 @@ scanZebra dbP zHost zPort b eChan net = do
|
|||
Left e2 -> liftIO $ BC.writeBChan eChan $ TickMsg e2
|
||||
Right hb -> do
|
||||
let blockTime = getBlockTime hb
|
||||
mapM_ (processTx zHost zPort blockTime pool (ZcashNetDB net)) $
|
||||
mapM_ (processTx zHost zPort blockTime pool (ZcashNetDB znet)) $
|
||||
bl_txs $ addTime blk blockTime
|
||||
liftIO $ BC.writeBChan eChan $ TickVal step
|
||||
addTime :: BlockResponse -> Int -> BlockResponse
|
||||
|
|
|
@ -237,7 +237,7 @@ findSaplingOutputs config b znet za = do
|
|||
let zebraPort = c_zebraPort config
|
||||
let zn = getNet znet
|
||||
pool <- runNoLoggingT $ initPool dbPath
|
||||
tList <- getShieldedOutputs pool b
|
||||
tList <- getShieldedOutputs pool b znet
|
||||
trees <- getCommitmentTrees zebraHost zebraPort (b - 1)
|
||||
let sT = SaplingCommitmentTree $ ztiSapling trees
|
||||
decryptNotes sT zn pool tList
|
||||
|
@ -328,7 +328,7 @@ findOrchardActions config b znet za = do
|
|||
let zebraPort = c_zebraPort config
|
||||
let zn = getNet znet
|
||||
pool <- runNoLoggingT $ initPool dbPath
|
||||
tList <- getOrchardActions pool b
|
||||
tList <- getOrchardActions pool b znet
|
||||
trees <- getCommitmentTrees zebraHost zebraPort (b - 1)
|
||||
let sT = OrchardCommitmentTree $ ztiOrchard trees
|
||||
decryptNotes sT zn pool tList
|
||||
|
@ -700,19 +700,20 @@ syncWallet ::
|
|||
syncWallet config w = do
|
||||
startTime <- liftIO getCurrentTime
|
||||
let walletDb = c_dbPath config
|
||||
let znet = zcashWalletNetwork $ entityVal w
|
||||
pool <- runNoLoggingT $ initPool walletDb
|
||||
accs <- runNoLoggingT $ getAccounts pool $ entityKey w
|
||||
addrs <- concat <$> mapM (runNoLoggingT . getAddresses pool . entityKey) accs
|
||||
intAddrs <-
|
||||
concat <$> mapM (runNoLoggingT . getInternalAddresses pool . entityKey) accs
|
||||
chainTip <- runNoLoggingT $ getMaxBlock pool
|
||||
chainTip <- getMaxBlock pool znet
|
||||
let lastBlock = zcashWalletLastSync $ entityVal w
|
||||
let startBlock =
|
||||
if lastBlock > 0
|
||||
then lastBlock
|
||||
else zcashWalletBirthdayHeight $ entityVal w
|
||||
mapM_ (liftIO . findTransparentNotes pool startBlock) addrs
|
||||
mapM_ (liftIO . findTransparentNotes pool startBlock) intAddrs
|
||||
mapM_ (liftIO . findTransparentNotes pool startBlock znet) addrs
|
||||
mapM_ (liftIO . findTransparentNotes pool startBlock znet) intAddrs
|
||||
mapM_ (liftIO . findTransparentSpends pool . entityKey) accs
|
||||
sapNotes <-
|
||||
liftIO $
|
||||
|
|
|
@ -450,14 +450,17 @@ saveAccount pool a =
|
|||
-- | Returns the largest block in storage
|
||||
getMaxBlock ::
|
||||
Pool SqlBackend -- ^ The database pool
|
||||
-> NoLoggingT IO Int
|
||||
getMaxBlock pool = do
|
||||
-> ZcashNetDB
|
||||
-> IO Int
|
||||
getMaxBlock pool net = do
|
||||
b <-
|
||||
runNoLoggingT $
|
||||
PS.retryOnBusy $
|
||||
flip PS.runSqlPool pool $ do
|
||||
selectOne $ do
|
||||
txs <- from $ table @ZcashTransaction
|
||||
where_ (txs ^. ZcashTransactionBlock >. val 0)
|
||||
where_ (txs ^. ZcashTransactionNetwork ==. val net)
|
||||
orderBy [desc $ txs ^. ZcashTransactionBlock]
|
||||
pure txs
|
||||
case b of
|
||||
|
@ -645,14 +648,16 @@ saveTransaction pool t n wt =
|
|||
getZcashTransactions ::
|
||||
ConnectionPool -- ^ The database path
|
||||
-> Int -- ^ Block
|
||||
-> ZcashNet -- ^ Network
|
||||
-> IO [Entity ZcashTransaction]
|
||||
getZcashTransactions pool b =
|
||||
getZcashTransactions pool b net =
|
||||
runNoLoggingT $
|
||||
PS.retryOnBusy $
|
||||
flip PS.runSqlPool pool $ do
|
||||
select $ do
|
||||
txs <- from $ table @ZcashTransaction
|
||||
where_ $ txs ^. ZcashTransactionBlock >. val b
|
||||
where_ (txs ^. ZcashTransactionBlock >. val b)
|
||||
where_ (txs ^. ZcashTransactionNetwork ==. val (ZcashNetDB net))
|
||||
orderBy [asc $ txs ^. ZcashTransactionBlock]
|
||||
return txs
|
||||
|
||||
|
@ -832,9 +837,10 @@ saveWalletOrchNote pool wId pos wit ch za zt dn = do
|
|||
findTransparentNotes ::
|
||||
ConnectionPool -- ^ The database path
|
||||
-> Int -- ^ Starting block
|
||||
-> ZcashNetDB -- ^ Network to use
|
||||
-> Entity WalletAddress
|
||||
-> IO ()
|
||||
findTransparentNotes pool b t = do
|
||||
findTransparentNotes pool b net t = do
|
||||
let tReceiver = t_rec =<< readUnifiedAddressDB (entityVal t)
|
||||
case tReceiver of
|
||||
Just tR -> do
|
||||
|
@ -854,6 +860,7 @@ findTransparentNotes pool b t = do
|
|||
(\(txs :& tNotes) ->
|
||||
txs ^. ZcashTransactionId ==. tNotes ^. TransparentNoteTx)
|
||||
where_ (txs ^. ZcashTransactionBlock >. val b)
|
||||
where_ (txs ^. ZcashTransactionNetwork ==. val net)
|
||||
where_ (tNotes ^. TransparentNoteScript ==. val s)
|
||||
pure (txs, tNotes)
|
||||
mapM_
|
||||
|
@ -907,8 +914,9 @@ saveSapNote pool wsn =
|
|||
getShieldedOutputs ::
|
||||
ConnectionPool -- ^ database path
|
||||
-> Int -- ^ block
|
||||
-> ZcashNetDB -- ^ network to use
|
||||
-> IO [(Entity ZcashTransaction, Entity ShieldOutput)]
|
||||
getShieldedOutputs pool b =
|
||||
getShieldedOutputs pool b net =
|
||||
runNoLoggingT $
|
||||
PS.retryOnBusy $
|
||||
flip PS.runSqlPool pool $ do
|
||||
|
@ -918,6 +926,7 @@ getShieldedOutputs pool b =
|
|||
(\(txs :& sOutputs) ->
|
||||
txs ^. ZcashTransactionId ==. sOutputs ^. ShieldOutputTx)
|
||||
where_ (txs ^. ZcashTransactionBlock >=. val b)
|
||||
where_ (txs ^. ZcashTransactionNetwork ==. val net)
|
||||
orderBy
|
||||
[ asc $ txs ^. ZcashTransactionId
|
||||
, asc $ sOutputs ^. ShieldOutputPosition
|
||||
|
@ -928,8 +937,9 @@ getShieldedOutputs pool b =
|
|||
getOrchardActions ::
|
||||
ConnectionPool -- ^ database path
|
||||
-> Int -- ^ block
|
||||
-> ZcashNetDB -- ^ network to use
|
||||
-> IO [(Entity ZcashTransaction, Entity OrchAction)]
|
||||
getOrchardActions pool b =
|
||||
getOrchardActions pool b net =
|
||||
runNoLoggingT $
|
||||
PS.retryOnBusy $
|
||||
flip PS.runSqlPool pool $ do
|
||||
|
@ -939,6 +949,7 @@ getOrchardActions pool b =
|
|||
(\(txs :& oActions) ->
|
||||
txs ^. ZcashTransactionId ==. oActions ^. OrchActionTx)
|
||||
where_ (txs ^. ZcashTransactionBlock >=. val b)
|
||||
where_ (txs ^. ZcashTransactionNetwork ==. val net)
|
||||
orderBy
|
||||
[asc $ txs ^. ZcashTransactionId, asc $ oActions ^. OrchActionPosition]
|
||||
pure (txs, oActions)
|
||||
|
|
|
@ -1151,7 +1151,7 @@ scanZebra dbPath zHost zPort net sendMsg = do
|
|||
bStatus <- liftIO $ checkBlockChain zHost zPort
|
||||
pool <- runNoLoggingT $ initPool dbPath
|
||||
b <- liftIO $ getMinBirthdayHeight pool
|
||||
dbBlock <- runNoLoggingT $ getMaxBlock pool
|
||||
dbBlock <- getMaxBlock pool $ ZcashNetDB net
|
||||
let sb = max dbBlock b
|
||||
confUp <- try $ updateConfs zHost zPort pool :: IO (Either IOError ())
|
||||
case confUp of
|
||||
|
|
|
@ -61,7 +61,7 @@ rescanZebra host port dbFilePath = do
|
|||
pool3 <- runNoLoggingT $ initPool dbFilePath
|
||||
clearWalletTransactions pool1
|
||||
clearWalletData pool1
|
||||
dbBlock <- runNoLoggingT $ getMaxBlock pool1
|
||||
dbBlock <- getMaxBlock pool1 znet
|
||||
b <- liftIO $ getMinBirthdayHeight pool1
|
||||
let sb = max dbBlock b
|
||||
if sb > zgb_blocks bStatus || sb < 1
|
||||
|
|
Loading…
Reference in a new issue