Skip to content

Commit

Permalink
Move BuildTxWith and associated types to a new module to avoid cyclical
Browse files Browse the repository at this point in the history
dependencies
  • Loading branch information
Jimbo4350 committed Feb 28, 2025
1 parent e82fddb commit 3011197
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 32 deletions.
32 changes: 0 additions & 32 deletions cardano-api/src/Cardano/Api/Internal/Tx/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,38 +1081,6 @@ fromBabbageTxOutDatum w _ (Plutus.DatumHash dh) =
fromBabbageTxOutDatum _ w (Plutus.Datum binData) =
TxOutDatumInline w $ binaryDataToScriptData w binData

-- ----------------------------------------------------------------------------
-- Building vs viewing transactions
--

data ViewTx

data BuildTx

data BuildTxWith build a where
ViewTx :: BuildTxWith ViewTx a
BuildTxWith :: a -> BuildTxWith BuildTx a

instance Functor (BuildTxWith build) where
fmap _ ViewTx = ViewTx
fmap f (BuildTxWith x) = BuildTxWith (f x)

instance Applicative (BuildTxWith ViewTx) where
pure _ = ViewTx
_ <*> _ = ViewTx

instance Applicative (BuildTxWith BuildTx) where
pure = BuildTxWith
(BuildTxWith f) <*> (BuildTxWith a) = BuildTxWith (f a)

buildTxWithToMaybe :: BuildTxWith build a -> Maybe a
buildTxWithToMaybe ViewTx = Nothing
buildTxWithToMaybe (BuildTxWith a) = Just a

deriving instance Eq a => Eq (BuildTxWith build a)

deriving instance Show a => Show (BuildTxWith build a)

-- ----------------------------------------------------------------------------
-- Transaction input values (era-dependent)
--
Expand Down
49 changes: 49 additions & 0 deletions cardano-api/src/Cardano/Api/Internal/Tx/BuildTxWith.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}

module Cardano.Api.Internal.Tx.BuildTxWith
( BuildTxWith (..)
, BuildTx
, ViewTx
, buildTxWithToMaybe
)
where

-- ----------------------------------------------------------------------------
-- Building vs viewing transactions
--

data ViewTx

data BuildTx

data BuildTxWith build a where
ViewTx :: BuildTxWith ViewTx a
BuildTxWith :: a -> BuildTxWith BuildTx a

instance Functor (BuildTxWith build) where
fmap _ ViewTx = ViewTx
fmap f (BuildTxWith x) = BuildTxWith (f x)

instance Applicative (BuildTxWith ViewTx) where
pure _ = ViewTx
_ <*> _ = ViewTx

instance Applicative (BuildTxWith BuildTx) where
pure = BuildTxWith
(BuildTxWith f) <*> (BuildTxWith a) = BuildTxWith (f a)

buildTxWithToMaybe :: BuildTxWith build a -> Maybe a
buildTxWithToMaybe ViewTx = Nothing
buildTxWithToMaybe (BuildTxWith a) = Just a

deriving instance Eq a => Eq (BuildTxWith build a)

deriving instance Show a => Show (BuildTxWith build a)

0 comments on commit 3011197

Please sign in to comment.