MCPcopy
hub / github.com/trustwallet/assets / ValidateLinks

Function ValidateLinks

internal/info/fields_validators.go:127–162  ·  view source on GitHub ↗
(links []Link)

Source from the content-addressed store, hash-verified

125}
126
127func ValidateLinks(links []Link) error {
128 if len(links) < 2 {
129 return nil
130 }
131
132 for _, l := range links {
133 if l.Name == nil || l.URL == nil {
134 return fmt.Errorf("%w: missing required fields links.url and links.name", validation.ErrMissingField)
135 }
136
137 if !linkNameAllowed(*l.Name) {
138 return fmt.Errorf("invalid value for links.name filed, allowed only: %s",
139 strings.Join(supportedLinkNames(), ", "))
140 }
141
142 prefix := allowedLinkKeys[*l.Name]
143 if prefix != "" {
144 if !strings.HasPrefix(*l.URL, prefix) {
145 return fmt.Errorf("invalid value '%s' for %s link url, allowed only with prefix: %s",
146 *l.URL, *l.Name, prefix)
147 }
148 }
149
150 if !strings.HasPrefix(*l.URL, "https://") {
151 return fmt.Errorf("invalid value for links.url field, allowed only with https:// prefix")
152 }
153
154 if *l.Name == "medium" {
155 if !strings.Contains(*l.URL, "medium.com") {
156 return fmt.Errorf("invalid value for links.url field, should contain medium.com")
157 }
158 }
159 }
160
161 return nil
162}
163
164func ValidateCoinType(assetType string) error {
165 if assetType != "coin" {

Callers 2

ValidateAssetFunction · 0.85
ValidateCoinFunction · 0.85

Calls 2

linkNameAllowedFunction · 0.85
supportedLinkNamesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…