diff --git a/iqshell/common/account/actions.go b/iqshell/common/account/actions.go index da5791db..0cea4ed7 100644 --- a/iqshell/common/account/actions.go +++ b/iqshell/common/account/actions.go @@ -116,12 +116,21 @@ func getAccount(pt string) (account Account, err *data.CodeError) { } acc, dErr := decrypt(string(accountBytes)) - if dErr != nil { - err = data.NewEmptyError().AppendDescF("Decrypt account bytes: %s, you can delete account file(%s) and use `account` command to reset the account", dErr, pt) + if dErr == nil { + account = acc return } - account = acc - return + + if len(acc.Name) == 0 { + return account, data.NewEmptyError().AppendDescF("Decrypt account bytes: %s, you can delete account file(%s) and use `account` command to reset the account", dErr, pt) + } + + accs, lErr := LookUp(acc.Name) + if lErr != nil || len(accs) == 0 { + return account, data.NewEmptyError().AppendDescF("Decrypt account bytes: %s, you can delete account file(%s) and use `account` command to reset the account", dErr, pt) + } + + return accs[0], nil } // qshell 会记录当前的user信息,当切换账户后, 老的账户信息会记录下来 diff --git a/iqshell/common/account/crypt.go b/iqshell/common/account/crypt.go index ffba4038..a231a05e 100644 --- a/iqshell/common/account/crypt.go +++ b/iqshell/common/account/crypt.go @@ -16,6 +16,10 @@ func splits(joinStr string) []string { // 对保存在account.json中的文件字符串进行揭秘操作, 返回Account func decrypt(joinStr string) (acc Account, err *data.CodeError) { ss := splits(joinStr) + if len(ss) > 0 { + acc.Name = ss[0] + } + if len(ss) != 3 { err = data.NewEmptyError().AppendDescF("account json style format error") return