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

Function topUp

cmd/cql-proxy/api/database.go:75–112  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

73}
74
75func topUp(c *gin.Context) {
76 r := struct {
77 Database proto.DatabaseID `json:"db" form:"db" uri:"db" binding:"required,len=64"`
78 Amount uint64 `json:"amount" form:"amount" binding:"gt=0"`
79 }{}
80
81 _ = c.ShouldBindUri(&r)
82
83 if err := c.ShouldBind(&r); err != nil {
84 abortWithError(c, http.StatusBadRequest, err)
85 return
86 }
87
88 developer := getDeveloperID(c)
89
90 p, err := model.GetMainAccount(model.GetDB(c), developer)
91 if err != nil {
92 _ = c.Error(err)
93 abortWithError(c, http.StatusBadRequest, ErrNoMainAccount)
94 return
95 }
96
97 // run task
98 taskID, err := getTaskManager(c).New(model.TaskTopUp, developer, p.ID, gin.H{
99 "db": r.Database,
100 "amount": r.Amount,
101 })
102 if err != nil {
103 _ = c.Error(err)
104 abortWithError(c, http.StatusInternalServerError, ErrCreateTaskFailed)
105 return
106 }
107
108 responseWithData(c, http.StatusOK, gin.H{
109 "task_id": taskID,
110 "amount": r.Amount,
111 })
112}
113
114func databaseBalance(c *gin.Context) {
115 r := struct {

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected