Skip to content

Commit

Permalink
added wrapper for querier to solve dist types signature issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gachouchani1999 committed Mar 26, 2024
1 parent 6e11ea0 commit 45bb0e7
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,15 +589,15 @@ func New(
// if we want to allow any custom callbacks
// See https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES-BUILT-IN.md
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2"

adapter := distrkeeper.QuerierAdapter{Querier: distrkeeper.NewQuerier(app.DistrKeeper)}
app.wasmKeeper = wasmkeeper.NewKeeper(
appCodec,
keys[wasmtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
// ad a distribution keeper to the wasm module
distrkeeper.NewQuerier(app.DistrKeeper),
adapter,
app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/andromedaprotocol/andromedad
go 1.20

require (
github.com/CosmWasm/wasmd v0.41.0
github.com/CosmWasm/wasmvm v1.3.0 // indirect
github.com/CosmWasm/wasmd v0.41.0
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogogateway v1.2.0 // indirect
Expand Down Expand Up @@ -62,6 +62,7 @@ require (
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/CosmWasm/wasmd v0.41.0 // indirect
github.com/aws/aws-sdk-go v1.44.203 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/CosmWasm/wasmd v0.41.2-andromeda h1:Boe7/H+ao1cd+XxUaaMRaWc4ERswx3ggnh0BXALNfoY=
github.com/CosmWasm/wasmd v0.41.2-andromeda/go.mod h1:GirPjCmG+eexyqyuhOD70sXbm6/mVXORmKDqHtHuwDw=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
Expand Down
2 changes: 1 addition & 1 deletion proto/andromeda/distribution/v1beta1/distribution.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package andromeda.distribution.v1beta1;

option go_package = "github.com/cosmos/cosmos-sdk/x/distribution/types";
option go_package = "github.com/andromedaprotocol/andromedad/x/distribution/types";
option (gogoproto.equal_all) = true;

import "gogoproto/gogo.proto";
Expand Down
2 changes: 1 addition & 1 deletion proto/andromeda/distribution/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package andromeda.distribution.v1beta1;

option go_package = "github.com/cosmos/cosmos-sdk/x/distribution/types";
option go_package = "github.com/andromedaprotocol/andromedad/x/distribution/types";
option (gogoproto.equal_all) = true;

import "gogoproto/gogo.proto";
Expand Down
2 changes: 1 addition & 1 deletion proto/andromeda/distribution/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "andromeda/distribution/v1beta1/distribution.proto";
import "cosmos_proto/cosmos.proto";
import "amino/amino.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/distribution/types";
option go_package = "github.com/andromedaprotocol/andromedad/x/distribution/types";

// Query defines the gRPC querier service for distribution module.
service Query {
Expand Down
2 changes: 1 addition & 1 deletion proto/andromeda/distribution/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package andromeda.distribution.v1beta1;

option go_package = "github.com/cosmos/cosmos-sdk/x/distribution/types";
option go_package = "github.com/andromedaprotocol/andromedad/x/distribution/types";
option (gogoproto.equal_all) = true;

import "gogoproto/gogo.proto";
Expand Down
25 changes: 24 additions & 1 deletion x/distribution/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

var _ types.QueryServer = Querier{}
var q types.QueryServer = Querier{}

type Querier struct {
Keeper
Expand Down Expand Up @@ -293,3 +294,25 @@ func (k Querier) CommunityPool(c context.Context, req *types.QueryCommunityPoolR

return &types.QueryCommunityPoolResponse{Pool: pool}, nil
}

// Create Adapter for distribution querier
type QuerierAdapter struct {
Querier
}

// DelegationRewards the total rewards accrued by a delegation
func (k QuerierAdapter) DelegationRewards(c context.Context, req *distrtypes.QueryDelegationRewardsRequest) (*distrtypes.QueryDelegationRewardsResponse, error) {
// Convert request from othertypes to distrtypes
convertedReq := *&types.QueryDelegationRewardsRequest{}
convertedReq.DelegatorAddress = req.DelegatorAddress
convertedReq.ValidatorAddress = req.ValidatorAddress
// Call the original Querier method
originalResp, err := k.Querier.DelegationRewards(c, &convertedReq)
if err != nil {
return nil, err
}

convertedResp := &distrtypes.QueryDelegationRewardsResponse{}
convertedResp.Rewards = originalResp.Rewards
return convertedResp, nil
}

0 comments on commit 45bb0e7

Please sign in to comment.