Skip to content

Commit

Permalink
Merge #895
Browse files Browse the repository at this point in the history
895: Genesis stake address and MIR certificates r=Jimbo4350 a=Jimbo4350

Issue
-----------
- Depends on #890 
- This PR **does not result** in breaking changes to upstream dependencies.

Checklist
---------

- [x] I have committed clear and descriptive commits. Be considerate as somebody else will have to read these.

- [x] I have added the appropriate labels to this PR.


Co-authored-by: Jordan Millar <jordan.millar@iohk.io>
  • Loading branch information
iohk-bors[bot] and Jimbo4350 committed May 9, 2020
2 parents 494f1fa + b084fe2 commit 07508cf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
21 changes: 20 additions & 1 deletion cardano-api/src/Cardano/Api.hs
Expand Up @@ -68,6 +68,8 @@ module Cardano.Api
, Certificate(..)
, shelleyDeregisterStakingAddress
, shelleyDelegateStake
, shelleyGenesisDelegateStake
, shelleyMIRCertificate
, shelleyRegisterStakingAddress
, shelleyRegisterStakePool
, shelleyRetireStakePool
Expand Down Expand Up @@ -209,6 +211,22 @@ mkShelleyStakingCredential :: ShelleyVerificationKeyHashStaking -> ShelleyCreden
mkShelleyStakingCredential vKey =
Shelley.KeyHashObj vKey

-- | Delegate your genesis key's stake
shelleyGenesisDelegateStake
:: ShelleyGenesisVerificationHash
-> ShelleyGenesisDelegateVerKeyHash
-> Certificate
shelleyGenesisDelegateStake genDelegatorHash genDelegateeHash = do
ShelleyGenesisDelegationCertificate . Shelley.DCertGenesis $ Shelley.GenesisDelegCert genDelegatorHash genDelegateeHash

-- | Move instantaneous rewards.
shelleyMIRCertificate
:: ShelleyMIRMap
-> Certificate
shelleyMIRCertificate mirMap =
ShelleyMIRCertificate . Shelley.DCertMir $ Shelley.MIRCert mirMap


-- Given key information (public key, and other network parameters), generate an Address.
-- Originally: mkAddress :: Network -> VerificationKey -> VerificationKeyInfo -> Address
-- but since VerificationKeyInfo already has the VerificationKey and Network, it can be simplified.
Expand Down Expand Up @@ -300,7 +318,8 @@ buildShelleyTransaction txins txouts ttl fee certs = do
certDiscrim :: Certificate -> ShelleyCertificate
certDiscrim (ShelleyDelegationCertificate delegCert) = delegCert
certDiscrim (ShelleyStakePoolCertificate sPoolCert) = sPoolCert

