forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions_account.go
104 lines (90 loc) · 2.39 KB
/
actions_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package horizon
import (
"github.com/stellar/go/services/horizon/internal/db2/core"
"github.com/stellar/go/services/horizon/internal/db2/history"
"github.com/stellar/go/services/horizon/internal/resource"
"github.com/stellar/go/support/render/hal"
"github.com/stellar/go/services/horizon/internal/render/sse"
)
// This file contains the actions:
//
// AccountShowAction: details for single account (including stellar-core state)
// AccountShowAction renders a account summary found by its address.
type AccountShowAction struct {
Action
Address string
HistoryRecord history.Account
CoreData []core.AccountData
CoreRecord core.Account
CoreSigners []core.Signer
CoreTrustlines []core.Trustline
Resource resource.Account
}
// JSON is a method for actions.JSON
func (action *AccountShowAction) JSON() {
action.Do(
action.loadParams,
action.loadRecord,
action.loadResource,
func() {
hal.Render(action.W, action.Resource)
},
)
}
// SSE is a method for actions.SSE
func (action *AccountShowAction) SSE(stream sse.Stream) {
action.Do(
action.loadParams,
action.loadRecord,
action.loadResource,
func() {
stream.SetLimit(10)
stream.Send(sse.Event{Data: action.Resource})
},
)
}
func (action *AccountShowAction) loadParams() {
action.Address = action.GetString("id")
}
func (action *AccountShowAction) loadRecord() {
action.Err = action.CoreQ().
AccountByAddress(&action.CoreRecord, action.Address)
if action.Err != nil {
return
}
action.Err = action.CoreQ().
AllDataByAddress(&action.CoreData, action.Address)
if action.Err != nil {
return
}
action.Err = action.CoreQ().
SignersByAddress(&action.CoreSigners, action.Address)
if action.Err != nil {
return
}
action.Err = action.CoreQ().
TrustlinesByAddress(&action.CoreTrustlines, action.Address)
if action.Err != nil {
return
}
action.Err = action.HistoryQ().
AccountByAddress(&action.HistoryRecord, action.Address)
// Do not fail when we cannot find the history record... it probably just
// means that the account was created outside of our known history range.
if action.HistoryQ().NoRows(action.Err) {
action.Err = nil
}
if action.Err != nil {
return
}
}
func (action *AccountShowAction) loadResource() {
action.Err = action.Resource.Populate(
action.Ctx,
action.CoreRecord,
action.CoreData,
action.CoreSigners,
action.CoreTrustlines,
action.HistoryRecord,
)
}