Skip to content

Commit

Permalink
Partial attempt to use latest cardano-api
Browse files Browse the repository at this point in the history
  • Loading branch information
noonio committed Jan 15, 2025
1 parent 6d43e60 commit e20263f
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 31 deletions.
20 changes: 12 additions & 8 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ repository cardano-haskell-packages

-- See CONTRIBUTING.md for information about when and how to update these.
index-state:
, hackage.haskell.org 2024-11-22T14:59:16Z
, cardano-haskell-packages 2024-12-20T15:52:56Z
, hackage.haskell.org 2025-01-15T13:32:16Z
, cardano-haskell-packages 2025-01-15T09:59:24Z

packages:
hydra-prelude
Expand Down Expand Up @@ -42,9 +42,13 @@ test-show-details: direct
program-options
ghc-options: -fwrite-ide-info

constraints:
quickcheck-instances==0.3.31,
data-default==0.7.1.3
--source-repository-package
-- type: git
-- location: https://github.com/IntersectMBO/cardano-api
-- tag: 271099ce20b9767367fc0ecdb1a6f2d0f71a00f7
-- --sha256: sha256-6PImVY8AHDPHk76wADaV+JIjtTVlKM9rwKw2sBFxD14=
-- subdir:
-- cardano-api

source-repository-package
type: git
Expand All @@ -57,10 +61,10 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/locallycompact/plutus
tag: b117b4460b5b5da2a599db8693b18dacd811bb91
--sha256: sha256-GUPwIwbTOy/eTBhjOwrR+XwJsML/jmBlAf1qU6zWvd8=
tag: d4f1bc056e4db3f3d71af9069f355a97d326b29b
--sha256: sha256-w3vtZ8v4nGAkeGoNjd5kZly7fv4QPm/iEgyg3EasZAM=
subdir:
prettyprinter-configurable
-- prettyprinter-configurable
plutus-core
plutus-ledger-api
plutus-tx-plugin
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hydra-cardano-api/hydra-cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ library
, aeson >=2
, base >=4.16
, bytestring
, cardano-api ^>=10.5
, cardano-api ^>=10.6
, cardano-api:gen
, cardano-binary
, cardano-crypto-class
Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Cardano.Crypto.Hash.Class qualified as CC
import Cardano.Ledger.Binary qualified as Ledger
import Cardano.Ledger.Core qualified as Ledger
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Ledger.Era (EraCrypto)
import Cardano.Ledger.Core (EraCrypto)
import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.ByteString (ByteString)
import Data.ByteString.Lazy (fromStrict, toStrict)
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 @@ -4,7 +4,7 @@ module Hydra.Cardano.Api.ScriptData where

import Hydra.Cardano.Api.Prelude hiding (left)

import Cardano.Ledger.Era qualified as Ledger
import Cardano.Ledger.Core qualified as Ledger
import Cardano.Ledger.Plutus.Data qualified as Ledger
import PlutusLedgerApi.V3 qualified as Plutus

Expand Down
11 changes: 6 additions & 5 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -457,19 +457,20 @@ singlePartyUsesSchnorrkelScriptOnL2 tracer workDir node hydraScriptsTxId =
ScriptWitness scriptWitnessInCtx $
mkScriptWitness serializedScript (mkScriptDatum ()) (toScriptData ())

-- Note: Bug! autobalancing breaks the script business
-- tx <- either (failure . show) pure =<< buildTransactionWithBody networkId nodeSocket (mkVkAddress networkId walletVk) body utxoToCommit

let txIn = mkTxIn signedL2tx 0
let body =
defaultTxBodyContent
& addTxIns [(txIn, scriptWitness)]

-- Note: Bug! autobalancing breaks the script business
tx <- either (failure . show) pure =<< buildTransactionWithBody networkId nodeSocket (mkVkAddress networkId walletVk) body utxoToCommit

-- Note: Fix! Use `createAndValidateTransactionBody` instead. This
-- means we _can_ construct the tx; but it doesn't submit (because it
-- isn't balanced! And it's missing collateral, etc...
txBody <- either (failure . show) pure (createAndValidateTransactionBody body)
let tx = makeSignedTransaction [] txBody
-- txBody <- either (failure . show) pure (createAndValidateTransactionBody body)
-- let tx = makeSignedTransaction [] txBody

let signedL2tx = signTx walletSk tx

send n1 $ input "NewTx" ["transaction" .= signedL2tx]
Expand Down
1 change: 1 addition & 0 deletions hydra-node/src/Hydra/Ledger/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ newLedgerEnv protocolParams =
Ledger.ledgerAccount = Ledger.AccountState mempty mempty
, Ledger.ledgerPp = protocolParams
, Ledger.ledgerMempool = False
, Ledger.ledgerEpochNo = Nothing
}

