-
Notifications
You must be signed in to change notification settings - Fork 19
/
admin_close_connection.go
58 lines (45 loc) · 1.55 KB
/
admin_close_connection.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
package api
import (
"context"
"code.vegaprotocol.io/vega/libs/jsonrpc"
"github.com/mitchellh/mapstructure"
)
type AdminCloseConnectionParams struct {
Hostname string `json:"hostname"`
Wallet string `json:"wallet"`
}
type AdminCloseConnection struct {
connectionsManager ConnectionsManager
}
// Handle closes the connection between a third-party application and a wallet
// opened in the service that run against the specified network.
// It does not fail if the service or the connection are already closed.
func (h *AdminCloseConnection) Handle(_ context.Context, rawParams jsonrpc.Params) (jsonrpc.Result, *jsonrpc.ErrorDetails) {
params, err := validateAdminCloseConnectionParams(rawParams)
if err != nil {
return nil, invalidParams(err)
}
h.connectionsManager.EndSessionConnection(params.Hostname, params.Wallet)
return nil, nil
}
func validateAdminCloseConnectionParams(rawParams jsonrpc.Params) (AdminCloseConnectionParams, error) {
if rawParams == nil {
return AdminCloseConnectionParams{}, ErrParamsRequired
}
params := AdminCloseConnectionParams{}
if err := mapstructure.Decode(rawParams, ¶ms); err != nil {
return AdminCloseConnectionParams{}, ErrParamsDoNotMatch
}
if params.Hostname == "" {
return AdminCloseConnectionParams{}, ErrHostnameIsRequired
}
if params.Wallet == "" {
return AdminCloseConnectionParams{}, ErrWalletIsRequired
}
return params, nil
}
func NewAdminCloseConnection(connectionsManager ConnectionsManager) *AdminCloseConnection {
return &AdminCloseConnection{
connectionsManager: connectionsManager,
}
}