Skip to content

Commit 83afdb2

Browse files
committed
Enable stake pool relays in cli creation of stake pool registration certificates
1 parent d948f9f commit 83afdb2

File tree

1 file changed

+70
-16
lines changed

1 file changed

+70
-16
lines changed

cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pAddressCmd =
109109
Opt.subparser $
110110
mconcat
111111
[ Opt.command "key-gen"
112-
(Opt.info pAddressKeyGen $ Opt.progDesc "Create a single address key pair.")
112+
(Opt.info pAddressKeyGen $ Opt.progDesc "Create an address key pair.")
113113
, Opt.command "key-hash"
114114
(Opt.info pAddressKeyHash $ Opt.progDesc "Print the hash of an address key to stdout.")
115115
, Opt.command "build"
@@ -1251,24 +1251,78 @@ pPoolMargin =
12511251
maybeOrFail (Just mgn) = mgn
12521252
maybeOrFail Nothing = panic "Pool margin outside of [0,1] range."
12531253

1254-
_pPoolRelay :: Parser ShelleyStakePoolRelay
1255-
_pPoolRelay = Shelley.SingleHostAddr Shelley.SNothing
1256-
<$> (Shelley.maybeToStrictMaybe <$> optional _pIpV4)
1257-
<*> (Shelley.maybeToStrictMaybe <$> optional _pIpV6)
1258-
1259-
_pIpV4 :: Parser IP.IPv4
1260-
_pIpV4 = Opt.option (Opt.maybeReader readMaybe :: Opt.ReadM IP.IPv4)
1254+
pPoolRelay :: Parser ShelleyStakePoolRelay
1255+
pPoolRelay = pSingleHostAddress <|> pSingleHostName <|> pMultiHostName
1256+
1257+
pMultiHostName :: Parser ShelleyStakePoolRelay
1258+
pMultiHostName =
1259+
Shelley.MultiHostName <$> (Shelley.maybeToStrictMaybe <$> optional pPort) <*> pDNSName
1260+
where
1261+
pDNSName :: Parser Shelley.DnsName
1262+
pDNSName = Opt.option (Opt.eitherReader eDNSName)
1263+
( Opt.long "multi-host-pool-relay"
1264+
<> Opt.metavar "STRING"
1265+
<> Opt.help "The stake pool relay's DNS name that corresponds to \
1266+
\an SRV DNS record"
1267+
)
1268+
1269+
pSingleHostName :: Parser ShelleyStakePoolRelay
1270+
pSingleHostName =
1271+
Shelley.SingleHostName <$> (Shelley.maybeToStrictMaybe <$> optional pPort) <*> pDNSName
1272+
where
1273+
pDNSName :: Parser Shelley.DnsName
1274+
pDNSName = Opt.option (Opt.eitherReader eDNSName)
1275+
( Opt.long "single-host-pool-relay"
1276+
<> Opt.metavar "STRING"
1277+
<> Opt.help "The stake pool relay's DNS name that corresponds to an\
1278+
\ A or AAAA DNS record"
1279+
)
1280+
1281+
eDNSName :: String -> Either String Shelley.DnsName
1282+
eDNSName str = maybe (Left "DNS name is more than 64 bytes") Right (Shelley.textToDns $ toS str)
1283+
1284+
pSingleHostAddress :: Parser ShelleyStakePoolRelay
1285+
pSingleHostAddress =
1286+
liftA3
1287+
(\port ip4 ip6 -> singleHostAddress port ip4 ip6)
1288+
pPort
1289+
(optional pIpV4)
1290+
(optional pIpV6)
1291+
where
1292+
singleHostAddress :: Shelley.Port -> Maybe IP.IPv4 -> Maybe IP.IPv6 -> ShelleyStakePoolRelay
1293+
singleHostAddress port ipv4 ipv6 =
1294+
case (ipv4, ipv6) of
1295+
(Nothing, Nothing) ->
1296+
panic $ "Please enter either an IPv4 or IPv6 address for the pool relay"
1297+
(Just i4, Nothing) ->
1298+
Shelley.SingleHostAddr (Shelley.SJust port) (Shelley.SJust i4) Shelley.SNothing
1299+
(Nothing, Just i6) ->
1300+
Shelley.SingleHostAddr (Shelley.SJust port) Shelley.SNothing (Shelley.SJust i6)
1301+
(Just i4, Just i6) ->
1302+
Shelley.SingleHostAddr (Shelley.SJust port) (Shelley.SJust i4) (Shelley.SJust i6)
1303+
1304+
1305+
1306+
pIpV4 :: Parser IP.IPv4
1307+
pIpV4 = Opt.option (Opt.maybeReader readMaybe :: Opt.ReadM IP.IPv4)
12611308
( Opt.long "pool-relay-ipv4"
12621309
<> Opt.metavar "STRING"
1263-
<> Opt.help "The stake pool relay's IpV4 address"
1310+
<> Opt.help "The stake pool relay's IPv4 address"
12641311
)
12651312

1266-
_pIpV6 :: Parser IP.IPv6
1267-
_pIpV6 = Opt.option (Opt.maybeReader readMaybe :: Opt.ReadM IP.IPv6)
1268-
( Opt.long "pool-relay-ipv6"
1269-
<> Opt.metavar "STRING"
1270-
<> Opt.help "The stake pool relay's IpV6 address"
1271-
)
1313+
pIpV6 :: Parser IP.IPv6
1314+
pIpV6 = Opt.option (Opt.maybeReader readMaybe :: Opt.ReadM IP.IPv6)
1315+
( Opt.long "pool-relay-ipv6"
1316+
<> Opt.metavar "STRING"
1317+
<> Opt.help "The stake pool relay's IPv6 address"
1318+
)
1319+
1320+
pPort :: Parser Shelley.Port
1321+
pPort = Opt.option (fromInteger <$> Opt.eitherReader readEither)
1322+
( Opt.long "pool-relay-port"
1323+
<> Opt.metavar "INT"
1324+
<> Opt.help "The stake pool relay's port"
1325+
)
12721326

12731327
pPoolMetaData :: Parser (Maybe ShelleyStakePoolMetaData)
12741328
pPoolMetaData =
@@ -1311,7 +1365,7 @@ pStakePoolRegistrationCert =
13111365
<*> pPoolMargin
13121366
<*> pRewardAcctVerificationKeyFile
13131367
<*> some pPoolOwner
1314-
<*> pure [] --TODO: the relays
1368+
<*> many pPoolRelay
13151369
<*> pPoolMetaData
13161370
<*> pNetwork
13171371
<*> pOutputFile

0 commit comments

Comments
 (0)