Compare commits

..

No commits in common. "e9fd87ef583a98227276e5b3fb93fbdbb3855b1a" and "1022944e67dc60d042303cde4e7f9b073f04f636" have entirely different histories.

6 changed files with 35 additions and 117 deletions

View file

@ -203,7 +203,6 @@ main = do
nodeUser <- require config "nodeUser"
nodePwd <- require config "nodePwd"
zebraPort <- require config "zebraPort"
zebraHost <- require config "zebraHost"
if not (null args)
then do
case head args of
@ -217,7 +216,7 @@ main = do
" ______ _ _ _ \n |___ / (_) | | | \n / / ___ _ __ _| |_| |__ \n / / / _ \\ '_ \\| | __| '_ \\ \n / /_| __/ | | | | |_| | | |\n /_____\\___|_| |_|_|\\__|_| |_|\n Zcash Full Node CLI v0.4.0"
}
(root nodeUser nodePwd)
"cli" -> runZenithCLI zebraHost zebraPort dbName
"cli" -> runZenithCLI zebraPort dbName
_ -> printUsage
else printUsage

View file

@ -12,25 +12,21 @@ import Lens.Micro.Mtl
import Lens.Micro.TH
import qualified Brick.AttrMap as A
import qualified Brick.Focus as F
import Brick.Forms (Form(..), (@@=), editTextField, newForm, renderForm)
import qualified Brick.Main as M
import qualified Brick.Types as BT
import Brick.Types (Widget)
import Brick.Util (fg, on, style)
import Brick.Util (fg, on)
import qualified Brick.Widgets.Border as B
import Brick.Widgets.Border.Style (unicode, unicodeBold)
import Brick.Widgets.Border.Style (unicode)
import qualified Brick.Widgets.Center as C
import Brick.Widgets.Core
( Padding(..)
, (<+>)
, (<=>)
, emptyWidget
, fill
, hLimit
, joinBorders
, padAll
, padBottom
, padRight
, str
, vBox
@ -50,15 +46,8 @@ data Name
| AList
| TList
| HelpDialog
| WalNameField
deriving (Eq, Show, Ord)
data WalletName = WalletName
{ _walName :: !T.Text
} deriving (Show)
makeLenses ''WalletName
data State = State
{ _network :: !String
, _wallets :: !(L.List Name String)
@ -66,16 +55,12 @@ data State = State
, _transactions :: !(L.List Name String)
, _msg :: !String
, _helpBox :: !Bool
, _walletBox :: !Bool
, _splashBox :: !Bool
, _walletForm :: !(Form WalletName () Name)
, _focusRing :: !(F.FocusRing Name)
}
} deriving (Show)
makeLenses ''State
drawUI :: State -> [Widget Name]
drawUI s = [splashDialog s, helpDialog s, walletDialog s, ui s]
drawUI s = [helpDialog s, ui s]
where
ui :: State -> Widget Name
ui s =
@ -103,43 +88,13 @@ drawUI s = [splashDialog s, helpDialog s, walletDialog s, ui s]
helpDialog s =
if s ^. helpBox
then D.renderDialog
(D.dialog (Just (str "Commands")) Nothing 55)
(D.dialog (Just (str "Commands")) Nothing 50)
(vBox ([C.hCenter $ str "Key", B.hBorder] <> keyList) <+>
vBox ([str "Actions", B.hBorder] <> actionList))
else emptyWidget
where
keyList = map (C.hCenter . str) ["?", "Esc", "c", "q"]
actionList =
map
(hLimit 40 . str)
["Open help", "Close dialog", "Create Wallet", "Quit"]
walletDialog :: State -> Widget Name
walletDialog s =
if s ^. walletBox
then D.renderDialog
(D.dialog (Just (str "Create Wallet")) Nothing 50)
(renderForm $ s ^. walletForm)
else emptyWidget
splashDialog :: State -> Widget Name
splashDialog s =
if s ^. splashBox
then withBorderStyle unicodeBold $
D.renderDialog
(D.dialog Nothing Nothing 30)
(withAttr
titleAttr
(str
" _____ _ _ _ \n|__ /___ _ __ (_) |_| |__\n / // _ \\ '_ \\| | __| '_ \\\n / /| __/ | | | | |_| | | |\n/____\\___|_| |_|_|\\__|_| |_|") <=>
C.hCenter (withAttr titleAttr (str "Zcash Wallet v0.4.1")) <=>
C.hCenter (withAttr blinkAttr $ str "Press any key..."))
else emptyWidget
mkWalletForm :: WalletName -> Form WalletName e Name
mkWalletForm =
newForm [label "Name" @@= editTextField walName WalNameField (Just 1)]
where
label s w =
padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w
keyList = map (C.hCenter . str) ["?", "Esc", "q"]
actionList = map (hLimit 40 . str) ["Open help", "Close dialog", "Quit"]
listDrawElement :: (Show a) => Bool -> a -> Widget Name
listDrawElement sel a =
@ -152,42 +107,15 @@ listDrawElement sel a =
customAttr :: A.AttrName
customAttr = L.listSelectedAttr <> A.attrName "custom"
titleAttr :: A.AttrName
titleAttr = A.attrName "title"
blinkAttr :: A.AttrName
blinkAttr = A.attrName "blink"
appEvent :: BT.BrickEvent Name e -> BT.EventM Name State ()
appEvent (BT.VtyEvent (V.EvKey (V.KChar '\t') [])) = focusRing %= F.focusNext
appEvent (BT.VtyEvent e) = do
r <- F.focusGetCurrent <$> use focusRing
s <- BT.get
if s ^. splashBox
then BT.modify $ set splashBox False
else if s ^. helpBox
then do
case e of
V.EvKey V.KEsc [] -> do
BT.modify $ set helpBox False
ev -> return ()
else do
if s ^. walletBox
then do
case e of
V.EvKey V.KEsc [] -> BT.modify $ set walletBox False
ev -> return ()
else do
case e of
V.EvKey (V.KChar 'q') [] -> M.halt
V.EvKey (V.KChar '?') [] -> BT.modify $ set helpBox True
V.EvKey (V.KChar 'c') [] -> BT.modify $ set walletBox True
V.EvKey (V.KChar 's') [] -> printMsg "You pressed S!"
ev ->
case r of
Just AList -> BT.zoom addresses $ L.handleListEvent ev
Just TList -> BT.zoom transactions $ L.handleListEvent ev
Nothing -> return ()
appEvent (BT.VtyEvent e) =
case e of
V.EvKey V.KEsc [] -> BT.modify $ set helpBox False
V.EvKey (V.KChar 'q') [] -> M.halt
V.EvKey (V.KChar '?') [] -> BT.modify $ set helpBox True
V.EvKey (V.KChar 'c') [] -> printMsg "You pressed C!"
V.EvKey (V.KChar 's') [] -> printMsg "You pressed S!"
ev -> BT.zoom addresses $ L.handleListEvent ev
where
printMsg :: String -> BT.EventM Name State ()
printMsg s = BT.modify $ updateMsg s
@ -200,9 +128,7 @@ theMap =
V.defAttr
[ (L.listAttr, V.white `on` V.blue)
, (L.listSelectedAttr, V.blue `on` V.white)
, (customAttr, fg V.black)
, (titleAttr, V.withStyle (fg V.brightGreen) V.bold)
, (blinkAttr, style V.blink)
, (customAttr, fg V.cyan)
]
theApp :: M.App State e Name
@ -215,12 +141,12 @@ theApp =
, M.appAttrMap = const theMap
}
runZenithCLI :: T.Text -> Int -> T.Text -> IO ()
runZenithCLI host port dbName = do
w <- checkZebra host port
runZenithCLI :: Int -> T.Text -> IO ()
runZenithCLI port dbName = do
w <- checkZebra port
case (w :: Maybe ZebraGetInfo) of
Just zebra -> do
bc <- checkBlockChain host port
bc <- checkBlockChain port
case (bc :: Maybe ZebraGetBlockChainInfo) of
Nothing -> print "Unable to determine blockchain status"
Just chainInfo -> do
@ -234,10 +160,6 @@ runZenithCLI host port dbName = do
("Start up Ok! Connected to Zebra " ++
(T.unpack . zgi_build) zebra ++ " on port " ++ show port ++ ".")
False
False
True
(mkWalletForm $ WalletName "Main")
(F.focusRing [AList, TList])
Nothing -> do
print $
"No Zebra node available on port " <>

