Skip to content

Commit

Permalink
Modify SQLite function selectUTxO to return tokens.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Dec 2, 2020
1 parent f4928ce commit 2af6f8c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/core/src/Cardano/Wallet/DB/Sqlite.hs
Expand Up @@ -1150,7 +1150,7 @@ mkCheckpointEntity wid wal =
-- and TxOut records must already by sorted by index.
checkpointFromEntity
:: Checkpoint
-> [UTxO]
-> [(UTxO, [UTxOToken])]
-> s
-> W.Wallet s
checkpointFromEntity cp utxo s =
Expand All @@ -1174,7 +1174,7 @@ checkpointFromEntity cp utxo s =
header = (W.BlockHeader slot (Quantity bh) headerHash parentHeaderHash)
utxo' = W.UTxO . Map.fromList $
[ (W.TxIn input ix, W.TxOut addr (TB.fromCoin coin))
| UTxO _ _ (TxId input) ix addr coin <- utxo
| UTxO _ _ (TxId input) ix addr coin <- fst <$> utxo
]
gp = W.GenesisParameters
{ getGenesisBlockHash = coerce genesisHash
Expand Down Expand Up @@ -1499,12 +1499,20 @@ deleteDelegationCertificates wid filters = do

selectUTxO
:: Checkpoint
-> SqlPersistT IO [UTxO]
selectUTxO cp = fmap entityVal <$>
selectList
[ UtxoWalletId ==. checkpointWalletId cp
, UtxoSlot ==. checkpointSlot cp
] []
-> SqlPersistT IO [(UTxO, [UTxOToken])]
selectUTxO cp = do
utxos <- fmap entityVal <$>
selectList
[ UtxoWalletId ==. checkpointWalletId cp
, UtxoSlot ==. checkpointSlot cp
] []
forM utxos $ \utxo -> do
(utxo, ) . fmap entityVal <$> selectList
[ UtxoTokenWalletId ==. utxoWalletId utxo
, UtxoTokenSlot ==. utxoSlot utxo
, UtxoTokenTxId ==. utxoInputId utxo
, UtxoTokenTxIndex ==. utxoInputIndex utxo
] []

-- This relies on available information from the database to reconstruct coin
-- selection information for __outgoing__ payments. We can't however guarantee
Expand Down

0 comments on commit 2af6f8c

Please sign in to comment.