Skip to content

Commit

Permalink
Merge branch 'cad-1920-staked-genesis-bulk' into cad-1859-k1000-assem…
Browse files Browse the repository at this point in the history
…blage
  • Loading branch information
deepfire committed Nov 24, 2020
2 parents ac751ac + 5755a62 commit 271eae2
Show file tree
Hide file tree
Showing 10 changed files with 529 additions and 67 deletions.
2 changes: 2 additions & 0 deletions cardano-api/src/Cardano/Api/Certificate.hs
Expand Up @@ -26,6 +26,8 @@ module Cardano.Api.Certificate (
makeMIRCertificate,
makeGenesisKeyDelegationCertificate,

toShelleyPoolParams,

-- * Data family instances
AsType(..)
) where
Expand Down
2 changes: 2 additions & 0 deletions cardano-api/src/Cardano/Api/Typed.hs
Expand Up @@ -386,6 +386,8 @@ module Cardano.Api.Typed (
toByronProtocolMagicId,
toByronRequiresNetworkMagic,
toShelleyNetwork,
toShelleyPoolParams,
toShelleyStakeAddr,
toNetworkMagic,

Shelley.Addr(..),
Expand Down
4 changes: 4 additions & 0 deletions cardano-cli/cardano-cli.cabal
Expand Up @@ -68,6 +68,7 @@ library
, aeson-pretty
, attoparsec
, bech32 >= 1.1.0
, binary
, bytestring
, base16-bytestring
, base58-bytestring
Expand All @@ -87,6 +88,7 @@ library
, contra-tracer
, cborg >= 0.2.4 && < 0.3
, containers
, cryptonite
, directory
, filepath
, formatting
Expand All @@ -103,10 +105,12 @@ library
, ouroboros-consensus-cardano
, ouroboros-consensus-shelley
, ouroboros-network
, primitive
, process
, scientific
, shelley-spec-ledger
, small-steps
, split
, text
, time
, transformers
Expand Down
2 changes: 2 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Expand Up @@ -311,6 +311,7 @@ renderTextViewCmd (TextViewInfo _ _) = "text-view decode-cbor"

data GenesisCmd
= GenesisCreate GenesisDir Word Word (Maybe SystemStart) (Maybe Lovelace) NetworkId
| GenesisCreateStaked GenesisDir Word Word Word Word (Maybe SystemStart) (Maybe Lovelace) Lovelace NetworkId Word Word Word
| GenesisKeyGenGenesis VerificationKeyFile SigningKeyFile
| GenesisKeyGenDelegate VerificationKeyFile SigningKeyFile OpCertCounterFile
| GenesisKeyGenUTxO VerificationKeyFile SigningKeyFile
Expand All @@ -325,6 +326,7 @@ renderGenesisCmd :: GenesisCmd -> Text
renderGenesisCmd cmd =
case cmd of
GenesisCreate {} -> "genesis create"
GenesisCreateStaked {} -> "genesis create-staked"
GenesisKeyGenGenesis {} -> "genesis key-gen-genesis"
GenesisKeyGenDelegate {} -> "genesis key-gen-delegate"
GenesisKeyGenUTxO {} -> "genesis key-gen-utxo"
Expand Down
84 changes: 80 additions & 4 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -784,6 +784,11 @@ pGenesisCmd =
Opt.progDesc ("Create a Shelley genesis file from a genesis "
++ "template and genesis/delegation/spending keys."))

, Opt.command "create-staked"
(Opt.info pGenesisCreateStaked $
Opt.progDesc ("Create a staked Shelley genesis file from a genesis "
++ "template and genesis/delegation/spending keys."))

, Opt.command "hash"
(Opt.info pGenesisHash $
Opt.progDesc "Compute the hash of a genesis file")
Expand Down Expand Up @@ -825,9 +830,25 @@ pGenesisCmd =
<*> pGenesisNumGenesisKeys
<*> pGenesisNumUTxOKeys
<*> pMaybeSystemStart
<*> pInitialSupply
<*> pInitialSupplyNonDelegated
<*> pNetworkId

pGenesisCreateStaked :: Parser GenesisCmd
pGenesisCreateStaked =
GenesisCreateStaked
<$> pGenesisDir
<*> pGenesisNumGenesisKeys
<*> pGenesisNumUTxOKeys
<*> pGenesisNumPools
<*> pGenesisNumStDelegs
<*> pMaybeSystemStart
<*> pInitialSupplyNonDelegated
<*> pInitialSupplyDelegated
<*> pNetworkId
<*> pBulkPoolCredFiles
<*> pBulkPoolsPerFile
<*> pStuffedUtxoCount

pGenesisHash :: Parser GenesisCmd
pGenesisHash =
GenesisHashFile <$> pGenesisFile
Expand Down Expand Up @@ -869,18 +890,73 @@ pGenesisCmd =
<> Opt.value 0
)

pGenesisNumPools :: Parser Word
pGenesisNumPools =
Opt.option Opt.auto
( Opt.long "gen-pools"
<> Opt.metavar "INT"
<> Opt.help "The number of stake pool credential sets to make [default is 0]."
<> Opt.value 0
)

pGenesisNumStDelegs :: Parser Word
pGenesisNumStDelegs =
Opt.option Opt.auto
( Opt.long "gen-stake-delegs"
<> Opt.metavar "INT"
<> Opt.help "The number of stake delegator credential sets to make [default is 0]."
<> Opt.value 0
)

pStuffedUtxoCount :: Parser Word
pStuffedUtxoCount =
Opt.option Opt.auto
( Opt.long "num-stuffed-utxo"
<> Opt.metavar "INT"
<> Opt.help "The number of fake UTxO entries to generate [default is 0]."
<> Opt.value 0
)

