This repository has been archived by the owner on May 14, 2021. It is now read-only.
forked from stellar/go
/
actions_account.go
115 lines (99 loc) · 3.24 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
105
106
107
108
109
110
111
112
113
114
115
package horizon
import (
"github.com/kinecosystem/go/protocols/horizon"
"github.com/kinecosystem/go/services/horizon/internal/actions"
"github.com/kinecosystem/go/services/horizon/internal/db2/core"
"github.com/kinecosystem/go/services/horizon/internal/db2/history"
"github.com/kinecosystem/go/services/horizon/internal/render/sse"
"github.com/kinecosystem/go/services/horizon/internal/resourceadapter"
"github.com/kinecosystem/go/support/render/hal"
)
// This file contains the actions:
//
// AccountShowAction: details for single account (including stellar-core state)
// Interface verifications
var _ actions.JSONer = (*AccountShowAction)(nil)
var _ actions.EventStreamer = (*AccountShowAction)(nil)
var _ actions.SingleObjectStreamer = (*AccountShowAction)(nil)
// 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 horizon.Account
}
// JSON is a method for actions.JSON
func (action *AccountShowAction) JSON() error {
action.Do(
action.loadParams,
action.loadRecord,
action.loadResource,
func() { hal.Render(action.W, action.Resource) },
)
return action.Err
}
// SSE is a method for actions.SSE
func (action *AccountShowAction) SSE(stream *sse.Stream) error {
action.Do(
action.loadParams,
action.loadRecord,
action.loadResource,
func() {
stream.SetLimit(10)
stream.Send(sse.Event{Data: action.Resource})
},
)
return action.Err
}
func (action *AccountShowAction) LoadEvent() (sse.Event, error) {
action.Do(action.loadParams, action.loadRecord, action.loadResource)
return sse.Event{Data: action.Resource}, action.Err
}
// GetPubsubTopic is a method for actions.SSE
func (action *AccountShowAction) GetPubsubTopic() string {
return action.GetString("account_id")
}
func (action *AccountShowAction) loadParams() {
action.Address = action.GetAddress("account_id", actions.RequiredParam)
}
func (action *AccountShowAction) loadRecord() {
app := AppFromContext(action.R.Context())
protocolVersion := app.coreSupportedProtocolVersion
action.Err = action.CoreQ().AccountByAddress(&action.CoreRecord, action.Address, protocolVersion)
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, protocolVersion)
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
}
}
func (action *AccountShowAction) loadResource() {
action.Err = resourceadapter.PopulateAccount(
action.R.Context(),
&action.Resource,
action.CoreRecord,
action.CoreData,
action.CoreSigners,
action.CoreTrustlines,
action.HistoryRecord,
)
}