Example #1
0
func makeTreasury() {
	treasury.StorePrivateKeyForMPKPubKey("0271b114194fd037a410366b693b338ef7d190c8c2a20ce6164f0c9bc40df417d9", "8b8e225c197e9606e04ae9f0a7582e43177934b7383efbc452055abfbf3a5d0e")

	// Get the main wallet for testing.
	user := auth.LoadUserByEmail("*****@*****.**")

	// Create a withdrawal request.
	account.AddWithdrawal(user.Id, "12uPSJQ9j3cHPwt2k2JgfkQ4MULwf5cxJH", "BTC", 20000)

	// Process the withdrawal request.
	treasury.Process("BTC")
}
Example #2
0
func generateRandomUsers() []*auth.User {
	Info("Inserting random users")
	users := []*auth.User{}
	for i := 0; i < 1000; i++ {
		email := fmt.Sprintf("*****@*****.**", i)
		user := auth.LoadUserByEmail(email)
		if user == nil {
			user = &auth.User{
				Email:  email,
				Scrypt: []byte{0},
				Salt:   []byte{0},
			}
			_, err := auth.SaveUser(user)
			if err != nil {
				panic(err)
			}
		}
		users = append(users, user)
	}
	Info("Done inserting random users")
	return users
}
Example #3
0
func CreditUserHandler(w http.ResponseWriter, r *http.Request, user *auth.User) {
    if !user.HasRole("treasury") { ReturnJSON(API_UNAUTHORIZED, UNAUTH_MSG) } // All handlers here should have this.

    coin :=     GetParamRegexp(r, "coin", RE_COIN,  true)
    email :=    GetParamRegexp(r, "email", RE_EMAIL, true)
    amountFloat :=  GetParamFloat64(r, "amountFloat")
    amount := F64ToUI64(amountFloat)

    target := auth.LoadUserByEmail(email)
    if target == nil { ReturnJSON(API_INVALID_PARAM, fmt.Sprintf("User with email %v doesn't exist", email)) }
    if amount == 0 { ReturnJSON(API_INVALID_PARAM, "Amount cannot be zero") }

    deposit := account.CreateDeposit(&account.Deposit{
        Type:       account.DEPOSIT_TYPE_FIAT,
        UserId:     target.Id,
        Wallet:     "main",
        Coin:       coin,
        Amount:     amount,
        Status:     account.DEPOSIT_STATUS_PENDING,
    })
    account.CreditDeposit(deposit)

    ReturnJSON(API_OK, nil)
}