View file

@ -25,27 +25,25 @@ checkWallets dbName znet = do
-- * Zebra Node interaction
-- | Checks the status of the `zebrad` node
checkZebra ::
T.Text -- ^ Host where `zebrad` is available
-> Int -- ^ Port where `zebrad` is available
Int -- ^ Port where `zebrad` is available
-> IO (Maybe ZebraGetInfo)
checkZebra host port = do
res <- makeZebraCall host port "getinfo" []
checkZebra port = do
res <- makeZebraCall port "getinfo" []
let body = responseBody (res :: Response (RpcResponse ZebraGetInfo))
return $ result body
-- | Checks the status of the Zcash blockchain
checkBlockChain ::
T.Text -- ^ Host where `zebrad` is available
-> Int -- ^ Port where `zebrad` is available
Int -- ^ Port where `zebrad` is available
-> IO (Maybe ZebraGetBlockChainInfo)
checkBlockChain host port = do
let f = makeZebraCall host port
checkBlockChain port = do
let f = makeZebraCall port
result <$> (responseBody <$> f "getblockchaininfo" [])
-- | Generic RPC call function
connectZebra ::
FromJSON a => T.Text -> Int -> T.Text -> [Data.Aeson.Value] -> IO (Maybe a)
connectZebra host port m params = do
res <- makeZebraCall host port m params
FromJSON a => Int -> T.Text -> [Data.Aeson.Value] -> IO (Maybe a)
connectZebra port m params = do
res <- makeZebraCall port m params
let body = responseBody res
return $ result body

