MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / applyToken

Function applyToken

cmd/cql-proxy/api/account.go:38–84  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

36)
37
38func 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
86func showAllAccounts(c *gin.Context) {
87 developer := getDeveloperID(c)

Callers

nothing calls this directly

Calls 10

GetMainAccountFunction · 0.92
GetDBFunction · 0.92
CheckTokenApplyLimitsFunction · 0.92
getConfigFunction · 0.85
abortWithErrorFunction · 0.85
getDeveloperIDFunction · 0.85
getTaskManagerFunction · 0.85
responseWithDataFunction · 0.85
ErrorMethod · 0.80
NewMethod · 0.65

Tested by

no test coverage detected