-
Notifications
You must be signed in to change notification settings - Fork 26
/
rest.go
111 lines (88 loc) · 2.36 KB
/
rest.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
package zcnbridge
import (
"fmt"
"github.com/0chain/gosdk/core/common"
"github.com/0chain/gosdk/zcnbridge/http"
"github.com/0chain/gosdk/zcnbridge/wallet"
"github.com/0chain/gosdk/zcncore"
)
// Models
type AuthorizerResponse struct {
AuthorizerID string `json:"id"`
URL string `json:"url"`
// Configuration
Fee common.Balance `json:"fee"`
// Geolocation
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
// Stats
LastHealthCheck int64 `json:"last_health_check"`
// stake_pool_settings
DelegateWallet string `json:"delegate_wallet"`
MinStake common.Balance `json:"min_stake"`
MaxStake common.Balance `json:"max_stake"`
NumDelegates int `json:"num_delegates"`
ServiceCharge float64 `json:"service_charge"`
}
type AuthorizerNodesResponse struct {
Nodes []*AuthorizerNode `json:"nodes"`
}
type AuthorizerNode struct {
ID string `json:"id"`
URL string `json:"url"`
}
// Rest endpoints
// getAuthorizers returns authorizers from smart contract
func getAuthorizers(active bool) ([]*AuthorizerNode, error) {
var (
authorizers = new(AuthorizerNodesResponse)
cb = wallet.NewZCNStatus(authorizers)
err error
)
cb.Begin()
if err = GetAuthorizers(active, cb); err != nil {
return nil, err
}
if err = cb.Wait(); err != nil {
return nil, err
}
if len(authorizers.Nodes) == 0 {
fmt.Println("no authorizers found")
return nil, err
}
return authorizers.Nodes, nil
}
// GetAuthorizer returned authorizer by ID
func GetAuthorizer(id string, cb zcncore.GetInfoCallback) (err error) {
err = zcncore.CheckConfig()
if err != nil {
return err
}
go http.MakeSCRestAPICall(
zcncore.OpZCNSCGetAuthorizer,
http.PathGetAuthorizer,
http.Params{
"id": id,
},
cb,
)
return
}
// GetAuthorizers Returns all or only active authorizers
func GetAuthorizers(active bool, cb zcncore.GetInfoCallback) (err error) {
err = zcncore.CheckConfig()
if err != nil {
return err
}
go http.MakeSCRestAPICall(zcncore.OpZCNSCGetAuthorizerNodes, fmt.Sprintf(http.PathGetAuthorizerNodes, active), nil, cb)
return
}
// GetGlobalConfig Returns global config
func GetGlobalConfig(cb zcncore.GetInfoCallback) (err error) {
err = zcncore.CheckConfig()
if err != nil {
return err
}
go http.MakeSCRestAPICall(zcncore.OpZCNSCGetGlobalConfig, http.PathGetGlobalConfig, nil, cb)
return
}