Skip to content

Commit

Permalink
Added HasFied address (Core.Txout era) Addr, to Wellformed.
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSheard committed Nov 4, 2021
1 parent 68024dd commit 8b7c7d0
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module Cardano.Ledger.Alonzo.PlutusScriptApi
where

import Cardano.Binary (FromCBOR (..), ToCBOR (..))
import Cardano.Ledger.Address (Addr)
import Cardano.Ledger.Alonzo.Data (getPlutusData)
import Cardano.Ledger.Alonzo.Language (Language (..))
import Cardano.Ledger.Alonzo.Scripts (CostModel (..), ExUnits (..))
Expand Down Expand Up @@ -253,7 +252,6 @@ scriptsNeeded ::
HasField "inputs" (Core.TxBody era) (Set (TxIn (Crypto era))),
HasField "wdrls" (Core.TxBody era) (Wdrl (Crypto era)),
HasField "certs" (Core.TxBody era) (StrictSeq (DCert (Crypto era))),
HasField "address" (Core.TxOut era) (Addr (Crypto era)),
HasField "body" tx (Core.TxBody era)
) =>
UTxO era ->
Expand All @@ -278,8 +276,7 @@ scriptsNeededFromBody ::
( Era era,
HasField "inputs" (Core.TxBody era) (Set (TxIn (Crypto era))),
HasField "wdrls" (Core.TxBody era) (Wdrl (Crypto era)),
HasField "certs" (Core.TxBody era) (StrictSeq (DCert (Crypto era))),
HasField "address" (Core.TxOut era) (Addr (Crypto era))
HasField "certs" (Core.TxBody era) (StrictSeq (DCert (Crypto era)))
) =>
UTxO era ->
Core.TxBody era ->
Expand Down
3 changes: 1 addition & 2 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ witsVKeyNeeded ::
HasField "certs" (Core.TxBody era) (StrictSeq (DCert (Crypto era))),
HasField "inputs" (Core.TxBody era) (Set (TxIn (Crypto era))),
HasField "collateral" (Core.TxBody era) (Set (TxIn (Crypto era))),
HasField "update" (Core.TxBody era) (StrictMaybe (Update era)),
HasField "address" (Core.TxOut era) (Addr (Crypto era))
HasField "update" (Core.TxBody era) (StrictMaybe (Update era))
) =>
UTxO era ->
tx ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ module Test.Cardano.Ledger.Alonzo.Trials
where

