Skip to content

Commit

Permalink
UtxoState
Browse files Browse the repository at this point in the history
  • Loading branch information
mmontin committed Apr 2, 2024
1 parent cecc66f commit 5b691c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/Cooked/MockChain/UtxoState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Ledger as Pl hiding (Value)
import qualified Plutus.Script.Utils.Value as Pl
import qualified Plutus.V2.Ledger.Api as PV2

-- | A description of who owns what in a blockchain. Owners are addresses
-- and they each own a 'UtxoPayloadSet'.
newtype UtxoState = UtxoState {utxoState :: Map Pl.Address UtxoPayloadSet}
deriving (Eq)

-- | Total value accessible to what's pointed by the address.
holdsInState :: PV2.Address -> UtxoState -> PV2.Value
holdsInState :: Pl.Address -> UtxoState -> Pl.Value
holdsInState address (UtxoState m) =
maybe mempty utxoPayloadSetTotal (Map.lookup address m)

Expand All @@ -40,7 +39,7 @@ newtype UtxoPayloadSet = UtxoPayloadSet
-- | A convenient wrapping of the interesting information of a UTxO.
data UtxoPayload = UtxoPayload
{ utxoPayloadTxOutRef :: Pl.TxOutRef,
utxoPayloadValue :: PV2.Value,
utxoPayloadValue :: Pl.Value,
utxoPayloadSkelOutDatum :: TxSkelOutDatum,
utxoPayloadReferenceScript :: Maybe Pl.ScriptHash
}
Expand All @@ -60,5 +59,5 @@ instance Monoid UtxoPayloadSet where
mempty = UtxoPayloadSet []

-- | Computes the total value in a set
utxoPayloadSetTotal :: UtxoPayloadSet -> PV2.Value
utxoPayloadSetTotal :: UtxoPayloadSet -> Pl.Value
utxoPayloadSetTotal = mconcat . fmap utxoPayloadValue . utxoPayloadSet
10 changes: 7 additions & 3 deletions src/Cooked/RawUPLC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,20 @@ typedValidatorFromUPLC = TScripts.unsafeMkTypedValidator . flip Versioned Plutus
fromPlc :: UPLC.Program UPLC.NamedDeBruijn UPLC.DefaultUni UPLC.DefaultFun () -> Script
fromPlc (UPLC.Program a v t) =
let nameless = UPLC.termMapNames UPLC.unNameDeBruijn t
in Script $ UPLC.Program a v nameless
in Script undefined -- UPLC.Program a v nameless

-- TODO

-- | Loads a typed validator from a bytestring that was produced by 'Flat.flat' the outputs
-- of [getPlc](https://github.com/input-output-hk/plutus/blob/master/plutus-tx/src/PlutusTx/Code.hs#L84)
-- applied to a 'TScripts.mkTypedValidator'. If the compiled validator was /not/ wrapped,
-- stick to 'typedValidatorFromBS'.
unsafeTypedValidatorFromBS :: forall a. BS.ByteString -> Either String (TScripts.TypedValidator a)
unsafeTypedValidatorFromBS = either (Left . show) (Right . unsafeTypedValidatorFromUPLC) . Flat.unflat
unsafeTypedValidatorFromBS = undefined -- either (Left . show) (Right . unsafeTypedValidatorFromUPLC) . Flat.unflat

-- TODO

-- | Loads a typed validator from a bytestring that was produced by 'Flat.flat' the outputs
-- of [getPlc](https://github.com/input-output-hk/plutus/blob/master/plutus-tx/src/PlutusTx/Code.hs#L84).
typedValidatorFromBS :: BS.ByteString -> Either String (TScripts.TypedValidator TScripts.Any)
typedValidatorFromBS = either (Left . show) (Right . unsafeTypedValidatorFromUPLC) . Flat.unflat
typedValidatorFromBS = undefined -- either (Left . show) (Right . unsafeTypedValidatorFromUPLC) . Flat.unflat

0 comments on commit 5b691c5

Please sign in to comment.