-
Notifications
You must be signed in to change notification settings - Fork 661
/
keystore_client.go
53 lines (43 loc) · 1.31 KB
/
keystore_client.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
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package gkeystore
import (
"context"
"github.com/hashicorp/go-plugin"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/rpcdb"
"github.com/ava-labs/avalanchego/database/rpcdb/rpcdbproto"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/vms/rpcchainvm/gkeystore/gkeystoreproto"
)
var (
_ snow.Keystore = &Client{}
)
// Client is an implementation of a messenger channel that talks over RPC.
type Client struct {
client gkeystoreproto.KeystoreClient
broker *plugin.GRPCBroker
}
// NewClient returns a keystore instance connected to a remote keystore instance
func NewClient(client gkeystoreproto.KeystoreClient, broker *plugin.GRPCBroker) *Client {
return &Client{
client: client,
broker: broker,
}
}
// GetDatabase ...
func (c *Client) GetDatabase(username, password string) (database.Database, error) {
resp, err := c.client.GetDatabase(context.Background(), &gkeystoreproto.GetDatabaseRequest{
Username: username,
Password: password,
})
if err != nil {
return nil, err
}
dbConn, err := c.broker.Dial(resp.DbServer)
if err != nil {
return nil, err
}
dbClient := rpcdb.NewClient(rpcdbproto.NewDatabaseClient(dbConn))
return dbClient, err
}