Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More API updates for the Allegra and Mary eras #2111

Merged
merged 31 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fc87d88
Generalise toShelleyStakeAddr to work for any ledger era
dcoutts Nov 21, 2020
12fd233
Move and generalise toShelley{Metadata,MetadataHash} functions
dcoutts Nov 21, 2020
b10061d
Generalise toShelleyWithdrawal over all ledger eras
dcoutts Nov 21, 2020
1d32e24
Move toShelleyUpdate to the ProtocolParameters module
dcoutts Nov 21, 2020
3225463
Change type of Praos extra entropy update parameter
dcoutts Nov 21, 2020
dfdb712
Add functions to convert from Shelley update proposal types
dcoutts Nov 21, 2020
73a6ebf
Change representation of UpdateProposal to use the API types
dcoutts Nov 21, 2020
9fff1ad
Export UpdateProposal and protocol params from the API
dcoutts Nov 21, 2020
e9b2245
Generalise to/fromShelleyUpdate over all ledger eras
dcoutts Nov 21, 2020
e29ce3c
Change the API's stake pool metadata URL type to match ledger type
dcoutts Nov 21, 2020
92b8158
Add a fromShelleyPoolParams to allow conversion both ways
dcoutts Nov 21, 2020
1354aa3
Add to/fromShelleyCertificate conversion functions
dcoutts Nov 21, 2020
c026892
Change certificate representation to use surface types
dcoutts Nov 22, 2020
e85ad6e
Generalise the toShelley*Credential functions for all eras
dcoutts Nov 22, 2020
eb6ea84
Generalise to/fromShelleyCertificate over all eras
dcoutts Nov 22, 2020
f095db2
Generalise toShelley{TxId,TxIn,TxOut} over all ledger eras
dcoutts Nov 22, 2020
7a9cd1f
Use single Eq, Show and HasTypeProxy instance for TxBody
dcoutts Nov 22, 2020
afa2961
Use single SerialiseAsCBOR and HasTextEnvelope instance for TxBody
dcoutts Nov 22, 2020
580e50c
Initial step to generalise makeShelleyTransaction over other eras
dcoutts Nov 22, 2020
630f02d
Switch TxBody from Shelley-specific type to era-dependent
dcoutts Nov 22, 2020
67b78cf
Generalise the ShelleyTxBody representation over multiple eras
dcoutts Nov 22, 2020
134403f
Generalise several tx and witness functions over eras
dcoutts Nov 22, 2020
b54ad58
Extend TxBody serialisation to the Allegra and Mary eras
dcoutts Nov 23, 2020
49edfcb
Partially fill in makeShelleyTransaction for the Allegra & Mary eras
dcoutts Nov 23, 2020
ea18858
Add to/fromShelleyScriptHash and use them
dcoutts Nov 23, 2020
4b476ce
Add to/fromMaryValue for converting the Value type
dcoutts Nov 23, 2020
f6db51c
Cover the multi-asset case in toShelleyTxOut
dcoutts Nov 23, 2020
844dde7
Adjust the sort order of Value entries
dcoutts Nov 23, 2020
eaa770e
Move toByronLovelace and TxIn/TxOut declarations
dcoutts Nov 23, 2020
dde3664
Move TxOutValue and MintValue types to TxBody module
dcoutts Nov 23, 2020
ee54b49
Make hlint suggestions
intricate Nov 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cardano-api/src/Cardano/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,14 @@ module Cardano.API (
makeMIRCertificate,
makeGenesisKeyDelegationCertificate,

NetworkMagic,
-- * Protocol parameter updates
UpdateProposal(..),
ProtocolParametersUpdate(..),
makeShelleyUpdateProposal,
PraosNonce,
makePraosNonce,

NetworkMagic,
) where

import Cardano.Api.Typed
91 changes: 66 additions & 25 deletions cardano-api/src/Cardano/Api/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module Cardano.Api.Address (
toShelleyAddr,
toShelleyStakeAddr,
toShelleyStakeCredential,
fromShelleyAddr,
fromShelleyStakeAddr,
fromShelleyStakeCredential,

-- * Serialising addresses
SerialiseAddress(..),
Expand All @@ -67,7 +70,10 @@ import Control.Applicative

import qualified Cardano.Chain.Common as Byron

import qualified Cardano.Ledger.Era as Ledger
import Ouroboros.Consensus.Shelley.Eras (StandardShelley)
import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto)