-- * Conversions and utilities
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Cardano.Ledger.Orphans ()
import Data.IP (IP, toIPv4w)
import Data.Text (pack, unpack)
import Network.Socket (PortNumber, close)
import Network.TypedProtocol.Pipelined ()
-- import Network.TypedProtocol.Pipelined ()
import Test.QuickCheck (elements, listOf, suchThat)
import Text.Read (Read (readsPrec))
import Text.Show (Show (show))
Expand Down
13 changes: 7 additions & 6 deletions hydra-node/src/Hydra/Network/Ouroboros/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Hydra.Prelude
import Cardano.Binary qualified as CBOR
import Codec.CBOR.Read qualified as CBOR
import GHC.Show (Show (show))
import Network.TypedProtocol (PeerHasAgency (ClientAgency), Protocol (..))
import Network.TypedProtocol.Core (ReflRelativeAgency (ReflClientAgency))
import Network.TypedProtocol (Protocol (..))
import Network.TypedProtocol.Codec (Codec)
import Network.TypedProtocol.Codec.CBOR (mkCodecCborLazyBS)
import Network.TypedProtocol.Core (PeerRole)
Expand Down Expand Up @@ -77,8 +78,8 @@ codecFireForget = mkCodecCborLazyBS encodeMsg decodeMsg
PeerHasAgency pr st ->
Message (FireForget a) st st' ->
CBOR.Encoding
encodeMsg (ClientAgency TokIdle) MsgDone = CBOR.encodeWord 0
encodeMsg (ClientAgency TokIdle) (MsgSend msg) = CBOR.encodeWord 1 <> toCBOR msg
encodeMsg (ReflClientAgency TokIdle) MsgDone = CBOR.encodeWord 0
encodeMsg (ReflClientAgency TokIdle) (MsgSend msg) = CBOR.encodeWord 1 <> toCBOR msg

decodeMsg ::
forall (pr :: PeerRole) s (st :: FireForget a).
Expand All @@ -87,9 +88,9 @@ codecFireForget = mkCodecCborLazyBS encodeMsg decodeMsg
decodeMsg stok = do
key <- CBOR.decodeWord
case (stok, key) of
(ClientAgency TokIdle, 0) ->
(ReflClientAgency TokIdle, 0) ->
return $ SomeMessage MsgDone
(ClientAgency TokIdle, 1) -> do
(ReflClientAgency TokIdle, 1) -> do
SomeMessage . MsgSend <$> fromCBOR
(ClientAgency TokIdle, _) ->
(ReflClientAgency TokIdle, _) ->
fail "codecFireForget.StIdle: unexpected key"
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import GHC.Natural (naturalFromInteger, naturalToInteger)
import GHC.Num (integerToInt)
import Hydra.Network (Host (..))
import Hydra.Network.Message (HydraVersionedProtocolNumber (..))
import Network.TypedProtocol.Pipelined ()
-- import Network.TypedProtocol.Pipelined ()
import Ouroboros.Network.CodecCBORTerm (CodecCBORTerm (..))
import Ouroboros.Network.Protocol.Handshake.Codec (VersionDataCodec, cborTermVersionDataCodec)
import Ouroboros.Network.Protocol.Handshake.Version (Accept (..), Acceptable, Queryable, acceptableVersion, queryVersion)
Expand Down
5 changes: 3 additions & 2 deletions hydra-plutus/src/Hydra/Contract/Head.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import PlutusLedgerApi.V3 (
TxOut (..),
UpperBound (..),
Value (Value),
mintValueMinted,
)
import PlutusLedgerApi.V3.Contexts (findOwnInput, findTxInByTxOutRef)
import PlutusTx (CompiledCode)
Expand Down Expand Up @@ -117,7 +118,7 @@ checkAbort ctx@ScriptContext{scriptContextTxInfo = txInfo} headCurrencySymbol pa
&& mustBeSignedByParticipant ctx headCurrencySymbol
&& mustReimburseCommittedUTxO
where
minted = txInfoMint txInfo
minted = mintValueMinted $ txInfoMint txInfo

mustReimburseCommittedUTxO =
traceIfFalse $(errorCode ReimbursedOutputsDontMatch) $
Expand Down Expand Up @@ -653,7 +654,7 @@ checkFanout ScriptContext{scriptContextTxInfo = txInfo} closedDatum numberOfFano
&& hasSameDecommitUTxOHash
&& afterContestationDeadline
where
minted = txInfoMint txInfo
minted = mintValueMinted $ txInfoMint txInfo

hasSameUTxOHash =
traceIfFalse $(errorCode FanoutUTxOHashMismatch) $
Expand Down
5 changes: 4 additions & 1 deletion hydra-plutus/src/Hydra/Contract/HeadTokens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import PlutusLedgerApi.V3 (
TxOutRef,
Value (getValue),
serialiseCompiledCode,
mintValueMinted
)
import PlutusLedgerApi.V3.Contexts (ownCurrencySymbol)
import PlutusTx (CompiledCode)
Expand Down Expand Up @@ -136,6 +137,7 @@ validateTokensMinting initialValidator headValidator seedInput context =
maybe 0 sum
. AssocMap.lookup currency
. getValue
. mintValueMinted
$ txInfoMint txInfo

(headId, seed, nParties) =
Expand Down Expand Up @@ -173,7 +175,8 @@ validateTokensBurning context =

ScriptContext{scriptContextTxInfo = txInfo} = context

minted = getValue $ txInfoMint txInfo
-- TODO: Should this be burned our minted?!
minted = getValue . mintValueMinted $ txInfoMint txInfo

burnHeadTokens =
case AssocMap.lookup currency minted of
Expand Down
3 changes: 2 additions & 1 deletion hydra-plutus/src/Hydra/Contract/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import PlutusLedgerApi.V3 (
TxOutRef (..),
Value (getValue),
toBuiltinData,
mintValueMinted
)
import PlutusTx.AssocMap qualified as AssocMap
import PlutusTx.Builtins (serialiseData)
Expand Down Expand Up @@ -57,7 +58,7 @@ mustBurnAllHeadTokens minted headCurrencySymbol parties =
mustNotMintOrBurn :: TxInfo -> Bool
mustNotMintOrBurn TxInfo{txInfoMint} =
traceIfFalse "U01" $
isZero txInfoMint
isZero (mintValueMinted txInfoMint)
{-# INLINEABLE mustNotMintOrBurn #-}

infix 4 ===
Expand Down

0 comments on commit e20263f

Please sign in to comment.