-
Notifications
You must be signed in to change notification settings - Fork 22
/
admin_list_networks.go
54 lines (45 loc) · 1.23 KB
/
admin_list_networks.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
package api
import (
"context"
"fmt"
"code.vegaprotocol.io/vega/libs/jsonrpc"
"code.vegaprotocol.io/vega/wallet/network"
)
type AdminListNetworksResult struct {
Networks []AdminListNetworkResult `json:"networks"`
}
type AdminListNetworkResult struct {
Name string `json:"name"`
Metadata []network.Metadata `json:"metadata"`
}
type AdminListNetworks struct {
networkStore NetworkStore
}
// Handle List all registered networks.
func (h *AdminListNetworks) Handle(_ context.Context, _ jsonrpc.Params) (jsonrpc.Result, *jsonrpc.ErrorDetails) {
networks, err := h.networkStore.ListNetworks()
if err != nil {
return nil, InternalError(fmt.Errorf("could not list the networks: %w", err))
}
netsWithMetadata := make([]AdminListNetworkResult, 0, len(networks))
for _, networkName := range networks {
net, err := h.networkStore.GetNetwork(networkName)
if err != nil {
continue
}
netsWithMetadata = append(netsWithMetadata, AdminListNetworkResult{
Name: networkName,
Metadata: net.Metadata,
})
}
return AdminListNetworksResult{
Networks: netsWithMetadata,
}, nil
}
func NewAdminListNetworks(
networkStore NetworkStore,
) *AdminListNetworks {
return &AdminListNetworks{
networkStore: networkStore,
}
}