Skip to content

Commit

Permalink
[plutus-chain-index]: fix utxo-at-adress beam query (#124). (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Akentev authored Dec 10, 2021
1 parent 373dc99 commit b4277aa
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions plutus-chain-index-core/src/Plutus/ChainIndex/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Data.Proxy (Proxy (..))
import Data.Set qualified as Set
import Data.Word (Word64)
import Database.Beam (Columnar, Identity, SqlSelect, TableEntity, aggregate_, all_, countAll_, delete, filter_, guard_,
limit_, nub_, select, val_)
limit_, not_, nub_, select, val_)
import Database.Beam.Backend.SQL (BeamSqlBackendCanSerialize)
import Database.Beam.Query (HasSqlEqualityCheck, asc_, desc_, exists_, orderBy_, update, (&&.), (<-.), (<.), (==.),
(>.))
Expand Down Expand Up @@ -198,12 +198,12 @@ getUtxoSetAtAddress pageQuery (toDbValue -> cred) = do
tp -> do
let query =
fmap _addressRowOutRef
$ filter_ (\row -> _addressRowCred row ==. val_ cred)
$ do
utxo <- all_ (unspentOutputRows db)
a <- all_ (addressRows db)
guard_ (_addressRowOutRef a ==. _unspentOutputRowOutRef utxo)
pure a
$ filter_ (\row ->
(_addressRowCred row ==. val_ cred)
&&. exists_ (filter_ (\utxo -> _addressRowOutRef row ==. _unspentOutputRowOutRef utxo) (all_ (unspentOutputRows db)))
&&. not_ (exists_ (filter_ (\utxi -> _addressRowOutRef row ==. _unmatchedInputRowOutRef utxi) (all_ (unmatchedInputRows db))))
)
$ all_ (addressRows db)

outRefs <- selectPage (fmap toDbValue pageQuery) query
let page = fmap fromDbValue outRefs
Expand Down

0 comments on commit b4277aa

Please sign in to comment.