forked from stellar/go
/
actions_data.go
70 lines (61 loc) · 1.36 KB
/
actions_data.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
package horizon
import (
"github.com/stellar/go/services/horizon/internal/db2/core"
"github.com/stellar/go/services/horizon/internal/render/sse"
"github.com/stellar/go/support/render/hal"
)
// DataShowAction renders a account summary found by its address.
type DataShowAction struct {
Action
Address string
Key string
Data core.AccountData
}
// JSON is a method for actions.JSON
func (action *DataShowAction) JSON() {
action.Do(
action.loadParams,
action.loadRecord,
func() {
hal.Render(action.W, map[string]string{
"value": action.Data.Value,
})
},
)
}
// Raw is a method for actions.Raw
func (action *DataShowAction) Raw() {
action.Do(
action.loadParams,
action.loadRecord,
func() {
var raw []byte
raw, action.Err = action.Data.Raw()
if action.Err != nil {
return
}
action.W.Write(raw)
},
)
}
// SSE is a method for actions.SSE
func (action *DataShowAction) SSE(stream sse.Stream) {
action.Do(
action.loadParams,
action.loadRecord,
func() {
stream.Send(sse.Event{Data: action.Data.Value})
},
)
}
func (action *DataShowAction) loadParams() {
action.Address = action.GetString("account_id")
action.Key = action.GetString("key")
}
func (action *DataShowAction) loadRecord() {
action.Err = action.CoreQ().
AccountDataByKey(&action.Data, action.Address, action.Key)
if action.Err != nil {
return
}
}