Skip to content

Commit a320c5e

Browse files
committed
Merge branch 'master' of github.com:desmos-labs/desmos into release/v2
� Conflicts: � CHANGELOG.md
2 parents b408d54 + aaf3cf6 commit a320c5e

File tree

3 files changed

+132
-7
lines changed

3 files changed

+132
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# ADR 009: Avoid accidental DTag override
2+
3+
## Changelog
4+
5+
- October 7th, 2021: Proposed
6+
- October 8th, 2021: First review
7+
- October 11th, 2021: Finalized ADR
8+
9+
## Status
10+
11+
PROPOSED
12+
13+
## Abstract
14+
15+
We SHOULD edit the behavior of the current `MsgSaveProfile` making the `DTag` an optional flag
16+
in order to prevent users from accidentally overriding their own DTags. In this way, users will edit
17+
their DTag only when they specify them with the flag.
18+
19+
## Context
20+
21+
Currently, the `desmos profile tx save` CLI command always requires to specify a DTag when using it. This means that
22+
users that do not want to edit their DTag need to specify it anyway. This could lead to the situation where a user
23+
accidentally makes a typo while inserting the DTag triggering its edit. If this happens, and the user doesn't notice it
24+
immediately, another user can register a profile with the now free DTag, stealing it from the original user.
25+
26+
## Decision
27+
28+
To avoid the situation described above, we need to perform some changes on the logic that handles a `MsgSaveProfile`.
29+
First, we need to edit the `desmos tx profiles save` CLI command so that the now required `dtag` field becomes
30+
an optional flag:
31+
```go
32+
func GetCmdSaveProfile() *cobra.Command {
33+
cmd := &cobra.Command{
34+
Use: "save",
35+
Args: cobra.NoArgs,
36+
Short: "Save your profile",
37+
Long: fmt.Sprintf(`
38+
Save a new profile or edit the existing one specifying a DTag, a nickname, biography, profile picture and cover picture.
39+
Every data given through the flags is optional.
40+
If you are editing an existing profile you should fill only the fields that you want to edit.
41+
The empty ones will be filled with a special [do-not-modify] flag that tells the system to not edit them.
42+
43+
%s tx profiles save
44+
--%s "LeoDiCaprio" \
45+
--%s "Leonardo Di Caprio" \
46+
--%s "Hollywood actor. Proud environmentalist" \
47+
--%s "https://profilePic.jpg" \
48+
--%s "https://profileCover.jpg"
49+
`, version.AppName, FlagDTag, FlagNickname, FlagBio, FlagProfilePic, FlagCoverPic),
50+
RunE: func(cmd *cobra.Command, args []string) error {
51+
clientCtx, err := client.GetClientTxContext(cmd)
52+
if err != nil {
53+
return err
54+
}
55+
56+
dTag, _ := cmd.Flags().GetString(FlagDTag)
57+
nickname, _ := cmd.Flags().GetString(FlagNickname)
58+
bio, _ := cmd.Flags().GetString(FlagBio)
59+
profilePic, _ := cmd.Flags().GetString(FlagProfilePic)
60+
coverPic, _ := cmd.Flags().GetString(FlagCoverPic)
61+
62+
msg := types.NewMsgSaveProfile(dTag, nickname, bio, profilePic, coverPic, clientCtx.FromAddress.String())
63+
if err = msg.ValidateBasic(); err != nil {
64+
return fmt.Errorf("message validation failed: %w", err)
65+
}
66+
67+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
68+
},
69+
}
70+
71+
cmd.Flags().String(FlagDTag, types.DoNotModify, "DTag to be used")
72+
cmd.Flags().String(FlagNickname, types.DoNotModify, "Nickname to be used")
73+
cmd.Flags().String(FlagBio, types.DoNotModify, "Biography to be used")
74+
cmd.Flags().String(FlagProfilePic, types.DoNotModify, "Profile picture")
75+
cmd.Flags().String(FlagCoverPic, types.DoNotModify, "Cover picture")
76+
77+
flags.AddTxFlagsToCmd(cmd)
78+
79+
return cmd
80+
}
81+
```
82+
Second, we need to remove the check on DTag inside `ValidateBasic()` that currently makes it impossible to specify an
83+
empty DTag inside a `MsgSaveProfile`:
84+
```go
85+
func (msg MsgSaveProfile) ValidateBasic() error {
86+
_, err := sdk.AccAddressFromBech32(msg.Creator)
87+
if err != nil {
88+
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, fmt.Sprintf("invalid creator: %s", msg.Creator))
89+
}
90+
return nil
91+
}
92+
```
93+
94+
## Consequences
95+
96+
### Backwards Compatibility
97+
98+
There are no backwards compatibility issues related to these changes.
99+
100+
### Positive
101+
102+
* Protect users from accidentally editing their DTag.
103+
104+
### Negative
105+
106+
- None known
107+
108+
### Neutral
109+
110+
- None known
111+
112+
## Further Discussions
113+
114+
## Test Cases [optional]
115+
116+
The following tests cases MUST to be present:
117+
1. Creating a profile with an empty DTag returns an error;
118+
2. Creating a profile with DTag `[do-not-modify]` returns an error;
119+
3. Updating a profile with a different DTag changes its value and returns no error;
120+
4. Updating a profile with DTag `[do-not-modify]` does not update its value and returns no error.
121+
122+
## References
123+
124+
- Issue [#622](https://github.com/desmos-labs/desmos/issues/622)

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ go 1.15
44

55
require (
66
github.com/armon/go-metrics v0.3.9
7-
github.com/cosmos/cosmos-sdk v0.44.0
7+
github.com/cosmos/cosmos-sdk v0.44.1
88
github.com/cosmos/go-bip39 v1.0.0
9-
github.com/cosmos/ibc-go v1.2.0
9+
github.com/cosmos/ibc-go v1.2.1
1010
github.com/desmos-labs/Go-Emoji-Utils v1.1.1-0.20210623064146-c30bc8196d0f
1111
github.com/ghodss/yaml v1.0.0
1212
github.com/gogo/protobuf v1.3.3
@@ -20,14 +20,14 @@ require (
2020
github.com/mr-tron/base58 v1.2.0
2121
github.com/rakyll/statik v0.1.7
2222
github.com/regen-network/cosmos-proto v0.3.1
23-
github.com/spf13/cast v1.3.1
23+
github.com/spf13/cast v1.4.1
2424
github.com/spf13/cobra v1.2.1
2525
github.com/stretchr/testify v1.7.0
2626
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 // indirect
2727
github.com/tendermint/tendermint v0.34.13
2828
github.com/tendermint/tm-db v0.6.4
2929
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c
30-
google.golang.org/grpc v1.40.0
30+
google.golang.org/grpc v1.41.0
3131
google.golang.org/protobuf v1.27.1
3232
gopkg.in/yaml.v2 v2.4.0
3333
)

go.sum

+4-3
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ github.com/cosmos/iavl v0.15.0-rc5/go.mod h1:WqoPL9yPTQ85QBMT45OOUzPxG/U/JcJoN7u
220220
github.com/cosmos/iavl v0.15.3/go.mod h1:OLjQiAQ4fGD2KDZooyJG9yz+p2ao2IAYSbke8mVvSA4=
221221
github.com/cosmos/iavl v0.17.1 h1:b/Cl8h1PRMvsu24+TYNlKchIu7W6tmxIBGe6E9u2Ybw=
222222
github.com/cosmos/iavl v0.17.1/go.mod h1:7aisPZK8yCpQdy3PMvKeO+bhq1NwDjUwjzxwwROUxFk=
223-
github.com/cosmos/ibc-go v1.2.0 h1:0RgxmKzCzIH9SwDp4ckL5VrzlO1KJ5hO0AsOAzOiWE4=
224-
github.com/cosmos/ibc-go v1.2.0/go.mod h1:wGjeNd+T4kpGrt0OC8DTiE/qXLrlmTPNpdoYsBZUjKI=
223+
github.com/cosmos/ibc-go v1.2.1 h1:eWi8EzcgSwVipvhyQ7Rh1KfBe66C1ZdDSskeKMtIg0Q=
224+
github.com/cosmos/ibc-go v1.2.1/go.mod h1:YieSs25Y0TSFR67qg6Elge34yJNEOjYhYB+HNQQLoSQ=
225225
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
226226
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8=
227227
github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI=
@@ -973,8 +973,9 @@ github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B
973973
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
974974
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
975975
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
976-
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
977976
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
977+
github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
978+
github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
978979
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
979980
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
980981
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=

0 commit comments

Comments
 (0)