Skip to content

Commit 8025a8f

Browse files
committed
Integrate Ledger-related changes
- Fix simple script decoding fallback for Conway - Introduce transaction levels. - Replace promoted constructors with types. - Introduce CoinPerByte. - Use StrictMaybe where necessary. - `PoolParams` -> `StakePoolParams`
1 parent 632dd5d commit 8025a8f

25 files changed

Lines changed: 136 additions & 122 deletions

File tree

cardano-cli/cardano-cli.cabal

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,8 @@ test-suite cardano-cli-golden
442442
cardano-cli,
443443
cardano-cli:cardano-cli-test-lib,
444444
cardano-crypto-wrapper,
445-
cardano-ledger-core,
446445
cardano-strict-containers ^>=0.1,
447446
cborg,
448-
containers,
449447
directory,
450448
exceptions,
451449
extra,

cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ getScriptWitnessDetails era tb =
284284
where
285285
aeo = convert era
286286
friendlyRedeemers
287-
:: Ledger.Tx (ShelleyLedgerEra era)
287+
:: Ledger.Tx C.TopTx (ShelleyLedgerEra era)
288288
-> Aeson.Value
289289
friendlyRedeemers tx =
290290
alonzoEraOnwardsConstraints aeo $ do
@@ -293,7 +293,7 @@ getScriptWitnessDetails era tb =
293293
Aeson.Array $ Vector.fromList redeemerList
294294

295295
friendlyRedeemerInfo
296-
:: Ledger.Tx (ShelleyLedgerEra era)
296+
:: Ledger.Tx C.TopTx (ShelleyLedgerEra era)
297297
-> Ledger.PlutusPurpose Ledger.AsIx (ShelleyLedgerEra era)
298298
-> (Ledger.Data (ShelleyLedgerEra era), ExUnits)
299299
-> Aeson.Value
@@ -373,7 +373,7 @@ getScriptWitnessDetails era tb =
373373
addLabelToPurpose Proposing pp = Aeson.object ["submitting a proposal following proposal policy" .= pp]
374374
addLabelToPurpose Guarding _ = error "TODO Dijkstra"
375375

376-
friendlyScriptData :: Ledger.Tx (ShelleyLedgerEra era) -> Aeson.Value
376+
friendlyScriptData :: Ledger.Tx C.TopTx (ShelleyLedgerEra era) -> Aeson.Value
377377
friendlyScriptData tx =
378378
alonzoEraOnwardsConstraints aeo $ do
379379
Aeson.Array $
@@ -386,7 +386,7 @@ getScriptWitnessDetails era tb =
386386
| (scriptHash, scriptData) <- Map.toList $ tx ^. Ledger.witsTxL . Ledger.scriptTxWitsL
387387
]
388388

389-
friendlyDats :: Ledger.Tx (ShelleyLedgerEra era) -> Aeson.Value
389+
friendlyDats :: Ledger.Tx C.TopTx (ShelleyLedgerEra era) -> Aeson.Value
390390
friendlyDats tx =
391391
alonzoEraOnwardsConstraints aeo $
392392
let Ledger.TxDats dats = tx ^. Ledger.witsTxL . Ledger.datsTxWitsL
@@ -633,7 +633,7 @@ renderCertificate sbe (Exp.Certificate c) =
633633

634634
renderDrepCredential
635635
:: ()
636-
=> L.Credential 'L.DRepRole
636+
=> L.Credential L.DRepRole
637637
-> Aeson.Value
638638
renderDrepCredential =
639639
object . \case

