Skip to content

Commit

Permalink
feat(#326): include PlutusV3 as a reference script when fetching UTxO…
Browse files Browse the repository at this point in the history
… details
  • Loading branch information
sourabhxyz committed Aug 25, 2024
1 parent 7b3253c commit ffc995c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
16 changes: 13 additions & 3 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ test-show-details: direct
package cardano-crypto-praos
flags: -external-libsodium-vrf

-- Temporary, until proposed changes are in upstream (track https://github.com/maestro-org/haskell-sdk/pull/72)
source-repository-package
type: git
location: https://github.com/maestro-org/haskell-sdk
tag: v1.7.0
--sha256: sha256-i0rRBxFHC2/cJoYjDP6sZHaI+e2hbU1jYeHe8EmJ1RE=
location: https://github.com/sourabhxyz/haskell-sdk
tag: 30a100d0e7ade9492a5eca8bef0fe701950c6171
--sha256: FIXME:

-- Temporary, until proposed changes are in upstream (track https://github.com/blockfrost/blockfrost-haskell/pull/54)
source-repository-package
type: git
location: https://github.com/sourabhxyz/blockfrost-haskell
tag: 85b9af545957c6d171d1c8767039dbcc26153117
--sha256: FIXME:
subdir:
blockfrost-api

source-repository-package
type: git
Expand Down
9 changes: 5 additions & 4 deletions src/GeniusYield/Providers/Blockfrost.hs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ blockfrostProtocolParams nid proj = do
Blockfrost.PlutusV2 -> (Ledger.PlutusV2, either (error (errPath <> "Couldn't build PlutusV2 cost models")) id $ Ledger.mkCostModel Ledger.PlutusV2 $ fromInteger <$> Map.elems x) : acc
-- Don't care about non plutus cost models.
Blockfrost.Timelock -> acc
Blockfrost.PlutusV3 -> acc

) [] (Blockfrost.unCostModels _protocolParamsCostModels)
, cppPrices = THKD $ Ledger.Prices {Ledger.prSteps = fromMaybe (error (errPath <> "Couldn't bound Blockfrost's cpu steps")) $ Ledger.boundRational _protocolParamsPriceStep, Ledger.prMem = fromMaybe (error (errPath <> "Couldn't bound Blockfrost's memory units")) $ Ledger.boundRational _protocolParamsPriceMem}
Expand Down Expand Up @@ -551,10 +552,10 @@ lookupScriptHash h = do
mcbor <- Blockfrost._scriptCborCbor <$> Blockfrost.getScriptCBOR h
case mcbor of
Nothing -> return Nothing
Just cbor -> return $
if t == Blockfrost.PlutusV1
then GYPlutusScript <$> scriptFromCBOR @'PlutusV1 cbor
else GYPlutusScript <$> scriptFromCBOR @'PlutusV2 cbor
Just cbor -> return $ case t of
Blockfrost.PlutusV1 -> GYPlutusScript <$> scriptFromCBOR @'PlutusV1 cbor
Blockfrost.PlutusV2 -> GYPlutusScript <$> scriptFromCBOR @'PlutusV2 cbor
Blockfrost.PlutusV3 -> GYPlutusScript <$> scriptFromCBOR @'PlutusV3 cbor

lookupScriptHashIO :: Blockfrost.Project -> Maybe Blockfrost.ScriptHash -> IO (Maybe GYAnyScript)
lookupScriptHashIO _ Nothing = return Nothing
Expand Down
5 changes: 3 additions & 2 deletions src/GeniusYield/Providers/Kupo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ instance FromJSON KupoDatum where
Right d -> pure $ KupoDatum (Just d)
) v

data KupoScriptLanguage = Native | PlutusV1 | PlutusV2
data KupoScriptLanguage = Native | PlutusV1 | PlutusV2 | PlutusV3
deriving stock (Eq, Ord, Show, Generic)
deriving (FromJSON) via CustomJSON '[ConstructorTagModifier '[Rename "Native" "native", Rename "PlutusV1" "plutus:v1", Rename "PlutusV2" "plutus:v2"]] KupoScriptLanguage
deriving (FromJSON) via CustomJSON '[ConstructorTagModifier '[Rename "Native" "native", Rename "PlutusV1" "plutus:v1", Rename "PlutusV2" "plutus:v2", Rename "PlutusV3" "plutus:v3"]] KupoScriptLanguage

newtype KupoScript = KupoScript (Maybe GYAnyScript)
deriving stock (Eq, Show, Generic)
Expand All @@ -153,6 +153,7 @@ instance FromJSON KupoScript where
Native -> pure $ KupoScript $ GYSimpleScript <$> simpleScriptFromCBOR scriptHex
PlutusV1 -> pure $ KupoScript $ GYPlutusScript <$> scriptFromCBOR @'GYTypes.PlutusV1 scriptHex
PlutusV2 -> pure $ KupoScript $ GYPlutusScript <$> scriptFromCBOR @'GYTypes.PlutusV2 scriptHex
PlutusV3 -> pure $ KupoScript $ GYPlutusScript <$> scriptFromCBOR @'GYTypes.PlutusV3 scriptHex
) v

data KupoValue = KupoValue
Expand Down
3 changes: 3 additions & 0 deletions src/GeniusYield/Providers/Maestro.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ scriptFromMaestro Maestro.Script {..} = case scriptType of
Maestro.PlutusV2 -> case scriptBytes of
Nothing -> Left $ DeserializeErrorImpossibleBranch "UTxO has PlutusV2 script but still no script bytes are present"
Just sb -> pure $ GYPlutusScript <$> scriptFromCBOR @'PlutusV2 sb
Maestro.PlutusV3 -> case scriptBytes of
Nothing -> Left $ DeserializeErrorImpossibleBranch "UTxO has PlutusV3 script but still no script bytes are present"
Just sb -> pure $ GYPlutusScript <$> scriptFromCBOR @'PlutusV3 sb

-- | Convert Maestro's UTxO to our GY type.
utxoFromMaestro :: Maestro.IsUtxo a => a -> Either SomeDeserializeError GYUTxO
Expand Down

0 comments on commit ffc995c

Please sign in to comment.