-
Notifications
You must be signed in to change notification settings - Fork 15
/
deprecated.go
74 lines (68 loc) · 1.92 KB
/
deprecated.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package api
import (
"encoding/json"
"fmt"
"github.com/gobicycle/bicycle/config"
"github.com/gobicycle/bicycle/core"
log "github.com/sirupsen/logrus"
"net/http"
)
// Deprecated
type balance struct {
Address string `json:"address"`
Balance string `json:"balance"`
Currency string `json:"currency"`
}
// Deprecated: GetBalance method renamed to GetIncome
type GetBalanceResponse struct {
Side string `json:"counting_side"`
Balances []balance `json:"balances"`
}
// Deprecated
func convertBalance(dbConn storage, totalIncomes []core.TotalIncome) GetBalanceResponse {
var res = GetBalanceResponse{
Balances: []balance{},
}
if config.Config.IsDepositSideCalculation {
res.Side = core.SideDeposit
} else {
res.Side = core.SideHotWallet
}
for _, b := range totalIncomes {
bal := balance{
Balance: b.Amount.String(),
Currency: b.Currency,
}
if b.Currency == core.TonSymbol {
bal.Address = b.Deposit.ToUserFormat()
} else {
owner := dbConn.GetOwner(b.Deposit)
if owner == nil {
// TODO: remove fatal
log.Fatalf("can not find owner for deposit: %s", b.Deposit.ToUserFormat())
}
bal.Address = owner.ToUserFormat()
}
res.Balances = append(res.Balances, bal)
}
return res
}
// Deprecated: getBalance is replaced by getTotalIncome
func (h *Handler) getBalance(resp http.ResponseWriter, req *http.Request) {
id := req.URL.Query().Get("user_id")
if id == "" {
writeHttpError(resp, http.StatusBadRequest, "need to provide user ID")
return
}
totalIncomes, err := h.storage.GetIncome(req.Context(), id, config.Config.IsDepositSideCalculation)
if err != nil {
writeHttpError(resp, http.StatusInternalServerError, fmt.Sprintf("get balances err: %v", err))
return
}
resp.Header().Add("Content-Type", "application/json")
resp.WriteHeader(http.StatusOK)
err = json.NewEncoder(resp).Encode(convertBalance(h.storage, totalIncomes))
if err != nil {
log.Errorf("json encode error: %v", err)
}
}