cardano-cli/src/Cardano/CLI/Compatible/Transaction/Run.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Cardano.Api.Compatible.Certificate qualified as Compatible
1818
import Cardano.Api.Experimental (obtainCommonConstraints)
1919
import Cardano.Api.Experimental qualified as Exp
2020
import Cardano.Api.Experimental.AnyScriptWitness qualified as Exp
21-
import Cardano.Api.Experimental.Plutus qualified as Exp
21+
import Cardano.Api.Experimental.Plutus qualified as Exp.Plutus
2222
import Cardano.Api.Experimental.Tx qualified as Exp
2323
import Cardano.Api.Ledger qualified as L hiding
2424
( VotingProcedures
@@ -158,9 +158,9 @@ readCertificateScriptWitnessSbe
158158
(OnDiskPlutusScriptCliArgs scriptFp Exp.NoScriptDatumAllowed redeemerFile execUnits)
159159
) = do
160160
let plutusScriptFp = unFile scriptFp
161-
Exp.AnyPlutusScript anyPlutusScript <- Compatible.readFilePlutusScript sbe plutusScriptFp
161+
Exp.Plutus.AnyPlutusScript anyPlutusScript <- Compatible.readFilePlutusScript sbe plutusScriptFp
162162
let
163-
lang = Exp.plutusScriptInEraSLanguage anyPlutusScript
163+
lang = Exp.Plutus.plutusScriptInEraSLanguage anyPlutusScript
164164
let script' = Exp.PScript anyPlutusScript
165165

166166
redeemer <-

cardano-cli/src/Cardano/CLI/Compatible/Transaction/ScriptWitness.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Cardano.Api
2121
)
2222
import Cardano.Api.Experimental qualified as Exp
2323
import Cardano.Api.Experimental.AnyScriptWitness qualified as Exp
24-
import Cardano.Api.Experimental.Plutus qualified as Exp
24+
import Cardano.Api.Experimental.Plutus qualified as Exp.Plutus
2525

2626
import Cardano.CLI.Compatible.Exception
2727
import Cardano.CLI.Compatible.Read (readFilePlutusScript, readFileSimpleScript)
@@ -68,8 +68,8 @@ readCertificateScriptWitness sbe certScriptReq =
6868
OnDiskPlutusScript
6969
(OnDiskPlutusScriptCliArgs scriptFp Exp.NoScriptDatumAllowed redeemerFile execUnits) -> do
7070
let plutusScriptFp = unFile scriptFp
71-
Exp.AnyPlutusScript anyPlutusScript <- readFilePlutusScript sbe plutusScriptFp
72-
let lang = Exp.plutusScriptInEraSLanguage anyPlutusScript
71+
Exp.Plutus.AnyPlutusScript anyPlutusScript <- readFilePlutusScript sbe plutusScriptFp
72+
let lang = Exp.Plutus.plutusScriptInEraSLanguage anyPlutusScript
7373
script' = Exp.PScript anyPlutusScript
7474
redeemer <-
7575
fromExceptTCli $

cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,13 @@ parseLovelace = do
374374
then fail $ show i <> " lovelace exceeds the Word64 upper bound"
375375
else return $ L.Coin i
376376

377+
parseCoinPerByte :: P.Parser L.CoinPerByte
378+
parseCoinPerByte = do
379+
i <- P.parseDecimal
380+
case L.toCompact (Coin i) of
381+
Nothing -> fail $ show i <> " lovelace exceeds the Word64 upper bound"
382+
Just c -> pure . L.CoinPerByte $ c
383+
377384
-- | The first argument is the optional prefix.
378385
pStakePoolVerificationKeyOrFile
379386
:: Maybe String
@@ -2712,9 +2719,9 @@ pCostModels =
27122719
, Opt.completer (Opt.bashCompleter "file")
27132720
]
27142721

