-
Notifications
You must be signed in to change notification settings - Fork 2
/
faucet.go
48 lines (40 loc) · 1.1 KB
/
faucet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cli
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/spf13/cobra"
)
func (cli *CLI) buildFaucetCmd() *cobra.Command {
faucetCmd := &cobra.Command{
Use: "faucet [address]",
Short: "Get free money for address",
Args: cobra.MinimumNArgs(1),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
var addressList []common.Address
all, _ := cmd.Flags().GetBool("all")
if all && len(args) <= 0 {
if err := cli.openWallet(true); err != nil {
fmt.Println(err)
return
}
for _, account := range cli.wallet.Accounts() {
addressList = append(addressList, account.Address)
}
} else {
for _, addressStr := range args {
if common.IsHexAddress(addressStr) {
addressList = append(addressList, common.HexToAddress(addressStr))
} else {
fmt.Println("address illegal:", addressStr)
}
}
}
for _, address := range addressList {
getFaucet(cli.rpcURL, address.String())
}
},
}
faucetCmd.Flags().Bool("all", false, "get faucet for all accounts under the wallet")
return faucetCmd
}