Skip to content

Commit

Permalink
AV-1475: *: proto migration (ava-labs#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexfusion authored Apr 6, 2022
1 parent 9fe80dc commit 3f113ac
Show file tree
Hide file tree
Showing 95 changed files with 4,551 additions and 4,576 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/buf-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
- uses: bufbuild/buf-setup-action@v1.3.1
- uses: bufbuild/buf-lint-action@v1
with:
input: 'api'
input: 'proto'
13 changes: 7 additions & 6 deletions api/keystore/gkeystore/keystore_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ import (
"github.com/hashicorp/go-plugin"

"github.com/ava-labs/avalanchego/api/keystore"
"github.com/ava-labs/avalanchego/api/proto/gkeystoreproto"
"github.com/ava-labs/avalanchego/api/proto/rpcdbproto"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/encdb"
"github.com/ava-labs/avalanchego/database/rpcdb"

keystorepb "github.com/ava-labs/avalanchego/proto/pb/keystore"
rpcdbpb "github.com/ava-labs/avalanchego/proto/pb/rpcdb"
)

var _ keystore.BlockchainKeystore = &Client{}

// Client is a snow.Keystore that talks over RPC.
type Client struct {
client gkeystoreproto.KeystoreClient
client keystorepb.KeystoreClient
broker *plugin.GRPCBroker
}

// NewClient returns a keystore instance connected to a remote keystore instance
func NewClient(client gkeystoreproto.KeystoreClient, broker *plugin.GRPCBroker) *Client {
func NewClient(client keystorepb.KeystoreClient, broker *plugin.GRPCBroker) *Client {
return &Client{
client: client,
broker: broker,
Expand All @@ -41,7 +42,7 @@ func (c *Client) GetDatabase(username, password string) (*encdb.Database, error)
}

func (c *Client) GetRawDatabase(username, password string) (database.Database, error) {
resp, err := c.client.GetDatabase(context.Background(), &gkeystoreproto.GetDatabaseRequest{
resp, err := c.client.GetDatabase(context.Background(), &keystorepb.GetDatabaseRequest{
Username: username,
Password: password,
})
Expand All @@ -54,6 +55,6 @@ func (c *Client) GetRawDatabase(username, password string) (database.Database, e
return nil, err
}

dbClient := rpcdb.NewClient(rpcdbproto.NewDatabaseClient(dbConn))
dbClient := rpcdb.NewClient(rpcdbpb.NewDatabaseClient(dbConn))
return dbClient, err
}
17 changes: 9 additions & 8 deletions api/keystore/gkeystore/keystore_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ import (
"github.com/hashicorp/go-plugin"

"github.com/ava-labs/avalanchego/api/keystore"
"github.com/ava-labs/avalanchego/api/proto/gkeystoreproto"
"github.com/ava-labs/avalanchego/api/proto/rpcdbproto"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/rpcdb"
"github.com/ava-labs/avalanchego/utils/math"
"github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils"

keystorepb "github.com/ava-labs/avalanchego/proto/pb/keystore"
rpcdbpb "github.com/ava-labs/avalanchego/proto/pb/rpcdb"
)

var _ gkeystoreproto.KeystoreServer = &Server{}
var _ keystorepb.KeystoreServer = &Server{}

// Server is a snow.Keystore that is managed over RPC.
type Server struct {
gkeystoreproto.UnimplementedKeystoreServer
keystorepb.UnimplementedKeystoreServer
ks keystore.BlockchainKeystore
broker *plugin.GRPCBroker
}
Expand All @@ -38,8 +39,8 @@ func NewServer(ks keystore.BlockchainKeystore, broker *plugin.GRPCBroker) *Serve

func (s *Server) GetDatabase(
_ context.Context,
req *gkeystoreproto.GetDatabaseRequest,
) (*gkeystoreproto.GetDatabaseResponse, error) {
req *keystorepb.GetDatabaseRequest,
) (*keystorepb.GetDatabaseResponse, error) {
db, err := s.ks.GetRawDatabase(req.Username, req.Password)
if err != nil {
return nil, err
Expand All @@ -57,10 +58,10 @@ func (s *Server) GetDatabase(
server := grpc.NewServer(opts...)
closer.closer.Add(server)
db := rpcdb.NewServer(&closer)
rpcdbproto.RegisterDatabaseServer(server, db)
rpcdbpb.RegisterDatabaseServer(server, db)
return server
})
return &gkeystoreproto.GetDatabaseResponse{DbServer: dbBrokerID}, nil
return &keystorepb.GetDatabaseResponse{DbServer: dbBrokerID}, nil
}

type dbCloser struct {
Expand Down
Loading

0 comments on commit 3f113ac

Please sign in to comment.