Skip to content

Commit

Permalink
Merge branch 'master' into cl/queryProposals
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosLopezDeLara authored Nov 26, 2024
2 parents 16f1dd9 + 5bb8f34 commit 47fe620
Show file tree
Hide file tree
Showing 35 changed files with 802 additions and 448 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ jobs:
cabal-version: ${{ matrix.cabal }}

- name: Install system dependencies
uses: input-output-hk/actions/base@latest
# TODO: switch to input-output-hk/actions/base@latest after https://github.com/input-output-hk/actions/pull/29 gets merged
uses: carbolymer/actions/base@latest
with:
use-sodium-vrf: true # default is true

Expand Down
21 changes: 21 additions & 0 deletions cardano-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog for cardano-api

## 10.3.0.0

- Add `sbeToSimpleScriptLanguageInEra`, `getScriptWitnessScript`, `getScriptWitnessReferenceInput`, `getScriptWitnessReferenceInputOrScript` function
Refactor `TxMintValue` to better represent minting state
Propagate `IsPlutusLanguage` constraint to `ScriptLanguage lang`, `AnyPlutusScriptVersion`, `Script lang` and `ScriptWitness witctx era` types.
Remove `Maybe ScriptHash` from `PReferenceScript` and `SReferenceScript`.
(breaking, refactoring)
[PR 663](https://github.com/IntersectMBO/cardano-api/pull/663)

- Improve plutus script failure error
(feature)
[PR 683](https://github.com/IntersectMBO/cardano-api/pull/683)

- Remove experimental code exposure in `Cardano.Api` non-experimental modules
(breaking)
[PR 681](https://github.com/IntersectMBO/cardano-api/pull/681)

- Deprecate eons conversion functions like `conwayEraOnwardsToBabbageEraOnwards`. Add [`Inject`](https://cardano-ledger.cardano.intersectmbo.org/cardano-ledger-core/Cardano-Ledger-BaseTypes.html#t:Inject) instances for eon conversions. See the PR description for migration aid.
(compatible, refactoring)
[PR 636](https://github.com/IntersectMBO/cardano-api/pull/636)

## 10.2.0.0

- ValueParser: rename publicly exposed function names to indicate they are parsers
Expand Down
11 changes: 9 additions & 2 deletions cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.4
name: cardano-api
version: 10.2.0.0
version: 10.3.0.0
synopsis: The cardano API
description: The cardano API.
category:
Expand Down Expand Up @@ -71,6 +71,7 @@ library internal
Cardano.Api.Eon.AlonzoEraOnwards
Cardano.Api.Eon.BabbageEraOnwards
Cardano.Api.Eon.ByronToAlonzoEra
Cardano.Api.Eon.Convert
Cardano.Api.Eon.ConwayEraOnwards
Cardano.Api.Eon.MaryEraOnwards
Cardano.Api.Eon.ShelleyBasedEra
Expand Down Expand Up @@ -123,6 +124,7 @@ library internal
Cardano.Api.NetworkId
Cardano.Api.OperationalCertificate
Cardano.Api.Orphans
Cardano.Api.Plutus
Cardano.Api.Pretty
Cardano.Api.Protocol
Cardano.Api.ProtocolParameters
Expand Down Expand Up @@ -161,6 +163,7 @@ library internal
attoparsec,
base16-bytestring >=1.0,
base58-bytestring,
base64-bytestring,
bech32 >=1.1.0,
bytestring,
cardano-binary,
Expand Down Expand Up @@ -278,6 +281,7 @@ library gen
Test.Hedgehog.Roundtrip.CBOR

build-depends:
Diff,
QuickCheck,
aeson >=1.5.6.0,
base16-bytestring,
Expand All @@ -293,6 +297,7 @@ library gen
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.14,
cardano-ledger-shelley >=1.13,
containers,
directory,
filepath,
hedgehog >=1.1,
hedgehog-extras,
Expand Down Expand Up @@ -380,6 +385,7 @@ test-suite cardano-api-golden
type: exitcode-stdio-1.0
build-depends:
aeson,
base64-bytestring,
bech32 >=1.1.0,
bytestring,
cardano-api,
Expand All @@ -391,6 +397,7 @@ test-suite cardano-api-golden
cardano-ledger-alonzo,
cardano-ledger-api ^>=1.9,
cardano-ledger-babbage >=1.9,
cardano-ledger-binary,
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.14,
cardano-ledger-shelley,
cardano-ledger-shelley-test >=1.2.0.1,
Expand All @@ -403,7 +410,7 @@ test-suite cardano-api-golden
microlens,
parsec,
plutus-core ^>=1.36,
plutus-ledger-api ^>=1.36,
plutus-ledger-api,
tasty,
tasty-hedgehog,
text,
Expand Down
61 changes: 44 additions & 17 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ import qualified Cardano.Binary as CBOR
import qualified Cardano.Crypto.Hash as Crypto
import qualified Cardano.Crypto.Hash.Class as CRYPTO
import qualified Cardano.Crypto.Seed as Crypto
import Cardano.Api.Eon.Convert
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.Core as Ledger
Expand Down Expand Up @@ -391,15 +392,13 @@ genLedgerValue w genAId genQuant =
genValueDefault :: MaryEraOnwards era -> Gen (L.Value (ShelleyLedgerEra era))
genValueDefault w = genLedgerValue w genAssetId genSignedNonZeroQuantity

genValueForRole :: forall era. MaryEraOnwards era -> ParserValueRole -> Gen Value
genValueForRole :: MaryEraOnwards era -> ParserValueRole -> Gen Value
genValueForRole w =
\case
RoleMint ->
genValueForMinting
RoleUTxO ->
fromLedgerValue sbe <$> genValueForTxOut sbe
where
sbe = inject w :: ShelleyBasedEra era
fromLedgerValue (convert w) <$> genValueForTxOut (convert w)

-- | Generate a 'Value' suitable for minting, i.e. non-ADA asset ID and a
-- positive or negative quantity.
Expand Down Expand Up @@ -468,7 +467,7 @@ genOperationalCertificateWithCounter = do
Gen.either (genSigningKey AsStakePoolKey) (genSigningKey AsGenesisDelegateExtendedKey)
kesP <- genKESPeriod
c <- Gen.integral $ Range.linear 0 1000
let stakePoolVer = either getVerificationKey (convert . getVerificationKey) stkPoolOrGenDelExtSign
let stakePoolVer = either getVerificationKey (convert' . getVerificationKey) stkPoolOrGenDelExtSign
iCounter = OperationalCertificateIssueCounter c stakePoolVer

case issueOperationalCertificate kesVKey stkPoolOrGenDelExtSign kesP iCounter of
Expand All @@ -477,10 +476,10 @@ genOperationalCertificateWithCounter = do
Left err -> error $ docToString $ prettyError err
Right pair -> return pair
where
convert
convert'
:: VerificationKey GenesisDelegateExtendedKey
-> VerificationKey StakePoolKey
convert =
convert' =
( castVerificationKey
:: VerificationKey GenesisDelegateKey
-> VerificationKey StakePoolKey
Expand Down Expand Up @@ -599,7 +598,7 @@ genTxAuxScripts era =
TxAuxScripts w
<$> Gen.list
(Range.linear 0 3)
(genScriptInEra (inject w))
(genScriptInEra $ convert w)
)

genTxWithdrawals :: CardanoEra era -> Gen (TxWithdrawals build era)
Expand Down Expand Up @@ -662,11 +661,18 @@ genTxMintValue :: CardanoEra era -> Gen (TxMintValue BuildTx era)
genTxMintValue =
inEonForEra
(pure TxMintNone)
$ \supported ->
$ \w -> do
policies <- Gen.list (Range.constant 1 3) genPolicyId
assets <- forM policies $ \policy ->
(,) policy <$>
Gen.list
(Range.constant 1 3)
((,,) <$> genAssetName
<*> genPositiveQuantity
<*> fmap (fmap pure) genScriptWitnessForMint (maryEraOnwardsToShelleyBasedEra w))
Gen.choice
[ pure TxMintNone
-- TODO write a generator for the last parameter of 'TxMintValue' constructor
, TxMintValue supported <$> genValueForMinting <*> return (pure mempty)
, pure $ TxMintValue w (fromList assets)
]

genTxBodyContent :: ShelleyBasedEra era -> Gen (TxBodyContent BuildTx era)
Expand Down Expand Up @@ -1162,7 +1168,7 @@ genProposals w = conwayEraOnwardsConstraints w $ do
-- We're doing it for the complete representation of possible values space of TxProposalProcedures.
-- Proposal procedures code in cardano-api should handle such invalid values just fine.
extraProposals <- Gen.list (Range.constant 0 10) (genProposal w)
let sbe = inject w
let sbe = convert w
proposalsWithWitnesses <-
forM (extraProposals <> proposalsToBeWitnessed) $ \proposal ->
(proposal,) <$> genScriptWitnessForStake sbe
Expand All @@ -1177,7 +1183,7 @@ genVotingProcedures :: Applicative (BuildTxWith build)
-> Gen (Api.TxVotingProcedures build era)
genVotingProcedures w = conwayEraOnwardsConstraints w $ do
voters <- Gen.list (Range.constant 0 10) Q.arbitrary
let sbe = inject w
let sbe = convert w
votersWithWitnesses <- fmap fromList . forM voters $ \voter ->
(voter,) <$> genScriptWitnessForStake sbe
Api.TxVotingProcedures <$> Q.arbitrary <*> pure (pure votersWithWitnesses)
Expand All @@ -1196,13 +1202,13 @@ genScriptWitnessForStake sbe = do
SimpleScript simpleScript -> do
simpleScriptOrReferenceInput <- Gen.choice
[ pure $ SScript simpleScript
, SReferenceScript <$> genTxIn <*> Gen.maybe genScriptHash
, SReferenceScript <$> genTxIn
]
pure $ Api.SimpleScriptWitness scriptLangInEra simpleScriptOrReferenceInput
PlutusScript plutusScriptVersion' plutusScript -> do
plutusScriptOrReferenceInput <- Gen.choice
[ pure $ PScript plutusScript
, PReferenceScript <$> genTxIn <*> Gen.maybe genScriptHash
, PReferenceScript <$> genTxIn
]
scriptRedeemer <- genHashableScriptData
PlutusScriptWitness
Expand All @@ -1213,6 +1219,27 @@ genScriptWitnessForStake sbe = do
scriptRedeemer
<$> genExecutionUnits



genScriptWitnessForMint :: ShelleyBasedEra era -> Gen (Api.ScriptWitness WitCtxMint era)
genScriptWitnessForMint sbe = do
ScriptInEra scriptLangInEra script' <- genScriptInEra sbe
case script' of
SimpleScript simpleScript -> do
simpleScriptOrReferenceInput <- Gen.choice
[ pure $ SScript simpleScript
, SReferenceScript <$> genTxIn
]
pure $ Api.SimpleScriptWitness scriptLangInEra simpleScriptOrReferenceInput
PlutusScript plutusScriptVersion' plutusScript -> do
plutusScriptOrReferenceInput <- Gen.choice
[ pure $ PScript plutusScript
, PReferenceScript <$> genTxIn
]
scriptRedeemer <- genHashableScriptData
PlutusScriptWitness
scriptLangInEra
plutusScriptVersion'
plutusScriptOrReferenceInput
NoScriptDatumForMint
scriptRedeemer
<$> genExecutionUnits

Loading

0 comments on commit 47fe620

Please sign in to comment.