forked from CosmWasm/wasmd
-
Notifications
You must be signed in to change notification settings - Fork 9
/
validation.go
48 lines (41 loc) · 1.31 KB
/
validation.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
package types
import (
sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
)
// MaxSaltSize is the longest salt that can be used when instantiating a contract
const MaxSaltSize = 64
var (
// MaxLabelSize is the longest label that can be used when instantiating a contract
MaxLabelSize = 128 // extension point for chains to customize via compile flag.
// MaxWasmSize is the largest a compiled contract code can be when storing code on chain
MaxWasmSize = 800 * 1024 // extension point for chains to customize via compile flag.
)
func validateWasmCode(s []byte) error {
if len(s) == 0 {
return sdkerrors.Wrap(ErrEmpty, "is required")
}
if len(s) > MaxWasmSize {
return sdkerrors.Wrapf(ErrLimit, "cannot be longer than %d bytes", MaxWasmSize)
}
return nil
}
// ValidateLabel ensure label constraints
func ValidateLabel(label string) error {
if label == "" {
return sdkerrors.Wrap(ErrEmpty, "is required")
}
if len(label) > MaxLabelSize {
return ErrLimit.Wrapf("cannot be longer than %d characters", MaxLabelSize)
}
return nil
}
// ValidateSalt ensure salt constraints
func ValidateSalt(salt []byte) error {
switch n := len(salt); {
case n == 0:
return sdkerrors.Wrap(ErrEmpty, "is required")
case n > MaxSaltSize:
return ErrLimit.Wrapf("cannot be longer than %d characters", MaxSaltSize)
}
return nil
}