diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PlutusScriptApi.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PlutusScriptApi.hs index be25a58a229..5e53a86af7e 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PlutusScriptApi.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PlutusScriptApi.hs @@ -57,13 +57,13 @@ import Cardano.Ledger.Shelley.Scripts (ScriptHash (..)) import Cardano.Ledger.Shelley.TxBody ( DelegCert (..), Delegation (..), - TxIn (..), Wdrl (..), getRwdCred, witKeyHash, ) import Cardano.Ledger.Shelley.UTxO (UTxO (..), getScriptHash, scriptCred) import Cardano.Ledger.ShelleyMA.Timelocks (evalTimelock) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Slotting.EpochInfo (EpochInfo) import Cardano.Slotting.Time (SystemStart) import Data.Coders diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxos.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxos.hs index 8f51e1488b4..77bb7a0f045 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxos.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxos.hs @@ -57,8 +57,9 @@ import qualified Cardano.Ledger.Shelley.LedgerState as Shelley import Cardano.Ledger.Shelley.PParams (Update) import Cardano.Ledger.Shelley.Rules.Ppup (PPUP, PPUPEnv (..), PpupPredicateFailure) import Cardano.Ledger.Shelley.Rules.Utxo (UtxoEnv (..)) -import Cardano.Ledger.Shelley.TxBody (DCert, TxIn (..), Wdrl) +import Cardano.Ledger.Shelley.TxBody (DCert, Wdrl) import Cardano.Ledger.Shelley.UTxO (balance, totalDeposits) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val as Val import Control.Iterate.SetAlgebra (eval, (∪), (⋪), (◁)) import Control.Monad.Except (MonadError (throwError)) diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs index 61eabab4cb2..d41657c8715 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs @@ -135,8 +135,9 @@ import Cardano.Ledger.SafeHash import Cardano.Ledger.Shelley.Address.Bootstrap (BootstrapWitness) import Cardano.Ledger.Shelley.Delegation.Certificates (DCert (..)) import Cardano.Ledger.Shelley.Scripts (ScriptHash) -import Cardano.Ledger.Shelley.TxBody (TxIn (..), Wdrl (..), WitVKey, unWdrl) +import Cardano.Ledger.Shelley.TxBody (Wdrl (..), WitVKey, unWdrl) import qualified Cardano.Ledger.Shelley.UTxO as Shelley +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val (Val (coin, (<+>), (<×>))) import Control.DeepSeq (NFData (..)) import qualified Data.ByteString.Lazy as LBS diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxBody.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxBody.hs index fc49ea8ae30..9b07ff22e52 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxBody.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxBody.hs @@ -113,8 +113,9 @@ import Cardano.Ledger.Shelley.CompactAddr (CompactAddr, compactAddr, decompactAd import Cardano.Ledger.Shelley.Delegation.Certificates (DCert) import Cardano.Ledger.Shelley.PParams (Update) import Cardano.Ledger.Shelley.Scripts (ScriptHash) -import Cardano.Ledger.Shelley.TxBody (TxIn (..), Wdrl (Wdrl), unWdrl) +import Cardano.Ledger.Shelley.TxBody (Wdrl (Wdrl), unWdrl) import Cardano.Ledger.ShelleyMA.Timelocks (ValidityInterval (..), ppValidityInterval) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val ( DecodeNonNegative, decodeMint, diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxInfo.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxInfo.hs index c1b46615e53..37f127a4d60 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxInfo.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxInfo.hs @@ -52,13 +52,12 @@ import Cardano.Ledger.Shelley.TxBody Delegation (..), PoolCert (..), PoolParams (..), - TxId (..), - TxIn (..), Wdrl (..), WitVKey (..), ) import Cardano.Ledger.Shelley.UTxO (UTxO (..)) import Cardano.Ledger.ShelleyMA.Timelocks (ValidityInterval (..)) +import Cardano.Ledger.TxIn (TxId (..), TxIn (..)) import Cardano.Ledger.Val (Val (..)) import Cardano.Slotting.EpochInfo (EpochInfo, epochInfoSlotToUTCTime) import Cardano.Slotting.Slot (EpochNo (..), SlotNo (..)) diff --git a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/AlonzoEraGen.hs b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/AlonzoEraGen.hs index b85538f3659..b33636a4d42 100644 --- a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/AlonzoEraGen.hs +++ b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/AlonzoEraGen.hs @@ -52,10 +52,11 @@ import Cardano.Ledger.Keys (KeyHash, KeyRole (Witness)) import Cardano.Ledger.Mary (MaryEra) import Cardano.Ledger.Mary.Value (AssetName (..), PolicyID (..), Value, policies, valueFromList) import Cardano.Ledger.Shelley.PParams (Update) -import Cardano.Ledger.Shelley.TxBody (DCert, TxIn, Wdrl) +import Cardano.Ledger.Shelley.TxBody (DCert, Wdrl) import Cardano.Ledger.Shelley.UTxO (UTxO (..), balance) import Cardano.Ledger.ShelleyMA.AuxiliaryData as Mary (pattern AuxiliaryData) import Cardano.Ledger.ShelleyMA.Timelocks (Timelock (..)) +import Cardano.Ledger.TxIn (TxIn) import Cardano.Ledger.Val (Val (coin), adaOnly, (<+>), (<×>)) import Cardano.Slotting.Slot (SlotNo (..)) import Control.Iterate.SetAlgebra (eval, (◁)) diff --git a/eras/shelley-ma/impl/src/Cardano/Ledger/ShelleyMA/TxBody.hs b/eras/shelley-ma/impl/src/Cardano/Ledger/ShelleyMA/TxBody.hs index b3a70069b80..a0449674660 100644 --- a/eras/shelley-ma/impl/src/Cardano/Ledger/ShelleyMA/TxBody.hs +++ b/eras/shelley-ma/impl/src/Cardano/Ledger/ShelleyMA/TxBody.hs @@ -74,11 +74,11 @@ import Cardano.Ledger.Shelley.Constraints (TransValue) import Cardano.Ledger.Shelley.PParams (Update) import Cardano.Ledger.Shelley.TxBody ( DCert (..), - TxIn (..), TxOut (..), Wdrl (..), ) import Cardano.Ledger.ShelleyMA.Timelocks (ValidityInterval (..), ppValidityInterval) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val ( DecodeMint (..), DecodeNonNegative, diff --git a/eras/shelley-ma/test-suite/src/Test/Cardano/Ledger/AllegraEraGen.hs b/eras/shelley-ma/test-suite/src/Test/Cardano/Ledger/AllegraEraGen.hs index 73be2085ecb..eaae53a8820 100644 --- a/eras/shelley-ma/test-suite/src/Test/Cardano/Ledger/AllegraEraGen.hs +++ b/eras/shelley-ma/test-suite/src/Test/Cardano/Ledger/AllegraEraGen.hs @@ -37,12 +37,13 @@ import Cardano.Ledger.Shelley.Constraints ) import Cardano.Ledger.Shelley.PParams (PParams, PParams' (..), Update) import Cardano.Ledger.Shelley.Tx (pattern Tx, pattern WitnessSet) -import Cardano.Ledger.Shelley.TxBody (DCert, TxIn, TxOut (..), Wdrl) +import Cardano.Ledger.Shelley.TxBody (DCert, TxOut (..), Wdrl) import Cardano.Ledger.ShelleyMA.Timelocks (Timelock (..)) import Cardano.Ledger.ShelleyMA.TxBody ( TxBody (..), ValidityInterval (ValidityInterval), ) +import Cardano.Ledger.TxIn (TxIn) import Cardano.Ledger.Val (Val (zero), (<+>)) import Cardano.Slotting.Slot (SlotNo (SlotNo)) import Control.Monad (replicateM) diff --git a/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/Allegra/ScriptTranslation.hs b/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/Allegra/ScriptTranslation.hs index b5edddc6237..be2f7499527 100644 --- a/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/Allegra/ScriptTranslation.hs +++ b/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/Allegra/ScriptTranslation.hs @@ -11,7 +11,7 @@ import qualified Cardano.Ledger.Shelley.API as S import Cardano.Ledger.Shelley.LedgerState () import Cardano.Ledger.Shelley.PParams (emptyPParams) import Cardano.Ledger.Shelley.Tx (hashScript, scriptWits) -import Cardano.Ledger.Shelley.UTxO (txid) +import Cardano.Ledger.TxIn (txid) import qualified Cardano.Ledger.Val as Val import Cardano.Slotting.Slot (SlotNo (..)) import Control.Monad.Except (runExcept) diff --git a/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/Mary/Examples/MultiAssets.hs b/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/Mary/Examples/MultiAssets.hs index 17a5a13e399..8d92ca69895 100644 --- a/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/Mary/Examples/MultiAssets.hs +++ b/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/Mary/Examples/MultiAssets.hs @@ -30,17 +30,13 @@ import Cardano.Ledger.Shelley.Tx WitnessSetHKD (..), hashScript, ) -import Cardano.Ledger.Shelley.TxBody - ( TxId, - TxIn (..), - TxOut (..), - Wdrl (..), - ) -import Cardano.Ledger.Shelley.UTxO (UTxO (..), makeWitnessesVKey, txid) +import Cardano.Ledger.Shelley.TxBody (TxOut (..), Wdrl (..)) +import Cardano.Ledger.Shelley.UTxO (UTxO (..), makeWitnessesVKey) import Cardano.Ledger.ShelleyMA.Rules.Utxo (UtxoPredicateFailure (..)) import Cardano.Ledger.ShelleyMA.Timelocks (Timelock (..), ValidityInterval (..)) import Cardano.Ledger.ShelleyMA.TxBody (TxBody (..)) import Cardano.Ledger.Slot (SlotNo (..)) +import Cardano.Ledger.TxIn (TxId, TxIn (..), txid) import Cardano.Ledger.Val ((<+>), (<->)) import qualified Cardano.Ledger.Val as Val import Control.Exception (ErrorCall (ErrorCall), evaluate, try) diff --git a/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/ShelleyMA/Serialisation/Golden/Encoding.hs b/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/ShelleyMA/Serialisation/Golden/Encoding.hs index e1b58bdc395..931606f633f 100644 --- a/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/ShelleyMA/Serialisation/Golden/Encoding.hs +++ b/eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/ShelleyMA/Serialisation/Golden/Encoding.hs @@ -33,7 +33,6 @@ import Cardano.Ledger.Shelley.TxBody ( DCert (..), DelegCert (..), RewardAcnt (..), - TxIn (..), TxOut (..), Wdrl (..), ) @@ -44,6 +43,7 @@ import Cardano.Ledger.ShelleyMA.Timelocks ) import Cardano.Ledger.ShelleyMA.TxBody (TxBody (..)) import Cardano.Ledger.Slot (EpochNo (..), SlotNo (..)) +import Cardano.Ledger.TxIn (TxIn (..)) import qualified Cardano.Ledger.Val as Val import Codec.CBOR.Encoding (Tokens (..)) import qualified Data.ByteString.Char8 as BS diff --git a/eras/shelley/impl/src/Cardano/Ledger/Pretty.hs b/eras/shelley/impl/src/Cardano/Ledger/Pretty.hs index 37794e9d43c..5fe762a057e 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Pretty.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Pretty.hs @@ -138,12 +138,9 @@ import Cardano.Ledger.Shelley.TxBody StakePoolRelay (..), TxBody (..), TxBodyRaw (..), - TxId (..), - TxIn (..), TxOut (..), Wdrl (..), WitVKey (..), - viewTxIn, ) import Cardano.Ledger.Shelley.UTxO (UTxO (..)) import Cardano.Ledger.Slot @@ -153,6 +150,7 @@ import Cardano.Ledger.Slot EpochSize (..), SlotNo (..), ) +import Cardano.Ledger.TxIn (TxId (..), TxIn (..), viewTxIn) import Cardano.Protocol.TPraos (IndividualPoolStake (..), PoolDistr (..)) import Cardano.Protocol.TPraos.BHeader ( BHBody (..), diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Types.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Types.hs index b84415b5c0e..30ed30c6700 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Types.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Types.hs @@ -128,7 +128,6 @@ import Cardano.Ledger.Shelley.StabilityWindow as X import Cardano.Ledger.Shelley.Tx as X ( Tx (..), TxBody (..), - TxIn (..), TxOut (..), WitnessSet, ) @@ -143,7 +142,6 @@ import Cardano.Ledger.Shelley.TxBody as X Ptr (..), StakeCreds (..), StakePoolRelay (..), - TxId (..), Wdrl (..), WitVKey (..), ) @@ -151,6 +149,7 @@ import Cardano.Ledger.Shelley.UTxO as X ( UTxO (..), balance, ) +import Cardano.Ledger.TxIn as X (TxId (..), TxIn (..)) import Cardano.Protocol.TPraos as X ( PoolDistr (..), individualPoolStake, diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs index 3965568157b..c8f054c40de 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs @@ -97,9 +97,10 @@ import Cardano.Ledger.Shelley.Rewards ) import Cardano.Ledger.Shelley.Rules.NewEpoch (calculatePoolDistr) import Cardano.Ledger.Shelley.Tx (Tx (..), WitnessSet, WitnessSetHKD (..)) -import Cardano.Ledger.Shelley.TxBody (DCert, PoolParams (..), TxIn (..), WitVKey (..)) +import Cardano.Ledger.Shelley.TxBody (DCert, PoolParams (..), WitVKey (..)) import Cardano.Ledger.Shelley.UTxO (UTxO (..), balance) import Cardano.Ledger.Slot (epochInfoSize) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val ((<->)) import qualified Cardano.Ledger.Val as Val import Cardano.Protocol.TPraos diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockChain.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockChain.hs index c8eb94efe81..c9fd20259ea 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockChain.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockChain.hs @@ -94,9 +94,9 @@ import Cardano.Ledger.Serialization encodeFoldableMapEncoder, ) import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade (..)) -import Cardano.Ledger.Shelley.Tx (Tx, TxIn (..), segwitTx) -import Cardano.Ledger.Shelley.UTxO (txid) +import Cardano.Ledger.Shelley.Tx (Tx, segwitTx) import Cardano.Ledger.Slot (SlotNo (..)) +import Cardano.Ledger.TxIn (TxIn (..), txid) import qualified Cardano.Protocol.TPraos.BHeader as TP import Cardano.Slotting.Slot (WithOrigin (..)) import Control.Monad (unless) diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Genesis.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Genesis.hs index 1a7ac3baead..a83d5ce7702 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Genesis.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Genesis.hs @@ -49,8 +49,9 @@ import Cardano.Ledger.Serialization import Cardano.Ledger.Shelley.Constraints (UsesTxOut (..)) import Cardano.Ledger.Shelley.PParams import Cardano.Ledger.Shelley.StabilityWindow -import Cardano.Ledger.Shelley.TxBody (PoolParams (..), TxId (..), TxIn (..)) +import Cardano.Ledger.Shelley.TxBody (PoolParams (..)) import Cardano.Ledger.Shelley.UTxO +import Cardano.Ledger.TxIn (TxId (..), TxIn (..)) import qualified Cardano.Ledger.Val as Val import Cardano.Prelude (forceElemsToWHNF) import Cardano.Slotting.EpochInfo diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs index 76b5dcb1e1a..51e2505785c 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs @@ -199,7 +199,6 @@ import Cardano.Ledger.Shelley.TxBody Ptr (..), RewardAcnt (..), TransTxId, - TxIn (..), Wdrl (..), WitVKey (..), getRwdCred, @@ -219,6 +218,7 @@ import Cardano.Ledger.Slot EpochSize (..), SlotNo (..), ) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val ((<+>), (<->), (<×>)) import qualified Cardano.Ledger.Val as Val import Cardano.Protocol.TPraos (PoolDistr (..)) diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Utxow.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Utxow.hs index f68571f4e56..05c251493c1 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Utxow.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Utxow.hs @@ -85,8 +85,9 @@ import Cardano.Ledger.Shelley.Tx hashScript, validateScript, ) -import Cardano.Ledger.Shelley.TxBody (DCert, EraIndependentTxBody, TxIn, Wdrl) +import Cardano.Ledger.Shelley.TxBody (DCert, EraIndependentTxBody, Wdrl) import Cardano.Ledger.Shelley.UTxO (UTxO, scriptsNeeded) +import Cardano.Ledger.TxIn (TxIn) import Control.Monad (when) import Control.Monad.Trans.Reader (asks) import Control.SetAlgebra (eval, (∩)) diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Tx.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Tx.hs index ccde9b1cd03..2fe648aeb96 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Tx.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Tx.hs @@ -83,12 +83,11 @@ import Cardano.Ledger.Shelley.Address.Bootstrap (BootstrapWitness) import Cardano.Ledger.Shelley.Scripts import Cardano.Ledger.Shelley.TxBody ( TxBody (..), - TxId (..), - TxIn (..), TxOut (..), WitVKey (..), witKeyHash, ) +import Cardano.Ledger.TxIn (TxId (..), TxIn (..)) import qualified Data.ByteString.Lazy as BSL import qualified Data.ByteString.Short as SBS import Data.Coders diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/TxBody.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/TxBody.hs index 2c1f058a97f..3509942ec31 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/TxBody.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/TxBody.hs @@ -49,9 +49,6 @@ module Cardano.Ledger.Shelley.TxBody _mdHash ), TxBodyRaw (..), - TxId (..), - TxIn (TxIn, ..), - viewTxIn, EraIndependentTxBody, -- eraIndTxBodyHash, TxOut (TxOut, TxOutCompact), @@ -67,6 +64,10 @@ module Cardano.Ledger.Shelley.TxBody TransTxId, TransTxOut, TransTxBody, + + -- * Deprecated + TxId, + TxIn, ) where @@ -127,13 +128,7 @@ import Cardano.Ledger.Keys hashKey, hashSignature, ) -import Cardano.Ledger.SafeHash - ( HashAnnotated, - SafeHash, - SafeToHash, - extractHash, - unsafeMakeSafeHash, - ) +import Cardano.Ledger.SafeHash (HashAnnotated, SafeToHash) import Cardano.Ledger.Serialization ( CBORGroup (..), CborSeq (..), @@ -163,9 +158,9 @@ import Cardano.Ledger.Shelley.Constraints (TransValue) import Cardano.Ledger.Shelley.Orphans () import Cardano.Ledger.Shelley.PParams (Update) import Cardano.Ledger.Slot (EpochNo (..), SlotNo (..)) +import qualified Cardano.Ledger.TxIn as Core import Cardano.Ledger.Val (DecodeNonNegative (..)) import Cardano.Prelude (HeapWords (..), panic) -import qualified Cardano.Prelude as HW import Control.DeepSeq (NFData (rnf)) import Control.SetAlgebra (BaseRep (MapR), Embed (..), Exp (Base), HasExp (toExp)) import Data.Aeson (FromJSON (..), ToJSON (..), Value, (.!=), (.:), (.:?), (.=)) @@ -204,16 +199,14 @@ import Data.Set (Set) import qualified Data.Set as Set import qualified Data.Text.Encoding as Text import Data.Typeable (Typeable) -import Data.Word (Word64, Word8) +import Data.Word (Word8) import GHC.Generics (Generic) import GHC.Records import NoThunks.Class ( AllowThunksIn (..), InspectHeapNamed (..), NoThunks (..), - noThunksInValues, ) -import Numeric.Natural (Natural) import Quiet -- ======================================================================== @@ -418,33 +411,6 @@ instance CC.Crypto crypto => FromJSON (PoolParams crypto) where <*> obj .: "relays" <*> obj .: "metadata" --- =================================================================================== --- Because we expect other Era's to import and use TxId, TxIn, TxOut, we use the weakest --- constraint possible when deriving their instances. A Stronger constraint, Gathering --- many constraints together, like: type Strong = (C1 x, C2 x, ..., Cn x) --- may make this file look systematic by having things like: --- derving instance (Strong x) => Foo x, for many Foo (Eq, Show, NfData, etc) BUT this --- forces unnecessary requirements on any new Era which tries to embed one of these --- types in their own datatypes, if they then try and derive (Foo TheirDataType). --- ==================================================================================== - --- | A unique ID of a transaction, which is computable from the transaction. -newtype TxId crypto = TxId {_unTxId :: SafeHash crypto EraIndependentTxBody} - deriving (Show, Eq, Ord, Generic) - deriving newtype (NoThunks, HeapWords) - -deriving newtype instance CC.Crypto crypto => ToCBOR (TxId crypto) - -deriving newtype instance CC.Crypto crypto => FromCBOR (TxId crypto) - -deriving newtype instance CC.Crypto crypto => NFData (TxId crypto) - -instance HeapWords (TxIn crypto) where - heapWords (TxInCompact32 a _ _ _ ix) = - 6 + (4 * HW.heapWordsUnpacked a) + HW.heapWordsUnpacked ix - heapWords (TxInCompactOther txid ix) = - 3 + HW.heapWords txid + HW.heapWordsUnpacked ix - type TransTxId (c :: Type -> Constraint) era = -- Transaction Ids are the hash of a transaction body, which contains -- a Core.TxBody and Core.TxOut, hence the need for the ToCBOR instances @@ -456,71 +422,6 @@ type TransTxId (c :: Type -> Constraint) era = TransValue c era ) --- | The input of a UTxO. -data TxIn crypto where - TxInCompact32 :: - HS.SizeHash (CC.HASH crypto) ~ 32 => - {-# UNPACK #-} !Word64 -> -- Hash part 1/4 - {-# UNPACK #-} !Word64 -> -- Hash part 2/4 - {-# UNPACK #-} !Word64 -> -- Hash part 3/4 - {-# UNPACK #-} !Word64 -> -- Hash part 4/4 - {-# UNPACK #-} !Word64 -> -- Index - TxIn crypto - TxInCompactOther :: !(TxId crypto) -> {-# UNPACK #-} !Word64 -> TxIn crypto - -pattern TxIn :: - CC.Crypto crypto => - TxId crypto -> - Natural -> -- TODO We might want to change this to Word64 generally - TxIn crypto -pattern TxIn txid index <- - (viewTxIn -> (txid, index)) - where - TxIn txid@(TxId sh) index = - case HS.viewHash32 (extractHash sh) of - HS.ViewHashNot32 -> TxInCompactOther txid (fromIntegral index) - HS.ViewHash32 a b c d -> TxInCompact32 a b c d (fromIntegral index) - -{-# COMPLETE TxIn #-} - -viewTxIn :: TxIn crypto -> (TxId crypto, Natural) -viewTxIn (TxInCompactOther txid i) = (txid, fromIntegral i) -viewTxIn (TxInCompact32 a b c d i) = (txid, fromIntegral i) - where - txid = TxId (unsafeMakeSafeHash $ HS.unsafeMkHash32 a b c d) - -instance Show (TxIn crypto) where - showsPrec d (viewTxIn -> (txid, ix)) = - showParen (d > app_prec) $ - showString "TxIn " - . showsPrec (app_prec + 1) txid - . showString " " - . showsPrec (app_prec + 1) ix - where - app_prec = 10 - -instance Ord (TxIn crypto) where - compare (TxInCompact32 a1 b1 c1 d1 i1) (TxInCompact32 a2 b2 c2 d2 i2) = - compare a1 a2 <> compare b1 b2 <> compare c1 c2 <> compare d1 d2 - <> compare i1 i2 - compare (viewTxIn -> (id1, ix1)) (viewTxIn -> (id2, ix2)) = - compare id1 id2 <> compare ix1 ix2 - -instance Eq (TxIn crypto) where - (==) (TxInCompact32 a1 b1 c1 d1 i1) (TxInCompact32 a2 b2 c2 d2 i2) = - (a1 == a2) && (b1 == b2) && (c1 == c2) && (d1 == d2) && (i1 == i2) - (==) (viewTxIn -> (id1, ix1)) (viewTxIn -> (id2, ix2)) = - (id1 == id2) && (ix1 == ix2) - -instance CC.Crypto crypto => NFData (TxIn crypto) where - rnf (TxInCompactOther txid _) = seq (rnf txid) () - rnf (TxInCompact32 _ _ _ _ _) = () - -instance NoThunks (TxIn crypto) where - showTypeOf _ = "TxIn" - wNoThunks c (TxInCompactOther txid _) = noThunksInValues c [txid] - wNoThunks _ (TxInCompact32 _ _ _ _ _) = pure Nothing -- always in normal form - -- | The output of a UTxO. data TxOut era = TxOutCompact @@ -720,7 +621,7 @@ instance NoThunks (DCert crypto) -- The underlying type for TxBody data TxBodyRaw era = TxBodyRaw - { _inputsX :: !(Set (TxIn (Crypto era))), + { _inputsX :: !(Set (Core.TxIn (Crypto era))), _outputsX :: !(StrictSeq (Core.TxOut era)), _certsX :: !(StrictSeq (DCert (Crypto era))), _wdrlsX :: !(Wdrl (Crypto era)), @@ -879,7 +780,7 @@ deriving via -- | Pattern for use by external users pattern TxBody :: (Era era, FromCBOR (Core.PParamsDelta era), TransTxBody ToCBOR era) => - Set (TxIn (Crypto era)) -> + Set (Core.TxIn (Crypto era)) -> StrictSeq (Core.TxOut era) -> StrictSeq (DCert (Crypto era)) -> Wdrl (Crypto era) -> @@ -917,7 +818,7 @@ instance (Era era, c ~ Crypto era) => HashAnnotated (TxBody era) EraIndependentT instance (Era era) => ToCBOR (TxBody era) where toCBOR (TxBodyConstr memo) = toCBOR memo -instance Crypto era ~ crypto => HasField "inputs" (TxBody era) (Set (TxIn crypto)) where +instance Crypto era ~ crypto => HasField "inputs" (TxBody era) (Set (Core.TxIn crypto)) where getField (TxBodyConstr (Memo m _)) = getField @"_inputsX" m instance Core.TxOut era ~ out => HasField "outputs" (TxBody era) (StrictSeq out) where @@ -949,7 +850,7 @@ instance c ~ Crypto era => HasField "minted" (TxBody era) (Set (ScriptHash c)) w instance c ~ Crypto era => - HasField "txinputs_fee" (TxBody era) (Set (TxIn c)) + HasField "txinputs_fee" (TxBody era) (Set (Core.TxIn c)) where getField (TxBodyConstr (Memo m _)) = getField @"_inputsX" m @@ -1103,28 +1004,6 @@ instance pure (2, DCertMir x) k -> invalidKey k -instance - CC.Crypto crypto => - ToCBOR (TxIn crypto) - where - toCBOR (viewTxIn -> (txId, index)) = - encodeListLen 2 - <> toCBOR txId - <> toCBOR index - -instance - CC.Crypto crypto => - FromCBOR (TxIn crypto) - where - fromCBOR = - decodeRecordNamed - "TxIn" - (const 2) - (TxIn <$> fromCBOR <*> fmap natural fromCBOR) - where - natural :: Word64 -> Natural - natural = fromIntegral - instance-- use the weakest constraint necessary (Era era, TransTxOut ToCBOR era) => @@ -1253,3 +1132,13 @@ instance _poolRelays = relays, _poolMD = maybeToStrictMaybe md } + +-- DEPRECATED + +{-# DEPRECATED TxId "Import from Cardano.Ledger.TxIn instead" #-} + +type TxId = Core.TxId + +{-# DEPRECATED TxIn "Import from Cardano.Ledger.TxIn instead" #-} + +type TxIn = Core.TxIn diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/UTxO.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/UTxO.hs index 46ecf9e0267..57180b9b8f5 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/UTxO.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/UTxO.hs @@ -19,7 +19,6 @@ module Cardano.Ledger.Shelley.UTxO UTxO (..), -- * Functions - txid, txins, txinLookup, txouts, @@ -38,6 +37,9 @@ module Cardano.Ledger.Shelley.UTxO -- * Utilities TransUTxO, + + -- * Deprecated + txid, ) where @@ -60,7 +62,7 @@ import Cardano.Ledger.Keys signedDSIGN, verifySignedDSIGN, ) -import Cardano.Ledger.SafeHash (SafeHash, extractHash, hashAnnotated) +import Cardano.Ledger.SafeHash (SafeHash, extractHash) import Cardano.Ledger.Shelley.Delegation.Certificates ( DCert (..), isRegKey, @@ -73,8 +75,6 @@ import Cardano.Ledger.Shelley.TxBody PoolCert (..), PoolParams (..), TransTxId, - TxId (..), - TxIn (..), Wdrl (..), WitVKey (..), getRwdCred, @@ -82,6 +82,8 @@ import Cardano.Ledger.Shelley.TxBody pattern Delegate, pattern Delegation, ) +import Cardano.Ledger.TxIn (TxId (..), TxIn (..)) +import qualified Cardano.Ledger.TxIn as Core (txid) import Cardano.Ledger.Val (zero, (<+>), (<×>)) import Control.DeepSeq (NFData) import Control.Iterate.SetAlgebra @@ -151,13 +153,13 @@ deriving via Show (Core.TxOut era) => Show (UTxO era) --- | Compute the id of a transaction. +{-# DEPRECATED txid "Import from Cardano.Ledger.TxIn instead" #-} txid :: forall era. Era era => Core.TxBody era -> TxId (Crypto era) -txid = TxId . hashAnnotated +txid = Core.txid -- | Compute the UTxO inputs of a transaction. -- txins has the same problems as txouts, see notes below. @@ -187,7 +189,7 @@ txouts tx = | (out, idx) <- zip (toList $ getField @"outputs" tx) [0 ..] ] where - transId = txid tx + transId = Core.txid tx -- | Lookup a txin for a given UTxO collection txinLookup :: diff --git a/eras/shelley/test-suite/bench/BenchUTxOAggregate.hs b/eras/shelley/test-suite/bench/BenchUTxOAggregate.hs index 11d90a456d3..7219505946a 100644 --- a/eras/shelley/test-suite/bench/BenchUTxOAggregate.hs +++ b/eras/shelley/test-suite/bench/BenchUTxOAggregate.hs @@ -28,13 +28,12 @@ import Cardano.Ledger.Shelley.LedgerState import Cardano.Ledger.Shelley.Scripts () import Cardano.Ledger.Shelley.TxBody ( PoolParams (..), - TxId (..), - TxIn (..), TxOut (..), ) import Cardano.Ledger.Shelley.UTxO ( UTxO (..), ) +import Cardano.Ledger.TxIn (TxId (..), TxIn (..)) import qualified Cardano.Ledger.Val as Val import Control.Iterate.SetAlgebra (compile, compute, run) import Control.Monad (replicateM) diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Address/Bootstrap.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Address/Bootstrap.hs index 32829e4e52c..530f9ba61d7 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Address/Bootstrap.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Address/Bootstrap.hs @@ -68,8 +68,6 @@ import Cardano.Ledger.Shelley.Tx ) import Cardano.Ledger.Shelley.TxBody ( TxBody (..), - TxId (..), - TxIn (..), TxOut (..), Wdrl (..), ) @@ -79,6 +77,7 @@ import Cardano.Ledger.Shelley.UTxO import Cardano.Ledger.Slot ( SlotNo (..), ) +import Cardano.Ledger.TxIn (TxId (..), TxIn (..)) import Cardano.Ledger.Val ((<->)) import Cardano.Prelude ( ByteString, diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/BenchmarkFunctions.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/BenchmarkFunctions.hs index aa5c59a0de4..224307cb381 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/BenchmarkFunctions.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/BenchmarkFunctions.hs @@ -68,7 +68,6 @@ import Cardano.Ledger.Shelley.TxBody PoolParams (..), RewardAcnt (..), TxBody (..), - TxIn (..), TxOut (..), Wdrl (..), _poolCost, @@ -83,6 +82,7 @@ import Cardano.Ledger.Shelley.TxBody ) import Cardano.Ledger.Shelley.UTxO (makeWitnessesVKey) import Cardano.Ledger.Slot (EpochNo (..), SlotNo (..)) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val (Val (inject)) import Control.State.Transition.Extended (TRC (..), applySTS) import Data.Default.Class (def) diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/EraGen.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/EraGen.hs index 2f7f283bb3c..6bf7ed0be22 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/EraGen.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/EraGen.hs @@ -59,10 +59,10 @@ import Cardano.Ledger.Shelley.Constraints (UsesPParams (..)) import Cardano.Ledger.Shelley.LedgerState (UTxOState (..)) import Cardano.Ledger.Shelley.PParams (ProtVer, Update) import Cardano.Ledger.Shelley.Rules.Utxo (UtxoEnv) -import Cardano.Ledger.Shelley.Tx (TxId (TxId)) -import Cardano.Ledger.Shelley.TxBody (DCert, TxIn, Wdrl, WitVKey) +import Cardano.Ledger.Shelley.TxBody (DCert, Wdrl, WitVKey) import Cardano.Ledger.Shelley.UTxO (UTxO) import Cardano.Ledger.Slot (EpochNo) +import Cardano.Ledger.TxIn (TxId (TxId), TxIn) import Cardano.Protocol.TPraos.BHeader (BHeader) import Cardano.Slotting.Slot (SlotNo) import Control.State.Transition.Extended (STS (..)) diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Trace/Ledger.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Trace/Ledger.hs index 07ff1d9b99a..a15f3c56165 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Trace/Ledger.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Trace/Ledger.hs @@ -40,8 +40,9 @@ import Cardano.Ledger.Shelley.Rules.Delpl (DELPL, DelplEnv, DelplPredicateFailur import Cardano.Ledger.Shelley.Rules.Ledger (LEDGER, LedgerEnv (..)) import Cardano.Ledger.Shelley.Rules.Ledgers (LEDGERS, LedgersEnv (..)) import Cardano.Ledger.Shelley.Rules.Utxo (UtxoEnv) -import Cardano.Ledger.Shelley.TxBody (DCert, Ix, TxIn) +import Cardano.Ledger.Shelley.TxBody (DCert, Ix) import Cardano.Ledger.Slot (SlotNo (..)) +import Cardano.Ledger.TxIn (TxIn) import Control.Monad (foldM) import Control.Monad.Trans.Reader (runReaderT) import Control.State.Transition diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/PropertyTests.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/PropertyTests.hs index 94a493c92c4..cc9770749ba 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/PropertyTests.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/PropertyTests.hs @@ -39,8 +39,9 @@ import Cardano.Ledger.Shelley.Delegation.Certificates (DCert) import Cardano.Ledger.Shelley.PParams (Update (..)) import Cardano.Ledger.Shelley.Rules.Ledger (LedgerEnv) import Cardano.Ledger.Shelley.Scripts (ScriptHash) -import Cardano.Ledger.Shelley.TxBody (TxIn, Wdrl, WitVKey) +import Cardano.Ledger.Shelley.TxBody (Wdrl, WitVKey) import Cardano.Ledger.Shelley.UTxO (makeWitnessVKey) +import Cardano.Ledger.TxIn (TxIn) import Control.Monad.Trans.Reader (ReaderT) import Control.State.Transition import qualified Control.State.Transition.Trace.Generator.QuickCheck as QC diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/ClassifyTraces.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/ClassifyTraces.hs index 3bcd0981d1f..c78a8715aeb 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/ClassifyTraces.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/ClassifyTraces.hs @@ -54,8 +54,9 @@ import Cardano.Ledger.Shelley.PParams pattern Update, ) import Cardano.Ledger.Shelley.PParams as PParams (Update) -import Cardano.Ledger.Shelley.TxBody (TxIn, Wdrl (..)) +import Cardano.Ledger.Shelley.TxBody (Wdrl (..)) import Cardano.Ledger.Slot (SlotNo (..), epochInfoSize) +import Cardano.Ledger.TxIn (TxIn) import Cardano.Protocol.TPraos.BHeader ( BHeader, bhbody, diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/TestChain.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/TestChain.hs index 8a3017584d0..43938b549b0 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/TestChain.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/TestChain.hs @@ -53,9 +53,10 @@ import Cardano.Ledger.Shelley.Rules.Ledger (LedgerEnv (..)) import Cardano.Ledger.Shelley.Rules.Pool (POOL, PoolEnv (..)) import Cardano.Ledger.Shelley.Rules.Upec (votedValue) import Cardano.Ledger.Shelley.Scripts (ScriptHash) -import Cardano.Ledger.Shelley.Tx -import Cardano.Ledger.Shelley.TxBody +import Cardano.Ledger.Shelley.Tx hiding (TxIn) +import Cardano.Ledger.Shelley.TxBody hiding (TxIn) import Cardano.Ledger.Shelley.UTxO (UTxO (..), balance, totalDeposits, txins, txouts, pattern UTxO) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val ((<+>), (<->)) import qualified Cardano.Ledger.Val as Val (coin) import Cardano.Prelude (HasField (..)) diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Shrinkers.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Shrinkers.hs index 9dc31c5871a..19ac009ab21 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Shrinkers.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Shrinkers.hs @@ -10,9 +10,10 @@ import qualified Cardano.Ledger.Core as Core import Cardano.Ledger.Shelley.BlockChain import Cardano.Ledger.Shelley.PParams import Cardano.Ledger.Shelley.Scripts -import Cardano.Ledger.Shelley.Tx -import Cardano.Ledger.Shelley.TxBody +import Cardano.Ledger.Shelley.Tx hiding (TxIn) +import Cardano.Ledger.Shelley.TxBody hiding (TxIn) import Cardano.Ledger.Slot +import Cardano.Ledger.TxIn (TxIn) import Cardano.Ledger.Val ((<+>), (<->)) import qualified Cardano.Ledger.Val as Val import Data.Foldable (toList) diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Combinators.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Combinators.hs index 214dfe352bd..4c066b429fd 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Combinators.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Combinators.hs @@ -84,9 +84,9 @@ import Cardano.Ledger.Shelley.LedgerState ) import Cardano.Ledger.Shelley.PParams (PParams, PParams' (..), ProposedPPUpdates, ProtVer) import Cardano.Ledger.Shelley.Rules.Mir (emptyInstantaneousRewards) -import Cardano.Ledger.Shelley.Tx (TxIn) import Cardano.Ledger.Shelley.TxBody (MIRPot (..), PoolParams (..), RewardAcnt (..)) import Cardano.Ledger.Shelley.UTxO (txins, txouts) +import Cardano.Ledger.TxIn (TxIn) import Cardano.Ledger.Val ((<+>), (<->)) import Cardano.Protocol.TPraos (PoolDistr (..)) import Cardano.Protocol.TPraos.BHeader diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/GenesisDelegation.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/GenesisDelegation.hs index 0abf3b2bcc3..007f0eb9f41 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/GenesisDelegation.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/GenesisDelegation.hs @@ -42,12 +42,12 @@ import Cardano.Ledger.Shelley.TxBody ( DCert (..), GenesisDelegCert (..), TxBody (..), - TxIn (..), TxOut (..), Wdrl (..), ) import Cardano.Ledger.Shelley.UTxO (UTxO (..), makeWitnessesVKey) import Cardano.Ledger.Slot (BlockNo (..), SlotNo (..)) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val ((<->)) import qualified Cardano.Ledger.Val as Val import Cardano.Protocol.TPraos.BHeader (BHeader, bhHash) diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Mir.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Mir.hs index 7a64937d9df..215b07c0be8 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Mir.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Mir.hs @@ -51,12 +51,12 @@ import Cardano.Ledger.Shelley.TxBody MIRPot (..), MIRTarget (..), TxBody (..), - TxIn (..), TxOut (..), Wdrl (..), ) import Cardano.Ledger.Shelley.UTxO (UTxO (..), makeWitnessesVKey) import Cardano.Ledger.Slot (BlockNo (..), SlotNo (..)) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val ((<+>), (<->)) import qualified Cardano.Ledger.Val as Val import Cardano.Protocol.TPraos.BHeader (BHeader, bhHash) diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs index 093f8315e81..1ea9338945a 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs @@ -73,11 +73,10 @@ import Cardano.Ledger.Shelley.TxBody PoolParams (..), RewardAcnt (..), TxBody (..), - TxIn (..), TxOut (..), Wdrl (..), ) -import Cardano.Ledger.Shelley.UTxO (UTxO (..), makeWitnessesVKey, txid) +import Cardano.Ledger.Shelley.UTxO (UTxO (..), makeWitnessesVKey) import Cardano.Ledger.Slot ( BlockNo (..), EpochNo (..), @@ -85,6 +84,7 @@ import Cardano.Ledger.Slot SlotNo (..), epochInfoSize, ) +import Cardano.Ledger.TxIn (TxIn (..), txid) import Cardano.Ledger.Val ((<+>), (<->), (<×>)) import qualified Cardano.Ledger.Val as Val import Cardano.Protocol.TPraos diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolReReg.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolReReg.hs index d2ec7c80cb2..356f436df2a 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolReReg.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolReReg.hs @@ -39,12 +39,12 @@ import Cardano.Ledger.Shelley.TxBody PoolCert (..), PoolParams (..), TxBody (..), - TxIn (..), TxOut (..), Wdrl (..), ) -import Cardano.Ledger.Shelley.UTxO (UTxO (..), makeWitnessesVKey, txid) +import Cardano.Ledger.Shelley.UTxO (UTxO (..), makeWitnessesVKey) import Cardano.Ledger.Slot (BlockNo (..), SlotNo (..)) +import Cardano.Ledger.TxIn (TxIn (..), txid) import Cardano.Ledger.Val ((<+>), (<->)) import qualified Cardano.Ledger.Val as Val import Cardano.Protocol.TPraos.BHeader (BHeader, bhHash) diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/TwoPools.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/TwoPools.hs index 3432773662a..0cba3ca5db2 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/TwoPools.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/TwoPools.hs @@ -79,7 +79,6 @@ import Cardano.Ledger.Shelley.TxBody PoolParams (..), RewardAcnt (..), TxBody (..), - TxIn (..), TxOut (..), Wdrl (..), ) @@ -89,6 +88,7 @@ import Cardano.Ledger.Slot EpochNo (..), SlotNo (..), ) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val ((<+>), (<->), (<×>)) import qualified Cardano.Ledger.Val as Val import Cardano.Protocol.TPraos diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Updates.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Updates.hs index b27ec126543..a42b6352317 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Updates.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Updates.hs @@ -42,16 +42,16 @@ import Cardano.Ledger.Shelley.Tx ) import Cardano.Ledger.Shelley.TxBody ( TxBody (..), - TxIn (..), TxOut (..), Wdrl (..), ) -import Cardano.Ledger.Shelley.UTxO (UTxO (..), makeWitnessesVKey, txid) +import Cardano.Ledger.Shelley.UTxO (UTxO (..), makeWitnessesVKey) import Cardano.Ledger.Slot ( BlockNo (..), EpochNo (..), SlotNo (..), ) +import Cardano.Ledger.TxIn (TxIn (..), txid) import Cardano.Ledger.Val ((<+>), (<->)) import qualified Cardano.Ledger.Val as Val import Cardano.Protocol.TPraos.BHeader (BHeader, bhHash) diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/MultiSigExamples.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/MultiSigExamples.hs index d2e602b0fc0..5dc1b131e27 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/MultiSigExamples.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/MultiSigExamples.hs @@ -73,12 +73,12 @@ import Cardano.Ledger.Shelley.Tx ) import Cardano.Ledger.Shelley.TxBody ( TxBody (..), - TxIn (..), TxOut (..), Wdrl (..), ) -import Cardano.Ledger.Shelley.UTxO (makeWitnessesVKey, txid) +import Cardano.Ledger.Shelley.UTxO (makeWitnessesVKey) import Cardano.Ledger.Slot (SlotNo (..)) +import Cardano.Ledger.TxIn (TxIn (..), txid) import qualified Cardano.Ledger.Val as Val import Control.State.Transition.Extended (PredicateFailure, TRC (..)) import Data.Foldable (fold) diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs index d72502ef084..9e242e4faa7 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs @@ -122,8 +122,6 @@ import Cardano.Ledger.Shelley.TxBody PoolMetadata (..), StakePoolRelay (..), TxBody (..), - TxId, - TxIn (..), TxOut (..), Wdrl (..), WitVKey (..), @@ -148,6 +146,7 @@ import Cardano.Ledger.Shelley.TxBody ) import Cardano.Ledger.Shelley.UTxO (makeWitnessVKey) import Cardano.Ledger.Slot (BlockNo (..), EpochNo (..), SlotNo (..)) +import Cardano.Ledger.TxIn (TxId, TxIn (..)) import Cardano.Prelude (LByteString) import Cardano.Protocol.TPraos (PoolDistr (..)) import Cardano.Protocol.TPraos.BHeader diff --git a/libs/cardano-ledger-core/cardano-ledger-core.cabal b/libs/cardano-ledger-core/cardano-ledger-core.cabal index 83c9db6bfab..ab41250fb69 100644 --- a/libs/cardano-ledger-core/cardano-ledger-core.cabal +++ b/libs/cardano-ledger-core/cardano-ledger-core.cabal @@ -57,6 +57,7 @@ library Cardano.Ledger.SafeHash Cardano.Ledger.Serialization Cardano.Ledger.Slot + Cardano.Ledger.TxIn Cardano.Ledger.Val build-depends: diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs index 2f858330cd9..006a9ac94fb 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs @@ -80,6 +80,7 @@ import Data.Coders (invalidKey) import Data.Default.Class (Default (def)) import qualified Data.Fixed as FP (Fixed, HasResolution, resolution) import Data.Functor.Identity +import Data.Map.Strict (Map) import Data.Maybe.Strict import Data.Ratio (Ratio, denominator, numerator, (%)) import Data.Scientific (Scientific, base10Exponent, coefficient, normalize, scientific) @@ -92,6 +93,7 @@ import GHC.Exception.Type (Exception) import GHC.Generics (Generic) import NoThunks.Class (NoThunks (..)) import Numeric.Natural (Natural) +import Quiet data E34 diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/TxIn.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/TxIn.hs new file mode 100644 index 00000000000..91f51a3a223 --- /dev/null +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/TxIn.hs @@ -0,0 +1,172 @@ +{-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingVia #-} +{-# LANGUAGE ExistentialQuantification #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE UndecidableInstances #-} +{-# LANGUAGE ViewPatterns #-} + +module Cardano.Ledger.TxIn + ( TxId (..), + TxIn (TxIn, ..), + viewTxIn, + txid, + ) +where + +import Cardano.Binary (FromCBOR (fromCBOR), ToCBOR (..), encodeListLen) +import qualified Cardano.Crypto.Hash.Class as HS +import Cardano.Ledger.Core (TxBody) +import qualified Cardano.Ledger.Crypto as CC +import Cardano.Ledger.Era (Crypto, Era) +import Cardano.Ledger.Hashes (EraIndependentTxBody) +import Cardano.Ledger.SafeHash + ( SafeHash, + extractHash, + hashAnnotated, + unsafeMakeSafeHash, + ) +import Cardano.Ledger.Serialization (decodeRecordNamed) +import Cardano.Prelude (HeapWords (..)) +import qualified Cardano.Prelude as HW +import Control.DeepSeq (NFData (rnf)) +import Data.Word (Word64) +import GHC.Generics (Generic) +import NoThunks.Class (NoThunks (..), noThunksInValues) +import Numeric.Natural (Natural) + +-- | Compute the id of a transaction. +txid :: + forall era. + Era era => + TxBody era -> + TxId (Crypto era) +txid = TxId . hashAnnotated + +-- =================================================================================== +-- Because we expect other Era's to import and use TxId, TxIn, TxOut, we use the weakest +-- constraint possible when deriving their instances. A Stronger constraint, Gathering +-- many constraints together, like: type Strong = (C1 x, C2 x, ..., Cn x) +-- may make this file look systematic by having things like: +-- derving instance (Strong x) => Foo x, for many Foo (Eq, Show, NfData, etc) BUT this +-- forces unnecessary requirements on any new Era which tries to embed one of these +-- types in their own datatypes, if they then try and derive (Foo TheirDataType). +-- ==================================================================================== + +-- | A unique ID of a transaction, which is computable from the transaction. +newtype TxId crypto = TxId {_unTxId :: SafeHash crypto EraIndependentTxBody} + deriving (Show, Eq, Ord, Generic) + deriving newtype (NoThunks, HeapWords) + +deriving newtype instance CC.Crypto crypto => ToCBOR (TxId crypto) + +deriving newtype instance CC.Crypto crypto => FromCBOR (TxId crypto) + +deriving newtype instance CC.Crypto crypto => NFData (TxId crypto) + +instance HeapWords (TxIn crypto) where + heapWords (TxInCompact32 a _ _ _ ix) = + 6 + (4 * HW.heapWordsUnpacked a) + HW.heapWordsUnpacked ix + heapWords (TxInCompactOther tid ix) = + 3 + HW.heapWords tid + HW.heapWordsUnpacked ix + +-- | The input of a UTxO. +data TxIn crypto where + TxInCompact32 :: + HS.SizeHash (CC.HASH crypto) ~ 32 => + {-# UNPACK #-} !Word64 -> -- Hash part 1/4 + {-# UNPACK #-} !Word64 -> -- Hash part 2/4 + {-# UNPACK #-} !Word64 -> -- Hash part 3/4 + {-# UNPACK #-} !Word64 -> -- Hash part 4/4 + {-# UNPACK #-} !Word64 -> -- Index + TxIn crypto + TxInCompactOther :: !(TxId crypto) -> {-# UNPACK #-} !Word64 -> TxIn crypto + +pattern TxIn :: + CC.Crypto crypto => + TxId crypto -> + Natural -> -- TODO We might want to change this to Word64 generally + TxIn crypto +pattern TxIn tid index <- + (viewTxIn -> (tid, index)) + where + TxIn tid@(TxId sh) index = + case HS.viewHash32 (extractHash sh) of + HS.ViewHashNot32 -> TxInCompactOther tid (fromIntegral index) + HS.ViewHash32 a b c d -> TxInCompact32 a b c d (fromIntegral index) + +{-# COMPLETE TxIn #-} + +viewTxIn :: TxIn crypto -> (TxId crypto, Natural) +viewTxIn (TxInCompactOther tid i) = (tid, fromIntegral i) +viewTxIn (TxInCompact32 a b c d i) = (tid, fromIntegral i) + where + tid = TxId (unsafeMakeSafeHash $ HS.unsafeMkHash32 a b c d) + +instance Show (TxIn crypto) where + showsPrec d (viewTxIn -> (tid, ix)) = + showParen (d > app_prec) $ + showString "TxIn " + . showsPrec (app_prec + 1) tid + . showString " " + . showsPrec (app_prec + 1) ix + where + app_prec = 10 + +instance Ord (TxIn crypto) where + compare (TxInCompact32 a1 b1 c1 d1 i1) (TxInCompact32 a2 b2 c2 d2 i2) = + compare a1 a2 <> compare b1 b2 <> compare c1 c2 <> compare d1 d2 + <> compare i1 i2 + compare (viewTxIn -> (id1, ix1)) (viewTxIn -> (id2, ix2)) = + compare id1 id2 <> compare ix1 ix2 + +instance Eq (TxIn crypto) where + (==) (TxInCompact32 a1 b1 c1 d1 i1) (TxInCompact32 a2 b2 c2 d2 i2) = + (a1 == a2) && (b1 == b2) && (c1 == c2) && (d1 == d2) && (i1 == i2) + (==) (viewTxIn -> (id1, ix1)) (viewTxIn -> (id2, ix2)) = + (id1 == id2) && (ix1 == ix2) + +instance CC.Crypto crypto => NFData (TxIn crypto) where + rnf (TxInCompactOther tid _) = seq (rnf tid) () + rnf (TxInCompact32 _ _ _ _ _) = () + +instance NoThunks (TxIn crypto) where + showTypeOf _ = "TxIn" + wNoThunks c (TxInCompactOther tid _) = noThunksInValues c [tid] + wNoThunks _ (TxInCompact32 _ _ _ _ _) = pure Nothing -- always in normal form + +instance + CC.Crypto crypto => + ToCBOR (TxIn crypto) + where + toCBOR (viewTxIn -> (txId, index)) = + encodeListLen 2 + <> toCBOR txId + <> toCBOR index + +instance + CC.Crypto crypto => + FromCBOR (TxIn crypto) + where + fromCBOR = + decodeRecordNamed + "TxIn" + (const 2) + (TxIn <$> fromCBOR <*> fmap natural fromCBOR) + where + natural :: Word64 -> Natural + natural = fromIntegral diff --git a/libs/cardano-ledger-test/bench/Bench/Cardano/Ledger/EpochBoundary.hs b/libs/cardano-ledger-test/bench/Bench/Cardano/Ledger/EpochBoundary.hs index 9f1ddd0d856..15ef70bff77 100644 --- a/libs/cardano-ledger-test/bench/Bench/Cardano/Ledger/EpochBoundary.hs +++ b/libs/cardano-ledger-test/bench/Bench/Cardano/Ledger/EpochBoundary.hs @@ -26,10 +26,11 @@ import Cardano.Ledger.SafeHash ) import Cardano.Ledger.Shelley.CompactAddr (compactAddr) import Cardano.Ledger.Shelley.EpochBoundary (aggregateUtxoCoinByCredential) -import Cardano.Ledger.Shelley.TxBody (TxId (..), TxIn (..), TxOut (..)) +import Cardano.Ledger.Shelley.TxBody (TxOut (..)) import Cardano.Ledger.Shelley.UTxO (UTxO (UTxO)) import Cardano.Ledger.ShelleyMA () import Cardano.Ledger.Slot (SlotNo (SlotNo)) +import Cardano.Ledger.TxIn (TxId (..), TxIn (..)) import qualified Cardano.Ledger.Val as Val import Control.DeepSeq (NFData (..)) import Criterion diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/TwoPhaseValidation.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/TwoPhaseValidation.hs index 61daaa301f0..6b7bf6223f5 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/TwoPhaseValidation.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/TwoPhaseValidation.hs @@ -97,11 +97,11 @@ import Cardano.Ledger.Shelley.TxBody PoolCert (..), PoolMetadata (..), RewardAcnt (..), - TxIn (..), Wdrl (..), ) -import Cardano.Ledger.Shelley.UTxO (makeWitnessVKey, txid) +import Cardano.Ledger.Shelley.UTxO (makeWitnessVKey) import Cardano.Ledger.ShelleyMA.Timelocks (ValidityInterval (..)) +import Cardano.Ledger.TxIn (TxIn (..), txid) import Cardano.Ledger.Val (inject, (<+>)) import Cardano.Slotting.EpochInfo (EpochInfo, fixedEpochInfo) import Cardano.Slotting.Slot (EpochSize (..), SlotNo (..)) diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/Updaters.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/Updaters.hs index 26f345a73e7..a4938fe4e36 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/Updaters.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/Updaters.hs @@ -59,10 +59,11 @@ import qualified Cardano.Ledger.Shelley.PParams as PP (PParams, PParams' (..), U import qualified Cardano.Ledger.Shelley.Scripts as Multi import Cardano.Ledger.Shelley.Tx as Shelley (WitnessSetHKD (addrWits, bootWits, scriptWits), pattern WitnessSet) import qualified Cardano.Ledger.Shelley.Tx as Shelley (Tx (..)) -import Cardano.Ledger.Shelley.TxBody (DCert (..), TxIn (..), Wdrl (..), WitVKey (..)) +import Cardano.Ledger.Shelley.TxBody (DCert (..), Wdrl (..), WitVKey (..)) import qualified Cardano.Ledger.Shelley.TxBody as Shelley (TxBody (..), TxOut (..)) import Cardano.Ledger.ShelleyMA.Timelocks (Timelock (..), ValidityInterval (..)) import qualified Cardano.Ledger.ShelleyMA.TxBody as MA (TxBody (..)) +import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.Val (inject, (<+>)) import Cardano.Slotting.Slot (EpochNo (..), SlotNo (..)) import qualified Data.ByteString.Char8 as BS