cmd/faucet: support testnet flags in the faucet (#22545)

Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
Mudit Gupta 2021-04-14 03:21:46 +05:30 committed by GitHub
parent 271e5b7fc9
commit 72e37942f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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