Skip to content

Commit

Permalink
Add basic support for the Conway era.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikd committed Mar 16, 2023
1 parent 0aa5432 commit 477b2ff
Show file tree
Hide file tree
Showing 49 changed files with 656 additions and 152 deletions.
31 changes: 6 additions & 25 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ repository cardano-haskell-packages
d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee

-- repeating the index-state for hackage to work around hackage.nix parsing limitation
index-state: 2023-01-30T00:00:00Z
index-state: 2023-03-06T05:24:58Z

index-state:
, hackage.haskell.org 2023-01-30T00:00:00Z
, cardano-haskell-packages 2022-12-14T00:40:15Z

-- with-compiler: ghc-8.10.7
, hackage.haskell.org 2023-03-06T05:24:58Z
, cardano-haskell-packages 2023-02-28T09:20:07Z

packages:
lib/balance-tx/
Expand Down Expand Up @@ -117,29 +115,11 @@ source-repository-package
-- for some reason, we're unable to retrieve the cardano-node executables in
-- our nix/haskell.nix file.

source-repository-package
type: git
location: https://github.com/input-output-hk/ouroboros-network
tag: 679c7da2079a5e9972a1c502b6a4d6af3eb76945
--sha256: 138mqd5cv0b13giwjvlz3pr6l1cwgpn38n0q3m11mrjwwmmxl0mw
subdir:
monoidal-synchronisation
network-mux
ouroboros-consensus
ouroboros-consensus-byron
ouroboros-consensus-cardano
ouroboros-consensus-protocol
ouroboros-consensus-shelley
ouroboros-network
ouroboros-network-framework
ouroboros-network-testing
ouroboros-consensus-cardano-tools

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-node
tag: 75130f1d496b44e80cbd842b27ac203adf35bcd4
--sha256: 1wy33hs5rg2n0haf5wc9s9mrrkdzyp95njkkpgs8g5mnllapdka8
tag: 84a871ed86fc1b86018231b9cb24ba7b83493c0d
--sha256: 0qnr847z4fvxvbjsa0x0vfhmdwwmr99d6m3j4sh6jxdyph099b2n
subdir:
cardano-api
cardano-git-rev
Expand Down Expand Up @@ -169,6 +149,7 @@ allow-newer:

constraints:
bimap >= 0.4.0
, cardano-binary == 1.5.*
, openapi3 >= 3.2.0
, libsystemd-journal >= 1.4.4
, systemd >= 2.3.0
Expand Down
3 changes: 3 additions & 0 deletions lib/wallet/cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ library
, cardano-ledger-babbage
, cardano-ledger-byron
, cardano-ledger-byron-test
, cardano-ledger-conway
, cardano-ledger-core
, cardano-ledger-shelley
, cardano-ledger-shelley-ma
Expand Down Expand Up @@ -150,6 +151,7 @@ library
, ouroboros-consensus-protocol
, ouroboros-consensus-shelley
, ouroboros-network
, ouroboros-network-api
, ouroboros-network-framework
, path-pieces
, persistent ^>=2.13
Expand Down Expand Up @@ -314,6 +316,7 @@ library
Cardano.Wallet.Read.Primitive.Tx.Alonzo
Cardano.Wallet.Read.Primitive.Tx.Babbage
Cardano.Wallet.Read.Primitive.Tx.Byron
Cardano.Wallet.Read.Primitive.Tx.Conway
Cardano.Wallet.Read.Primitive.Tx.Features.Certificates
Cardano.Wallet.Read.Primitive.Tx.Features.CollateralInputs
Cardano.Wallet.Read.Primitive.Tx.Features.CollateralOutputs
Expand Down
47 changes: 31 additions & 16 deletions lib/wallet/src/Cardano/Api/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import Cardano.Api
, ScriptInEra (..)
, ScriptLanguageInEra (..)
, ShelleyBasedEra (..)
, SimpleScriptVersion (..)
, TimeLocksSupported (TimeLocksInSimpleScriptV2)
, Tx (..)
)
import Cardano.Api.Shelley
Expand Down Expand Up @@ -73,6 +71,8 @@ asAnyShelleyBasedEra = \case
Just $ InAnyShelleyBasedEra ShelleyBasedEraAlonzo a
InAnyCardanoEra BabbageEra a ->
Just $ InAnyShelleyBasedEra ShelleyBasedEraBabbage a
InAnyCardanoEra ConwayEra a ->
Just $ InAnyShelleyBasedEra ShelleyBasedEraConway a

