forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx_approve_response.go
80 lines (69 loc) · 2.18 KB
/
tx_approve_response.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
package serve
import (
"net/http"
"github.com/pownieh/stellar_go/support/render/httpjson"
)
type txApprovalResponse struct {
Error string `json:"error,omitempty"`
Message string `json:"message,omitempty"`
Status sep8Status `json:"status"`
StatusCode int `json:"-"`
Tx string `json:"tx,omitempty"`
ActionURL string `json:"action_url,omitempty"`
ActionMethod string `json:"action_method,omitempty"`
ActionFields []string `json:"action_fields,omitempty"`
Timeout *int64 `json:"timeout,omitempty"`
}
func (t *txApprovalResponse) Render(w http.ResponseWriter) {
httpjson.RenderStatus(w, t.StatusCode, t, httpjson.JSON)
}
func NewRejectedTxApprovalResponse(errMessage string) *txApprovalResponse {
return &txApprovalResponse{
Status: sep8StatusRejected,
Error: errMessage,
StatusCode: http.StatusBadRequest,
}
}
func NewRevisedTxApprovalResponse(tx string) *txApprovalResponse {
return &txApprovalResponse{
Status: sep8StatusRevised,
Tx: tx,
StatusCode: http.StatusOK,
Message: "Authorization and deauthorization operations were added.",
}
}
func NewActionRequiredTxApprovalResponse(message, actionURL string, actionFields []string) *txApprovalResponse {
return &txApprovalResponse{
Status: sep8StatusActionRequired,
Message: message,
ActionMethod: "POST",
StatusCode: http.StatusOK,
ActionURL: actionURL,
ActionFields: actionFields,
}
}
func NewSuccessTxApprovalResponse(tx, message string) *txApprovalResponse {
return &txApprovalResponse{
Status: sep8StatusSuccess,
Tx: tx,
Message: message,
StatusCode: http.StatusOK,
}
}
func NewPendingTxApprovalResponse(message string) *txApprovalResponse {
timeout := int64(0)
return &txApprovalResponse{
Status: sep8StatusPending,
Message: message,
StatusCode: http.StatusOK,
Timeout: &timeout,
}
}
type sep8Status string
const (
sep8StatusRejected sep8Status = "rejected"
sep8StatusRevised sep8Status = "revised"
sep8StatusActionRequired sep8Status = "action_required"
sep8StatusSuccess sep8Status = "success"
sep8StatusPending sep8Status = "pending"
)