-
Notifications
You must be signed in to change notification settings - Fork 340
/
description.go
74 lines (59 loc) · 2.27 KB
/
description.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package types
import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// constant for maximum string length of the Description fields
const (
MaxMonikerLength = 70
MaxIdentityLength = 3000
MaxWebsiteLength = 140
MaxSecurityContactLength = 140
MaxDetailsLength = 280
)
// DoNotModifyDesc constant is used in flags to indicate that description field should not be updated
const DoNotModifyDesc = "[do-not-modify]"
// UpdateDescription updates the fields of a given description. An error is
// returned if the resulting description contains an invalid length.
func (d Description) UpdateDescription(d2 Description) (Description, error) {
if d2.Moniker == DoNotModifyDesc {
d2.Moniker = d.Moniker
}
if d2.Identity == DoNotModifyDesc {
d2.Identity = d.Identity
}
if d2.Website == DoNotModifyDesc {
d2.Website = d.Website
}
if d2.SecurityContact == DoNotModifyDesc {
d2.SecurityContact = d.SecurityContact
}
if d2.Details == DoNotModifyDesc {
d2.Details = d.Details
}
return Description{
Moniker: d2.Moniker,
Identity: d2.Identity,
Website: d2.Website,
SecurityContact: d2.SecurityContact,
Details: d2.Details,
}.EnsureLength()
}
// EnsureLength ensures the length of a sequencer's description.
func (d Description) EnsureLength() (Description, error) {
if len(d.Moniker) > MaxMonikerLength {
return d, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid moniker length; got: %d, max: %d", len(d.Moniker), MaxMonikerLength)
}
if len(d.Identity) > MaxIdentityLength {
return d, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid identity length; got: %d, max: %d", len(d.Identity), MaxIdentityLength)
}
if len(d.Website) > MaxWebsiteLength {
return d, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid website length; got: %d, max: %d", len(d.Website), MaxWebsiteLength)
}
if len(d.SecurityContact) > MaxSecurityContactLength {
return d, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid security contact length; got: %d, max: %d", len(d.SecurityContact), MaxSecurityContactLength)
}
if len(d.Details) > MaxDetailsLength {
return d, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid details length; got: %d, max: %d", len(d.Details), MaxDetailsLength)
}
return d, nil
}