Skip to content

Commit

Permalink
Support validatorId.
Browse files Browse the repository at this point in the history
  • Loading branch information
abizjak committed Nov 14, 2023
1 parent d2d97e4 commit 9956ea2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 11 additions & 4 deletions src/Concordium/Client/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ data BakerCredentials = BakerCredentials
}

instance AE.ToJSON BakerCredentials where
toJSON BakerCredentials{..} = object (("bakerId" .= bcIdentity) : bakerKeysToPairs bcKeys)
toJSON BakerCredentials{..} = object (("bakerId" .= bcIdentity) : ("validatorId" .= bcIdentity) : bakerKeysToPairs bcKeys)

instance AE.FromJSON BakerKeys where
parseJSON = withObject "Baker keys" $ \v -> do
Expand All @@ -279,7 +279,14 @@ instance AE.FromJSON BakerKeys where
bkElectionVerifyKey <- v .: "electionVerifyKey"
bkSigSignKey <- v .: "signatureSignKey"
bkSigVerifyKey <- v .: "signatureVerifyKey"
bkBakerId <- v .:? "bakerId"
mbkBakerId <- v .:? "bakerId"
mvalidatorId <- v .:? "validatorId"
bkBakerId <- case (mbkBakerId, mvalidatorId) of
(Just bid, Just vid) | bid == vid -> return (Just bid)
| otherwise -> fail "Both 'bakerId' and 'validatorId' are present, and different."
(Just bid, Nothing) -> return (Just bid)
(Nothing, Just vid) -> return (Just vid)
(Nothing, Nothing) -> return Nothing
return BakerKeys{..}

bakerKeysToPairs :: BakerKeys -> [Pair]
Expand All @@ -291,7 +298,7 @@ bakerKeysToPairs v =
"signatureSignKey" .= bkSigSignKey v,
"signatureVerifyKey" .= bkSigVerifyKey v
]
++ ["bakerId" .= bid | bid <- maybeToList (bkBakerId v)]
++ concat [["bakerId" .= bid, "validatorId" .= bid] | bid <- maybeToList (bkBakerId v)]

instance AE.ToJSON BakerKeys where
toJSON = object . bakerKeysToPairs
Expand All @@ -303,7 +310,7 @@ bakerPublicKeysToPairs v =
"electionVerifyKey" .= bkElectionVerifyKey v,
"signatureVerifyKey" .= bkSigVerifyKey v
]
++ ["bakerId" .= bid | bid <- maybeToList (bkBakerId v)]
++ concat [["bakerId" .= bid, "validatorId" .= bid] | bid <- maybeToList (bkBakerId v)]

-- | Hardcoded network ID.
defaultNetId :: Int
Expand Down
8 changes: 4 additions & 4 deletions src/Concordium/Client/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2981,9 +2981,9 @@ processBakerConfigureCmd baseCfgDir verbose backend txOpts isBakerConfigure cbCa
in unless encrypted $
case inputKeysFile of
Nothing ->
logInfo [printf "To use it add \"bakerId\": %s to the keys file." (show bakerId)]
logInfo [printf "To use it add \"validatorId\": %s to the keys file." (show bakerId)]
Just inf ->
logInfo [printf "To use it add \"bakerId\": %s to the keys file %s." (show bakerId) inf]
logInfo [printf "To use it add \"validatorId\": %s to the keys file %s." (show bakerId) inf]

eventsFromTransactionResult Nothing = return []
eventsFromTransactionResult (Just result) = do
Expand Down Expand Up @@ -3201,7 +3201,7 @@ processBakerAddCmd baseCfgDir verbose backend txOpts abBakingStake abRestakeEarn
_ ->
let encrypted = snd bakerKeys
in unless encrypted $
logInfo [printf "To use it add \"bakerId\": %s to the keys file %s." (show bakerId) inputKeysFile]
logInfo [printf "To use it add \"validatorId\": %s to the keys file %s." (show bakerId) inputKeysFile]

eventsFromTransactionResult Nothing = return []
eventsFromTransactionResult (Just result) = do
Expand Down Expand Up @@ -3361,7 +3361,7 @@ processBakerSetKeysCmd baseCfgDir verbose backend txOpts inputKeysFile outputKey
_ ->
let encrypted = snd bakerKeys
in unless encrypted $
logInfo [printf "To use it add \"bakerId\": %s to the keys file %s." (show bakerId) inputKeysFile]
logInfo [printf "To use it add \"validatorId\": %s to the keys file %s." (show bakerId) inputKeysFile]

eventsFromTransactionResult Nothing = return []
eventsFromTransactionResult (Just result) = do
Expand Down

0 comments on commit 9956ea2

Please sign in to comment.