Milestone 3: RPC server, ZIP-320 #104

Merged
pitmutt merged 152 commits from milestone3 into master 2024-11-21 15:39:19 +00:00
3 changed files with 89 additions and 15 deletions
Showing only changes of commit c4a879b09b - Show all commits

View file

@ -100,6 +100,7 @@ import Zenith.Types
, HexStringDB(..) , HexStringDB(..)
, PhraseDB(..) , PhraseDB(..)
, PrivacyPolicy(..) , PrivacyPolicy(..)
, ShieldDeshieldOp(..)
, UnifiedAddressDB(..) , UnifiedAddressDB(..)
, ZcashNetDB(..) , ZcashNetDB(..)
, ZenithStatus(..) , ZenithStatus(..)
@ -108,6 +109,7 @@ import Zenith.Utils
( displayTaz ( displayTaz
, displayZec , displayZec
, isRecipientValid , isRecipientValid
, isRecipientValidGUI
, jsonNumber , jsonNumber
, parseAddressUA , parseAddressUA
, showAddress , showAddress
@ -132,6 +134,10 @@ data Name
| PrivacyLowField | PrivacyLowField
| PrivacyMediumField | PrivacyMediumField
| PrivacyFullField | PrivacyFullField
| ShieldField
| DeshieldField
| TotalTranspField
| TotalShieldedField
deriving (Eq, Show, Ord) deriving (Eq, Show, Ord)
data DialogInput = DialogInput data DialogInput = DialogInput
@ -156,6 +162,15 @@ data AdrBookEntry = AdrBookEntry
makeLenses ''AdrBookEntry makeLenses ''AdrBookEntry
data ShDshEntry = ShDshEntry
{ _totalTransparent :: !Float
, _totalShielded :: !Float
, _shieldOp :: !ShieldDeshieldOp
, _shAmt :: !Float
} deriving (Show)
makeLenses ''ShDshEntry
data DialogType data DialogType
= WName = WName
| AName | AName
@ -168,6 +183,7 @@ data DialogType
| AdrBookForm | AdrBookForm
| AdrBookUpdForm | AdrBookUpdForm
| AdrBookDelForm | AdrBookDelForm
| ShieldDeshieldForm
data DisplayType data DisplayType
= AddrDisplay = AddrDisplay
@ -216,6 +232,7 @@ data State = State
, _abCurAdrs :: !T.Text -- used for address book CRUD operations , _abCurAdrs :: !T.Text -- used for address book CRUD operations
, _sentTx :: !(Maybe HexString) , _sentTx :: !(Maybe HexString)
, _unconfBalance :: !Integer , _unconfBalance :: !Integer
, _shdshForm :: !(Form ShDshEntry () Name)
} }
makeLenses ''State makeLenses ''State
@ -263,17 +280,23 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
(C.hCenter (C.hCenter
(str ("Last block seen: " ++ show (st ^. syncBlock) ++ "\n")) <=> (str ("Last block seen: " ++ show (st ^. syncBlock) ++ "\n")) <=>
listTxBox " Transactions " (st ^. network) (st ^. transactions))) <=> listTxBox " Transactions " (st ^. network) (st ^. transactions))) <=>
C.hCenter (vBox
(hBox [ C.hCenter
[ capCommand "W" "allets" (hBox
, capCommand "A" "ccounts" [ capCommand "W" "allets"
, capCommand "V" "iew address" , capCommand "A" "ccounts"
, capCommand "S" "end Tx" , capCommand "V" "iew address"
, capCommand2 "Address " "B" "ook" , capCommand3 "" "S" "end Tx"
, capCommand "Q" "uit" ])
, capCommand "?" " Help" , C.hCenter
, str $ show (st ^. timer) (hBox
]) [ capCommand2 "Address " "B" "ook"
, capCommand2 "Shield/" "D" "eshield"
, capCommand "Q" "uit"
, capCommand "?" " Help"
, str $ show (st ^. timer)
])
])
listBox :: Show e => String -> L.List Name e -> Widget Name listBox :: Show e => String -> L.List Name e -> Widget Name
listBox titleLabel l = listBox titleLabel l =
C.vCenter $ C.vCenter $
@ -339,7 +362,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
else emptyWidget else emptyWidget
where where
keyList = keyList =
map (C.hCenter . str) ["?", "Esc", "w", "a", "v", "s", "b", "q"] map (C.hCenter . str) ["?", "Esc", "w", "a", "v", "s", "b", "d", "q"]
actionList = actionList =
map map
(hLimit 40 . str) (hLimit 40 . str)
@ -350,6 +373,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
, "View address" , "View address"
, "Send Tx" , "Send Tx"
, "Address Book" , "Address Book"
, "Shield/De-Shield"
, "Quit" , "Quit"
] ]
inputDialog :: State -> Widget Name inputDialog :: State -> Widget Name
@ -396,6 +420,12 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
(renderForm (st ^. txForm) <=> (renderForm (st ^. txForm) <=>
C.hCenter C.hCenter
(hBox [capCommand "" "Send", capCommand "<esc> " "Cancel"])) (hBox [capCommand "" "Send", capCommand "<esc> " "Cancel"]))
ShieldDeshieldForm ->
D.renderDialog
(D.dialog (Just (str " Shield / De-Shield ")) Nothing 50)
(renderForm (st ^. shdshForm) <=>
C.hCenter
(hBox [capCommand "P" "roceed", capCommand "<esc> " "Cancel"]))
Blank -> emptyWidget Blank -> emptyWidget
-- Address Book List -- Address Book List
AdrBook -> AdrBook ->
@ -639,6 +669,34 @@ mkSendForm bal =
label s w = label s w =
padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w
mkshieldDeshieldForm :: Integer -> ShDshEntry -> Form ShDshEntry e Name
mkshieldDeshieldForm bal =
newForm
[ label "Total Transp. : " @@=
editShowableFieldWithValidate
totalTransparent
TotalTranspField
(isAmountValid bal)
, label "Total Shielded : " @@=
editShowableFieldWithValidate
totalShielded
TotalShieldedField
(isAmountValid bal)
, label "Select :" @@=
radioField
shieldOp
[ (Shield, ShieldField, "Shield")
, (Deshield, DeshieldField, "De-Shield")
]
, label "Amount: " @@=
editShowableFieldWithValidate shAmt AmtField (isAmountValid bal)
]
where
isAmountValid :: Integer -> Float -> Bool
isAmountValid b i = (fromIntegral b / 100000000.0) >= i
label s w =
padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w
mkNewABForm :: AdrBookEntry -> Form AdrBookEntry e Name mkNewABForm :: AdrBookEntry -> Form AdrBookEntry e Name
mkNewABForm = mkNewABForm =
newForm newForm
@ -902,6 +960,7 @@ appEvent (BT.AppEvent t) = do
AdrBookForm -> return () AdrBookForm -> return ()
AdrBookUpdForm -> return () AdrBookUpdForm -> return ()
AdrBookDelForm -> return () AdrBookDelForm -> return ()
ShieldDeshieldForm -> return ()
Blank -> do Blank -> do
if s ^. timer == 90 if s ^. timer == 90
then do then do
@ -1148,8 +1207,15 @@ appEvent (BT.VtyEvent e) = do
fs <- BT.gets formState fs <- BT.gets formState
BT.modify $ BT.modify $
setFieldValid setFieldValid
(isRecipientValid (fs ^. sendTo)) (isRecipientValidGUI
(fs ^. policyField)
(fs ^. sendTo))
RecField RecField
ShieldDeshieldForm -> do
case e of
V.EvKey V.KEsc [] -> BT.modify $ set dialogBox Blank
ev ->
BT.zoom shdshForm $ do handleFormEvent (BT.VtyEvent ev)
AdrBook -> do AdrBook -> do
case e of case e of
V.EvKey (V.KChar 'x') [] -> V.EvKey (V.KChar 'x') [] ->
@ -1359,6 +1425,8 @@ appEvent (BT.VtyEvent e) = do
BT.modify $ set dialogBox SendTx BT.modify $ set dialogBox SendTx
V.EvKey (V.KChar 'b') [] -> V.EvKey (V.KChar 'b') [] ->
BT.modify $ set dialogBox AdrBook BT.modify $ set dialogBox AdrBook
V.EvKey (V.KChar 'd') [] ->
BT.modify $ set dialogBox ShieldDeshieldForm
ev -> ev ->
case r of case r of
Just AList -> Just AList ->
@ -1373,6 +1441,8 @@ appEvent (BT.VtyEvent e) = do
printMsg s = BT.modify $ updateMsg s printMsg s = BT.modify $ updateMsg s
updateMsg :: String -> State -> State updateMsg :: String -> State -> State
updateMsg = set msg updateMsg = set msg
-- fs <- BT.gets formState
-- ev -> BT.zoom shdshForm $ L.handleListEvent ev
appEvent _ = return () appEvent _ = return ()
theMap :: A.AttrMap theMap :: A.AttrMap
@ -1497,6 +1567,7 @@ runZenithTUI config = do
"" ""
Nothing Nothing
uBal uBal
(mkshieldDeshieldForm 0 (ShDshEntry 0 0 Shield 0.0))
Left _e -> do Left _e -> do
print $ print $
"No Zebra node available on port " <> "No Zebra node available on port " <>

View file

@ -268,6 +268,11 @@ data TransactionType
| Deshielding | Deshielding
deriving (Eq, Prelude.Show) deriving (Eq, Prelude.Show)
data ShieldDeshieldOp
= Shield
| Deshield
deriving (Eq, Show, Read, Ord)
-- ** `zebrad` -- ** `zebrad`
-- | Type for modeling the tree state response -- | Type for modeling the tree state response
data ZebraTreeInfo = ZebraTreeInfo data ZebraTreeInfo = ZebraTreeInfo

View file

@ -170,10 +170,8 @@ isRecipientValidGUI p a = do
Unified ua -> True Unified ua -> True
Sapling sa -> True Sapling sa -> True
Transparent ta -> True Transparent ta -> True
Exchange ea -> True
_ -> False _ -> False
Nothing -> False Nothing -> False
None -> case adr of None -> case adr of
Just a -> Just a ->
case a of case a of