Skip to content

Commit

Permalink
Fix parseFraction so that it will parse a Double but convert it to a
Browse files Browse the repository at this point in the history
`Rational` as required
Update `./scripts/genesis.sh` to reflect the above change.
  • Loading branch information
Jimbo4350 committed Feb 14, 2020
1 parent cd9ef4d commit f4e5cc6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
21 changes: 11 additions & 10 deletions cardano-node/src/Cardano/CLI/Parsers.hs
Expand Up @@ -298,26 +298,27 @@ parseLovelace optname desc =

parseFraction :: String -> String -> Parser Rational
parseFraction optname desc =
option readFraction $
option (toRational <$> readDouble) $
long optname
<> metavar "INT"
<> metavar "DOUBLE"
<> help desc
where

parseFractionWithDefault
:: String
-> String
-> Rational
-> Double
-> Parser Rational
parseFractionWithDefault optname desc w =
option readFraction $
long optname
<> metavar "INT"
<> help desc
<> value w
toRational <$> ( option readDouble
$ long optname
<> metavar "DOUBLE"
<> help desc
<> value w
)

readFraction :: ReadM Rational
readFraction = do
readDouble :: ReadM Double
readDouble = do
f <- auto
when (f < 0) $ readerError "fraction must be >= 0"
when (f > 1) $ readerError "fraction must be <= 1"
Expand Down
20 changes: 10 additions & 10 deletions scripts/genesis.sh
Expand Up @@ -25,7 +25,7 @@ protocol_magic=459045235
n_poors=128
n_delegates=7
total_balance=8000000000000000
delegate_share=900000000000000
delegate_share=0.9
avvm_entries=128
avvm_entry_balance=10000000000000
not_so_secret=2718281828
Expand All @@ -35,16 +35,16 @@ args=(
--genesis-output-dir "${tmpdir}"
--start-time "${start_time}"
--protocol-parameters-file "${protocol_params}"
--k ${parameter_k}
--protocol-magic ${protocol_magic}
--n-poor-addresses ${n_poors}
--n-delegate-addresses ${n_delegates}
--total-balance ${total_balance}
--delegate-share ${delegate_share}
--avvm-entry-count ${avvm_entries}
--avvm-entry-balance ${avvm_entry_balance}
--k "${parameter_k}"
--protocol-magic "${protocol_magic}"
--n-poor-addresses "${n_poors}"
--n-delegate-addresses "${n_delegates}"
--total-balance "${total_balance}"
--avvm-entry-count "${avvm_entries}"
--avvm-entry-balance "${avvm_entry_balance}"
--delegate-share "${delegate_share}"
--real-pbft
--secret-seed ${not_so_secret}
--secret-seed "${not_so_secret}"
)

set -xe
Expand Down

0 comments on commit f4e5cc6

Please sign in to comment.