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

[Bugfix] Gov Deposits Querier (Initial Deposit) #8813

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/bank) [\#8434](https://github.com/cosmos/cosmos-sdk/pull/8434) Fix legacy REST API `GET /bank/total` and `GET /bank/total/{denom}` in swagger
* (x/slashing) [\#8427](https://github.com/cosmos/cosmos-sdk/pull/8427) Fix query signing infos command
* (server) [\#8399](https://github.com/cosmos/cosmos-sdk/pull/8399) fix gRPC-web flag default value
* (x/gov) [\#8813](https://github.com/cosmos/cosmos-sdk/pull/8813) fix `GET /cosmos/gov/v1beta1/proposals/{proposal_id}/deposits` to include initial deposit

## [v0.41.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.41.3) - 2021-03-02

Expand Down
56 changes: 54 additions & 2 deletions x/gov/client/utils/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ func (p Proposer) String() string {
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
func QueryDepositsByTxQuery(clientCtx client.Context, params types.QueryProposalParams) ([]byte, error) {
var deposits []types.Deposit

// initial deposit was submitted with proposal, so must be queried separately
initialDeposit, err := QueryInitialDepositByTxQuery(clientCtx, params.ProposalID)
if err != nil {
return nil, err
}

if !initialDeposit.Amount.IsZero() {
deposits = append(deposits, initialDeposit)
}

searchResult, err := combineEvents(
clientCtx, defaultPage,
// Query old Msgs
Expand All @@ -54,8 +66,6 @@ func QueryDepositsByTxQuery(clientCtx client.Context, params types.QueryProposal
return nil, err
}

var deposits []types.Deposit

for _, info := range searchResult.Txs {
for _, msg := range info.GetTx().GetMsgs() {
var depMsg *types.MsgDeposit
Expand Down Expand Up @@ -346,6 +356,48 @@ func QueryProposerByTxQuery(clientCtx client.Context, proposalID uint64) (Propos
return Proposer{}, fmt.Errorf("failed to find the proposer for proposalID %d", proposalID)
}

// QueryInitialDepositByTxQuery will query for a initial deposit of a governance proposal by
// ID.
func QueryInitialDepositByTxQuery(clientCtx client.Context, proposalID uint64) (types.Deposit, error) {
yun-yeo marked this conversation as resolved.
Show resolved Hide resolved
searchResult, err := combineEvents(
clientCtx, defaultPage,
// Query old Msgs
[]string{
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgSubmitProposal),
fmt.Sprintf("%s.%s='%s'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", proposalID))),
},
// Query service Msgs
[]string{
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeSvcMsgSubmitProposal),
fmt.Sprintf("%s.%s='%s'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", proposalID))),
},
)

if err != nil {
return types.Deposit{}, err
}

for _, info := range searchResult.Txs {
for _, msg := range info.GetTx().GetMsgs() {
// there should only be a single proposal under the given conditions
var subMsg *types.MsgSubmitProposal
if msg.Type() == types.TypeSvcMsgSubmitProposal {
subMsg = msg.(sdk.ServiceMsg).Request.(*types.MsgSubmitProposal)
} else if protoSubMsg, ok := msg.(*types.MsgSubmitProposal); ok {
subMsg = protoSubMsg
}

return types.Deposit{
yun-yeo marked this conversation as resolved.
Show resolved Hide resolved
ProposalId: proposalID,
Depositor: subMsg.Proposer,
Amount: subMsg.InitialDeposit,
}, nil
}
}

return types.Deposit{}, fmt.Errorf("failed to find the initial deposit for proposalID %d", proposalID)
Copy link
Contributor

Choose a reason for hiding this comment

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

could you use sdkerrors.Wrapf here?

Copy link
Member

Choose a reason for hiding this comment

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

ping @YunSuk-Yeo

}

// QueryProposalByID takes a proposalID and returns a proposal
func QueryProposalByID(proposalID uint64, clientCtx client.Context, queryRoute string) ([]byte, error) {
params := types.NewQueryProposalParams(proposalID)
Expand Down