Skip to content

Commit

Permalink
Merge #1193
Browse files Browse the repository at this point in the history
1193: re-use 'deleteWallet' function to avoid logic duplication r=KtorZ a=KtorZ



# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#1071 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [ ] I have re-used 'deleteWallet' function to implement byron delete to avoid logic duplication And seemingly, share fixes when they are done..... !


# Comments

<!-- Additional comments or screenshots to attach if any -->



<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: KtorZ <matthias.benkort@gmail.com>
  • Loading branch information
iohk-bors[bot] and KtorZ authored Dec 16, 2019
2 parents 6feffaf + 3835ae3 commit a6f100d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
16 changes: 4 additions & 12 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,8 @@ wallets ctx =
:<|> getUTxOsStatistics ctx

deleteWallet
:: forall ctx s t k n.
( s ~ SeqState n k
, ctx ~ ApiLayer s t k
:: forall ctx s t k.
( ctx ~ ApiLayer s t k
)
=> ctx
-> ApiT WalletId
Expand Down Expand Up @@ -1009,15 +1008,8 @@ deleteByronWallet
=> ApiLayer s t k
-> ApiT WalletId
-> Handler NoContent
deleteByronWallet ctx (ApiT wid) = do
liftHandler $ withWorkerCtx ctx wid throwE $
\worker -> W.deleteWallet worker wid
liftIO $ Registry.remove re wid
liftIO $ (df ^. #removeDatabase) wid
return NoContent
where
re = ctx ^. workerRegistry @s @k
df = ctx ^. dbFactory @s @k
deleteByronWallet =
deleteWallet

getByronWallet
:: forall t k. ()
Expand Down
32 changes: 17 additions & 15 deletions lib/core/src/Cardano/Wallet/DB/Sqlite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -220,28 +220,30 @@ newDBFactory
-- ^ Path to database directory, or Nothing for in-memory database
-> IO (DBFactory IO s k)
newDBFactory cfg tr mDatabaseDir = do
mvar <- newEmptyMVar
case mDatabaseDir of
Nothing -> pure DBFactory
{ withDatabase = \_ action ->
withDBLayer cfg tracerDB Nothing (action . snd)
, removeDatabase = \_ ->
pure ()
}
Just databaseDir -> pure DBFactory
{ withDatabase = \wid action ->
withDBLayer cfg tracerDB (Just $ databaseFile wid) $ \(ctx,db) -> do
putMVar mvar ctx
action db
, removeDatabase = \wid -> do
let files =
[ databaseFile wid
, databaseFile wid <> "-wal"
, databaseFile wid <> "-shm"
]
readMVar mvar >>= destroyDBLayer
mapM_ removePathForcibly files
}
Just databaseDir -> do
mvar <- newEmptyMVar
pure DBFactory
{ withDatabase = \wid action ->
withDBLayer cfg tracerDB (Just $ databaseFile wid)
$ \(ctx,db) -> do
putMVar mvar ctx
action db
, removeDatabase = \wid -> do
let files =
[ databaseFile wid
, databaseFile wid <> "-wal"
, databaseFile wid <> "-shm"
]
readMVar mvar >>= destroyDBLayer
mapM_ removePathForcibly files
}
where
databaseFilePrefix = keyTypeDescriptor $ Proxy @k
databaseFile wid =
Expand Down

0 comments on commit a6f100d

Please sign in to comment.