Commit 22060611 authored by gary rong's avatar gary rong Committed by Guillaume Ballet

cmd/abigen: refactor command line interface (#19797)

* cmd, common: refactor abigen command line interface

* cmd/abigen: address comment
parent cdfe9a3a
This diff is collapsed.
...@@ -944,7 +944,7 @@ func setWS(ctx *cli.Context, cfg *node.Config) { ...@@ -944,7 +944,7 @@ func setWS(ctx *cli.Context, cfg *node.Config) {
// setIPC creates an IPC path configuration from the set command line flags, // setIPC creates an IPC path configuration from the set command line flags,
// returning an empty string if IPC was explicitly disabled, or the set path. // returning an empty string if IPC was explicitly disabled, or the set path.
func setIPC(ctx *cli.Context, cfg *node.Config) { func setIPC(ctx *cli.Context, cfg *node.Config) {
checkExclusive(ctx, IPCDisabledFlag, IPCPathFlag) CheckExclusive(ctx, IPCDisabledFlag, IPCPathFlag)
switch { switch {
case ctx.GlobalBool(IPCDisabledFlag.Name): case ctx.GlobalBool(IPCDisabledFlag.Name):
cfg.IPCPath = "" cfg.IPCPath = ""
...@@ -1329,10 +1329,10 @@ func setWhitelist(ctx *cli.Context, cfg *eth.Config) { ...@@ -1329,10 +1329,10 @@ func setWhitelist(ctx *cli.Context, cfg *eth.Config) {
} }
} }
// checkExclusive verifies that only a single instance of the provided flags was // CheckExclusive verifies that only a single instance of the provided flags was
// set by the user. Each flag might optionally be followed by a string type to // set by the user. Each flag might optionally be followed by a string type to
// specialize it further. // specialize it further.
func checkExclusive(ctx *cli.Context, args ...interface{}) { func CheckExclusive(ctx *cli.Context, args ...interface{}) {
set := make([]string, 0, 1) set := make([]string, 0, 1)
for i := 0; i < len(args); i++ { for i := 0; i < len(args); i++ {
// Make sure the next argument is a flag and skip if not set // Make sure the next argument is a flag and skip if not set
...@@ -1386,10 +1386,10 @@ func SetShhConfig(ctx *cli.Context, stack *node.Node, cfg *whisper.Config) { ...@@ -1386,10 +1386,10 @@ func SetShhConfig(ctx *cli.Context, stack *node.Node, cfg *whisper.Config) {
// SetEthConfig applies eth-related command line flags to the config. // SetEthConfig applies eth-related command line flags to the config.
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
// Avoid conflicting network flags // Avoid conflicting network flags
checkExclusive(ctx, DeveloperFlag, TestnetFlag, RinkebyFlag, GoerliFlag) CheckExclusive(ctx, DeveloperFlag, TestnetFlag, RinkebyFlag, GoerliFlag)
checkExclusive(ctx, LightServFlag, SyncModeFlag, "light") CheckExclusive(ctx, LightServFlag, SyncModeFlag, "light")
// Can't use both ephemeral unlocked and external signer // Can't use both ephemeral unlocked and external signer
checkExclusive(ctx, DeveloperFlag, ExternalSignerFlag) CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag)
var ks *keystore.KeyStore var ks *keystore.KeyStore
if keystores := stack.AccountManager().Backends(keystore.KeyStoreType); len(keystores) > 0 { if keystores := stack.AccountManager().Backends(keystore.KeyStoreType); len(keystores) > 0 {
ks = keystores[0].(*keystore.KeyStore) ks = keystores[0].(*keystore.KeyStore)
......
...@@ -142,7 +142,6 @@ func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion strin ...@@ -142,7 +142,6 @@ func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion strin
if err := json.Unmarshal(combinedJSON, &output); err != nil { if err := json.Unmarshal(combinedJSON, &output); err != nil {
return nil, err return nil, err
} }
// Compilation succeeded, assemble and return the contracts. // Compilation succeeded, assemble and return the contracts.
contracts := make(map[string]*Contract) contracts := make(map[string]*Contract)
for name, info := range output.Contracts { for name, info := range output.Contracts {
...@@ -151,14 +150,10 @@ func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion strin ...@@ -151,14 +150,10 @@ func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion strin
if err := json.Unmarshal([]byte(info.Abi), &abi); err != nil { if err := json.Unmarshal([]byte(info.Abi), &abi); err != nil {
return nil, fmt.Errorf("solc: error reading abi definition (%v)", err) return nil, fmt.Errorf("solc: error reading abi definition (%v)", err)
} }
var userdoc interface{} var userdoc, devdoc interface{}
if err := json.Unmarshal([]byte(info.Userdoc), &userdoc); err != nil { json.Unmarshal([]byte(info.Userdoc), &userdoc)
return nil, fmt.Errorf("solc: error reading user doc: %v", err) json.Unmarshal([]byte(info.Devdoc), &devdoc)
}
var devdoc interface{}
if err := json.Unmarshal([]byte(info.Devdoc), &devdoc); err != nil {
return nil, fmt.Errorf("solc: error reading dev doc: %v", err)
}
contracts[name] = &Contract{ contracts[name] = &Contract{
Code: "0x" + info.Bin, Code: "0x" + info.Bin,
RuntimeCode: "0x" + info.BinRuntime, RuntimeCode: "0x" + info.BinRuntime,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment