-
Notifications
You must be signed in to change notification settings - Fork 19
/
session_disconnect_wallet.go
56 lines (44 loc) · 1.28 KB
/
session_disconnect_wallet.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
package api
import (
"context"
"code.vegaprotocol.io/vega/libs/jsonrpc"
"github.com/mitchellh/mapstructure"
)
type DisconnectWallet struct {
sessions *Sessions
}
type DisconnectWalletParams struct {
Token string `json:"hostname"`
}
// Handle disconnect a wallet for a third-party application.
//
// It does not fail. If there's no connected wallet for the given token, nothing
// happens.
//
// The wallet resources are unloaded.
func (h *DisconnectWallet) Handle(_ context.Context, rawParams jsonrpc.Params) (jsonrpc.Result, *jsonrpc.ErrorDetails) {
params, err := validateDisconnectWalletParams(rawParams)
if err != nil {
return nil, invalidParams(err)
}
h.sessions.DisconnectWallet(params.Token)
return nil, nil
}
func validateDisconnectWalletParams(rawParams jsonrpc.Params) (DisconnectWalletParams, error) {
if rawParams == nil {
return DisconnectWalletParams{}, ErrParamsRequired
}
params := DisconnectWalletParams{}
if err := mapstructure.Decode(rawParams, ¶ms); err != nil {
return DisconnectWalletParams{}, ErrParamsDoNotMatch
}
if params.Token == "" {
return DisconnectWalletParams{}, ErrConnectionTokenIsRequired
}
return params, nil
}
func NewDisconnectWallet(sessions *Sessions) *DisconnectWallet {
return &DisconnectWallet{
sessions: sessions,
}
}