2715-
pMinFeePerByteFactor :: Parser Lovelace
2722+
pMinFeePerByteFactor :: Parser L.CoinPerByte
27162723
pMinFeePerByteFactor =
2717-
Opt.option (readerFromParsecParser parseLovelace) $
2724+
Opt.option (readerFromParsecParser parseCoinPerByte) $
27182725
mconcat
27192726
[ Opt.long "min-fee-linear"
27202727
, Opt.metavar "LOVELACE"
@@ -2935,9 +2942,9 @@ pExtraEntropy =
29352942
. BSC.pack
29362943
=<< some P.hexDigit
29372944

2938-
pUTxOCostPerByte :: Parser Lovelace
2945+
pUTxOCostPerByte :: Parser L.CoinPerByte
29392946
pUTxOCostPerByte =
2940-
Opt.option (readerFromParsecParser parseLovelace) $
2947+
Opt.option (readerFromParsecParser parseCoinPerByte) $
29412948
mconcat
29422949
[ Opt.long "utxo-cost-per-byte"
29432950
, Opt.metavar "LOVELACE"
@@ -3004,7 +3011,7 @@ pMaxBlockExecutionUnits =
30043011
]
30053012
)
30063013

3007-
pMaxValueSize :: Parser Natural
3014+
pMaxValueSize :: Parser Word32
30083015
pMaxValueSize =
30093016
Opt.option integralReader $
30103017
mconcat
@@ -3016,7 +3023,7 @@ pMaxValueSize =
30163023
]
30173024
]
30183025

3019-
pCollateralPercent :: Parser Natural
3026+
pCollateralPercent :: Parser Word16
30203027
pCollateralPercent =
30213028
Opt.option integralReader $
30223029
mconcat
@@ -3030,7 +3037,7 @@ pCollateralPercent =
30303037
]
30313038
]
30323039

3033-
pMaxCollateralInputs :: Parser Natural
3040+
pMaxCollateralInputs :: Parser Word16
30343041
pMaxCollateralInputs =
30353042
Opt.option integralReader $
30363043
mconcat
@@ -3208,7 +3215,7 @@ pDRepVotingThresholds =
32083215
, Opt.help "Acceptance threshold for DRep votes on treasury withdrawals."
32093216
]
32103217

3211-
pMinCommitteeSize :: Parser Natural
3218+
pMinCommitteeSize :: Parser Word16
32123219
pMinCommitteeSize =
32133220
Opt.option integralReader $
32143221
mconcat

cardano-cli/src/Cardano/CLI/EraBased/Genesis/CreateTestnetData/Run.hs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ runGenesisCreateTestNetDataCmd
382382
addDRepsToConwayGenesis dRepKeys (map snd delegatorKeys) conwayGenesis
383383
<&> addCommitteeToConwayGenesis ccColdKeys
384384

