From 0c259c79d353ed2cf63d33b181bb64e734d1621f Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Wed, 2 Dec 2020 11:34:57 +0100 Subject: [PATCH] go/consensus/api: Add Registry/Staking/Scheduler to ClientBackend This makes it more convenient to use the consensus client backend. --- .changelog/3511.feature.md | 3 +++ go/consensus/api/api.go | 18 +++++++++--------- go/consensus/api/grpc.go | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 .changelog/3511.feature.md diff --git a/.changelog/3511.feature.md b/.changelog/3511.feature.md new file mode 100644 index 00000000000..80057c297eb --- /dev/null +++ b/.changelog/3511.feature.md @@ -0,0 +1,3 @@ +go/consensus/api: Add Registry/Staking/Scheduler to ClientBackend + +This makes it more convenient to use the consensus client backend. diff --git a/go/consensus/api/api.go b/go/consensus/api/api.go index 2a92d48153d..cdf8f37a719 100644 --- a/go/consensus/api/api.go +++ b/go/consensus/api/api.go @@ -137,6 +137,15 @@ type ClientBackend interface { // GetStatus returns the current status overview. GetStatus(ctx context.Context) (*Status, error) + + // Registry returns the registry backend. + Registry() registry.Backend + + // Staking returns the staking backend. + Staking() staking.Backend + + // Scheduler returns the scheduler backend. + Scheduler() scheduler.Backend } // Block is a consensus block. @@ -233,17 +242,8 @@ type ServicesBackend interface { // KeyManager returns the keymanager backend. KeyManager() keymanager.Backend - // Registry returns the registry backend. - Registry() registry.Backend - // RootHash returns the roothash backend. RootHash() roothash.Backend - - // Staking returns the staking backend. - Staking() staking.Backend - - // Scheduler returns the scheduler backend. - Scheduler() scheduler.Backend } // TransactionAuthHandler is the interface for handling transaction authentication diff --git a/go/consensus/api/grpc.go b/go/consensus/api/grpc.go index 49c3854abc9..b0d3ed48ee9 100644 --- a/go/consensus/api/grpc.go +++ b/go/consensus/api/grpc.go @@ -10,6 +10,9 @@ import ( "github.com/oasisprotocol/oasis-core/go/consensus/api/transaction" epochtime "github.com/oasisprotocol/oasis-core/go/epochtime/api" genesis "github.com/oasisprotocol/oasis-core/go/genesis/api" + registry "github.com/oasisprotocol/oasis-core/go/registry/api" + scheduler "github.com/oasisprotocol/oasis-core/go/scheduler/api" + staking "github.com/oasisprotocol/oasis-core/go/staking/api" "github.com/oasisprotocol/oasis-core/go/storage/mkvs/syncer" ) @@ -823,6 +826,18 @@ func (c *consensusClient) WatchBlocks(ctx context.Context) (<-chan *Block, pubsu return ch, sub, nil } +func (c *consensusClient) Registry() registry.Backend { + return registry.NewRegistryClient(c.conn) +} + +func (c *consensusClient) Staking() staking.Backend { + return staking.NewStakingClient(c.conn) +} + +func (c *consensusClient) Scheduler() scheduler.Backend { + return scheduler.NewSchedulerClient(c.conn) +} + // NewConsensusClient creates a new gRPC consensus client service. func NewConsensusClient(c *grpc.ClientConn) ClientBackend { return &consensusClient{