diff --git a/cmd/common/selector.go b/cmd/common/selector.go index 03dfe1d3..95fa1362 100644 --- a/cmd/common/selector.go +++ b/cmd/common/selector.go @@ -82,8 +82,9 @@ func GetNPASelection(cfg *cliConfig.Config) *NPASelection { s.AccountSetExplicitly = true } if s.AccountName != "" { - accCfg, err := LoadAccountConfig(cfg, s.AccountName) + accountName, accCfg, err := LoadAccountConfig(cfg, s.AccountName) cobra.CheckErr(err) + s.AccountName = accountName s.Account = accCfg } diff --git a/cmd/common/wallet.go b/cmd/common/wallet.go index c72dbf2e..3b5cb87f 100644 --- a/cmd/common/wallet.go +++ b/cmd/common/wallet.go @@ -111,7 +111,7 @@ func LoadAccount(cfg *config.Config, name string) wallet.Account { return acc } - acfg, err := LoadAccountConfig(cfg, name) + name, acfg, err := LoadAccountConfig(cfg, name) cobra.CheckErr(err) af, err := acfg.LoadFactory() @@ -156,18 +156,32 @@ func ParseTestAccountAddress(name string) string { return "" } -// LoadAccountConfig loads the config instance of the given named account. -func LoadAccountConfig(cfg *config.Config, name string) (*config.Account, error) { +// LoadAccountConfig loads the name and config instance of the given account name or address. +func LoadAccountConfig(cfg *config.Config, name string) (string, *config.Account, error) { if testName := ParseTestAccountAddress(name); testName != "" { - return LoadTestAccountConfig(testName) + acfg, err := LoadTestAccountConfig(testName) + return name, acfg, err } // Early check for whether the account exists so that we don't ask for passphrase first. if acfg, exists := cfg.Wallet.All[name]; exists { - return acfg, nil + return name, acfg, nil + } + + // Name may be a native or Ethereum address instead; resolve it to the matching configured + // wallet account, if any. + if addr, ethAddr, err := helpers.ResolveEthOrOasisAddress(name); err == nil && addr != nil { + for accName, acfg := range cfg.Wallet.All { + switch { + case acfg.GetAddress() == *addr: + return accName, acfg, nil + case ethAddr != nil && acfg.GetEthAddress() != nil && *acfg.GetEthAddress() == *ethAddr: + return accName, acfg, nil + } + } } - return nil, fmt.Errorf("account '%s' does not exist in the wallet", name) + return "", nil, fmt.Errorf("account '%s' does not exist in the wallet", name) } // LoadTestAccount loads the given named test account. diff --git a/cmd/rofl/common/manifest.go b/cmd/rofl/common/manifest.go index 5b611bcf..4381dad2 100644 --- a/cmd/rofl/common/manifest.go +++ b/cmd/rofl/common/manifest.go @@ -109,11 +109,11 @@ func MaybeLoadManifestAndSetNPA(cfg *cliConfig.Config, npa *common.NPASelection, case npa.AccountSetExplicitly, common.TxUnsigned: // Account explicitly overridden on the command line, leave unchanged. default: - accCfg, err := common.LoadAccountConfig(cfg, d.Admin) + accountName, accCfg, err := common.LoadAccountConfig(cfg, d.Admin) switch { case err == nil: npa.Account = accCfg - npa.AccountName = d.Admin + npa.AccountName = accountName case opts != nil && opts.NeedAdmin: return nil, "", nil, err default: diff --git a/cmd/rofl/provider/mgmt.go b/cmd/rofl/provider/mgmt.go index a0250e13..edbd75aa 100644 --- a/cmd/rofl/provider/mgmt.go +++ b/cmd/rofl/provider/mgmt.go @@ -444,12 +444,12 @@ func maybeLoadManifestAndSetNPA(cfg *cliConfig.Config, npa *common.NPASelection) switch manifest.Provider { case "": default: - accCfg, err := common.LoadAccountConfig(cfg, manifest.Provider) + accountName, accCfg, err := common.LoadAccountConfig(cfg, manifest.Provider) if err != nil { return nil, err } npa.Account = accCfg - npa.AccountName = manifest.Provider + npa.AccountName = accountName } return manifest, nil } diff --git a/cmd/wallet/export.go b/cmd/wallet/export.go index 08553726..2da9d9dc 100644 --- a/cmd/wallet/export.go +++ b/cmd/wallet/export.go @@ -19,7 +19,7 @@ var exportCmd = &cobra.Command{ common.Warn("WARNING: Exporting the account will expose secret key material!") acc := common.LoadAccount(config.Global(), name) - accCfg, _ := common.LoadAccountConfig(config.Global(), name) + _, accCfg, _ := common.LoadAccountConfig(config.Global(), name) showPublicWalletInfo(name, acc, accCfg) diff --git a/cmd/wallet/show.go b/cmd/wallet/show.go index c23a5fbf..c4120280 100644 --- a/cmd/wallet/show.go +++ b/cmd/wallet/show.go @@ -20,7 +20,7 @@ var showCmd = &cobra.Command{ name := args[0] acc := common.LoadAccount(config.Global(), name) - accCfg, _ := common.LoadAccountConfig(config.Global(), name) + _, accCfg, _ := common.LoadAccountConfig(config.Global(), name) showPublicWalletInfo(name, acc, accCfg) }, }