import qualified Shelley.Spec.Ledger.Address as Shelley
import qualified Shelley.Spec.Ledger.BaseTypes as Shelley
import qualified Shelley.Spec.Ledger.Credential as Shelley
Expand Down Expand Up @@ -484,45 +490,80 @@ toShelleyAddr (AddressInEra (ShelleyAddressInEra _)
Shelley.Addr nw
(coerceShelleyPaymentCredential pc)
(coerceShelleyStakeReference scr)
where
-- The era parameter in these types is a phantom type so it is safe to cast.
-- We choose to cast because we need to use an era-independent address
-- representation, but have to produce an era-dependent format used by the
-- Shelley ledger lib.
coerceShelleyPaymentCredential :: Shelley.PaymentCredential eraA
-> Shelley.PaymentCredential eraB
coerceShelleyPaymentCredential = coerce

coerceShelleyStakeReference :: Shelley.StakeReference eraA
-> Shelley.StakeReference eraB
coerceShelleyStakeReference = coerce

toShelleyStakeAddr :: StakeAddress -> Shelley.RewardAcnt StandardShelley

toShelleyStakeAddr :: StakeAddress -> Shelley.RewardAcnt ledgerera
toShelleyStakeAddr (StakeAddress nw sc) =
Shelley.RewardAcnt {
Shelley.getRwdNetwork = nw,
Shelley.getRwdCred = sc
Shelley.getRwdCred = coerceShelleyStakeCredential sc
}

toShelleyPaymentCredential :: PaymentCredential
-> Shelley.PaymentCredential StandardShelley
toShelleyPaymentCredential :: Ledger.Crypto ledgerera ~ StandardCrypto
=> PaymentCredential
-> Shelley.PaymentCredential ledgerera
toShelleyPaymentCredential (PaymentCredentialByKey (PaymentKeyHash kh)) =
Shelley.KeyHashObj kh
toShelleyPaymentCredential (PaymentCredentialByScript (ScriptHash sh)) =
Shelley.ScriptHashObj sh
toShelleyPaymentCredential (PaymentCredentialByScript sh) =
Shelley.ScriptHashObj (toShelleyScriptHash sh)

toShelleyStakeCredential :: StakeCredential
-> Shelley.StakeCredential StandardShelley
toShelleyStakeCredential :: Ledger.Crypto ledgerera ~ StandardCrypto
=> StakeCredential
-> Shelley.StakeCredential ledgerera
toShelleyStakeCredential (StakeCredentialByKey (StakeKeyHash kh)) =
Shelley.KeyHashObj kh
toShelleyStakeCredential (StakeCredentialByScript (ScriptHash kh)) =
Shelley.ScriptHashObj kh
toShelleyStakeCredential (StakeCredentialByScript sh) =
Shelley.ScriptHashObj (toShelleyScriptHash sh)

toShelleyStakeReference :: StakeAddressReference
-> Shelley.StakeReference StandardShelley
toShelleyStakeReference :: Ledger.Crypto ledgerera ~ StandardCrypto
=> StakeAddressReference
-> Shelley.StakeReference ledgerera
toShelleyStakeReference (StakeAddressByValue stakecred) =
Shelley.StakeRefBase (toShelleyStakeCredential stakecred)
toShelleyStakeReference (StakeAddressByPointer ptr) =
Shelley.StakeRefPtr ptr
toShelleyStakeReference NoStakeAddress =
Shelley.StakeRefNull


fromShelleyAddr :: IsShelleyBasedEra era
=> Shelley.Addr (ShelleyLedgerEra era) -> AddressInEra era
fromShelleyAddr (Shelley.AddrBootstrap (Shelley.BootstrapAddress addr)) =
AddressInEra ByronAddressInAnyEra (ByronAddress addr)

fromShelleyAddr (Shelley.Addr nw pc scr) =
AddressInEra
(ShelleyAddressInEra shelleyBasedEra)
(ShelleyAddress
nw
(coerceShelleyPaymentCredential pc)
(coerceShelleyStakeReference scr))

fromShelleyStakeAddr :: Shelley.RewardAcnt ledgerera -> StakeAddress
fromShelleyStakeAddr (Shelley.RewardAcnt nw sc) =
StakeAddress nw (coerceShelleyStakeCredential sc)

fromShelleyStakeCredential :: Ledger.Crypto ledgerera ~ StandardCrypto
=> Shelley.StakeCredential ledgerera
-> StakeCredential
fromShelleyStakeCredential (Shelley.KeyHashObj kh) =
StakeCredentialByKey (StakeKeyHash kh)
fromShelleyStakeCredential (Shelley.ScriptHashObj sh) =
StakeCredentialByScript (fromShelleyScriptHash sh)


-- The era parameter in these types is a phantom type so it is safe to cast.
-- We choose to cast because we need to use an era-independent address
-- representation, but have to produce an era-dependent format used by the
-- Shelley ledger lib.
Comment on lines +554 to +557
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍.

I'm slightly concerned that someone reading through the types will be confused, but doc like this should help.

coerceShelleyPaymentCredential :: Shelley.PaymentCredential eraA
-> Shelley.PaymentCredential eraB
coerceShelleyPaymentCredential = coerce

coerceShelleyStakeCredential :: Shelley.StakeCredential eraA
-> Shelley.StakeCredential eraB
coerceShelleyStakeCredential = coerce

coerceShelleyStakeReference :: Shelley.StakeReference eraA
-> Shelley.StakeReference eraB
coerceShelleyStakeReference = coerce

Loading