Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Adds all stargate queries for smart contracts #715

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 144 additions & 14 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

globalfeetypes "github.com/CosmosContracts/juno/v16/x/globalfee/types"
"github.com/CosmosContracts/juno/v16/x/ibchooks"
ibchookskeeper "github.com/CosmosContracts/juno/v16/x/ibchooks/keeper"
ibchookstypes "github.com/CosmosContracts/juno/v16/x/ibchooks/types"
Expand All @@ -22,19 +24,23 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtype "github.com/cosmos/cosmos-sdk/x/auth/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/authz"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
evedencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
Expand Down Expand Up @@ -468,31 +474,42 @@ func NewAppKeepers(
wasmOpts = append(wasmOpts, tfOpts...)

// Stargate Queries
// (Define custom modules here, then the next function takes care of the standard SDK types)
accepted := wasmkeeper.AcceptedStargateQueries{
// wasm
"/cosmwasm.wasm.v1/Query/ContractInfo": &wasmtypes.QueryContractInfoResponse{},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be .v1.Query/ oops

"/cosmwasm.wasm.v1/Query/ContractHistory": &wasmtypes.QueryContractHistoryResponse{},
"/cosmwasm.wasm.v1/Query/ContractsByCode": &wasmtypes.QueryContractsByCodeResponse{},
"/cosmwasm.wasm.v1/Query/AllContractState": &wasmtypes.QueryAllContractStateResponse{},
"/cosmwasm.wasm.v1/Query/RawContractState": &wasmtypes.QueryRawContractStateResponse{},
"/cosmwasm.wasm.v1/Query/SmartContractState": &wasmtypes.QuerySmartContractStateResponse{},
"/cosmwasm.wasm.v1/Query/Code": &wasmtypes.QueryCodeResponse{},
"/cosmwasm.wasm.v1/Query/Codes": &wasmtypes.QueryCodesResponse{},
"/cosmwasm.wasm.v1/Query/PinnedCodes": &wasmtypes.QueryPinnedCodesResponse{},
"/cosmwasm.wasm.v1/Query/Params": &wasmtypes.QueryParamsResponse{},
"/cosmwasm.wasm.v1/Query/ContractsByCreator": &wasmtypes.QueryContractsByCreatorResponse{},

// ibc
"/ibc.core.client.v1.Query/ClientState": &ibcclienttypes.QueryClientStateResponse{},
"/ibc.core.client.v1.Query/ConsensusState": &ibcclienttypes.QueryConsensusStateResponse{},
"/ibc.core.connection.v1.Query/Connection": &ibcconnectiontypes.QueryConnectionResponse{},

// governance
"/cosmos.gov.v1beta1.Query/Vote": &govv1.QueryVoteResponse{},

// distribution
"/cosmos.distribution.v1beta1.Query/DelegationRewards": &distrtypes.QueryDelegationRewardsResponse{},

// staking
"/cosmos.staking.v1beta1.Query/Delegation": &stakingtypes.QueryDelegationResponse{},
"/cosmos.staking.v1beta1.Query/Redelegations": &stakingtypes.QueryRedelegationsResponse{},
"/cosmos.staking.v1beta1.Query/UnbondingDelegation": &stakingtypes.QueryUnbondingDelegationResponse{},
"/cosmos.staking.v1beta1.Query/Validator": &stakingtypes.QueryValidatorResponse{},
"/cosmos.staking.v1beta1.Query/Params": &stakingtypes.QueryParamsResponse{},
"/cosmos.staking.v1beta1.Query/Pool": &stakingtypes.QueryPoolResponse{},

// token factory
"/osmosis.tokenfactory.v1beta1.Query/Params": &tokenfactorytypes.QueryParamsResponse{},
"/osmosis.tokenfactory.v1beta1.Query/DenomAuthorityMetadata": &tokenfactorytypes.QueryDenomAuthorityMetadataResponse{},
"/osmosis.tokenfactory.v1beta1.Query/DenomsFromCreator": &tokenfactorytypes.QueryDenomsFromCreatorResponse{},

// feeshare
"/juno.feeshare.v1.Query/FeeShares": &feesharetypes.QueryFeeSharesResponse{},
"/juno.feeshare.v1.Query/FeeShare": &feesharetypes.QueryFeeShareResponse{},
"/juno.feeshare.v1.Query/Params": &feesharetypes.QueryParamsResponse{},
"/juno.feeshare.v1.Query/DeployerFeeShares": &feesharetypes.QueryDeployerFeeSharesResponse{},
"/juno.feeshare.v1.Query/WithdrawerFeeShares": &feesharetypes.QueryWithdrawerFeeSharesResponse{},

// globalfee
"/gaia.globalfee.v1beta1.Query/MinimumGasPrices": &globalfeetypes.QueryMinimumGasPricesResponse{},
}
accepted = addCosmosSDKStdStargateQueries(accepted)

querierOpts := wasmkeeper.WithQueryPlugins(
&wasmkeeper.QueryPlugins{
Expand Down Expand Up @@ -594,6 +611,119 @@ func NewAppKeepers(
return appKeepers
}

func addCosmosSDKStdStargateQueries(asq wasmkeeper.AcceptedStargateQueries) wasmkeeper.AcceptedStargateQueries {
std := map[string]codec.ProtoMarshaler{
// auth
"/cosmos.auth.v1beta1.Query/Account": &authtype.QueryAccountResponse{},
"/cosmos.auth.v1beta1.Query/AccountAddressByID": &authtype.QueryAccountAddressByIDResponse{},
"/cosmos.auth.v1beta1.Query/Params": &authtype.QueryParamsResponse{},
"/cosmos.auth.v1beta1.Query/ModuleAccounts": &authtype.QueryModuleAccountsResponse{},
"/cosmos.auth.v1beta1.Query/ModuleAccountByName": &authtype.QueryModuleAccountByNameResponse{},
"/cosmos.auth.v1beta1.Query/Bech32Prefix": &authtype.Bech32PrefixResponse{},
"/cosmos.auth.v1beta1.Query/AddressBytesToString": &authtype.AddressBytesToStringResponse{},
"/cosmos.auth.v1beta1.Query/AddressStringToBytes": &authtype.AddressStringToBytesResponse{},
"/cosmos.auth.v1beta1.Query/AccountInfo": &authtype.QueryAccountInfoResponse{},

// authz
"/cosmos.authz.v1beta1.Query/Grants": &authz.QueryGrantsResponse{},
"/cosmos.authz.v1beta1.Query/GranterGrants": &authz.QueryGranterGrantsResponse{},

// bank
"/cosmos.bank.v1beta1.Query/Balance": &banktypes.QueryBalanceResponse{},
"/cosmos.bank.v1beta1.Query/AllBalances": &banktypes.QueryAllBalancesResponse{},
"/cosmos.bank.v1beta1.Query/SpendableBalances": &banktypes.QuerySpendableBalancesResponse{},
"/cosmos.bank.v1beta1.Query/SpendableBalanceByDenom": &banktypes.QuerySpendableBalanceByDenomResponse{},
"/cosmos.bank.v1beta1.Query/TotalSupply": &banktypes.QueryTotalSupplyResponse{},
"/cosmos.bank.v1beta1.Query/SupplyOf": &banktypes.QuerySupplyOfResponse{},
"/cosmos.bank.v1beta1.Query/Params": &banktypes.QueryParamsResponse{},
"/cosmos.bank.v1beta1.Query/DenomMetadata": &banktypes.QueryDenomMetadataResponse{},
"/cosmos.bank.v1beta1.Query/DenomsMetadata": &banktypes.QueryDenomsMetadataResponse{},
"/cosmos.bank.v1beta1.Query/DenomOwners": &banktypes.QueryDenomOwnersResponse{},
"/cosmos.bank.v1beta1.Query/SendEnabled": &banktypes.QuerySendEnabledResponse{},

// consensus
"/cosmos.consensus.v1beta1.Query/Params": &consensustypes.QueryParamsResponse{},

// distribution
"/cosmos.distribution.v1beta1.Query/ParamsRequest": &distrtypes.QueryParamsRequest{},
"/cosmos.distribution.v1beta1.Query/ValidatorDistributionInfo": &distrtypes.QueryValidatorDistributionInfoResponse{},
"/cosmos.distribution.v1beta1.Query/ValidatorOutstandingRewards": &distrtypes.QueryValidatorOutstandingRewardsResponse{},
"/cosmos.distribution.v1beta1.Query/ValidatorCommission": &distrtypes.QueryValidatorCommissionResponse{},
"/cosmos.distribution.v1beta1.Query/ValidatorSlashes": &distrtypes.QueryValidatorSlashesResponse{},
"/cosmos.distribution.v1beta1.Query/DelegationRewards": &distrtypes.QueryDelegationRewardsResponse{},
"/cosmos.distribution.v1beta1.Query/DelegationTotalRewards": &distrtypes.QueryDelegationTotalRewardsResponse{},
"/cosmos.distribution.v1beta1.Query/DelegatorValidators": &distrtypes.QueryDelegatorValidatorsResponse{},
"/cosmos.distribution.v1beta1.Query/DelegatorWithdrawAddress": &distrtypes.QueryDelegatorWithdrawAddressResponse{},
"/cosmos.distribution.v1beta1.Query/CommunityPool": &distrtypes.QueryCommunityPoolResponse{},

// evidence
"/cosmos.evidence.v1beta1.Query/Evidence": &evedencetypes.QueryEvidenceResponse{},
"/cosmos.evidence.v1beta1.Query/AllEvidence": &evedencetypes.QueryAllEvidenceResponse{},

// feegrant
"/cosmos.feegrant.v1beta1.Query/Allowance": &feegrant.QueryAllowanceResponse{},
"/cosmos.feegrant.v1beta1.Query/Allowances": &feegrant.QueryAllowancesResponse{},
"/cosmos.feegrant.v1beta1.Query/AllowancesByGranter": &feegrant.QueryAllowancesByGranterResponse{},

// governance
"/cosmos.gov.v1beta1.Query/Proposal": &govv1.QueryProposalResponse{},
"/cosmos.gov.v1beta1.Query/Proposals": &govv1.QueryProposalsResponse{},
"/cosmos.gov.v1beta1.Query/Vote": &govv1.QueryVoteResponse{},
"/cosmos.gov.v1beta1.Query/Votes": &govv1.QueryVotesResponse{},
"/cosmos.gov.v1beta1.Query/Params": &govv1.QueryParamsResponse{},
"/cosmos.gov.v1beta1.Query/Deposit": &govv1.QueryDepositResponse{},
"/cosmos.gov.v1beta1.Query/TallyResult": &govv1.QueryTallyResultResponse{},

// mint
"/juno.mint.Query/Params": &minttypes.QueryParamsResponse{},
"/juno.mint.Query/Inflation": &minttypes.QueryInflationResponse{},
"/juno.mint.Query/AnnualProvisions": &minttypes.QueryAnnualProvisionsResponse{},

// nft
"/cosmos.nft.v1beta1.Query/Balance": &nft.QueryBalanceResponse{},
"/cosmos.nft.v1beta1.Query/Owner": &nft.QueryOwnerResponse{},
"/cosmos.nft.v1beta1.Query/Supply": &nft.QuerySupplyResponse{},
"/cosmos.nft.v1beta1.Query/NFTs": &nft.QueryNFTsResponse{},
"/cosmos.nft.v1beta1.Query/NFT": &nft.QueryNFTResponse{},
"/cosmos.nft.v1beta1.Query/Class": &nft.QueryClassResponse{},
"/cosmos.nft.v1beta1.Query/Classes": &nft.QueryClassesResponse{},

// slashing
"/cosmos.slashing.v1beta1.Query/Params": &slashingtypes.QueryParamsResponse{},
"/cosmos.slashing.v1beta1.Query/SigningInfo": &slashingtypes.QuerySigningInfoResponse{},
"/cosmos.slashing.v1beta1.Query/SigningInfos": &slashingtypes.QuerySigningInfosResponse{},

// staking
"/cosmos.staking.v1beta1.Query/Validators": &stakingtypes.QueryValidatorsResponse{},
"/cosmos.staking.v1beta1.Query/Validator": &stakingtypes.QueryValidatorResponse{},
"/cosmos.staking.v1beta1.Query/ValidatorDelegations": &stakingtypes.QueryValidatorDelegationsResponse{},
"/cosmos.staking.v1beta1.Query/ValidatorUnbondingDelegations": &stakingtypes.QueryValidatorUnbondingDelegationsResponse{},
"/cosmos.staking.v1beta1.Query/Delegation": &stakingtypes.QueryDelegationResponse{},
"/cosmos.staking.v1beta1.Query/UnbondingDelegation": &stakingtypes.QueryUnbondingDelegationResponse{},
"/cosmos.staking.v1beta1.Query/DelegatorDelegations": &stakingtypes.QueryDelegatorDelegationsResponse{},
"/cosmos.staking.v1beta1.Query/DelegatorUnbondingDelegations": &stakingtypes.QueryDelegatorUnbondingDelegationsResponse{},
"/cosmos.staking.v1beta1.Query/Redelegations": &stakingtypes.QueryRedelegationsResponse{},
"/cosmos.staking.v1beta1.Query/DelegatorValidators": &stakingtypes.QueryDelegatorValidatorsResponse{},
"/cosmos.staking.v1beta1.Query/DelegatorValidator": &stakingtypes.QueryDelegatorValidatorResponse{},
"/cosmos.staking.v1beta1.Query/HistoricalInfo": &stakingtypes.QueryHistoricalInfoResponse{},
"/cosmos.staking.v1beta1.Query/Params": &stakingtypes.QueryParamsResponse{},
"/cosmos.staking.v1beta1.Query/Pool": &stakingtypes.QueryPoolResponse{},

// upgrade
"/cosmos.upgrade.v1beta1.Query/CurrentPlan": &upgradetypes.QueryCurrentPlanResponse{},
"/cosmos.upgrade.v1beta1.Query/AppliedPlan": &upgradetypes.QueryAppliedPlanResponse{},
"/cosmos.upgrade.v1beta1.Query/UpgradedConsensusState": &upgradetypes.QueryUpgradedConsensusStateResponse{},
"/cosmos.upgrade.v1beta1.Query/QueryModuleVersionsResponse": &upgradetypes.QueryModuleVersionsResponse{},
"/cosmos.upgrade.v1beta1.Query/QueryAuthorityResponse": &upgradetypes.QueryAuthorityResponse{},
}

updated := asq
for k, v := range std {
Reecepbcups marked this conversation as resolved.
Show resolved Hide resolved
updated[k] = v
}
Dismissed Show dismissed Hide dismissed
return updated
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)
Expand Down