import Cardano.Binary (ToCBOR)
import Cardano.Ledger.Address (Addr)
import Cardano.Ledger.Alonzo (AlonzoEra)
import Cardano.Ledger.Alonzo.Data (Data (..))
import Cardano.Ledger.Alonzo.PParams (PParams' (..))
Expand Down Expand Up @@ -150,7 +149,6 @@ import Test.Tasty.QuickCheck
-- See genAlonzoTx and genAlonzoBlock as examples of its use.
genstuff ::
( EraGen era,
HasField "address" (Core.TxOut era) (Addr (Crypto era)),
Default (State (Core.EraRule "PPUP" era))
) =>
Proxy era ->
Expand Down
12 changes: 4 additions & 8 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ getPoolParameters = Map.restrictKeys . f
-- This is not based on any snapshot, but uses the current ledger state.
poolsByTotalStakeFraction ::
forall era.
(UsesValue era, HasField "address" (Core.TxOut era) (Addr (Crypto era))) =>
(UsesValue era) =>
Globals ->
NewEpochState era ->
PoolDistr (Crypto era)
Expand Down Expand Up @@ -251,8 +251,7 @@ getTotalStake globals ss =
getNonMyopicMemberRewards ::
( UsesValue era,
HasField "_a0" (Core.PParams era) NonNegativeInterval,
HasField "_nOpt" (Core.PParams era) Natural,
HasField "address" (Core.TxOut era) (Addr (Crypto era))
HasField "_nOpt" (Core.PParams era) Natural
) =>
Globals ->
NewEpochState era ->
Expand Down Expand Up @@ -325,9 +324,7 @@ getNonMyopicMemberRewards globals ss creds =
-- do not want to use one of the regular snapshots, but rather the most recent
-- ledger state.
currentSnapshot ::
( UsesValue era,
HasField "address" (Core.TxOut era) (Addr (Crypto era))
) =>
(UsesValue era) =>
NewEpochState era ->
EB.SnapShot (Crypto era)
currentSnapshot ss =
Expand Down Expand Up @@ -398,8 +395,7 @@ deriving instance ToJSON RewardParams
getRewardInfoPools ::
( UsesValue era,
HasField "_a0" (Core.PParams era) NonNegativeInterval,
HasField "_nOpt" (Core.PParams era) Natural,
HasField "address" (Core.TxOut era) (Addr (Crypto era))
HasField "_nOpt" (Core.PParams era) Natural
) =>
Globals ->
NewEpochState era ->
Expand Down
23 changes: 9 additions & 14 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ pvCanFollow (ProtVer m n) (SJust (ProtVer m' n')) =

-- | Incremental Stake, Stake along with possible missed coins from danging Ptrs
data IncrementalStake crypto = IStake
{ getStake :: !(Map (Credential 'Staking crypto) Coin),
dangling :: !(Map Ptr Coin)
{ credMap :: !(Map (Credential 'Staking crypto) Coin),
ptrMap :: !(Map Ptr Coin)
}
deriving (Generic, Show, Eq, Ord, NoThunks, NFData)

Expand Down Expand Up @@ -895,8 +895,7 @@ witsVKeyNeeded ::
HasField "wdrls" (Core.TxBody era) (Wdrl (Crypto era)),
HasField "certs" (Core.TxBody era) (StrictSeq (DCert (Crypto era))),
HasField "inputs" (Core.TxBody era) (Set (TxIn (Crypto era))),
HasField "update" (Core.TxBody era) (StrictMaybe (Update era)),
HasField "address" (Core.TxOut era) (Addr (Crypto era))
HasField "update" (Core.TxBody era) (StrictMaybe (Update era))
) =>
UTxO era ->
tx ->
Expand Down Expand Up @@ -1039,7 +1038,7 @@ reapRewards dStateRewards withdrawals =
-- Now its is called in the tests to see that its incremental analog 'incrementaStakeDistr' agrees.
stakeDistr ::
forall era.
(Era era, HasField "address" (Core.TxOut era) (Addr (Crypto era))) =>
Era era =>
UTxO era ->
DState (Crypto era) ->
PState (Crypto era) ->
Expand Down Expand Up @@ -1068,8 +1067,7 @@ stakeDistr u ds ps =
-- incremental analog. See 'incrementalAggregateUtxoCoinByCredential'
aggregateUtxoCoinByCredential ::
forall era.
( Era era,
HasField "address" (Core.TxOut era) (Addr (Crypto era))
( Era era
) =>
Map Ptr (Credential 'Staking (Crypto era)) ->
UTxO era ->
Expand All @@ -1093,8 +1091,7 @@ aggregateUtxoCoinByCredential ptrs (UTxO u) initial =

-- | Incrementally add the inserts 'utxoAdd' and the deletes 'utxoDel' to the IncrementalStake.
updateStakeDistribution ::
( Era era,
HasField "address" (Core.TxOut era) (Addr (Crypto era))
( Era era
) =>
IncrementalStake (Crypto era) ->
UTxO era ->
Expand All @@ -1111,8 +1108,7 @@ updateStakeDistribution incStake0 utxoDel utxoAdd = incStake2
-- analog 'aggregateUtxoCoinByCredential'
incrementalAggregateUtxoCoinByCredential ::
forall era.
( Era era,
HasField "address" (Core.TxOut era) (Addr (Crypto era))
( Era era
) =>
(Coin -> Coin) ->
UTxO era ->
Expand Down Expand Up @@ -1176,8 +1172,7 @@ incrementalStakeDistr incstake ds ps =
-- which defeats the purpose of memoizing the _stakeDistro field. So use of this function should be
-- restricted to tests and initializations, where the invariant should be maintained.
smartUTxOState ::
( Era era,
HasField "address" (Core.TxOut era) (Addr (Crypto era))
( Era era
) =>
UTxO era ->
Coin ->
Expand Down Expand Up @@ -1525,7 +1520,7 @@ updateNES

returnRedeemAddrsToReserves ::
forall era.
(Era era, HasField "address" (Core.TxOut era) (Addr (Crypto era))) =>
(Era era) =>
EpochState era ->
EpochState era
returnRedeemAddrsToReserves es = es {esAccountState = acnt', esLState = ls'}
Expand Down
3 changes: 1 addition & 2 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ scriptsNeeded ::
HasField "body" tx (Core.TxBody era),
HasField "certs" (Core.TxBody era) (StrictSeq (DCert (Crypto era))),
HasField "wdrls" (Core.TxBody era) (Wdrl (Crypto era)),
HasField "inputs" (Core.TxBody era) (Set (TxIn (Crypto era))),
HasField "address" (Core.TxOut era) (Addr (Crypto era))
HasField "inputs" (Core.TxBody era) (Set (TxIn (Crypto era)))
) =>
UTxO era ->
tx ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ lastByronHeaderHash _ = HashHeader $ mkHash 0
mkGenesisChainState ::
forall era a.
( Default (State (Core.EraRule "PPUP" era)),
HasField "address" (Core.TxOut era) (Addr (Crypto era)),
EraGen era
) =>
GenEnv era ->
Expand Down Expand Up @@ -193,9 +192,7 @@ mkOCertIssueNos (GenDelegs delegs0) =
-- This allows stake pools to produce blocks from genesis.
registerGenesisStaking ::
forall era.
( Era era,
HasField "address" (Core.TxOut era) (Addr (Crypto era))
) =>
(Era era) =>
ShelleyGenesisStaking (Crypto era) ->
ChainState era ->
ChainState era
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module Test.Cardano.Ledger.Shelley.Rules.Chain
)
where

import Cardano.Ledger.Address (Addr)
import Cardano.Ledger.BHeaderView (BHeaderView)
import Cardano.Ledger.BaseTypes (BlocksMade (..), Globals (..), Nonce (..), ProtVer (..), ShelleyBase, StrictMaybe (..), UnitInterval)
import Cardano.Ledger.Block (Block (..))
Expand Down Expand Up @@ -183,7 +182,6 @@ instance
-- | Creates a valid initial chain state
initialShelleyState ::
( Era era,
HasField "address" (Core.TxOut era) (Addr (Crypto era)),
Default (State (Core.EraRule "PPUP" era))
) =>
WithOrigin (LastAppliedBlock (Crypto era)) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ relevantCasesAreCovered ::
HasField "certs" (Core.TxBody era) (StrictSeq (DCert (Crypto era))),
HasField "wdrls" (Core.TxBody era) (Wdrl (Crypto era)),
HasField "update" (Core.TxBody era) (StrictMaybe (PParams.Update era))
-- HasField "address" (Core.TxOut era) (Addr (Crypto era))
) =>
Property
relevantCasesAreCovered = do
Expand All @@ -133,7 +132,6 @@ relevantCasesAreCoveredForTrace ::
HasField "certs" (Core.TxBody era) (StrictSeq (DCert (Crypto era))),
HasField "wdrls" (Core.TxBody era) (Wdrl (Crypto era)),
HasField "update" (Core.TxBody era) (StrictMaybe (PParams.Update era))
-- HasField "address" (Core.TxOut era) (Addr (Crypto era))
) =>
Trace (CHAIN era) ->
Property
Expand Down Expand Up @@ -255,7 +253,7 @@ ratioInt x y =
-- | Transaction has script locked TxOuts
txScriptOutputsRatio ::
forall era.
HasField "address" (Core.TxOut era) (Addr (Crypto era)) =>
Era era =>
Proxy era ->
[StrictSeq (Core.TxOut era)] ->
Double
Expand Down Expand Up @@ -401,7 +399,6 @@ onlyValidChainSignalsAreGenerated ::
forall era.
( EraGen era,
Default (State (Core.EraRule "PPUP" era)),
HasField "address" (Core.TxOut era) (Addr (Crypto era)),
QC.HasTrace (CHAIN era) (GenEnv era),
Show (TxSeq era)
) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module Test.Cardano.Ledger.Shelley.Rules.TestChain
)
where

import Cardano.Ledger.Address (Addr)
import Cardano.Ledger.BaseTypes (Globals, ProtVer, StrictMaybe (..))
import Cardano.Ledger.Block
( Block (..),
Expand Down Expand Up @@ -253,7 +252,7 @@ incrStakeComp SourceSignalTarget {source = chainSt, signal = block} =
counterExampleTooBig x = Map.size (unUTxO x) > 50

utxoBal = Val.coin $ balance u'
incrStakeBal = fold (getStake sd') <> fold (dangling sd')
incrStakeBal = fold (credMap sd') <> fold (ptrMap sd')
ptrs = _ptrs . _dstate $ dp
ptrs' = _ptrs . _dstate $ dp'

Expand Down Expand Up @@ -1192,7 +1191,6 @@ forAllChainTrace ::
( Testable prop,
Default (State (Core.EraRule "PPUP" era)),
EraGen era,
HasField "address" (Core.TxOut era) (Addr (Crypto era)),
QC.HasTrace (CHAIN era) (GenEnv era)
) =>
Word64 -> -- trace length
Expand Down Expand Up @@ -1226,8 +1224,7 @@ atEpoch ::
( EraGen era,
Testable prop,
QC.HasTrace (CHAIN era) (GenEnv era),
Default (State (Core.EraRule "PPUP" era)),
HasField "address" (Core.TxOut era) (Addr (Crypto era))
Default (State (Core.EraRule "PPUP" era))
) =>
(LedgerState era -> LedgerState era -> prop) ->
Property
Expand All @@ -1244,9 +1241,7 @@ ledgerStateFromChainState = esLState . nesEs . chainNes

testIncrementalStake ::
forall era.
( Era era,
HasField "address" (Core.TxOut era) (Addr (Crypto era))
) =>
(Era era) =>
LedgerState era ->
LedgerState era ->
Property
Expand All @@ -1264,8 +1259,7 @@ incrementalStakeProp ::
forall era.
( EraGen era,
QC.HasTrace (CHAIN era) (GenEnv era),
Default (State (Core.EraRule "PPUP" era)),
HasField "address" (Core.TxOut era) (Addr (Crypto era))
Default (State (Core.EraRule "PPUP" era))
) =>
Proxy era ->
Property
Expand Down
2 changes: 2 additions & 0 deletions libs/cardano-ledger-core/src/Cardano/Ledger/Era.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Cardano.Ledger.Era
where

import qualified Cardano.Crypto.Hash as Hash
import Cardano.Ledger.Address (Addr)
import Cardano.Ledger.AuxiliaryData (AuxiliaryDataHash)
import Cardano.Ledger.Coin (Coin)
import Cardano.Ledger.Compactible (Compactible)
Expand Down Expand Up @@ -255,6 +256,7 @@ type WellFormed era =
HasField "scriptWits" (Core.Tx era) (Map (ScriptHash (Crypto era)) (Core.Script era)),
-- TxOut
HasField "value" (Core.TxOut era) (Core.Value era),
HasField "address" (Core.TxOut era) (Addr (Crypto era)),
-- HashAnnotated
HashAnnotated (Core.AuxiliaryData era) EraIndependentAuxiliaryData (Crypto era),
HashAnnotated (Core.TxBody era) EraIndependentTxBody (Crypto era),
Expand Down
4 changes: 2 additions & 2 deletions libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ ppIncrementalStake :: IncrementalStake crypto -> PDoc
ppIncrementalStake (IStake st dangle) =
ppRecord
"IncrementalStake"
[ ("getStake", ppStake (Stake st)),
("dangling", ppMap ppPtr ppCoin dangle)
[ ("credMap", ppStake (Stake st)),
("ptrMap", ppMap ppPtr ppCoin dangle)
]

ppUTxOState ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ import Cardano.Ledger.Shelley.API
)
import Cardano.Ledger.Shelley.BlockChain (bBodySize)
import Cardano.Ledger.Shelley.LedgerState
( IncrementalStake (..),
UTxOState (..),
( UTxOState (..),
WitHashes (..),
smartUTxOState,
)
Expand Down Expand Up @@ -122,7 +121,6 @@ import Data.Maybe (fromJust)
import qualified Data.Sequence.Strict as StrictSeq
import qualified Data.Set as Set
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
import GHC.Records (HasField (..))
import Numeric.Natural (Natural)
import Plutus.V1.Ledger.Api (defaultCostModelParams)
import qualified Plutus.V1.Ledger.Api as Plutus
Expand Down Expand Up @@ -1129,8 +1127,7 @@ utxoEx12 pf = expectedUTxO pf (ExpectSuccess (nonScriptOutWithDatumTxBody pf) (o

utxoStEx12 ::
( Default (State (EraRule "PPUP" era)),
PostShelley era,
HasField "address" (Core.TxOut era) (Addr (Crypto era))
PostShelley era
) =>
Proof era ->
UTxOState era
Expand Down

0 comments on commit 8b7c7d0

Please sign in to comment.