示例#1
0
文件: main.go 项目: 5mil/go-expanse
func unlockAccount(ctx *cli.Context, am *accounts.Manager, addr string, i int, inputpassphrases []string) (addrHex, auth string, passphrases []string) {
	var err error
	passphrases = inputpassphrases
	addrHex, err = utils.ParamToAddress(addr, am)
	if err == nil {
		// Attempt to unlock the account 3 times
		attempts := 3
		for tries := 0; tries < attempts; tries++ {
			msg := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", addr, tries+1, attempts)
			auth, passphrases = getPassPhrase(ctx, msg, false, i, passphrases)
			err = am.Unlock(common.HexToAddress(addrHex), auth)
			if err == nil || passphrases != nil {
				break
			}
		}
	}

	if err != nil {
		utils.Fatalf("Unlock account '%s' (%v) failed: %v", addr, addrHex, err)
	}
	fmt.Printf("Account '%s' (%v) unlocked.\n", addr, addrHex)
	return
}
示例#2
0
func unlockAccount(ctx *cli.Context, am *accounts.Manager, addr string, i int) (addrHex, auth string) {
	utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))

	var err error
	addrHex, err = utils.ParamToAddress(addr, am)
	if err == nil {
		// Attempt to unlock the account 3 times
		attempts := 3
		for tries := 0; tries < attempts; tries++ {
			msg := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", addr, tries+1, attempts)
			auth = getPassPhrase(ctx, msg, false, i)
			err = am.Unlock(common.HexToAddress(addrHex), auth)
			if err == nil {
				break
			}
		}
	}

	if err != nil {
		utils.Fatalf("Unlock account failed '%v'", err)
	}
	fmt.Printf("Account '%s' unlocked.\n", addr)
	return
}