Skip to content

Commit

Permalink
Add VersionService to gRPC server to query server versions.
Browse files Browse the repository at this point in the history
Fixes #375.
  • Loading branch information
jrick committed Feb 24, 2016
1 parent f03556b commit 620a3c6
Show file tree
Hide file tree
Showing 5 changed files with 373 additions and 203 deletions.
14 changes: 14 additions & 0 deletions rpc/api.proto
Expand Up @@ -2,6 +2,20 @@ syntax = "proto3";

package walletrpc;

service VersionService {
rpc Version (VersionRequest) returns (VersionResponse);
}

message VersionRequest {}
message VersionResponse {
string version_string = 1;
uint32 major = 2;
uint32 minor = 3;
uint32 patch = 4;
string prerelease = 5;
string build_metadata = 6;
}

service WalletService {
// Queries
rpc Ping (PingRequest) returns (PingResponse);
Expand Down
41 changes: 39 additions & 2 deletions rpc/documentation/api.md
@@ -1,6 +1,6 @@
# RPC API Specification

Version: 0.2.0
Version: 0.3.0

**Note:** This document assumes the reader is familiar with gRPC concepts.
Refer to the [gRPC Concepts documentation](http://www.grpc.io/docs/guides/concepts.html)
Expand All @@ -20,7 +20,7 @@ perceived usefulness and ease-of-use over alternatives, and user feedback.
This document is the authoritative source on the RPC API's definitions and
semantics. Any divergence from this document is an implementation error. API
fixes and additions require a version increase according to the rules of
[Semantic Versioning 2.0](http://semver.org/).
[Semantic Versioning 2.0.0](http://semver.org/).

Only optional proto3 message fields are used (the `required` keyword is never
used in the `.proto` file). If a message field must be set to something other
Expand All @@ -35,9 +35,46 @@ server may be running without a loaded wallet, in which case the Wallet service
is not running and the Loader service must be used to create a new or load an
existing wallet.

- [`VersionService`](#versionservice)
- [`LoaderService`](#loaderservice)
- [`WalletService`](#walletservice)

## `VersionService`

The `VersionService` service provides the caller with versioning information
regarding the RPC server. It has no dependencies and is always running.

**Methods:**

- [`Version`](#version)

### Methods

#### `Version`

The `Version` method returns the RPC server version. Versioning follows the
rules of Semantic Versioning (SemVer) 2.0.0.

**Request:** `VersionRequest`

**Response:** `VersionResponse`

- `string version_string`: The version encoded as a string.

- `uint32 major`: The SemVer major version number.

- `uint32 minor`: The SemVer minor version number.

- `uint32 patch`: The SemVer patch version number.

- `string prerelease`: The SemVer pre-release version identifier, if any.

- `string build_metadata`: Extra SemVer build metadata, if any.

**Expected errors:** None

**Stability:** Stable

## `LoaderService`

The `LoaderService` service provides the caller with functions related to the
Expand Down
32 changes: 30 additions & 2 deletions rpc/rpcserver/server.go
Expand Up @@ -51,6 +51,14 @@ import (
"github.com/btcsuite/btcwallet/walletdb"
)

// Public API version constants
const (
semverString = "0.3.0"
semverMajor = 0
semverMinor = 3
semverPatch = 0
)

// translateError creates a new gRPC error with an appropiate error code for
// recognized errors.
//
Expand Down Expand Up @@ -99,6 +107,11 @@ func errorCode(err error) codes.Code {
}
}

// versionServer provides RPC clients with the ability to query the RPC server
// version.
type versionServer struct {
}

// walletServer provides wallet services for RPC clients.
type walletServer struct {
wallet *wallet.Wallet
Expand All @@ -113,7 +126,22 @@ type loaderServer struct {
mu sync.Mutex
}

// StartWalletService creates a implementation of the WalletService and
// StartVersionService creates an implementation of the VersionService and
// registers it with the gRPC server.
func StartVersionService(server *grpc.Server) {
pb.RegisterVersionServiceServer(server, &versionServer{})
}

func (*versionServer) Version(ctx context.Context, req *pb.VersionRequest) (*pb.VersionResponse, error) {
return &pb.VersionResponse{
VersionString: semverString,
Major: semverMajor,
Minor: semverMinor,
Patch: semverPatch,
}, nil
}

// StartWalletService creates an implementation of the WalletService and
// registers it with the gRPC server.
func StartWalletService(server *grpc.Server, wallet *wallet.Wallet) {
service := &walletServer{wallet}
Expand Down Expand Up @@ -715,7 +743,7 @@ func (s *walletServer) AccountNotifications(req *pb.AccountNotificationsRequest,
}
}

// StartWalletLoaderService creates a implementation of the WalletLoaderService
// StartWalletLoaderService creates an implementation of the WalletLoaderService
// and registers it with the gRPC server.
func StartWalletLoaderService(server *grpc.Server, loader *wallet.Loader,
activeNet *netparams.Params) {
Expand Down

0 comments on commit 620a3c6

Please sign in to comment.