forked from stellar-deprecated/horizon
/
actions_friendbot.go
48 lines (39 loc) · 1.01 KB
/
actions_friendbot.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
package horizon
import (
"github.com/stellar/horizon/render/hal"
"github.com/stellar/horizon/render/problem"
"net/http"
)
type FriendbotAction struct {
TransactionCreateAction
Address string
}
// JSON is a method for actions.JSON
func (action *FriendbotAction) JSON() {
action.Do(
action.CheckEnabled,
action.LoadAddress,
action.LoadResult,
action.LoadResource,
func() {
hal.Render(action.W, action.Resource)
})
}
func (action *FriendbotAction) CheckEnabled() {
if action.App.friendbot != nil {
return
}
action.Err = &problem.P{
Type: "friendbot_disabled",
Title: "Friendbot is disabled",
Status: http.StatusForbidden,
Detail: "This horizon server is not configured to provide a friendbot. " +
"Contact the server administrator if you believe this to be in error.",
}
}
func (action *FriendbotAction) LoadAddress() {
action.Address = action.GetAddress("addr")
}
func (action *FriendbotAction) LoadResult() {
action.Result = action.App.friendbot.Pay(action.Ctx, action.Address)
}