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

Function showAllAccounts

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

Source from the content-addressed store, hash-verified

84}
85
86func showAllAccounts(c *gin.Context) {
87 developer := getDeveloperID(c)
88 d, err := model.GetDeveloper(model.GetDB(c), developer)
89 if err != nil {
90 _ = c.Error(err)
91 abortWithError(c, http.StatusForbidden, ErrInvalidDeveloper)
92 return
93 }
94
95 accounts, err := model.GetAllAccounts(model.GetDB(c), developer)
96 if err != nil {
97 _ = c.Error(err)
98 abortWithError(c, http.StatusInternalServerError, ErrGetAccountFailed)
99 return
100 }
101
102 var (
103 apiResp = gin.H{}
104 keys []gin.H
105 )
106
107 for _, account := range accounts {
108 var (
109 req = new(types.QueryAccountTokenBalanceReq)
110 resp = new(types.QueryAccountTokenBalanceResp)
111 keyData = gin.H{}
112 )
113
114 req.Addr, err = account.Account.Get()
115 if err != nil {
116 _ = c.Error(err)
117 abortWithError(c, http.StatusBadRequest, ErrParseAccountFailed)
118 return
119 }
120
121 if account.ID == d.MainAccount {
122 apiResp["main"] = req.Addr.String()
123 }
124
125 keyData["account"] = req.Addr.String()
126
127 if err = rpc.RequestBP(route.MCCQueryAccountTokenBalance.String(), req, resp); err == nil {
128 keyData["balance"] = resp.Balance
129 } else {
130 err = nil
131 }
132
133 keys = append(keys, keyData)
134 }
135
136 apiResp["keypairs"] = keys
137
138 responseWithData(c, http.StatusOK, apiResp)
139}
140
141func getBalance(c *gin.Context) {
142 developer := getDeveloperID(c)

Callers

nothing calls this directly

Calls 9

GetDeveloperFunction · 0.92
GetDBFunction · 0.92
GetAllAccountsFunction · 0.92
getDeveloperIDFunction · 0.85
abortWithErrorFunction · 0.85
responseWithDataFunction · 0.85
ErrorMethod · 0.80
GetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected