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

Function databaseBalance

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

Source from the content-addressed store, hash-verified

112}
113
114func databaseBalance(c *gin.Context) {
115 r := struct {
116 Database proto.DatabaseID `json:"db" form:"db" uri:"db" binding:"required,len=64"`
117 }{}
118
119 _ = c.ShouldBindUri(&r)
120
121 if err := c.ShouldBind(&r); err != nil {
122 abortWithError(c, http.StatusBadRequest, err)
123 return
124 }
125
126 developer := getDeveloperID(c)
127 p, err := model.GetMainAccount(model.GetDB(c), developer)
128 if err != nil {
129 _ = c.Error(err)
130 abortWithError(c, http.StatusForbidden, ErrNoMainAccount)
131 return
132 }
133
134 var profile *types.SQLChainProfile
135 if profile, err = getDatabaseProfile(r.Database); err != nil {
136 _ = c.Error(err)
137 abortWithError(c, http.StatusInternalServerError, ErrSendETLSRPCFailed)
138 return
139 }
140
141 accountAddr, err := p.Account.Get()
142 if err != nil {
143 _ = c.Error(err)
144 abortWithError(c, http.StatusBadRequest, ErrParseAccountFailed)
145 return
146 }
147
148 for _, user := range profile.Users {
149 if user.Address == accountAddr {
150 responseWithData(c, http.StatusOK, gin.H{
151 "deposit": user.Deposit,
152 "arrears": user.Arrears,
153 "advance_payment": user.AdvancePayment,
154 })
155 return
156 }
157 }
158
159 abortWithError(c, http.StatusForbidden, ErrNotAuthorizedAdmin)
160}
161
162func databasePricing(c *gin.Context) {
163

Callers

nothing calls this directly

Calls 8

GetMainAccountFunction · 0.92
GetDBFunction · 0.92
abortWithErrorFunction · 0.85
getDeveloperIDFunction · 0.85
getDatabaseProfileFunction · 0.85
responseWithDataFunction · 0.85
ErrorMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected