mlabs-haskell / tx-village

Opinionated Rust/Haskell ecosystem of libraries and tools to work with Cardano smart contracts
https://mlabs-haskell.github.io/tx-village/
Apache License 2.0
3 stars 0 forks source link

ledger-sim: UTxOs map in Ledger state should be `Map TxOutRef TxInInfo` #47

Closed bladyjoker closed 2 months ago

bladyjoker commented 2 months ago

I understand the need to not duplicate information as currently the Map TxOutRef TxOut has the necessary information to reconstruct a [TxInInfo].

However, the use sites suffer for it as much revolves around [TxInInfo] and then the indexUTxOs :: [TxInInfo] -> Map TxOutRef TxInInfo is a convenient and natural function to use throughout.

Rule of thumb when considering various maps that are but one possible index into some collection is the following index :: (a -> k) -> [a] -> Map k a.

I understand it's sometimes (not generally) redundant to keep the entire a in the map, but keeping it makes further data analysis/pivoting pipelines work much easier as it doesn't require the user to understand how to reconstruct a values.

chfanghr commented 2 months ago

Will add these

lookupUTxO' :: TxOutRef -> LedgerSim ctx st e (Maybe TxInInfo)
mustLookupUTxO :: TxOutRef -> LedgerSim ctx st e TxOut
mustLookupUTxO' :: TxOutRef -> LedgerSim ctx st e TxInInfo

mkLedgerState :: [TxInInfo] -> LedgerState