Skip to content
Permalink
Browse files

support ErrWalletAlreadyExists

  • Loading branch information...
paweljakubas committed May 15, 2019
1 parent c60dc16 commit 2d6218690736fb1ddfcd1ab5ca10f3bf588f8ab8
Showing with 14 additions and 5 deletions.
  1. +13 −4 lib/core/src/Cardano/Wallet/DB/Sqlite.hs
  2. +1 −1 lib/core/test/unit/Cardano/Wallet/DB/SqliteSpec.hs
@@ -25,7 +25,11 @@ import Prelude
import Cardano.Crypto.Wallet
( XPrv, unXPrv )
import Cardano.Wallet.DB
( DBLayer (..), ErrNoSuchWallet (..), PrimaryKey (..) )
( DBLayer (..)
, ErrNoSuchWallet (..)
, ErrWalletAlreadyExists (..)
, PrimaryKey (..)
)
import Cardano.Wallet.DB.SqliteTypes
( AddressScheme (..), TxId (..) )
import Cardano.Wallet.Primitive.AddressDerivation
@@ -301,16 +305,21 @@ newDBLayer fp = do
-----------------------------------------------------------------------}

{ createWallet = \(PrimaryKey wid) cp meta ->
ExceptT $ unsafeRunQuery conn $ Right <$> do
insert_ (mkWalletEntity wid meta)
insertCheckpoint wid cp
ExceptT $ unsafeRunQuery conn $
selectFirst [WalTableId ==. wid] [] >>= \case
Just _ ->
pure $ Left $ ErrWalletAlreadyExists wid
Nothing -> Right <$> do
insert_ (mkWalletEntity wid meta)
insertCheckpoint wid cp

, removeWallet = \(PrimaryKey wid) ->
ExceptT $ unsafeRunQuery conn $ do
n <- deleteWhereCount [WalTableId ==. wid]
pure $ if n == 0
then Left (ErrNoSuchWallet wid)
else Right ()

, listWallets = unsafeRunQuery conn $
map (PrimaryKey . unWalletKey) <$> selectKeysList [] []

@@ -46,7 +46,7 @@ spec = do
describe "Extra Properties about DB initialization" $ do
it "createWallet . listWallets yields expected results"
(property . prop_createListWallet)
xit "creating same wallet twice yields an error"
it "creating same wallet twice yields an error"
(property . prop_createWalletTwice)
it "removing the same wallet twice yields an error"
(property . prop_removeWalletTwice)

0 comments on commit 2d62186

Please sign in to comment.
You can’t perform that action at this time.