Implement Account creation #68
3 changed files with 21 additions and 10 deletions
|
@ -212,9 +212,7 @@ appEvent (BT.VtyEvent e) = do
|
||||||
V.EvKey V.KEnter [] -> do
|
V.EvKey V.KEnter [] -> do
|
||||||
fs <- BT.zoom inputForm $ BT.gets formState
|
fs <- BT.zoom inputForm $ BT.gets formState
|
||||||
nw <- liftIO $ addNewWallet (fs ^. dialogInput) s
|
nw <- liftIO $ addNewWallet (fs ^. dialogInput) s
|
||||||
BT.modify $ set wallets nw
|
BT.put nw
|
||||||
printMsg $
|
|
||||||
"Creating new wallet " <> T.unpack (fs ^. dialogInput)
|
|
||||||
BT.modify $ set dialogBox Blank
|
BT.modify $ set dialogBox Blank
|
||||||
ev -> BT.zoom inputForm $ handleFormEvent (BT.VtyEvent ev)
|
ev -> BT.zoom inputForm $ handleFormEvent (BT.VtyEvent ev)
|
||||||
AName -> do
|
AName -> do
|
||||||
|
@ -311,12 +309,24 @@ runZenithCLI host port dbFilePath = do
|
||||||
"No Zebra node available on port " <>
|
"No Zebra node available on port " <>
|
||||||
show port <> ". Check your configuration"
|
show port <> ". Check your configuration"
|
||||||
|
|
||||||
addNewWallet ::
|
addNewWallet :: T.Text -> State -> IO State
|
||||||
T.Text -> State -> IO (L.GenericList Name Vec.Vector (Entity ZcashWallet))
|
|
||||||
addNewWallet n s = do
|
addNewWallet n s = do
|
||||||
sP <- generateWalletSeedPhrase
|
sP <- generateWalletSeedPhrase
|
||||||
let bH = s ^. startBlock
|
let bH = s ^. startBlock
|
||||||
let netName = read $ s ^. network
|
let netName = read $ s ^. network
|
||||||
_ <- saveWallet (s ^. dbPath) $ ZcashWallet sP bH n netName
|
r <- saveWallet (s ^. dbPath) $ ZcashWallet sP bH n netName
|
||||||
wL <- getWallets (s ^. dbPath) netName
|
case r of
|
||||||
return $ L.listReplace (Vec.fromList wL) (Just 0) $ s ^. wallets
|
Nothing -> do
|
||||||
|
wL <- getWallets (s ^. dbPath) netName
|
||||||
|
return $
|
||||||
|
(s & wallets .~ L.listReplace (Vec.fromList wL) (Just 0) (s ^. wallets)) &
|
||||||
|
msg .~
|
||||||
|
"Wallet already exists: " ++
|
||||||
|
T.unpack n
|
||||||
|
Just _ -> do
|
||||||
|
wL <- getWallets (s ^. dbPath) netName
|
||||||
|
return $
|
||||||
|
(s & wallets .~ L.listReplace (Vec.fromList wL) (Just 0) (s ^. wallets)) &
|
||||||
|
msg .~
|
||||||
|
"Created new wallet: " ++
|
||||||
|
T.unpack n
|
||||||
|
|
|
@ -24,8 +24,8 @@ initDb dbName = do
|
||||||
saveWallet ::
|
saveWallet ::
|
||||||
T.Text -- ^ The database path to use
|
T.Text -- ^ The database path to use
|
||||||
-> ZcashWallet -- ^ The wallet to add to the database
|
-> ZcashWallet -- ^ The wallet to add to the database
|
||||||
-> IO ZcashWalletId
|
-> IO (Maybe (Entity ZcashWallet))
|
||||||
saveWallet dbFp w = runSqlite dbFp $ insert w
|
saveWallet dbFp w = runSqlite dbFp $ insertUniqueEntity w
|
||||||
|
|
||||||
-- | Returns a list of accounts associated with the given wallet
|
-- | Returns a list of accounts associated with the given wallet
|
||||||
getAccounts ::
|
getAccounts ::
|
||||||
|
|
|
@ -34,6 +34,7 @@ share
|
||||||
birthdayHeight Int
|
birthdayHeight Int
|
||||||
name T.Text
|
name T.Text
|
||||||
network ZcashNet
|
network ZcashNet
|
||||||
|
UniqueWallet name network
|
||||||
deriving Show
|
deriving Show
|
||||||
ZcashAccount
|
ZcashAccount
|
||||||
walletId ZcashWalletId
|
walletId ZcashWalletId
|
||||||
|
|
Loading…
Reference in a new issue