-- Copied from cardano-api because it is not exported.
fromShelleyBasedScript
Expand All @@ -81,23 +81,23 @@ fromShelleyBasedScript
-> ScriptInEra era
fromShelleyBasedScript era script = case era of
ShelleyBasedEraShelley ->
ScriptInEra SimpleScriptV1InShelley $
SimpleScript SimpleScriptV1 $
ScriptInEra SimpleScriptInShelley $
SimpleScript $
fromShelleyMultiSig script
ShelleyBasedEraAllegra ->
ScriptInEra SimpleScriptV2InAllegra $
SimpleScript SimpleScriptV2 $
fromAllegraTimelock TimeLocksInSimpleScriptV2 script
ScriptInEra SimpleScriptInAllegra $
SimpleScript $
fromAllegraTimelock script
ShelleyBasedEraMary ->
ScriptInEra SimpleScriptV2InMary $
SimpleScript SimpleScriptV2 $
fromAllegraTimelock TimeLocksInSimpleScriptV2 script
ScriptInEra SimpleScriptInMary $
SimpleScript $
fromAllegraTimelock script
ShelleyBasedEraAlonzo ->
case script of
Alonzo.TimelockScript s ->
ScriptInEra SimpleScriptV2InAlonzo $
SimpleScript SimpleScriptV2 $
fromAllegraTimelock TimeLocksInSimpleScriptV2 s
ScriptInEra SimpleScriptInAlonzo $
SimpleScript $
fromAllegraTimelock s
Alonzo.PlutusScript Alonzo.PlutusV1 s ->
ScriptInEra PlutusScriptV1InAlonzo $
PlutusScript PlutusScriptV1 $
Expand All @@ -109,9 +109,9 @@ fromShelleyBasedScript era script = case era of
ShelleyBasedEraBabbage ->
case script of
Alonzo.TimelockScript s ->
ScriptInEra SimpleScriptV2InBabbage $
SimpleScript SimpleScriptV2 $
fromAllegraTimelock TimeLocksInSimpleScriptV2 s
ScriptInEra SimpleScriptInBabbage $
SimpleScript $
fromAllegraTimelock s
Alonzo.PlutusScript Alonzo.PlutusV1 s ->
ScriptInEra PlutusScriptV1InBabbage $
PlutusScript PlutusScriptV1 $
Expand All @@ -120,3 +120,18 @@ fromShelleyBasedScript era script = case era of
ScriptInEra PlutusScriptV2InBabbage $
PlutusScript PlutusScriptV2 $
PlutusScriptSerialised s

ShelleyBasedEraConway ->
case script of
Alonzo.TimelockScript s ->
ScriptInEra SimpleScriptInConway $
SimpleScript $
fromAllegraTimelock s
Alonzo.PlutusScript Alonzo.PlutusV1 s ->
ScriptInEra PlutusScriptV1InConway $
PlutusScript PlutusScriptV1 $
PlutusScriptSerialised s
Alonzo.PlutusScript Alonzo.PlutusV2 s ->
ScriptInEra PlutusScriptV2InConway $
PlutusScript PlutusScriptV2 $
PlutusScriptSerialised s
57 changes: 28 additions & 29 deletions lib/wallet/src/Cardano/Api/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ import Data.List
( nub )
import Data.Map
( Map )
import Data.Maybe
( maybeToList )
import Data.Maybe.Strict
( strictMaybeToMaybe )
import Data.Ratio
Expand Down Expand Up @@ -445,8 +443,8 @@ genPlutusScriptOrReferenceInput lang =
-- TODO add proper generator, perhaps as part of ADP-1655
PScript <$> genPlutusScript lang

genSimpleScript :: SimpleScriptVersion lang -> Gen (SimpleScript lang)
genSimpleScript lang =
genSimpleScript :: Gen SimpleScript
genSimpleScript =
sized genTerm
where
genTerm 0 = oneof nonRecursive
Expand All @@ -457,14 +455,10 @@ genSimpleScript lang =

