Skip to content

Commit

Permalink
cmd/faucet: support testnet flags in the faucet (ethereum#22545)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Lange <[email protected]>
Co-authored-by: Martin Holst Swende <[email protected]>
  • Loading branch information
3 people authored and atif-konasl committed Oct 15, 2021
1 parent 14ee549 commit 16dd0d8
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ var (

twitterTokenFlag = flag.String("twitter.token", "", "Bearer token to authenticate with the v2 Twitter API")
twitterTokenV1Flag = flag.String("twitter.token.v1", "", "Bearer token to authenticate with the v1.1 Twitter API")

goerliFlag = flag.Bool("goerli", false, "Initializes the faucet with Görli network config")
rinkebyFlag = flag.Bool("rinkeby", false, "Initializes the faucet with Rinkeby network config")
)

var (
Expand Down Expand Up @@ -144,13 +147,9 @@ func main() {
log.Crit("Failed to render the faucet template", "err", err)
}
// Load and parse the genesis block requested by the user
blob, err := ioutil.ReadFile(*genesisFlag)
genesis, err := getGenesis(genesisFlag, *goerliFlag, *rinkebyFlag)
if err != nil {
log.Crit("Failed to read genesis block contents", "genesis", *genesisFlag, "err", err)
}
genesis := new(core.Genesis)
if err = json.Unmarshal(blob, genesis); err != nil {
log.Crit("Failed to parse genesis block json", "err", err)
log.Crit("Failed to parse genesis config", "err", err)
}
// Convert the bootnodes to internal enode representations
var enodes []*enode.Node
Expand All @@ -162,7 +161,8 @@ func main() {
}
}
// Load up the account key and decrypt its password
if blob, err = ioutil.ReadFile(*accPassFlag); err != nil {
blob, err := ioutil.ReadFile(*accPassFlag)
if err != nil {
log.Crit("Failed to read account password contents", "file", *accPassFlag, "err", err)
}
pass := strings.TrimSuffix(string(blob), "\n")
Expand Down Expand Up @@ -884,3 +884,19 @@ func authNoAuth(url string) (string, string, common.Address, error) {
}
return address.Hex() + "@noauth", "", address, nil
}

// getGenesis returns a genesis based on input args
func getGenesis(genesisFlag *string, goerliFlag bool, rinkebyFlag bool) (*core.Genesis, error) {
switch {
case genesisFlag != nil:
var genesis core.Genesis
err := common.LoadJSON(*genesisFlag, &genesis)
return &genesis, err
case goerliFlag:
return core.DefaultGoerliGenesisBlock(), nil
case rinkebyFlag:
return core.DefaultRinkebyGenesisBlock(), nil
default:
return nil, fmt.Errorf("no genesis flag provided")
}
}

0 comments on commit 16dd0d8

Please sign in to comment.