Skip to content

Commit

Permalink
Merge pull request #4655 from oasisprotocol/ptrus/stable/22.1.x/backp…
Browse files Browse the repository at this point in the history
…ort-4652

go/staking/grpc: rename misnamed GovernanceDeposits method
  • Loading branch information
ptrus authored Apr 8, 2022
2 parents 250bdb0 + c3fa16e commit 5c22143
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .changelog/4652.feature.md
Original file line number Diff line number Diff line change
@@ -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.
52 changes: 30 additions & 22 deletions go/staking/api/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -83,7 +85,11 @@ var (
},
{
MethodName: methodGovernanceDeposits.ShortName(),
Handler: handlerGovernanceDeposits,
Handler: getHandlerGovernanceDeposits(methodGovernanceDeposits),
},
{
MethodName: methodGovernanceDepositsDeprecated.ShortName(),
Handler: getHandlerGovernanceDeposits(methodGovernanceDepositsDeprecated),
},
{
MethodName: methodThreshold.ShortName(),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5c22143

Please sign in to comment.