-- Non-recursive generators
nonRecursive =
(RequireSignature . verificationKeyHash <$>
genVerificationKey AsPaymentKey)

: [ RequireTimeBefore supported <$> genSlotNo
| supported <- maybeToList (timeLocksSupported lang) ]

++ [ RequireTimeAfter supported <$> genSlotNo
| supported <- maybeToList (timeLocksSupported lang) ]
[ RequireSignature . verificationKeyHash <$> genVerificationKey AsPaymentKey
, RequireTimeBefore <$> genSlotNo
, RequireTimeAfter <$> genSlotNo
]

-- Recursive generators
recursive n =
Expand All @@ -485,19 +479,18 @@ genReferenceInput :: Gen TxIn
genReferenceInput = genTxIn

genSimpleScriptOrReferenceInput
:: SimpleScriptVersion lang
-> Gen (SimpleScriptOrReferenceInput lang)
genSimpleScriptOrReferenceInput lang =
:: Gen (SimpleScriptOrReferenceInput lang)
genSimpleScriptOrReferenceInput =
oneof [ SScript
<$> genSimpleScript lang
<$> genSimpleScript
, SReferenceScript
<$> genReferenceInput
<*> liftArbitrary genScriptHash
]

genScript :: ScriptLanguage lang -> Gen (Script lang)
genScript (SimpleScriptLanguage lang) =
SimpleScript lang <$> genSimpleScript lang
genScript SimpleScriptLanguage =
SimpleScript <$> genSimpleScript
genScript (PlutusScriptLanguage lang) =
PlutusScript lang <$> genPlutusScript lang

Expand Down Expand Up @@ -645,10 +638,16 @@ genStakeCredential =
genStakeAddress :: Gen StakeAddress
genStakeAddress = makeStakeAddress <$> genNetworkId <*> genStakeCredential

genHashableScriptData :: Gen HashableScriptData
genHashableScriptData = do
sd <- genScriptData
case deserialiseFromCBOR AsHashableScriptData $ serialiseToCBOR sd of
Left e -> error $ "genHashableScriptData: " <> show e
Right r -> return r

genScriptData :: Gen ScriptData
genScriptData =
sized genTerm

where
genTerm 0 = oneof nonRecursive
genTerm n = frequency
Expand Down Expand Up @@ -767,41 +766,41 @@ genScriptWitnessMint
-> Gen (ScriptWitness WitCtxMint era)
genScriptWitnessMint langEra =
case languageOfScriptLanguageInEra langEra of
(SimpleScriptLanguage ver) ->
SimpleScriptWitness langEra ver <$> genSimpleScriptOrReferenceInput ver
SimpleScriptLanguage ->
SimpleScriptWitness langEra <$> genSimpleScriptOrReferenceInput
(PlutusScriptLanguage ver) ->
PlutusScriptWitness langEra ver
<$> genPlutusScriptOrReferenceInput ver
<*> pure NoScriptDatumForMint
<*> genScriptData
<*> genHashableScriptData
<*> genExecutionUnits

genScriptWitnessStake
:: ScriptLanguageInEra lang era
-> Gen (ScriptWitness WitCtxStake era)
genScriptWitnessStake langEra =
case languageOfScriptLanguageInEra langEra of
(SimpleScriptLanguage ver) ->
SimpleScriptWitness langEra ver <$> genSimpleScriptOrReferenceInput ver
SimpleScriptLanguage ->
SimpleScriptWitness langEra <$> genSimpleScriptOrReferenceInput
(PlutusScriptLanguage ver) ->
PlutusScriptWitness langEra ver
<$> genPlutusScriptOrReferenceInput ver
<*> pure NoScriptDatumForStake
<*> genScriptData
<*> genHashableScriptData
<*> genExecutionUnits

