Skip to content

Commit

Permalink
Switch to PlutusV3 data types in scripts and off-chain code
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo authored and locallycompact committed Jul 24, 2024
1 parent ed9a238 commit fe35d8b
Show file tree
Hide file tree
Showing 41 changed files with 97 additions and 76 deletions.
4 changes: 2 additions & 2 deletions hydra-cardano-api/src/Hydra/Cardano/Api/AddressInEra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import Cardano.Ledger.Credential qualified as Ledger
import Cardano.Ledger.Hashes qualified as Ledger
import Cardano.Ledger.Keys qualified as Ledger
import Hydra.Cardano.Api.Network (Network)
import PlutusLedgerApi.V2 (
import PlutusLedgerApi.V3 (
Address (..),
Credential (..),
StakingCredential (StakingHash, StakingPtr),
fromBuiltin,
)
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 qualified as Plutus

-- * Extras

Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Cardano.Ledger.Plutus.TxInfo (transKeyHash)
import Cardano.Ledger.SafeHash (unsafeMakeSafeHash)
import Cardano.Ledger.Shelley.Scripts qualified as Ledger
import Data.ByteString qualified as BS
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 qualified as Plutus

-- * Type conversions

Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/PolicyId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Cardano.Ledger.Alonzo.Plutus.TxInfo qualified as Ledger
import Cardano.Ledger.Hashes qualified as Ledger
import Cardano.Ledger.Mary.Value qualified as Ledger
import Hydra.Cardano.Api.ScriptHash ()
import PlutusLedgerApi.V2 (CurrencySymbol, fromBuiltin, unCurrencySymbol)
import PlutusLedgerApi.V3 (CurrencySymbol, fromBuiltin, unCurrencySymbol)

-- * Orphans

Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/ReferenceScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Hydra.Cardano.Api.ReferenceScript where
import Hydra.Cardano.Api.Prelude

import Hydra.Cardano.Api.PlutusScript (fromPlutusScript)
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 qualified as Plutus

-- | Construct a 'ReferenceScript' from any given Plutus script.
--
Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Data.Aeson (Value (String), withText)
import Data.ByteString qualified as BS
import Data.ByteString.Base16 qualified as Base16
import Data.Map qualified as Map
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 qualified as Plutus
import Test.QuickCheck (arbitrarySizedNatural, choose, oneof, scale, sized, vector)

-- * Extras
Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Data.Map qualified as Map
import Hydra.Cardano.Api.PlutusScript (fromLedgerScript)
import Hydra.Cardano.Api.PolicyId (toLedgerPolicyID, toLedgerScriptHash)
import Hydra.Cardano.Api.TxIn (toLedgerTxIn)
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 qualified as Plutus

-- | Find and deserialise from 'ScriptData', a redeemer from the transaction
-- associated to the given input.
Expand Down
11 changes: 8 additions & 3 deletions hydra-cardano-api/src/Hydra/Cardano/Api/TxIn.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ module Hydra.Cardano.Api.TxIn where

import Hydra.Cardano.Api.Prelude

import Cardano.Ledger.BaseTypes (txIxToInt)
import Cardano.Ledger.BaseTypes qualified as Ledger
import Cardano.Ledger.Binary qualified as Ledger
import Cardano.Ledger.Plutus (transTxIn)
import Cardano.Ledger.Plutus (transSafeHash)
import Cardano.Ledger.TxIn qualified as Ledger
import Data.ByteString qualified as BS
import Data.Set qualified as Set
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 qualified as Plutus
import Test.QuickCheck (choose, vectorOf)

-- * Extras
Expand Down Expand Up @@ -54,7 +55,11 @@ fromPlutusTxOutRef (Plutus.TxOutRef (Plutus.TxId bytes) ix) =

-- | Convert a cardano-api 'TxIn' into a plutus 'TxOutRef'.
toPlutusTxOutRef :: TxIn -> Plutus.TxOutRef
toPlutusTxOutRef = transTxIn . toLedgerTxIn
toPlutusTxOutRef txIn =
-- XXX: The upstream 'transTxIn' works only with the the PlutusV1 type, so we
-- needed to vendor its definition here.
let (Ledger.TxIn (Ledger.TxId safe) txIx) = toLedgerTxIn txIn
in Plutus.TxOutRef (Plutus.TxId $ transSafeHash safe) (toInteger $ txIxToInt txIx)

-- * Arbitrary values

Expand Down
4 changes: 2 additions & 2 deletions hydra-cardano-api/src/Hydra/Cardano/Api/TxOut.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import Hydra.Cardano.Api.Hash (unsafeScriptDataHashFromBytes)
import Hydra.Cardano.Api.Network (Network)
import Hydra.Cardano.Api.ScriptData (toScriptData)
import Hydra.Cardano.Api.Value (fromPlutusValue, minUTxOValue)
import PlutusLedgerApi.V2 (OutputDatum (..), fromBuiltin)
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 (OutputDatum (..), fromBuiltin)
import PlutusLedgerApi.V3 qualified as Plutus

-- * Extras

Expand Down
4 changes: 2 additions & 2 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import Data.Word (Word64)
import Hydra.Cardano.Api.CtxUTxO (ToUTxOContext (..))
import Hydra.Cardano.Api.PolicyId (fromPlutusCurrencySymbol)
import PlutusLedgerApi.V1.Value (flattenValue)
import PlutusLedgerApi.V2 (adaSymbol, adaToken, fromBuiltin, unTokenName)
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 (adaSymbol, adaToken, fromBuiltin, unTokenName)
import PlutusLedgerApi.V3 qualified as Plutus

-- * Extras

Expand Down
2 changes: 1 addition & 1 deletion hydra-node/bench/tx-cost/TxCost.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import Hydra.Ledger.Cardano.Evaluate (
import Hydra.Ledger.Cardano.Time (slotNoFromUTCTime)
import Hydra.Plutus.Orphans ()
import Hydra.Snapshot (genConfirmedSnapshot)
import PlutusLedgerApi.V2 (toBuiltinData)
import PlutusLedgerApi.V3 (toBuiltinData)
import PlutusTx.Builtins (lengthOfByteString, serialiseData)
import Test.QuickCheck (generate)

Expand Down
4 changes: 2 additions & 2 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ import Hydra.Party (Party, partyFromChain, partyToChain)
import Hydra.Plutus.Extras (posixFromUTCTime, posixToUTCTime)
import Hydra.Plutus.Orphans ()
import Hydra.Snapshot (ConfirmedSnapshot (..), Snapshot (..), SnapshotNumber, SnapshotVersion, fromChainSnapshotNumber, fromChainSnapshotVersion, getSnapshot)
import PlutusLedgerApi.V2 (CurrencySymbol (CurrencySymbol), fromBuiltin, getPubKeyHash, toBuiltin)
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 (CurrencySymbol (CurrencySymbol), fromBuiltin, getPubKeyHash, toBuiltin)
import PlutusLedgerApi.V3 qualified as Plutus
import Test.QuickCheck (vectorOf)

-- | Needed on-chain data to create Head transactions.
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/Crypto.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import Hydra.Cardano.Api (
serialiseToRawBytesHexText,
)
import Hydra.Contract.HeadState qualified as OnChain
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 qualified as Plutus
import Test.QuickCheck (vectorOf)
import Test.QuickCheck.Instances.ByteString ()
import Text.Show (Show (..))
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/Ledger/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Formatting.Buildable (build)
import Hydra.Cardano.Api.UTxO qualified as Api
import Hydra.Contract.Head qualified as Head
import Hydra.Ledger (ChainSlot (..), IsTx (..), Ledger (..), ValidationError (..))
import PlutusLedgerApi.V2 (fromBuiltin)
import PlutusLedgerApi.V3 (fromBuiltin)
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.QuickCheck (
choose,
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/Snapshot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Hydra.Contract.HeadState qualified as Onchain
import Hydra.Crypto (HydraKey, MultiSignature, aggregate, sign)
import Hydra.HeadId (HeadId)
import Hydra.Ledger (IsTx (..))
import PlutusLedgerApi.V2 (toBuiltin, toData)
import PlutusLedgerApi.V3 (toBuiltin, toData)
import Test.QuickCheck (frequency, suchThat)
import Test.QuickCheck.Instances.Natural ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import Hydra.Plutus.Orphans ()
import Hydra.Snapshot (Snapshot (..))
import Hydra.Snapshot qualified as Snapshot
import PlutusLedgerApi.V1.Time (DiffMilliSeconds (..), fromMilliSeconds)
import PlutusLedgerApi.V2 (POSIXTime, PubKeyHash (PubKeyHash), toBuiltin)
import PlutusLedgerApi.V3 (POSIXTime, PubKeyHash (PubKeyHash), toBuiltin)
import Test.QuickCheck (arbitrarySizedNatural, choose, elements, listOf1, oneof, resize, suchThat)
import Test.QuickCheck.Instances ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Hydra.Ledger (hashUTxO)
import Hydra.Plutus.Extras (posixFromUTCTime)
import Hydra.Plutus.Orphans ()
import Hydra.Snapshot (ConfirmedSnapshot (..), SnapshotNumber, SnapshotVersion)
import PlutusLedgerApi.V2 (POSIXTime, toBuiltin)
import PlutusLedgerApi.V3 (POSIXTime, toBuiltin)
import Test.QuickCheck (oneof, suchThat)
import Test.QuickCheck.Instances ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import Hydra.Plutus.Extras (posixFromUTCTime)
import Hydra.Plutus.Orphans ()
import Hydra.Snapshot (ConfirmedSnapshot, Snapshot (..), SnapshotNumber, SnapshotVersion, getSnapshot, signatures)
import PlutusLedgerApi.V1.Time (DiffMilliSeconds (..), fromMilliSeconds)
import PlutusLedgerApi.V2 (POSIXTime, PubKeyHash (PubKeyHash), toBuiltin)
import PlutusLedgerApi.V3 (POSIXTime, PubKeyHash (PubKeyHash), toBuiltin)
import Test.QuickCheck (arbitrarySizedNatural, choose, elements, listOf1, oneof, suchThat)
import Test.QuickCheck.Instances ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Hydra.Ledger.Cardano.Evaluate (genValidityBoundsFromContestationPeriod)
import Hydra.Party (Party, deriveParty, partyToChain)
import Hydra.Plutus.Orphans ()
import Hydra.Snapshot (ConfirmedSnapshot (..), Snapshot)
import PlutusLedgerApi.V2 (BuiltinByteString, toBuiltin)
import PlutusLedgerApi.V3 (BuiltinByteString, toBuiltin)
import Test.Hydra.Fixture (aliceSk, bobSk, carolSk, genForParty)
import Test.QuickCheck (elements)
import Test.QuickCheck.Instances ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ import Hydra.Party (Party, deriveParty, partyToChain)
import Hydra.Plutus.Extras (posixFromUTCTime)
import Hydra.Plutus.Orphans ()
import Hydra.Snapshot (Snapshot (..), SnapshotNumber, SnapshotVersion)
import PlutusLedgerApi.V2 (BuiltinByteString, toBuiltin)
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 (BuiltinByteString, toBuiltin)
import PlutusLedgerApi.V3 qualified as Plutus
import Test.Hydra.Fixture (aliceSk, bobSk, carolSk, genForParty)
import Test.QuickCheck (arbitrarySizedNatural, elements, listOf, listOf1, oneof, resize, suchThat, vectorOf)
import Test.QuickCheck.Gen (choose)
Expand Down
4 changes: 2 additions & 2 deletions hydra-node/test/Hydra/Chain/Direct/Contract/Mutation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ import Hydra.Ledger.Cardano (genKeyPair, genOutput)
import Hydra.Ledger.Cardano.Evaluate (evaluateTx)
import Hydra.Plutus.Orphans ()
import Hydra.Prelude hiding (label)
import PlutusLedgerApi.V2 (CurrencySymbol, POSIXTime, toData)
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 (CurrencySymbol, POSIXTime, toData)
import PlutusLedgerApi.V3 qualified as Plutus
import System.Directory.Internal.Prelude qualified as Prelude
import Test.Hydra.Prelude
import Test.QuickCheck (
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/test/Hydra/Chain/Direct/ContractSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import Hydra.Ledger.Simple (SimpleTx)
import Hydra.Party (deriveParty, partyToChain)
import Hydra.Plutus.Orphans ()
import Hydra.Snapshot (Snapshot (..))
import PlutusLedgerApi.V2 (fromBuiltin, toBuiltin)
import PlutusLedgerApi.V3 (fromBuiltin, toBuiltin)
import Test.QuickCheck (
Property,
conjoin,
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/test/Hydra/Chain/Direct/StateSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ import Hydra.Ledger.Cardano.Time (slotNoFromUTCTime)
import Hydra.Snapshot (ConfirmedSnapshot (InitialSnapshot, initialUTxO))
import Hydra.Snapshot qualified as Snapshot
import PlutusLedgerApi.Test.Examples qualified as Plutus
import PlutusLedgerApi.V2 qualified as Plutus
import PlutusLedgerApi.V3 qualified as Plutus
import Test.Aeson.GenericSpecs (roundtripAndGoldenSpecs)
import Test.QuickCheck (
Property,
Expand Down
2 changes: 1 addition & 1 deletion hydra-plutus-extras/src/Hydra/Plutus/Extras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Cardano.Api (
)
import Cardano.Api.Shelley (PlutusScript (PlutusScriptSerialised))
import PlutusLedgerApi.Common (SerialisedScript)
import PlutusLedgerApi.V2 (ScriptHash (..))
import PlutusLedgerApi.V3 (ScriptHash (..))
import PlutusTx (BuiltinData, UnsafeFromData (..))
import PlutusTx.Prelude (BuiltinUnit, check, toBuiltin)

Expand Down
2 changes: 1 addition & 1 deletion hydra-plutus-extras/src/Hydra/Plutus/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Data.Aeson (object, withObject, (.:), (.=))
import Data.Aeson qualified as Aeson
import Data.ByteString qualified as BS
import Data.ByteString.Base16 qualified as Base16
import PlutusLedgerApi.V2 (CurrencySymbol, POSIXTime (..), PubKeyHash (..), TokenName, TxId (..), TxOutRef (..), UpperBound, Value, upperBound)
import PlutusLedgerApi.V3 (CurrencySymbol, POSIXTime (..), PubKeyHash (..), TokenName, TxId (..), TxOutRef (..), UpperBound, Value, upperBound)
import PlutusTx.AssocMap qualified as AssocMap
import PlutusTx.Prelude (BuiltinByteString, Eq, fromBuiltin, toBuiltin)
import Test.QuickCheck (choose, vectorOf)
Expand Down
2 changes: 1 addition & 1 deletion hydra-plutus/exe/inspect-script/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Hydra.Contract.Head as Head
import Hydra.Contract.HeadState as Head
import Hydra.Contract.HeadTokens qualified as HeadTokens
import Hydra.Contract.Initial as Initial
import PlutusLedgerApi.V2 (Data, SerialisedScript, toData)
import PlutusLedgerApi.V3 (Data, SerialisedScript, toData)
import PlutusTx (getPlc)
import PlutusTx.Code (CompiledCode)
import Prettyprinter (defaultLayoutOptions, layoutPretty)
Expand Down
Loading

0 comments on commit fe35d8b

Please sign in to comment.