-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions_balance_account.go
57 lines (47 loc) · 1.14 KB
/
actions_balance_account.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
package horizon
import (
"database/sql"
"gitlab.com/tokend/horizon/db2/core"
"gitlab.com/tokend/horizon/db2/history"
"gitlab.com/tokend/horizon/render/hal"
"gitlab.com/tokend/horizon/render/problem"
"gitlab.com/tokend/horizon/resource"
)
type BalanceAccountAction struct {
Action
BalanceID string
Record history.Account
Resource resource.HistoryAccount
}
func (action *BalanceAccountAction) JSON() {
action.Do(
action.loadParams,
action.loadRecord,
action.loadResource,
func() {
hal.Render(action.W, action.Resource)
},
)
}
func (action *BalanceAccountAction) loadParams() {
action.BalanceID = action.GetNonEmptyString("balance_id")
}
func (action *BalanceAccountAction) loadRecord() {
var balance core.Balance
err := action.CoreQ().BalanceByID(&balance, action.BalanceID)
if err == sql.ErrNoRows {
action.Err = &problem.NotFound
return
}
if err != nil {
action.Log.WithError(err).Error("failed to get balance")
action.Err = &problem.ServerError
return
}
action.Record = history.Account{
Address: balance.AccountID,
}
}
func (action *BalanceAccountAction) loadResource() {
action.Resource.Populate(action.Record)
}