Skip to content

Commit

Permalink
unified sender tag (cosmos#4057)
Browse files Browse the repository at this point in the history
Closes: cosmos#3775
  • Loading branch information
fedekunze authored and alessio committed Apr 10, 2019
1 parent cf0f73a commit 8550d87
Show file tree
Hide file tree
Showing 22 changed files with 81 additions and 68 deletions.
1 change: 1 addition & 0 deletions .pending/breaking/sdk/3775-unify-sender-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#3775 unify sender transaction tag for ease of querying
12 changes: 6 additions & 6 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func TestTxs(t *testing.T) {
txs = getTransactions(t, port, fmt.Sprintf("sender=%s", addr.String()))
require.Equal(t, emptyTxs, txs)

txs = getTransactions(t, port, fmt.Sprintf("action=submit%%20proposal&proposer=%s", addr.String()))
txs = getTransactions(t, port, fmt.Sprintf("action=submit%%20proposal&sender=%s", addr.String()))
require.Equal(t, emptyTxs, txs)

// create tx
Expand Down Expand Up @@ -455,7 +455,7 @@ func TestBonding(t *testing.T) {

// query tx
txs := getTransactions(t, port,
fmt.Sprintf("action=delegate&delegator=%s", addr),
fmt.Sprintf("action=delegate&sender=%s", addr),
fmt.Sprintf("destination-validator=%s", operAddrs[0]),
)
require.Len(t, txs, 1)
Expand Down Expand Up @@ -508,7 +508,7 @@ func TestBonding(t *testing.T) {

// query tx
txs = getTransactions(t, port,
fmt.Sprintf("action=begin_unbonding&delegator=%s", addr),
fmt.Sprintf("action=begin_unbonding&sender=%s", addr),
fmt.Sprintf("source-validator=%s", operAddrs[0]),
)
require.Len(t, txs, 1)
Expand Down Expand Up @@ -545,7 +545,7 @@ func TestBonding(t *testing.T) {

// query tx
txs = getTransactions(t, port,
fmt.Sprintf("action=begin_redelegate&delegator=%s", addr),
fmt.Sprintf("action=begin_redelegate&sender=%s", addr),
fmt.Sprintf("source-validator=%s", operAddrs[0]),
fmt.Sprintf("destination-validator=%s", operAddrs[1]),
)
Expand Down Expand Up @@ -669,7 +669,7 @@ func TestDeposit(t *testing.T) {
require.Equal(t, expectedBalance.Amount.Sub(depositTokens), acc.GetCoins().AmountOf(sdk.DefaultBondDenom))

// query tx
txs := getTransactions(t, port, fmt.Sprintf("action=deposit&depositor=%s", addr))
txs := getTransactions(t, port, fmt.Sprintf("action=deposit&sender=%s", addr))
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)

Expand Down Expand Up @@ -728,7 +728,7 @@ func TestVote(t *testing.T) {
expectedBalance = coins[0]

// query tx
txs := getTransactions(t, port, fmt.Sprintf("action=vote&voter=%s", addr))
txs := getTransactions(t, port, fmt.Sprintf("action=vote&sender=%s", addr))
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)

Expand Down
2 changes: 1 addition & 1 deletion client/lcd/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ paths:
- in: query
name: tag
type: string
description: "transaction tags such as 'action=submit-proposal' and 'proposer=cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc' which results in the following endpoint: 'GET /txs?action=submit-proposal&proposer=cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc'"
description: "transaction tags such as 'action=submit-proposal' and 'sender=cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc' which results in the following endpoint: 'GET /txs?action=submit-proposal&sender=cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc'"
required: true
x-example: 'TODO'
- in: query
Expand Down
6 changes: 3 additions & 3 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
tests.WaitForNextNBlocksTM(1, f.Port)

// Ensure transaction tags can be queried
txs := f.QueryTxs(1, 50, "action:submit_proposal", fmt.Sprintf("proposer:%s", fooAddr))
txs := f.QueryTxs(1, 50, "action:submit_proposal", fmt.Sprintf("sender:%s", fooAddr))
require.Len(t, txs, 1)

// Ensure deposit was deducted
Expand Down Expand Up @@ -512,7 +512,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.Equal(t, proposalTokens.Add(depositTokens), deposit.Amount.AmountOf(denom))

// Ensure tags are set on the transaction
txs = f.QueryTxs(1, 50, "action:deposit", fmt.Sprintf("depositor:%s", fooAddr))
txs = f.QueryTxs(1, 50, "action:deposit", fmt.Sprintf("sender:%s", fooAddr))
require.Len(t, txs, 1)

// Ensure account has expected amount of funds
Expand Down Expand Up @@ -549,7 +549,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.Equal(t, gov.OptionYes, votes[0].Option)

// Ensure tags are applied to voting transaction properly
txs = f.QueryTxs(1, 50, "action:vote", fmt.Sprintf("voter:%s", fooAddr))
txs = f.QueryTxs(1, 50, "action:vote", fmt.Sprintf("sender:%s", fooAddr))
require.Len(t, txs, 1)

// Ensure no proposals in deposit period
Expand Down
22 changes: 11 additions & 11 deletions docs/spec/distribution/06_tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ The distribution module emits the following events/tags:

### MsgSetWithdrawAddress

| Key | Value |
|-------------|---------------------------|
| `action` | `set_withdraw_address` |
| `category` | `distribution` |
| `delegator` | {delegatorAccountAddress} |
| Key | Value |
|------------|---------------------------|
| `action` | `set_withdraw_address` |
| `category` | `distribution` |
| `sender` | {delegatorAccountAddress} |

### MsgWithdrawDelegatorReward

| Key | Value |
|--------------------|-----------------------------|
| `action` | `withdraw_delegator_reward` |
| `category` | `distribution` |
| `delegator` | {delegatorAccountAddress} |
| `sender` | {delegatorAccountAddress} |
| `source-validator` | {srcOperatorAddress} |

### MsgWithdrawValidatorCommission

| Key | Value |
|--------------------|---------------------------------|
| `action` | `withdraw_validator_commission` |
| `category` | `distribution` |
| `source-validator` | {srcOperatorAddress} |
| Key | Value |
|------------|---------------------------------|
| `action` | `withdraw_validator_commission` |
| `category` | `distribution` |
| `sender` | {srcOperatorAddress} |
6 changes: 3 additions & 3 deletions docs/spec/governance/04_tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The governance module emits the following events/tags:
|---------------------------|--------------------------|
| `action` | `submit_proposal` |
| `category` | `governance` |
| `proposer` | {proposerAccountAddress} |
| `sender` | {proposerAccountAddress} |
| `proposal-id` | {proposalID} |
| `voting-period-start` [0] | {proposalID} |

Expand All @@ -28,7 +28,7 @@ The governance module emits the following events/tags:
|---------------|-----------------------|
| `action` | `vote` |
| `category` | `governance` |
| `voter` | {voterAccountAddress} |
| `sender` | {voterAccountAddress} |
| `proposal-id` | {proposalID} |

### MsgDeposit
Expand All @@ -37,5 +37,5 @@ The governance module emits the following events/tags:
|---------------|---------------------------|
| `action` | `deposit` |
| `category` | `governance` |
| `depositor` | {depositorAccountAddress} |
| `sender` | {depositorAccountAddress} |
| `proposal-id` | {proposalID} |
10 changes: 5 additions & 5 deletions docs/spec/slashing/06_tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ The slashing module emits the following events/tags:

### MsgUnjail

| Key | Value |
|-------------|----------------------------|
| `action` | `unjail` |
| `category` | `slashing` |
| `validator` | {validatorOperatorAddress} |
| Key | Value |
|------------|----------------------------|
| `action` | `unjail` |
| `category` | `slashing` |
| `sender` | {validatorOperatorAddress} |
26 changes: 13 additions & 13 deletions docs/spec/staking/06_tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ The staking module emits the following events/tags:

### MsgCreateValidator

| Key | Value |
|-------------------------|----------------------|
| `action` | `create_validator` |
| `category` | `staking` |
| `destination-validator` | {dstOperatorAddress} |
| Key | Value |
|------------|----------------------|
| `action` | `create_validator` |
| `category` | `staking` |
| `sender` | {dstOperatorAddress} |

### MsgEditValidator

| Key | Value |
|-------------------------|----------------------|
| `action` | `edit_validator` |
| `category` | `staking` |
| `destination-validator` | {dstOperatorAddress} |
| Key | Value |
|------------|----------------------|
| `action` | `edit_validator` |
| `category` | `staking` |
| `sender` | {dstOperatorAddress} |

### MsgDelegate

| Key | Value |
|-------------------------|---------------------------|
| `action` | `delegate` |
| `category` | `staking` |
| `delegator` | {delegatorAccountAddress} |
| `sender` | {delegatorAccountAddress} |
| `destination-validator` | {dstOperatorAddress} |

### MsgBeginRedelegate
Expand All @@ -45,7 +45,7 @@ The staking module emits the following events/tags:
|-------------------------|---------------------------|
| `action` | `begin_redelegate` |
| `category` | `staking` |
| `delegator` | {delegatorAccountAddress} |
| `sender` | {delegatorAccountAddress} |
| `source-validator` | {srcOperatorAddress} |
| `destination-validator` | {dstOperatorAddress} |
| `end-time` [0] | {delegationFinishTime} |
Expand All @@ -58,7 +58,7 @@ The staking module emits the following events/tags:
|--------------------|---------------------------|
| `action` | `begin_unbonding` |
| `category` | `staking` |
| `delegator` | {delegatorAccountAddress} |
| `sender` | {delegatorAccountAddress} |
| `source-validator` | {srcOperatorAddress} |
| `end-time` [0] | {delegationFinishTime} |

Expand Down
1 change: 1 addition & 0 deletions types/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func MakeTag(k string, v string) Tag {
var (
TagAction = "action"
TagCategory = "category"
TagSender = "sender"
TagSrcValidator = "source-validator"
TagDstValidator = "destination-validator"
TagDelegator = "delegator"
Expand Down
9 changes: 5 additions & 4 deletions x/crisis/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package crisis

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/crisis/tags"
)

// ModuleName is the module name for this module
Expand Down Expand Up @@ -70,11 +71,11 @@ func handleMsgVerifyInvariant(ctx sdk.Context, msg MsgVerifyInvariant, k Keeper)
panic(invarianceErr)
}

tags := sdk.NewTags(
"sender", msg.Sender.String(),
"invariant", msg.InvariantRoute,
resTags := sdk.NewTags(
tags.Sender, msg.Sender.String(),
tags.Invariant, msg.InvariantRoute,
)
return sdk.Result{
Tags: tags,
Tags: resTags,
}
}
11 changes: 11 additions & 0 deletions x/crisis/tags/tags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tags

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Crisis module tags
var (
Sender = sdk.TagSender
Invariant = "invariant"
)
1 change: 0 additions & 1 deletion x/distribution/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ var (
ErrNilValidatorAddr = types.ErrNilValidatorAddr

TagValidator = tags.Validator
TagDelegator = tags.Delegator

NewMsgSetWithdrawAddress = types.NewMsgSetWithdrawAddress
NewMsgWithdrawDelegatorReward = types.NewMsgWithdrawDelegatorReward
Expand Down
6 changes: 3 additions & 3 deletions x/distribution/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func handleMsgModifyWithdrawAddress(ctx sdk.Context, msg types.MsgSetWithdrawAdd

resTags := sdk.NewTags(
tags.Category, tags.TxCategory,
tags.Delegator, msg.DelegatorAddress.String(),
tags.Sender, msg.DelegatorAddress.String(),
)
return sdk.Result{
Tags: resTags,
Expand All @@ -50,7 +50,7 @@ func handleMsgWithdrawDelegatorReward(ctx sdk.Context, msg types.MsgWithdrawDele

resTags := sdk.NewTags(
tags.Category, tags.TxCategory,
tags.Delegator, msg.DelegatorAddress.String(),
tags.Sender, msg.DelegatorAddress.String(),
tags.Validator, msg.ValidatorAddress.String(),
)
return sdk.Result{
Expand All @@ -67,7 +67,7 @@ func handleMsgWithdrawValidatorCommission(ctx sdk.Context, msg types.MsgWithdraw

resTags := sdk.NewTags(
tags.Category, tags.TxCategory,
tags.Validator, msg.ValidatorAddress.String(),
tags.Sender, msg.ValidatorAddress.String(),
)
return sdk.Result{
Tags: resTags,
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ var (
TxCategory = "distribution"

Validator = sdk.TagSrcValidator
Delegator = sdk.TagDelegator
Category = sdk.TagCategory
Sender = sdk.TagSender
)
4 changes: 2 additions & 2 deletions x/gov/client/utils/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func QueryVoteByTxQuery(
tags := []string{
fmt.Sprintf("%s='%s'", tags.Action, gov.MsgVote{}.Type()),
fmt.Sprintf("%s='%s'", tags.ProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
fmt.Sprintf("%s='%s'", tags.Voter, []byte(params.Voter.String())),
fmt.Sprintf("%s='%s'", tags.Sender, []byte(params.Voter.String())),
}

// NOTE: SearchTxs is used to facilitate the txs query which does not currently
Expand Down Expand Up @@ -172,7 +172,7 @@ func QueryDepositByTxQuery(
tags := []string{
fmt.Sprintf("%s='%s'", tags.Action, gov.MsgDeposit{}.Type()),
fmt.Sprintf("%s='%s'", tags.ProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
fmt.Sprintf("%s='%s'", tags.Depositor, []byte(params.Depositor.String())),
fmt.Sprintf("%s='%s'", tags.Sender, []byte(params.Depositor.String())),
}

// NOTE: SearchTxs is used to facilitate the txs query which does not currently
Expand Down
6 changes: 3 additions & 3 deletions x/gov/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func handleMsgSubmitProposal(ctx sdk.Context, keeper Keeper, msg MsgSubmitPropos
resTags := sdk.NewTags(
tags.ProposalID, proposalIDStr,
tags.Category, tags.TxCategory,
tags.Proposer, msg.Proposer.String(),
tags.Sender, msg.Proposer.String(),
)

if votingStarted {
Expand All @@ -73,7 +73,7 @@ func handleMsgDeposit(ctx sdk.Context, keeper Keeper, msg MsgDeposit) sdk.Result
resTags := sdk.NewTags(
tags.ProposalID, proposalIDStr,
tags.Category, tags.TxCategory,
tags.Depositor, msg.Depositor.String(),
tags.Sender, msg.Depositor.String(),
)

if votingStarted {
Expand All @@ -97,7 +97,7 @@ func handleMsgVote(ctx sdk.Context, keeper Keeper, msg MsgVote) sdk.Result {
Tags: sdk.NewTags(
tags.ProposalID, proposalIDStr,
tags.Category, tags.TxCategory,
tags.Voter, msg.Voter.String(),
tags.Sender, msg.Voter.String(),
),
}
}
4 changes: 1 addition & 3 deletions x/gov/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ var (

Action = sdk.TagAction
Category = sdk.TagCategory
Proposer = "proposer"
Sender = sdk.TagSender
ProposalID = "proposal-id"
VotingPeriodStart = "voting-period-start"
Depositor = "depositor"
Voter = "voter"
ProposalResult = "proposal-result"
)
2 changes: 1 addition & 1 deletion x/slashing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) sdk.Result {

tags := sdk.NewTags(
tags.Category, tags.TxCategory,
tags.Validator, msg.ValidatorAddr.String(),
tags.Sender, msg.ValidatorAddr.String(),
)

return sdk.Result{
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (
var (
TxCategory = "slashing"

Category = sdk.TagCategory
Validator = "validator"
Category = sdk.TagCategory
Sender = sdk.TagSender
)
2 changes: 1 addition & 1 deletion x/staking/client/rest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func queryTxs(cliCtx context.CLIContext, cdc *codec.Codec, tag string, delegator
limit := 100
tags := []string{
fmt.Sprintf("%s='%s'", tags.Action, tag),
fmt.Sprintf("%s='%s'", tags.Delegator, delegatorAddr),
fmt.Sprintf("%s='%s'", tags.Sender, delegatorAddr),
}

return tx.SearchTxs(cliCtx, cdc, tags, page, limit)
Expand Down
Loading

0 comments on commit 8550d87

Please sign in to comment.