Ejemplo n.º 1
0
func newAddrHandler(r *http.Request, w http.ResponseWriter,
	redis *models.RedisLogger, user *models.Account) {

	wal, err := getWallet(user.Wallet.Id, user.Wallet.Key)
	if err != nil {
		writeResponse(r.RequestURI, w, nil, errors.NewError(errors.DbError, err.Error()))
		return
	}
	k, err := wal.GenKey("")
	if err != nil {
		writeResponse(r.RequestURI, w, nil, errors.NewError(errors.DbError, err.Error()))
		return
	}
	wal.AddKey(k)
	if _, err = saveWallet(user.Wallet.Id, wal); err != nil {
		writeResponse(r.RequestURI, w, nil, errors.NewError(errors.DbError, err.Error()))
		return
	}

	user.Wallet.Addrs = append(user.Wallet.Addrs, k.PubKey)
	if err = user.AddWalletAddr(k.PubKey); err != nil {
		writeResponse(r.RequestURI, w, nil, err)
		return
	}

	writeResponse(r.RequestURI, w, k, nil)
}