385-
let stake = second L.ppId . mkDelegationMapEntry <$> delegations
386-
stakePools = [(L.ppId poolParams', poolParams') | poolParams' <- snd . mkDelegationMapEntry <$> delegations]
385+
let stake = second L.sppId . mkDelegationMapEntry <$> delegations
386+
stakePools = [(L.sppId poolParams', poolParams') | poolParams' <- snd . mkDelegationMapEntry <$> delegations]
387387
delegAddrs = dInitialUtxoAddr <$> delegations
388388
!shelleyGenesis' <-
389389
fromExceptTCli $
@@ -447,7 +447,7 @@ runGenesisCreateTestNetDataCmd
447447
mkPoolDir idx = poolsDir </> ("pool" <> show idx)
448448

449449
mkDelegationMapEntry
450-
:: Delegation -> (L.KeyHash L.Staking, L.PoolParams)
450+
:: Delegation -> (L.KeyHash L.Staking, L.StakePoolParams)
451451
mkDelegationMapEntry d = (dDelegStaking d, dPoolParams d)
452452

453453
addCommitteeToConwayGenesis
@@ -751,7 +751,7 @@ createPoolCredentials fmt dir = do
751751
data Delegation = Delegation
752752
{ dInitialUtxoAddr :: !(AddressInEra ShelleyEra)
753753
, dDelegStaking :: !(L.KeyHash L.Staking)
754-
, dPoolParams :: !L.PoolParams
754+
, dPoolParams :: !L.StakePoolParams
755755
}
756756
deriving (Generic, NFData)
757757

@@ -763,7 +763,7 @@ buildPoolParams
763763
-- ^ The index of the pool being built. Starts at 0.
764764
-> Map Word [L.StakePoolRelay]
765765
-- ^ User submitted stake pool relay map. Starts at 0
766-
-> ExceptT GenesisCmdError IO L.PoolParams
766+
-> ExceptT GenesisCmdError IO L.StakePoolParams
767767
buildPoolParams nw dir index specifiedRelays = do
768768
StakePoolVerificationKey poolColdVK <-
769769
firstExceptT (GenesisCmdStakePoolCmdError . StakePoolCmdReadFileError)
@@ -780,17 +780,17 @@ buildPoolParams nw dir index specifiedRelays = do
780780
$ readFileTextEnvelope poolRewardVKF
781781

782782
pure
783-
L.PoolParams
784-
{ L.ppId = L.hashKey poolColdVK
785-
, L.ppVrf = C.hashVerKeyVRF @StandardCrypto poolVrfVK
786-
, L.ppPledge = L.Coin 0
787-
, L.ppCost = L.Coin 0
788-
, L.ppMargin = minBound
789-
, L.ppRewardAccount =
783+
L.StakePoolParams
784+
{ L.sppId = L.hashKey poolColdVK
785+
, L.sppVrf = C.hashVerKeyVRF @StandardCrypto poolVrfVK
786+
, L.sppPledge = L.Coin 0
787+
, L.sppCost = L.Coin 0
788+
, L.sppMargin = minBound
789+
, L.sppAccountAddress =
790790
toShelleyStakeAddr $ makeStakeAddress nw $ StakeCredentialByKey (verificationKeyHash rewardsSVK)
791-
, L.ppOwners = mempty
792-
, L.ppRelays = lookupPoolRelay specifiedRelays
793-
, L.ppMetadata = L.SNothing
791+
, L.sppOwners = mempty
792+
, L.sppRelays = lookupPoolRelay specifiedRelays
793+
, L.sppMetadata = L.SNothing
794794
}
795795
where
796796
lookupPoolRelay :: Map Word [L.StakePoolRelay] -> Seq.StrictSeq L.StakePoolRelay
@@ -812,7 +812,7 @@ computeInsecureStakeKeyAddr g0 = do
812812
computeDelegation
813813
:: NetworkId
814814
-> (VerificationKey PaymentKey, VerificationKey StakeKey)
815-
-> L.PoolParams
815+
-> L.StakePoolParams
816816
-> Delegation
817817
computeDelegation nw (paymentVK, stakeVK) dPoolParams = do
818818
let paymentCredential = PaymentCredentialByKey (verificationKeyHash paymentVK)
@@ -835,9 +835,9 @@ updateOutputTemplate
835835
-- ^ Total amount of lovelace
836836
-> [AddressInEra ShelleyEra]
837837
-- ^ UTxO addresses that are not delegating
838-
-> [(L.KeyHash 'L.StakePool, L.PoolParams)]
838+
-> [(L.KeyHash L.StakePool, L.StakePoolParams)]
839839
-- ^ Pool map
840-
-> [(L.KeyHash 'L.Staking, L.KeyHash 'L.StakePool)]
840+
-> [(L.KeyHash L.Staking, L.KeyHash L.StakePool)]
841841
-- ^ Delegaton map
842842
-> Maybe Lovelace
843843
-- ^ Amount of lovelace to delegate

cardano-cli/src/Cardano/CLI/EraBased/Genesis/Run.hs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ runGenesisCreateStakedCmd
681681
stuffedUtxoAddrs <-
682682
liftIO $ Lazy.replicateM (fromIntegral numStuffedUtxo) $ genStuffedAddress network
683683

684-
let stake = second L.ppId . mkDelegationMapEntry <$> delegations
685-
stakePools = [(L.ppId poolParams', poolParams') | poolParams' <- snd . mkDelegationMapEntry <$> delegations]
684+
let stake = second L.sppId . mkDelegationMapEntry <$> delegations
685+
stakePools = [(L.sppId poolParams', poolParams') | poolParams' <- snd . mkDelegationMapEntry <$> delegations]
686686
delegAddrs = dInitialUtxoAddr <$> delegations
687687
!shelleyGenesis =
688688
updateOutputTemplate
@@ -740,7 +740,7 @@ runGenesisCreateStakedCmd
740740
where
741741
adjustTemplate t = t{sgNetworkMagic = unNetworkMagic (toNetworkMagic networkId)}
742742
mkDelegationMapEntry
743-
:: Delegation -> (L.KeyHash L.Staking, L.PoolParams)
743+
:: Delegation -> (L.KeyHash L.Staking, L.StakePoolParams)
744744
mkDelegationMapEntry d = (dDelegStaking d, dPoolParams d)
745745

746746
-- -------------------------------------------------------------------------------------------------
@@ -756,9 +756,9 @@ updateOutputTemplate
756756
-- ^ Number of UTxO addresses that are delegating
757757
-> [AddressInEra ShelleyEra]
758758
-- ^ UTxO addresses that are not delegating
759-
-> [(L.KeyHash 'L.StakePool, L.PoolParams)]
759+
-> [(L.KeyHash L.StakePool, L.StakePoolParams)]
760760
-- ^ Pool map
761-
-> [(L.KeyHash 'L.Staking, L.KeyHash 'L.StakePool)]
761+
-> [(L.KeyHash L.Staking, L.KeyHash L.StakePool)]
762762
-- ^ Delegaton map
763763
-> Maybe Lovelace
764764
-- ^ Amount of lovelace to delegate
@@ -939,7 +939,7 @@ createPoolCredentials fmt dir index = do
939939
data Delegation = Delegation
940940
{ dInitialUtxoAddr :: !(AddressInEra ShelleyEra)
941941
, dDelegStaking :: !(L.KeyHash L.Staking)
942-
, dPoolParams :: !L.PoolParams
942+
, dPoolParams :: !L.StakePoolParams
943943
}
944944
deriving (Generic, NFData)
945945

@@ -950,7 +950,7 @@ buildPoolParams
950950
-> Maybe Word
951951
-> Map Word [L.StakePoolRelay]
952952
-- ^ User submitted stake pool relay map
953-
-> ExceptT GenesisCmdError IO L.PoolParams
953+
-> ExceptT GenesisCmdError IO L.StakePoolParams
954954
buildPoolParams nw dir index specifiedRelays = do
955955
StakePoolVerificationKey poolColdVK <-
956956
firstExceptT (GenesisCmdStakePoolCmdError . StakePoolCmdReadFileError)
@@ -967,17 +967,17 @@ buildPoolParams nw dir index specifiedRelays = do
967967
$ readFileTextEnvelope @(VerificationKey StakeKey) poolRewardVKF
968968

969969
pure
970-
L.PoolParams
971-
{ L.ppId = L.hashKey poolColdVK
972-
, L.ppVrf = C.hashVerKeyVRF @C.StandardCrypto poolVrfVK
973-
, L.ppPledge = L.Coin 0
974-
, L.ppCost = L.Coin 0
975-
, L.ppMargin = minBound
976-
, L.ppRewardAccount =
970+
L.StakePoolParams
971+
{ L.sppId = L.hashKey poolColdVK
972+
, L.sppVrf = C.hashVerKeyVRF @C.StandardCrypto poolVrfVK
973+
, L.sppPledge = L.Coin 0
974+
, L.sppCost = L.Coin 0
975+
, L.sppMargin = minBound
976+
, L.sppAccountAddress =
977977
toShelleyStakeAddr $ makeStakeAddress nw $ StakeCredentialByKey (verificationKeyHash rewardsSVK)
978-
, L.ppOwners = mempty
979-
, L.ppRelays = lookupPoolRelay specifiedRelays
980-
, L.ppMetadata = L.SNothing
978+
, L.sppOwners = mempty
979+
, L.sppRelays = lookupPoolRelay specifiedRelays
980+
, L.sppMetadata = L.SNothing
981981
}
982982
where
983983
lookupPoolRelay
@@ -1030,7 +1030,7 @@ writeBulkPoolCredentials dir bulkIx poolIxs = do
10301030
computeInsecureDelegation
10311031
:: StdGen
10321032
-> NetworkId
1033-
-> L.PoolParams
1033+
-> L.StakePoolParams
10341034
-> IO (StdGen, Delegation)
10351035
computeInsecureDelegation g0 nw pool = do
10361036
(paymentVK, g1) <- first getVerificationKey <$> generateInsecureSigningKey g0 AsPaymentKey
@@ -1080,7 +1080,7 @@ updateTemplate
10801080
-- ^ Amount of lovelace not delegated
10811081
-> [AddressInEra ShelleyEra]
10821082
-- ^ UTxO addresses that are not delegating
1083-
-> Map (L.KeyHash 'L.Staking) L.PoolParams
1083+
-> Map (L.KeyHash L.Staking) L.StakePoolParams
10841084
-- ^ Genesis staking: pools/delegation map & delegated initial UTxO spec
10851085
-> Lovelace
10861086
-- ^ Number of UTxO Addresses for delegation
@@ -1120,10 +1120,10 @@ updateTemplate
11201120
ShelleyGenesisStaking
11211121
{ sgsPools =
11221122
fromList
1123-
[ (L.ppId poolParams, poolParams)
1123+
[ (L.sppId poolParams, poolParams)
11241124
| poolParams <- Map.elems poolSpecs
11251125
]
1126-
, sgsStake = ListMap.fromMap $ L.ppId <$> poolSpecs
1126+
, sgsStake = ListMap.fromMap $ L.sppId <$> poolSpecs
11271127
}
11281128
, sgProtocolParams = pparamsFromTemplate
11291129
}

cardano-cli/src/Cardano/CLI/EraBased/Governance/Actions/Option.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ pAlonzoOnwardsPParams =
287287
pIntroducedInBabbagePParams :: Parser (IntroducedInBabbagePParams ledgerera)
288288
pIntroducedInBabbagePParams =
289289
IntroducedInBabbagePParams
290-
<$> convertToLedger L.CoinPerByte (optional pUTxOCostPerByte)
290+
<$> convertToLedger id (optional pUTxOCostPerByte)
291291

292292
pIntroducedInConwayPParams :: Parser (IntroducedInConwayPParams ledgerera)
293293
pIntroducedInConwayPParams =

cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ getQueryStakeAddressInfo
10511051
| gas <- toList govActionStates
10521052
, let proc = L.gasProposalProcedure gas
10531053
, let rewardAccount = L.pProcReturnAddr proc
1054-
stakeCredential :: Api.StakeCredential = fromShelleyStakeCredential (rewardAccount ^. L.accountAddressCredentialL)
1054+
stakeCredential :: Api.StakeCredential = fromShelleyStakeCredential ( rewardAccount ^. L.accountAddressCredentialL)
10551055
, stakeCredential == fromShelleyStakeCredential addr
10561056
]
10571057

@@ -1818,10 +1818,10 @@ runQuerySPOStakeDistribution
18181818
PoolState poolStateResult <-
18191819
fromEitherCli $ decodePoolState (convert eon) serialisedPoolState
18201820

1821-
let spoToRewardCred :: Map (L.KeyHash L.StakePool) (L.Credential 'L.Staking)
1821+
let spoToRewardCred :: Map (L.KeyHash L.StakePool) (L.Credential L.Staking)
18221822
spoToRewardCred =
18231823
Map.map
1824-
(L.raCredential . L.ppRewardAccount)
1824+
(\params -> L.sppAccountAddress params ^. L.accountAddressCredentialL)
18251825
(L.qpsrStakePoolParams poolStateResult)
18261826

18271827
allRewardCreds :: Set StakeCredential

0 commit comments

Comments
 (0)