convertTime :: String -> UTCTime
convertTime =
parseTimeOrError False defaultTimeLocale (iso8601DateFormat $ Just "%H:%M:%SZ")

pInitialSupply :: Parser (Maybe Lovelace)
pInitialSupply =
pInitialSupplyNonDelegated :: Parser (Maybe Lovelace)
pInitialSupplyNonDelegated =
Opt.optional $
Lovelace <$>
Opt.option Opt.auto
( Opt.long "supply"
<> Opt.metavar "LOVELACE"
<> Opt.help "The initial coin supply in Lovelace which will be evenly distributed across initial stake holders."
<> Opt.help "The initial coin supply in Lovelace which will be evenly distributed across initial, non-delegating stake holders."
)

pInitialSupplyDelegated :: Parser Lovelace
pInitialSupplyDelegated =
fmap (Lovelace . fromMaybe 0) $ Opt.optional $
Opt.option Opt.auto
( Opt.long "supply-delegated"
<> Opt.metavar "LOVELACE"
<> Opt.help "The initial coin supply in Lovelace which will be evenly distributed across initial, delegating stake holders."
<> Opt.value 0
)

pBulkPoolCredFiles :: Parser Word
pBulkPoolCredFiles =
Opt.option Opt.auto
( Opt.long "bulk-pool-cred-files"
<> Opt.metavar "INT"
<> Opt.help "Generate bulk pool credential files [default is 0]."
<> Opt.value 0
)

pBulkPoolsPerFile :: Parser Word
pBulkPoolsPerFile =
Opt.option Opt.auto
( Opt.long "bulk-pools-per-file"
<> Opt.metavar "INT"
<> Opt.help "Each bulk pool to contain this many pool credential sets [default is 0]."
<> Opt.value 0
)


Expand Down
55 changes: 31 additions & 24 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Address.hs
@@ -1,9 +1,13 @@
{-# LANGUAGE RankNTypes #-}

module Cardano.CLI.Shelley.Run.Address
( ShelleyAddressCmdError
( ShelleyAddressCmdError(..)
, SomeAddressVerificationKey(..)
, buildShelleyAddress
, renderShelleyAddressCmdError
, runAddressCmd
, runAddressKeyGen
, readAddressVerificationKeyTextOrFile
) where

import Cardano.Prelude hiding (putStrLn)
Expand Down Expand Up @@ -113,40 +117,42 @@ runAddressBuild payVkeyTextOrFile mbStkVkeyOrFile nw mOutFp = do
return (AddressByron (makeByronAddress nw vk))

APaymentVerificationKey vk ->
AddressShelley <$> buildShelleyAddress vk
AddressShelley <$> buildShelleyAddress vk mbStkVkeyOrFile nw

APaymentExtendedVerificationKey vk ->
AddressShelley <$> buildShelleyAddress (castVerificationKey vk)
AddressShelley <$> buildShelleyAddress (castVerificationKey vk) mbStkVkeyOrFile nw

AGenesisUTxOVerificationKey vk ->
AddressShelley <$> buildShelleyAddress (castVerificationKey vk)
AddressShelley <$> buildShelleyAddress (castVerificationKey vk) mbStkVkeyOrFile nw

let addrText = serialiseAddress (addr :: AddressAny)

case mOutFp of
Just (OutputFile fpath) -> liftIO $ Text.writeFile fpath addrText
Nothing -> liftIO $ Text.putStrLn addrText

where
buildShelleyAddress :: VerificationKey PaymentKey
-> ExceptT ShelleyAddressCmdError IO (Address ShelleyAddr)
buildShelleyAddress vkey = do
mstakeVKey <-
case mbStkVkeyOrFile of
Nothing -> pure Nothing
Just stkVkeyOrFile ->
firstExceptT ShelleyAddressCmdReadKeyFileError $
fmap Just $ newExceptT $
readVerificationKeyOrFile AsStakeKey stkVkeyOrFile

let paymentCred = PaymentCredentialByKey (verificationKeyHash vkey)
stakeAddrRef = maybe NoStakeAddress
(StakeAddressByValue . StakeCredentialByKey
. verificationKeyHash)
mstakeVKey
address = makeShelleyAddress nw paymentCred stakeAddrRef

return address
buildShelleyAddress
:: VerificationKey PaymentKey
-> Maybe (VerificationKeyOrFile StakeKey)
-> NetworkId
-> ExceptT ShelleyAddressCmdError IO (Address ShelleyAddr)
buildShelleyAddress vkey mbStkVkeyOrFile nw = do
mstakeVKey <-
case mbStkVkeyOrFile of
Nothing -> pure Nothing
Just stkVkeyOrFile ->
firstExceptT ShelleyAddressCmdReadKeyFileError $
fmap Just $ newExceptT $
readVerificationKeyOrFile AsStakeKey stkVkeyOrFile

let paymentCred = PaymentCredentialByKey (verificationKeyHash vkey)
stakeAddrRef = maybe NoStakeAddress
(StakeAddressByValue . StakeCredentialByKey
. verificationKeyHash)
mstakeVKey
address = makeShelleyAddress nw paymentCred stakeAddrRef

return address


--
Expand All @@ -160,6 +166,7 @@ data SomeAddressVerificationKey
| APaymentVerificationKey (VerificationKey PaymentKey)
| APaymentExtendedVerificationKey (VerificationKey PaymentExtendedKey)
| AGenesisUTxOVerificationKey (VerificationKey GenesisUTxOKey)
deriving (Show)

foldSomeAddressVerificationKey :: (forall keyrole. Key keyrole =>
VerificationKey keyrole -> a)
Expand Down

0 comments on commit 271eae2

Please sign in to comment.