From c3fa16e5c717965a259bbe371f3f23358c25f568 Mon Sep 17 00:00:00 2001 From: ptrus Date: Thu, 7 Apr 2022 16:38:11 +0200 Subject: [PATCH] go/staking/grpc: rename misnamed GovernanceDeposits method --- .changelog/4652.feature.md | 4 +++ go/staking/api/grpc.go | 52 ++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 .changelog/4652.feature.md diff --git a/.changelog/4652.feature.md b/.changelog/4652.feature.md new file mode 100644 index 00000000000..fef82eb74cc --- /dev/null +++ b/.changelog/4652.feature.md @@ -0,0 +1,4 @@ +go/staking/grpc: rename misnamed GovernanceDeposits method + +Previous misnamed method is deprecated, but will work in the `22.1.x` +releases. diff --git a/go/staking/api/grpc.go b/go/staking/api/grpc.go index ea7a237b1a3..e5dac6ef229 100644 --- a/go/staking/api/grpc.go +++ b/go/staking/api/grpc.go @@ -25,7 +25,9 @@ var ( // methodLastBlockFees is the LastBlockFees method. methodLastBlockFees = serviceName.NewMethod("LastBlockFees", int64(0)) // methodGovernanceDeposits is the GovernanceDeposits method. - methodGovernanceDeposits = serviceName.NewMethod("methodGovernanceDeposits", int64(0)) + methodGovernanceDeposits = serviceName.NewMethod("GovernanceDeposits", int64(0)) + // methodGovernanceDepositsDeprecated is the deprecated GovernanceDeposits method. + methodGovernanceDepositsDeprecated = serviceName.NewMethod("methodGovernanceDeposits", int64(0)) // methodThreshold is the Threshold method. methodThreshold = serviceName.NewMethod("Threshold", ThresholdQuery{}) // methodAddresses is the Addresses method. @@ -83,7 +85,11 @@ var ( }, { MethodName: methodGovernanceDeposits.ShortName(), - Handler: handlerGovernanceDeposits, + Handler: getHandlerGovernanceDeposits(methodGovernanceDeposits), + }, + { + MethodName: methodGovernanceDepositsDeprecated.ShortName(), + Handler: getHandlerGovernanceDeposits(methodGovernanceDepositsDeprecated), }, { MethodName: methodThreshold.ShortName(), @@ -255,27 +261,29 @@ func handlerLastBlockFees( // nolint: golint return interceptor(ctx, height, info, handler) } -func handlerGovernanceDeposits( // nolint: golint - srv interface{}, - ctx context.Context, - dec func(interface{}) error, - interceptor grpc.UnaryServerInterceptor, -) (interface{}, error) { - var height int64 - if err := dec(&height); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(Backend).GovernanceDeposits(ctx, height) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: methodGovernanceDeposits.FullName(), - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(Backend).GovernanceDeposits(ctx, req.(int64)) +func getHandlerGovernanceDeposits(methodDesc *cmnGrpc.MethodDesc) func(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { // nolint: golint + return func( + srv interface{}, + ctx context.Context, + dec func(interface{}) error, + interceptor grpc.UnaryServerInterceptor, + ) (interface{}, error) { + var height int64 + if err := dec(&height); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(Backend).GovernanceDeposits(ctx, height) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: methodDesc.FullName(), + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(Backend).GovernanceDeposits(ctx, req.(int64)) + } + return interceptor(ctx, height, info, handler) } - return interceptor(ctx, height, info, handler) } func handlerThreshold( // nolint: golint