Пример #1
0
func ParamToAddress(addr string, am *accounts.Manager) (addrHex string, err error) {
	if !((len(addr) == 40) || (len(addr) == 42)) { // with or without 0x
		index, err := strconv.Atoi(addr)
		if err != nil {
			Fatalf("Invalid account address '%s'", addr)
		}

		addrHex, err = am.AddressByIndex(index)
		if err != nil {
			return "", err
		}
	} else {
		addrHex = addr
	}
	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
}