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

Function ValidateAssetRequiredKeys

internal/info/fields_validators.go:15–51  ·  view source on GitHub ↗

Asset info specific validators.

(a AssetModel)

Source from the content-addressed store, hash-verified

13// Asset info specific validators.
14
15func ValidateAssetRequiredKeys(a AssetModel) error {
16 var fields []string
17 if a.Name != nil && !isEmpty(*a.Name) {
18 fields = append(fields, "name")
19 }
20 if a.Symbol != nil && !isEmpty(*a.Symbol) {
21 fields = append(fields, "symbol")
22 }
23 if a.Type != nil && !isEmpty(*a.Type) {
24 fields = append(fields, "type")
25 }
26 if a.Decimals != nil {
27 fields = append(fields, "decimals")
28 }
29 if a.Description != nil && !isEmpty(*a.Description) {
30 fields = append(fields, "description")
31 }
32 if a.Website != nil {
33 fields = append(fields, "website")
34 }
35 if a.Explorer != nil && !isEmpty(*a.Explorer) {
36 fields = append(fields, "explorer")
37 }
38 if a.Status != nil && !isEmpty(*a.Status) {
39 fields = append(fields, "status")
40 }
41 if a.ID != nil && !isEmpty(*a.ID) {
42 fields = append(fields, "id")
43 }
44
45 if len(fields) != len(requiredAssetFields) {
46 return fmt.Errorf("%w: %s", validation.ErrMissingField,
47 strings.Join(str.Difference(requiredAssetFields, fields), ", "))
48 }
49
50 return nil
51}
52
53func ValidateAssetType(assetType string, chain coin.Coin) error {
54 chainFromType, err := types.GetChainFromAssetType(assetType)

Callers 1

ValidateAssetFunction · 0.85

Calls 1

isEmptyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…