Milestone 3: RPC server, ZIP-320 #104

Merged
pitmutt merged 152 commits from milestone3 into master 2024-11-21 15:39:19 +00:00
Showing only changes of commit 538216944d - Show all commits

View file

@ -50,25 +50,19 @@ import Zenith.Core
import Zenith.DB
import Zenith.GUI.Theme
import Zenith.Scanner (processTx, updateConfs)
import Zenith.Types
( ZcashNetDB
)
import Zenith.Types
hiding
( ZcashAddress(..)
)
import Zenith.Types hiding (ZcashAddress(..))
import Zenith.Utils
( displayAmount
, getZenithPath
, isEmpty
, isRecipientValid
, isValidString
, jsonNumber
, padWithZero
, parseAddress
, showAddress
, validBarValue
, validateAddressBool
, isValidString
, padWithZero
, getZenithPath
, isEmpty
)
data AppEvent
@ -125,7 +119,6 @@ data AppEvent
| CheckValidDescrip !T.Text
| SaveNewABEntry
| ShowMessage !T.Text
deriving (Eq, Show)
data AppModel = AppModel
@ -795,37 +788,34 @@ buildUI wenv model = widgetTree
(label "Address Book" `styleBasic`
[textFont "Bold", textSize 12, textColor white]) `styleBasic`
[bgColor btnColor, radius 2, padding 3]
, boxShadow $
box_
, boxShadow $
box_
[alignMiddle]
(vstack
[ vscroll (vstack (zipWith abookRow [0 ..] (model ^. abaddressList))) `nodeKey` "txScroll"
]) `styleBasic`
[ vscroll
(vstack (zipWith abookRow [0 ..] (model ^. abaddressList))) `nodeKey`
"txScroll"
]) `styleBasic`
[radius 2, padding 3, bgColor white]
, spacer
, hstack [
button "New" NewAdrBkEntry
, spacer
, button "Edit" notImplemented
, spacer
, button "Copy" notImplemented
, hstack
[ button "New" NewAdrBkEntry
, spacer
, button "Edit" notImplemented
, spacer
, button "Copy" notImplemented
]
]
]
abookRow :: Int -> Entity AddressBook -> WidgetNode AppModel AppEvent
abookRow idx ab =
box_
[onClick $ ShowMessage (addressBookAbaddress $ entityVal ab), alignLeft]
(hstack
[
label
(T.pack $
padWithZero 3 $
show (fromSqlKey (entityKey ab))) `styleBasic` [textFont "Bold"]
, spacer
, label
(T.pack $
show (addressBookAbdescrip $ entityVal ab))
]) `styleBasic`
[ label (T.pack $ padWithZero 3 $ show (fromSqlKey (entityKey ab))) `styleBasic`
[textFont "Bold"]
, spacer
, label (T.pack $ show (addressBookAbdescrip $ entityVal ab))
]) `styleBasic`
[padding 2, borderB 1 gray]
newAdrBkOverlay =
alert CloseNewAdrBook $
@ -834,16 +824,14 @@ buildUI wenv model = widgetTree
[]
(label "New Address Book Entry" `styleBasic`
[textFont "Bold", textSize 10, textColor white]) `styleBasic`
[bgColor btnColor, radius 2, padding 3]
[bgColor btnColor, radius 2, padding 3]
, spacer
, hstack
[ label "Description: " `styleBasic` [width 80]
, spacer
, textField_ abdescrip [onChange CheckValidDescrip] `styleBasic`
, textField_ abdescrip [onChange CheckValidDescrip] `styleBasic`
[ width 320
, styleIf
(not $ model ^. abDescripValid)
(textColor red)
, styleIf (not $ model ^. abDescripValid) (textColor red)
]
]
, spacer
@ -852,19 +840,17 @@ buildUI wenv model = widgetTree
, spacer
, textField_ abaddress [onChange CheckValidAddress] `styleBasic`
[ width 350
, styleIf
(not $ model ^. abAddressValid)
(textColor red)
, styleIf (not $ model ^. abAddressValid) (textColor red)
]
]
, spacer
, hstack
[ button "Save" SaveNewABEntry `nodeEnabled`
((model ^. abAddressValid) && (model ^. abDescripValid))
((model ^. abAddressValid) && (model ^. abDescripValid))
, spacer
, button "Cancel" CloseNewAdrBook `nodeEnabled` True
]
]
]
msgAdrBookOverlay =
alert CloseMsgAB $
hstack
@ -873,7 +859,7 @@ buildUI wenv model = widgetTree
[textSize 32, textColor btnColor] `nodeVisible`
(model ^. inError)
, spacer
, label_ (txtWrapN (fromMaybe "" (model ^. msgAB)) 64) [multiline]
, label_ (txtWrapN (fromMaybe "" (model ^. msgAB)) 64) [multiline]
, filler
]
@ -1191,20 +1177,36 @@ handleEvent wenv node model evt =
-- |
-- | Address Book Events
-- |
CheckValidAddress a -> [Model $ model & abAddressValid .~ isRecipientValid a]
CheckValidDescrip a -> [Model $ model & abDescripValid .~ isValidString a]
CheckValidAddress a ->
[Model $ model & abAddressValid .~ isRecipientValid a]
CheckValidDescrip a -> [Model $ model & abDescripValid .~ isValidString a]
ShowAdrBook -> [Model $ model & showAdrBook .~ True & menuPopup .~ False]
CloseAdrBook -> [Model $ model & showAdrBook .~ False]
NewAdrBkEntry -> [Model $ model & newAdrBkEntry .~ True & menuPopup .~ False]
NewAdrBkEntry ->
[Model $ model & newAdrBkEntry .~ True & menuPopup .~ False]
CloseNewAdrBook -> do
[Model $ model & newAdrBkEntry .~ False]
SaveNewABEntry ->
[ Task $ saveAddrBook (model ^. configuration) (ZcashNetDB (model ^. network)) (model ^. abdescrip) (model ^. abaddress)
, Model $ model & abdescrip .~ "" & abaddress .~ "" & newAdrBkEntry .~ False
[ Task $
saveAddrBook
(model ^. configuration)
(ZcashNetDB (model ^. network))
(model ^. abdescrip)
(model ^. abaddress)
, Model $
model & abdescrip .~ "" & abaddress .~ "" & newAdrBkEntry .~ False
, Task $ do
dbPool <- runNoLoggingT $ initPool $ c_dbPath $ model ^. configuration
abList <- getAdrBook dbPool $ model ^. network
return $ LoadAbList abList
]
NotImplemented ->
[ Model $
model & msgAB ?~ "Function not implemented..." & menuPopup .~ False
]
NotImplemented -> [Model $ model & msgAB ?~ "Function not implemented..." & menuPopup .~ False]
CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False]
ShowMessage a -> [Model $ model & msgAB ?~ a & menuPopup .~ False]
LoadAbList a -> [Model $ model & abaddressList .~ a]
where
currentWallet =
if null (model ^. wallets)
@ -1297,25 +1299,19 @@ handleEvent wenv node model evt =
-- |
saveAddrBook :: Config -> ZcashNetDB -> T.Text -> T.Text -> IO AppEvent
saveAddrBook config n d a = do
let dbPath = c_dbPath config
let dbPath = c_dbPath config
pool <- runNoLoggingT $ initPool dbPath
res <-
liftIO $
saveAdrsInAdrBook pool $
AddressBook
n
d
a
res <- liftIO $ saveAdrsInAdrBook pool $ AddressBook n d a
case res of
Nothing -> return $ ShowMessage "Error saving the AddressBook entry..."
Just _ -> return $ ShowMessage "New Address Book entry added!!"
Just _ -> return $ ShowMessage "New Address Book entry added!!"
-- |
-- |
-- |
-- loadABList :: Config -> ZcashNet -> IO AppEvent
-- loadABList config n = do
-- pool <- runNoLoggingT $ initPool $ c_dbPath config
scanZebra :: T.Text -> T.Text -> Int -> (AppEvent -> IO ()) -> IO ()
scanZebra dbPath zHost zPort sendMsg = do
_ <- liftIO $ initDb dbPath
@ -1414,8 +1410,8 @@ timeTicker sendMsg = do
threadDelay $ 1000 * 1000
timeTicker sendMsg
txtWrapN :: T.Text -> Int -> T.Text
txtWrapN t n = wrapText (WrapSettings False True NoFill FillAfterFirst) n t
txtWrapN :: T.Text -> Int -> T.Text
txtWrapN t n = wrapText (WrapSettings False True NoFill FillAfterFirst) n t
txtWrap :: T.Text -> T.Text
txtWrap = wrapText (WrapSettings False True NoFill FillAfterFirst) 32
@ -1484,7 +1480,9 @@ runZenithGUI config = do
Nothing
True
bal
(if unconfBal == 0 then Nothing else Just unconfBal)
(if unconfBal == 0
then Nothing
else Just unconfBal)
Orchard
qr
False
@ -1495,7 +1493,10 @@ runZenithGUI config = do
Nothing
""
""
(SaveAddress (if not (null accList) then Just (head accList) else Nothing ) )
(SaveAddress
(if not (null accList)
then Just (head accList)
else Nothing))
False
False
Nothing
@ -1533,9 +1534,9 @@ runZenithGUI config = do
0
[]
0
(Just (
"Couldn't connect to Zebra on " <>
host <> ":" <> showt port <> ". Check your configuration." ) )
(Just
("Couldn't connect to Zebra on " <>
host <> ":" <> showt port <> ". Check your configuration."))
False
314259000
(Just 30000)