Skip to content

Commit ed84de0

Browse files
author
Michal Mrozek
committed
[ETCM-202] PR remarks
1 parent c74f480 commit ed84de0

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ Possible networks: `etc`, `eth`, `mordor`, `testnet-internal`
2626

2727
### Command Line Interface
2828

29-
`mantis-cli` is a tool that can be used to:
29+
`cli` is a tool that can be used to:
3030

3131
- generate a new private key
3232
```
33-
./bin/mantis mantis-cli generate-private-key
33+
./bin/mantis cli generate-private-key
3434
```
3535
- derive an address from private key
3636
```
37-
./bin/mantis mantis-cli derive-address 00b11c32957057651d56cd83085ef3b259319057e0e887bd0fdaee657e6f75d0
37+
./bin/mantis cli derive-address 00b11c32957057651d56cd83085ef3b259319057e0e887bd0fdaee657e6f75d0
3838
```
3939
- generate genesis allocs (using private keys or addresses)
4040
```
41-
(private keys) `./bin/mantis mantis-cli generate-alloc --balance=42 00b11c32957057651d56cd83085ef3b259319057e0e887bd0fdaee657e6f75d0 00b11c32957057651d56cd83085ef3b259319057e0e887bd0fdaee657e6f75d1`
42-
(addresses) `./bin/mantis mantis-cli generate-alloc --balance=42 --useAddresses 8b196738d90cf3d9fc299e0ec28e15ebdcbb0bdcb281d9d5084182c9c66d5d12`
41+
(private keys) `./bin/mantis cli generate-alloc --balance=42 00b11c32957057651d56cd83085ef3b259319057e0e887bd0fdaee657e6f75d0 00b11c32957057651d56cd83085ef3b259319057e0e887bd0fdaee657e6f75d1`
42+
(addresses) `./bin/mantis cli generate-alloc --balance=42 --useAddresses 8b196738d90cf3d9fc299e0ec28e15ebdcbb0bdcb281d9d5084182c9c66d5d12`
4343
```
4444

4545
### Building the client

src/main/scala/io/iohk/ethereum/cli/CliCommands.scala

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ object CliCommands {
1414
val generatePrivateKeyCommand = "generate-private-key"
1515
val deriveAddressCommand = "derive-address"
1616
val generateAllocsCommand = "generate-allocs"
17-
val useAddressesFlag = "useAddresses"
1817
val balanceOption = "balance"
18+
val keyOption = "key"
19+
val addressOption = "address"
1920

2021
private val GeneratePrivateKeyCommand: Command[String] =
2122
Command(name = generatePrivateKeyCommand, header = "Generate private key") {
@@ -38,21 +39,17 @@ object CliCommands {
3839
private val GenerateAllocs: Command[String] =
3940
Command(name = generateAllocsCommand, header = "Generate genesis allocs") {
4041

41-
val useAddressesOpt: Opts[Boolean] = Opts
42-
.flag(long = useAddressesFlag, help = "Use addresses instead of private keys")
43-
.orFalse
42+
val keysOpt: Opts[NonEmptyList[String]] =
43+
Opts
44+
.options[String](long = keyOption, help = "Private key")
45+
.map(_.map(key => privKeyToAddress(Hex.decode(key))))
4446

45-
val keysOpt: Opts[NonEmptyList[String]] = Opts.arguments[String]("key")
47+
val addressesOpt: Opts[NonEmptyList[String]] = Opts.options[String](long = addressOption, help = "Address")
4648

4749
val balanceOpt =
4850
Opts.option[BigInt](long = balanceOption, help = "Initial balance for account", metavar = "balance")
4951

50-
val addresesOpt = (useAddressesOpt, keysOpt).mapN {
51-
case (false, keys) => keys.map(key => privKeyToAddress(Hex.decode(key)))
52-
case (true, keys) => keys
53-
}
54-
55-
(addresesOpt, balanceOpt).mapN { (addresses, balance) =>
52+
(keysOpt.orElse(addressesOpt), balanceOpt).mapN { (addresses, balance) =>
5653
allocs(addresses.toList, balance)
5754
}
5855
}
@@ -68,7 +65,7 @@ object CliCommands {
6865
Hex.toHexString(address)
6966
}
7067

71-
val api: Command[String] = Command.apply(name = "mantis-cli", header = "Mantis CLI") {
68+
val api: Command[String] = Command.apply(name = "cli", header = "Mantis CLI") {
7269
Opts.subcommands(GeneratePrivateKeyCommand, DeriveAddressFromPrivateKey, GenerateAllocs)
7370
}
7471
}

src/test/scala/io/iohk/ethereum/cli/CliCommandsSpec.scala

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,27 @@ class CliCommandsSpec extends AnyFlatSpec with Matchers with EitherValues {
2626
behavior of generateAllocsCommand
2727
it should "generate correct alloc using private key" in {
2828
api
29-
.parse(Seq(generateAllocsCommand, privateKey, argument(balanceOption, Some(requestedBalance))))
29+
.parse(
30+
Seq(
31+
generateAllocsCommand,
32+
argument(keyOption, Some(privateKey)),
33+
argument(balanceOption, Some(requestedBalance))
34+
)
35+
)
3036
.right
3137
.value shouldBe s""""alloc": {$address: { "balance": $requestedBalance }}"""
3238
}
3339

3440
it should "generate more than one alloc" in {
3541
api
36-
.parse(Seq(generateAllocsCommand, privateKey, privateKey2, argument(balanceOption, Some(requestedBalance))))
42+
.parse(
43+
Seq(
44+
generateAllocsCommand,
45+
argument(keyOption, Some(privateKey)),
46+
argument(keyOption, Some(privateKey2)),
47+
argument(balanceOption, Some(requestedBalance))
48+
)
49+
)
3750
.right
3851
.value shouldBe s""""alloc": {$address: { "balance": $requestedBalance }, $address2: { "balance": $requestedBalance }}"""
3952
}
@@ -43,10 +56,9 @@ class CliCommandsSpec extends AnyFlatSpec with Matchers with EitherValues {
4356
.parse(
4457
Seq(
4558
generateAllocsCommand,
46-
address,
47-
address2,
48-
argument(balanceOption, Some(requestedBalance)),
49-
argument(useAddressesFlag)
59+
argument(addressOption, Some(address)),
60+
argument(addressOption, Some(address2)),
61+
argument(balanceOption, Some(requestedBalance))
5062
)
5163
)
5264
.right

0 commit comments

Comments
 (0)