(c *gin.Context)
| 36 | ) |
| 37 | |
| 38 | func applyToken(c *gin.Context) { |
| 39 | var ( |
| 40 | amount uint64 |
| 41 | userLimits int64 |
| 42 | accountLimits int64 |
| 43 | ) |
| 44 | |
| 45 | cfg := getConfig(c) |
| 46 | if cfg != nil && cfg.Faucet != nil && cfg.Faucet.Enabled { |
| 47 | amount = cfg.Faucet.Amount |
| 48 | userLimits = cfg.Faucet.AccountDailyQuota |
| 49 | accountLimits = cfg.Faucet.AddressDailyQuota |
| 50 | } else { |
| 51 | abortWithError(c, http.StatusForbidden, ErrTokenApplyDisabled) |
| 52 | return |
| 53 | } |
| 54 | |
| 55 | developer := getDeveloperID(c) |
| 56 | p, err := model.GetMainAccount(model.GetDB(c), developer) |
| 57 | if err != nil { |
| 58 | _ = c.Error(err) |
| 59 | abortWithError(c, http.StatusBadRequest, ErrNoMainAccount) |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | err = model.CheckTokenApplyLimits(model.GetDB(c), developer, p.Account, userLimits, accountLimits) |
| 64 | if err != nil { |
| 65 | _ = c.Error(err) |
| 66 | abortWithError(c, http.StatusInternalServerError, ErrTokenApplyLimitExceeded) |
| 67 | return |
| 68 | } |
| 69 | |
| 70 | // run task |
| 71 | taskID, err := getTaskManager(c).New(model.TaskApplyToken, developer, p.ID, gin.H{ |
| 72 | "amount": amount, |
| 73 | }) |
| 74 | if err != nil { |
| 75 | _ = c.Error(err) |
| 76 | abortWithError(c, http.StatusInternalServerError, ErrCreateTaskFailed) |
| 77 | return |
| 78 | } |
| 79 | |
| 80 | responseWithData(c, http.StatusOK, gin.H{ |
| 81 | "task_id": taskID, |
| 82 | "amount": amount, |
| 83 | }) |
| 84 | } |
| 85 | |
| 86 | func showAllAccounts(c *gin.Context) { |
| 87 | developer := getDeveloperID(c) |
nothing calls this directly
no test coverage detected