Skip to content

Commit

Permalink
Sqlite: Allow adding the same transaction with putTxHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed May 30, 2019
1 parent de5c3b8 commit 1df0e8a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/core/src/Cardano/Wallet/DB/Sqlite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ newDBLayer fp = do
Just _ -> do
let (metas, txins, txouts) = mkTxHistory wid txs
putTxMetas wid metas
putMany txins
putMany txouts
deleteLooseTransactions
putTxs (TxId <$> Map.keys txs) txins txouts
pure $ Right ()
Nothing -> pure $ Left $ ErrNoSuchWallet wid

Expand Down Expand Up @@ -549,6 +547,14 @@ putTxMetas wid metas = do
, TxMetaTableTxId <-. map txMetaTableTxId metas ]
insertMany_ metas

-- | Insert multiple transactions, removing old instances first.
putTxs :: [TxId] -> [TxIn] -> [TxOut] -> SqlPersistM ()
putTxs txIds txins txouts = do
deleteWhere [TxInputTableTxId <-. txIds]
putMany txins
deleteWhere [TxOutputTableTxId <-. txIds]
putMany txouts

-- | Delete transactions that aren't referred to by either Pending or TxMeta of
-- any wallet.
deleteLooseTransactions :: SqlPersistM ()
Expand Down

0 comments on commit 1df0e8a

Please sign in to comment.