certDiscrim (ShelleyGenesisDelegationCertificate sGenDelegCert) = sGenDelegCert
certDiscrim (ShelleyMIRCertificate mirCert) = mirCert
{-
inputs outputs, attributes:
ATxAux { Tx TxWiness Annotation }
Expand Down
5 changes: 4 additions & 1 deletion cardano-api/src/Cardano/Api/CBOR.hs
Expand Up @@ -69,6 +69,8 @@ certificateFromCBOR bs =
case tag of
180 -> ShelleyDelegationCertificate <$> fromCBOR
181 -> ShelleyStakePoolCertificate <$> fromCBOR
182 -> ShelleyGenesisDelegationCertificate <$> fromCBOR
183 -> ShelleyMIRCertificate <$> fromCBOR
_ -> cborError $ DecoderErrorUnknownTag "ShelleyCertificate" tag

certificateToCBOR :: Certificate -> ByteString
Expand All @@ -77,7 +79,8 @@ certificateToCBOR sc =
case sc of
ShelleyDelegationCertificate cert -> mconcat [ toCBOR (180 :: Word8) , toCBOR cert]
ShelleyStakePoolCertificate cert -> mconcat [ toCBOR (181 :: Word8) , toCBOR cert]

ShelleyGenesisDelegationCertificate cert -> mconcat [ toCBOR (182 :: Word8), toCBOR cert ]
ShelleyMIRCertificate cert -> mconcat [ toCBOR (183 :: Word8), toCBOR cert ]

signingKeyFromCBOR :: ByteString -> Either ApiError SigningKey
signingKeyFromCBOR bs =
Expand Down
20 changes: 19 additions & 1 deletion cardano-api/src/Cardano/Api/Types.hs
Expand Up @@ -45,6 +45,12 @@ module Cardano.Api.Types
-- ** Shelley
, ShelleyCertificate
, ShelleyCoin
, ShelleyGenesisDelegationCertificate
, ShelleyGenesisDelegateVerKeyHash
, ShelleyGenesisVerificationKey
, ShelleyGenesisVerificationHash
, ShelleyMIRCertificate
, ShelleyMIRMap
, ShelleyStakePoolMargin
, ShelleyStakePoolCertificate
, ShelleyStakePoolMetaData
Expand Down Expand Up @@ -93,6 +99,7 @@ import qualified Cardano.Crypto as Byron
import qualified Ouroboros.Consensus.Shelley.Protocol.Crypto as Shelley
import qualified Shelley.Spec.Ledger.BaseTypes as Shelley
import qualified Shelley.Spec.Ledger.Coin as Shelley
import qualified Shelley.Spec.Ledger.Delegation.Certificates as Shelley
import qualified Shelley.Spec.Ledger.Keys as Shelley
import qualified Shelley.Spec.Ledger.TxData as Shelley
import qualified Shelley.Spec.Ledger.Tx as Shelley
Expand Down Expand Up @@ -130,10 +137,17 @@ type ShelleyDelegationCertificate = Shelley.DCert Shelley.TPraosStan

type ShelleyStakePoolCertificate = Shelley.PoolCert Shelley.TPraosStandardCrypto
type ShelleyStakePoolOwners = Set (Shelley.KeyHash Shelley.Staking Shelley.TPraosStandardCrypto)

type ShelleyGenesisVerificationKey = Shelley.VKey Shelley.Genesis Shelley.TPraosStandardCrypto
type ShelleyGenesisVerificationHash = Shelley.KeyHash Shelley.Genesis Shelley.TPraosStandardCrypto
type ShelleyGenesisDelegateVerKeyHash = Shelley.KeyHash Shelley.GenesisDelegate Shelley.TPraosStandardCrypto
type ShelleyGenesisDelegationCertificate = Shelley.GenesisDelegCert Shelley.TPraosStandardCrypto
type ShelleyMIRCertificate = Shelley.MIRCert Shelley.TPraosStandardCrypto
type ShelleyMIRMap = Map (Shelley.Credential Shelley.Staking Shelley.TPraosStandardCrypto) Shelley.Coin
type ShelleyStakePoolMargin = Shelley.UnitInterval
type ShelleyStakePoolMetaData = Shelley.PoolMetaData
type ShelleyStakePoolRelay = Shelley.StakePoolRelay
type ShelleyRewardAccount = Shelley.RewardAcnt Shelley.TPraosStandardCrypto
type ShelleyRewardAccount = Shelley.RewardAcnt Shelley.TPraosStandardCrypto

-- The 'Address' data type in 'cardano-sl' is a design train wreck.
-- We need something that is compatible and discard as much of the insanity as possible.
Expand All @@ -147,8 +161,12 @@ data Address
data Certificate
= ShelleyDelegationCertificate !ShelleyCertificate
| ShelleyStakePoolCertificate !ShelleyCertificate
| ShelleyGenesisDelegationCertificate !ShelleyCertificate
| ShelleyMIRCertificate !ShelleyCertificate
deriving (Eq, Show)



-- | The combination of a verification key and a signing key.
--
-- Verification keys are also commonly known as \"public keys\".
Expand Down
3 changes: 3 additions & 0 deletions cardano-api/src/Cardano/Api/View.hs
Expand Up @@ -80,6 +80,9 @@ renderCertificateView cert =
case cert of
ShelleyDelegationCertificate {} -> renderTextView $ TextView "DelegationCertificateShelley" "Free form text" cbor
ShelleyStakePoolCertificate {} -> renderTextView $ TextView "StakePoolCertificateShelley" "Free form text" cbor
ShelleyGenesisDelegationCertificate {} -> renderTextView $ TextView "GenesisDelegationCertificateShelley" "Free form text" cbor
ShelleyMIRCertificate {} -> renderTextView $ TextView "MIRCertificateShelley" "Free form text" cbor

where
cbor :: ByteString
cbor = certificateToCBOR cert
Expand Down

0 comments on commit 07508cf

Please sign in to comment.