genScriptWitnessSpend
:: ScriptLanguageInEra lang era
-> Gen (ScriptWitness WitCtxTxIn era)
genScriptWitnessSpend langEra =
case languageOfScriptLanguageInEra langEra of
(SimpleScriptLanguage ver) ->
SimpleScriptWitness langEra ver <$> genSimpleScriptOrReferenceInput ver
SimpleScriptLanguage ->
SimpleScriptWitness langEra <$> genSimpleScriptOrReferenceInput
(PlutusScriptLanguage ver) ->
PlutusScriptWitness langEra ver
<$> genPlutusScriptOrReferenceInput ver
<*> (ScriptDatumForTxIn <$> genScriptData)
<*> genScriptData
<*> (ScriptDatumForTxIn <$> genHashableScriptData)
<*> genHashableScriptData
<*> genExecutionUnits

genTxAuxScripts :: CardanoEra era -> Gen (TxAuxScripts era)
Expand Down
2 changes: 1 addition & 1 deletion lib/wallet/src/Cardano/DB/Sqlite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ newConnectionPool tr fp = do
let releaseConnection (backend, _) =
destroySqliteBackend tr backend fp

createPool
newPool
acquireConnection
releaseConnection
numberOfStripes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ withinEra = (>=) `on` numberEra
MaryEra -> 4
AlonzoEra -> 5
BabbageEra -> 6
ConwayEra -> 7

-- | Deserialise a transaction to construct a 'SealedTx'.
sealedTxFromBytes :: ByteString -> Either DecoderError SealedTx
Expand Down
2 changes: 2 additions & 0 deletions lib/wallet/src/Cardano/Wallet/Read/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Cardano.Wallet.Read.Eras
, mary
, alonzo
, babbage
, conway
-- * Era specific prism shortcuts.
, inject
, project
Expand Down Expand Up @@ -53,6 +54,7 @@ import Cardano.Wallet.Read.Eras.EraValue
, alonzo
, babbage
, byron
, conway
, eraValueSerialize
, extractEraValue
, inject
Expand Down
3 changes: 2 additions & 1 deletion lib/wallet/src/Cardano/Wallet/Read/Eras/EraFun.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Prelude hiding
( id, (.) )

import Cardano.Api
( AllegraEra, AlonzoEra, BabbageEra, ByronEra, MaryEra, ShelleyEra )
( AllegraEra, AlonzoEra, BabbageEra, ByronEra, ConwayEra, MaryEra, ShelleyEra )
import Cardano.Wallet.Read.Eras.EraValue
( EraValue (..) )
import Cardano.Wallet.Read.Eras.KnownEras
Expand Down Expand Up @@ -80,6 +80,7 @@ data EraFun f g = EraFun
, maryFun :: f MaryEra -> g MaryEra
, alonzoFun :: f AlonzoEra -> g AlonzoEra
, babbageFun :: f BabbageEra -> g BabbageEra
, conwayFun :: f ConwayEra -> g ConwayEra
}

deriveGeneric ''EraFun
Expand Down
8 changes: 7 additions & 1 deletion lib/wallet/src/Cardano/Wallet/Read/Eras/EraValue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Cardano.Wallet.Read.Eras.EraValue
-- * Era specific prisms
, MkEraValue (..)
, byron
, conway
, shelley
, allegra
, mary
Expand Down Expand Up @@ -53,6 +54,7 @@ import Cardano.Api
, BabbageEra
, ByronEra
, CardanoEra (..)
, ConwayEra
, IsCardanoEra
, MaryEra
, ShelleyEra
Expand Down Expand Up @@ -104,6 +106,7 @@ cardanoEras =
:* MaryEra
:* AlonzoEra
:* BabbageEra
:* ConwayEra
:* Nil

-- | Add an era witness to an era independent EraValue.
Expand Down Expand Up @@ -148,7 +151,10 @@ alonzo :: MkEraValue f AlonzoEra
-- | Babbage era prism.
babbage :: MkEraValue f BabbageEra

byron :* shelley :* allegra :* mary :* alonzo :* babbage :* Nil
-- | Conway era prism.
conway :: MkEraValue f ConwayEra

byron :* shelley :* allegra :* mary :* alonzo :* babbage :* conway :* Nil
= zipWith_NP g injections ejections
where
g i e = MkEraValue $ prism (inject' i) (project' e)
Expand Down

0 comments on commit 477b2ff

Please sign in to comment.