View file

@ -44,7 +44,7 @@ packages:
# extra-deps: []
extra-deps:
- git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
commit: 73d8125b83cda3b69d91770e1617b4a4d6a98c58
commit: 09cee9a064219e4be89413ef86341aa18b62be68
- git: https://git.vergara.tech/Vergara_Tech/haskell-hexstring.git
commit: fd1ddce73c0ad18a2a4509a299c6e93f8c6c383d
- git: https://git.vergara.tech/Vergara_Tech/haskell-foreign-rust.git

View file

@ -5,15 +5,15 @@
packages:
- completed:
commit: 73d8125b83cda3b69d91770e1617b4a4d6a98c58
commit: 09cee9a064219e4be89413ef86341aa18b62be68
git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
name: zcash-haskell
pantry-tree:
sha256: 0b7870345d7ccc65ff51fbfe7c4e579fd497014ab0e0ee2084ba0ad0f68b8b69
sha256: 6bf1902a377bf9399442de6f0b89219479fa908e70706918e81b88caa28dc0f5
size: 1367
version: 0.4.2
version: 0.4.1
original:
commit: 73d8125b83cda3b69d91770e1617b4a4d6a98c58
commit: 09cee9a064219e4be89413ef86341aa18b62be68
git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
- completed:
commit: fd1ddce73c0ad18a2a4509a299c6e93f8c6c383d

View file

@ -1,5 +1,4 @@
nodeUser = "user"
nodePwd = "superSecret"
dbName = "zenith.db"
zebraHost = "127.0.0.1"
zebraPort = 18232