Compare commits
2 commits
1022944e67
...
e9fd87ef58
Author | SHA1 | Date | |
---|---|---|---|
e9fd87ef58 | |||
5fec52bdd0 |
6 changed files with 117 additions and 35 deletions
|
@ -203,6 +203,7 @@ main = do
|
||||||
nodeUser <- require config "nodeUser"
|
nodeUser <- require config "nodeUser"
|
||||||
nodePwd <- require config "nodePwd"
|
nodePwd <- require config "nodePwd"
|
||||||
zebraPort <- require config "zebraPort"
|
zebraPort <- require config "zebraPort"
|
||||||
|
zebraHost <- require config "zebraHost"
|
||||||
if not (null args)
|
if not (null args)
|
||||||
then do
|
then do
|
||||||
case head args of
|
case head args of
|
||||||
|
@ -216,7 +217,7 @@ main = do
|
||||||
" ______ _ _ _ \n |___ / (_) | | | \n / / ___ _ __ _| |_| |__ \n / / / _ \\ '_ \\| | __| '_ \\ \n / /_| __/ | | | | |_| | | |\n /_____\\___|_| |_|_|\\__|_| |_|\n Zcash Full Node CLI v0.4.0"
|
" ______ _ _ _ \n |___ / (_) | | | \n / / ___ _ __ _| |_| |__ \n / / / _ \\ '_ \\| | __| '_ \\ \n / /_| __/ | | | | |_| | | |\n /_____\\___|_| |_|_|\\__|_| |_|\n Zcash Full Node CLI v0.4.0"
|
||||||
}
|
}
|
||||||
(root nodeUser nodePwd)
|
(root nodeUser nodePwd)
|
||||||
"cli" -> runZenithCLI zebraPort dbName
|
"cli" -> runZenithCLI zebraHost zebraPort dbName
|
||||||
_ -> printUsage
|
_ -> printUsage
|
||||||
else printUsage
|
else printUsage
|
||||||
|
|
||||||
|
|
|
@ -12,21 +12,25 @@ import Lens.Micro.Mtl
|
||||||
import Lens.Micro.TH
|
import Lens.Micro.TH
|
||||||
|
|
||||||
import qualified Brick.AttrMap as A
|
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.Main as M
|
||||||
import qualified Brick.Types as BT
|
import qualified Brick.Types as BT
|
||||||
import Brick.Types (Widget)
|
import Brick.Types (Widget)
|
||||||
import Brick.Util (fg, on)
|
import Brick.Util (fg, on, style)
|
||||||
import qualified Brick.Widgets.Border as B
|
import qualified Brick.Widgets.Border as B
|
||||||
import Brick.Widgets.Border.Style (unicode)
|
import Brick.Widgets.Border.Style (unicode, unicodeBold)
|
||||||
import qualified Brick.Widgets.Center as C
|
import qualified Brick.Widgets.Center as C
|
||||||
import Brick.Widgets.Core
|
import Brick.Widgets.Core
|
||||||
( Padding(..)
|
( Padding(..)
|
||||||
, (<+>)
|
, (<+>)
|
||||||
, (<=>)
|
, (<=>)
|
||||||
, emptyWidget
|
, emptyWidget
|
||||||
|
, fill
|
||||||
, hLimit
|
, hLimit
|
||||||
, joinBorders
|
, joinBorders
|
||||||
, padAll
|
, padAll
|
||||||
|
, padBottom
|
||||||
, padRight
|
, padRight
|
||||||
, str
|
, str
|
||||||
, vBox
|
, vBox
|
||||||
|
@ -46,8 +50,15 @@ data Name
|
||||||
| AList
|
| AList
|
||||||
| TList
|
| TList
|
||||||
| HelpDialog
|
| HelpDialog
|
||||||
|
| WalNameField
|
||||||
deriving (Eq, Show, Ord)
|
deriving (Eq, Show, Ord)
|
||||||
|
|
||||||
|
data WalletName = WalletName
|
||||||
|
{ _walName :: !T.Text
|
||||||
|
} deriving (Show)
|
||||||
|
|
||||||
|
makeLenses ''WalletName
|
||||||
|
|
||||||
data State = State
|
data State = State
|
||||||
{ _network :: !String
|
{ _network :: !String
|
||||||
, _wallets :: !(L.List Name String)
|
, _wallets :: !(L.List Name String)
|
||||||
|
@ -55,12 +66,16 @@ data State = State
|
||||||
, _transactions :: !(L.List Name String)
|
, _transactions :: !(L.List Name String)
|
||||||
, _msg :: !String
|
, _msg :: !String
|
||||||
, _helpBox :: !Bool
|
, _helpBox :: !Bool
|
||||||
} deriving (Show)
|
, _walletBox :: !Bool
|
||||||
|
, _splashBox :: !Bool
|
||||||
|
, _walletForm :: !(Form WalletName () Name)
|
||||||
|
, _focusRing :: !(F.FocusRing Name)
|
||||||
|
}
|
||||||
|
|
||||||
makeLenses ''State
|
makeLenses ''State
|
||||||
|
|
||||||
drawUI :: State -> [Widget Name]
|
drawUI :: State -> [Widget Name]
|
||||||
drawUI s = [helpDialog s, ui s]
|
drawUI s = [splashDialog s, helpDialog s, walletDialog s, ui s]
|
||||||
where
|
where
|
||||||
ui :: State -> Widget Name
|
ui :: State -> Widget Name
|
||||||
ui s =
|
ui s =
|
||||||
|
@ -88,13 +103,43 @@ drawUI s = [helpDialog s, ui s]
|
||||||
helpDialog s =
|
helpDialog s =
|
||||||
if s ^. helpBox
|
if s ^. helpBox
|
||||||
then D.renderDialog
|
then D.renderDialog
|
||||||
(D.dialog (Just (str "Commands")) Nothing 50)
|
(D.dialog (Just (str "Commands")) Nothing 55)
|
||||||
(vBox ([C.hCenter $ str "Key", B.hBorder] <> keyList) <+>
|
(vBox ([C.hCenter $ str "Key", B.hBorder] <> keyList) <+>
|
||||||
vBox ([str "Actions", B.hBorder] <> actionList))
|
vBox ([str "Actions", B.hBorder] <> actionList))
|
||||||
else emptyWidget
|
else emptyWidget
|
||||||
where
|
where
|
||||||
keyList = map (C.hCenter . str) ["?", "Esc", "q"]
|
keyList = map (C.hCenter . str) ["?", "Esc", "c", "q"]
|
||||||
actionList = map (hLimit 40 . str) ["Open help", "Close dialog", "Quit"]
|
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
|
||||||
|
|
||||||
listDrawElement :: (Show a) => Bool -> a -> Widget Name
|
listDrawElement :: (Show a) => Bool -> a -> Widget Name
|
||||||
listDrawElement sel a =
|
listDrawElement sel a =
|
||||||
|
@ -107,15 +152,42 @@ listDrawElement sel a =
|
||||||
customAttr :: A.AttrName
|
customAttr :: A.AttrName
|
||||||
customAttr = L.listSelectedAttr <> A.attrName "custom"
|
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.BrickEvent Name e -> BT.EventM Name State ()
|
||||||
appEvent (BT.VtyEvent e) =
|
appEvent (BT.VtyEvent (V.EvKey (V.KChar '\t') [])) = focusRing %= F.focusNext
|
||||||
case e of
|
appEvent (BT.VtyEvent e) = do
|
||||||
V.EvKey V.KEsc [] -> BT.modify $ set helpBox False
|
r <- F.focusGetCurrent <$> use focusRing
|
||||||
V.EvKey (V.KChar 'q') [] -> M.halt
|
s <- BT.get
|
||||||
V.EvKey (V.KChar '?') [] -> BT.modify $ set helpBox True
|
if s ^. splashBox
|
||||||
V.EvKey (V.KChar 'c') [] -> printMsg "You pressed C!"
|
then BT.modify $ set splashBox False
|
||||||
V.EvKey (V.KChar 's') [] -> printMsg "You pressed S!"
|
else if s ^. helpBox
|
||||||
ev -> BT.zoom addresses $ L.handleListEvent ev
|
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 ()
|
||||||
where
|
where
|
||||||
printMsg :: String -> BT.EventM Name State ()
|
printMsg :: String -> BT.EventM Name State ()
|
||||||
printMsg s = BT.modify $ updateMsg s
|
printMsg s = BT.modify $ updateMsg s
|
||||||
|
@ -128,7 +200,9 @@ theMap =
|
||||||
V.defAttr
|
V.defAttr
|
||||||
[ (L.listAttr, V.white `on` V.blue)
|
[ (L.listAttr, V.white `on` V.blue)
|
||||||
, (L.listSelectedAttr, V.blue `on` V.white)
|
, (L.listSelectedAttr, V.blue `on` V.white)
|
||||||
, (customAttr, fg V.cyan)
|
, (customAttr, fg V.black)
|
||||||
|
, (titleAttr, V.withStyle (fg V.brightGreen) V.bold)
|
||||||
|
, (blinkAttr, style V.blink)
|
||||||
]
|
]
|
||||||
|
|
||||||
theApp :: M.App State e Name
|
theApp :: M.App State e Name
|
||||||
|
@ -141,12 +215,12 @@ theApp =
|
||||||
, M.appAttrMap = const theMap
|
, M.appAttrMap = const theMap
|
||||||
}
|
}
|
||||||
|
|
||||||
runZenithCLI :: Int -> T.Text -> IO ()
|
runZenithCLI :: T.Text -> Int -> T.Text -> IO ()
|
||||||
runZenithCLI port dbName = do
|
runZenithCLI host port dbName = do
|
||||||
w <- checkZebra port
|
w <- checkZebra host port
|
||||||
case (w :: Maybe ZebraGetInfo) of
|
case (w :: Maybe ZebraGetInfo) of
|
||||||
Just zebra -> do
|
Just zebra -> do
|
||||||
bc <- checkBlockChain port
|
bc <- checkBlockChain host port
|
||||||
case (bc :: Maybe ZebraGetBlockChainInfo) of
|
case (bc :: Maybe ZebraGetBlockChainInfo) of
|
||||||
Nothing -> print "Unable to determine blockchain status"
|
Nothing -> print "Unable to determine blockchain status"
|
||||||
Just chainInfo -> do
|
Just chainInfo -> do
|
||||||
|
@ -160,6 +234,10 @@ runZenithCLI port dbName = do
|
||||||
("Start up Ok! Connected to Zebra " ++
|
("Start up Ok! Connected to Zebra " ++
|
||||||
(T.unpack . zgi_build) zebra ++ " on port " ++ show port ++ ".")
|
(T.unpack . zgi_build) zebra ++ " on port " ++ show port ++ ".")
|
||||||
False
|
False
|
||||||
|
False
|
||||||
|
True
|
||||||
|
(mkWalletForm $ WalletName "Main")
|
||||||
|
(F.focusRing [AList, TList])
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
print $
|
print $
|
||||||
"No Zebra node available on port " <>
|
"No Zebra node available on port " <>
|
||||||
|
|
|
@ -25,25 +25,27 @@ checkWallets dbName znet = do
|
||||||
-- * Zebra Node interaction
|
-- * Zebra Node interaction
|
||||||
-- | Checks the status of the `zebrad` node
|
-- | Checks the status of the `zebrad` node
|
||||||
checkZebra ::
|
checkZebra ::
|
||||||
Int -- ^ Port where `zebrad` is available
|
T.Text -- ^ Host where `zebrad` is available
|
||||||
|
-> Int -- ^ Port where `zebrad` is available
|
||||||
-> IO (Maybe ZebraGetInfo)
|
-> IO (Maybe ZebraGetInfo)
|
||||||
checkZebra port = do
|
checkZebra host port = do
|
||||||
res <- makeZebraCall port "getinfo" []
|
res <- makeZebraCall host port "getinfo" []
|
||||||
let body = responseBody (res :: Response (RpcResponse ZebraGetInfo))
|
let body = responseBody (res :: Response (RpcResponse ZebraGetInfo))
|
||||||
return $ result body
|
return $ result body
|
||||||
|
|
||||||
-- | Checks the status of the Zcash blockchain
|
-- | Checks the status of the Zcash blockchain
|
||||||
checkBlockChain ::
|
checkBlockChain ::
|
||||||
Int -- ^ Port where `zebrad` is available
|
T.Text -- ^ Host where `zebrad` is available
|
||||||
|
-> Int -- ^ Port where `zebrad` is available
|
||||||
-> IO (Maybe ZebraGetBlockChainInfo)
|
-> IO (Maybe ZebraGetBlockChainInfo)
|
||||||
checkBlockChain port = do
|
checkBlockChain host port = do
|
||||||
let f = makeZebraCall port
|
let f = makeZebraCall host port
|
||||||
result <$> (responseBody <$> f "getblockchaininfo" [])
|
result <$> (responseBody <$> f "getblockchaininfo" [])
|
||||||
|
|
||||||
-- | Generic RPC call function
|
-- | Generic RPC call function
|
||||||
connectZebra ::
|
connectZebra ::
|
||||||
FromJSON a => Int -> T.Text -> [Data.Aeson.Value] -> IO (Maybe a)
|
FromJSON a => T.Text -> Int -> T.Text -> [Data.Aeson.Value] -> IO (Maybe a)
|
||||||
connectZebra port m params = do
|
connectZebra host port m params = do
|
||||||
res <- makeZebraCall port m params
|
res <- makeZebraCall host port m params
|
||||||
let body = responseBody res
|
let body = responseBody res
|
||||||
return $ result body
|
return $ result body
|
||||||
|
|
|
@ -44,7 +44,7 @@ packages:
|
||||||
# extra-deps: []
|
# extra-deps: []
|
||||||
extra-deps:
|
extra-deps:
|
||||||
- git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
|
- git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
|
||||||
commit: 09cee9a064219e4be89413ef86341aa18b62be68
|
commit: 73d8125b83cda3b69d91770e1617b4a4d6a98c58
|
||||||
- git: https://git.vergara.tech/Vergara_Tech/haskell-hexstring.git
|
- git: https://git.vergara.tech/Vergara_Tech/haskell-hexstring.git
|
||||||
commit: fd1ddce73c0ad18a2a4509a299c6e93f8c6c383d
|
commit: fd1ddce73c0ad18a2a4509a299c6e93f8c6c383d
|
||||||
- git: https://git.vergara.tech/Vergara_Tech/haskell-foreign-rust.git
|
- git: https://git.vergara.tech/Vergara_Tech/haskell-foreign-rust.git
|
||||||
|
|
|
@ -5,15 +5,15 @@
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
- completed:
|
- completed:
|
||||||
commit: 09cee9a064219e4be89413ef86341aa18b62be68
|
commit: 73d8125b83cda3b69d91770e1617b4a4d6a98c58
|
||||||
git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
|
git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
|
||||||
name: zcash-haskell
|
name: zcash-haskell
|
||||||
pantry-tree:
|
pantry-tree:
|
||||||
sha256: 6bf1902a377bf9399442de6f0b89219479fa908e70706918e81b88caa28dc0f5
|
sha256: 0b7870345d7ccc65ff51fbfe7c4e579fd497014ab0e0ee2084ba0ad0f68b8b69
|
||||||
size: 1367
|
size: 1367
|
||||||
version: 0.4.1
|
version: 0.4.2
|
||||||
original:
|
original:
|
||||||
commit: 09cee9a064219e4be89413ef86341aa18b62be68
|
commit: 73d8125b83cda3b69d91770e1617b4a4d6a98c58
|
||||||
git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
|
git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
|
||||||
- completed:
|
- completed:
|
||||||
commit: fd1ddce73c0ad18a2a4509a299c6e93f8c6c383d
|
commit: fd1ddce73c0ad18a2a4509a299c6e93f8c6c383d
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
nodeUser = "user"
|
nodeUser = "user"
|
||||||
nodePwd = "superSecret"
|
nodePwd = "superSecret"
|
||||||
dbName = "zenith.db"
|
dbName = "zenith.db"
|
||||||
|
zebraHost = "127.0.0.1"
|
||||||
zebraPort = 18232
|
zebraPort = 18232
|
||||||
|
|
Loading…
Reference in a new issue