x/wasm/types compiles
This commit is contained in:
@@ -97,13 +97,6 @@ func (p StoreCodeProposal) ValidateBasic() error {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error())
|
||||
}
|
||||
|
||||
if err := validateSourceURL(p.Source); err != nil {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "source %s", err.Error())
|
||||
}
|
||||
|
||||
if err := validateBuilder(p.Builder); err != nil {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "builder %s", err.Error())
|
||||
}
|
||||
if p.InstantiatePermission != nil {
|
||||
if err := p.InstantiatePermission.ValidateBasic(); err != nil {
|
||||
return sdkerrors.Wrap(err, "instantiate permission")
|
||||
@@ -119,9 +112,7 @@ func (p StoreCodeProposal) String() string {
|
||||
Description: %s
|
||||
Run as: %s
|
||||
WasmCode: %X
|
||||
Source: %s
|
||||
Builder: %s
|
||||
`, p.Title, p.Description, p.RunAs, p.WASMByteCode, p.Source, p.Builder)
|
||||
`, p.Title, p.Description, p.RunAs, p.WASMByteCode)
|
||||
}
|
||||
|
||||
// MarshalYAML pretty prints the wasm byte code
|
||||
@@ -131,16 +122,12 @@ func (p StoreCodeProposal) MarshalYAML() (interface{}, error) {
|
||||
Description string `yaml:"description"`
|
||||
RunAs string `yaml:"run_as"`
|
||||
WASMByteCode string `yaml:"wasm_byte_code"`
|
||||
Source string `yaml:"source"`
|
||||
Builder string `yaml:"builder"`
|
||||
InstantiatePermission *AccessConfig `yaml:"instantiate_permission"`
|
||||
}{
|
||||
Title: p.Title,
|
||||
Description: p.Description,
|
||||
RunAs: p.RunAs,
|
||||
WASMByteCode: base64.StdEncoding.EncodeToString(p.WASMByteCode),
|
||||
Source: p.Source,
|
||||
Builder: p.Builder,
|
||||
InstantiatePermission: p.InstantiatePermission,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -74,8 +74,6 @@ func CodeInfoFixture(mutators ...func(*CodeInfo)) CodeInfo {
|
||||
fixture := CodeInfo{
|
||||
CodeHash: codeHash[:],
|
||||
Creator: anyAddress,
|
||||
Source: "https://example.com",
|
||||
Builder: "my/builder:tag",
|
||||
InstantiateConfig: AllowEverybody,
|
||||
}
|
||||
for _, m := range mutators {
|
||||
@@ -132,8 +130,6 @@ func MsgStoreCodeFixture(mutators ...func(*MsgStoreCode)) *MsgStoreCode {
|
||||
r := &MsgStoreCode{
|
||||
Sender: anyAddress,
|
||||
WASMByteCode: wasmIdent,
|
||||
Source: "https://example.com/code",
|
||||
Builder: "foo/bar:latest",
|
||||
InstantiatePermission: &AllowEverybody,
|
||||
}
|
||||
for _, m := range mutators {
|
||||
@@ -188,8 +184,6 @@ func StoreCodeProposalFixture(mutators ...func(*StoreCodeProposal)) *StoreCodePr
|
||||
Description: "Bar",
|
||||
RunAs: anyAddress,
|
||||
WASMByteCode: []byte{0x0},
|
||||
Source: "https://example.com/code",
|
||||
Builder: "foo/bar:latest",
|
||||
}
|
||||
for _, m := range mutators {
|
||||
m(p)
|
||||
|
||||
@@ -25,13 +25,6 @@ func (msg MsgStoreCode) ValidateBasic() error {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error())
|
||||
}
|
||||
|
||||
if err := validateSourceURL(msg.Source); err != nil {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "source %s", err.Error())
|
||||
}
|
||||
|
||||
if err := validateBuilder(msg.Builder); err != nil {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "builder %s", err.Error())
|
||||
}
|
||||
if msg.InstantiatePermission != nil {
|
||||
if err := msg.InstantiatePermission.ValidateBasic(); err != nil {
|
||||
return sdkerrors.Wrap(err, "instantiate permission")
|
||||
|
||||
@@ -30,25 +30,17 @@ func (c CodeInfo) ValidateBasic() error {
|
||||
if _, err := sdk.AccAddressFromBech32(c.Creator); err != nil {
|
||||
return sdkerrors.Wrap(err, "creator")
|
||||
}
|
||||
if err := validateSourceURL(c.Source); err != nil {
|
||||
return sdkerrors.Wrap(err, "source")
|
||||
}
|
||||
if err := validateBuilder(c.Builder); err != nil {
|
||||
return sdkerrors.Wrap(err, "builder")
|
||||
}
|
||||
if err := c.InstantiateConfig.ValidateBasic(); err != nil {
|
||||
return sdkerrors.Wrap(err, "instantiate config")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewCodeInfo fills a new Contract struct
|
||||
func NewCodeInfo(codeHash []byte, creator sdk.AccAddress, source string, builder string, instantiatePermission AccessConfig) CodeInfo {
|
||||
// NewCodeInfo fills a new CodeInfo struct
|
||||
func NewCodeInfo(codeHash []byte, creator sdk.AccAddress, instantiatePermission AccessConfig) CodeInfo {
|
||||
return CodeInfo{
|
||||
CodeHash: codeHash,
|
||||
Creator: creator.String(),
|
||||
Source: source,
|
||||
Builder: builder,
|
||||
InstantiateConfig: instantiatePermission,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"regexp"
|
||||
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
@@ -12,53 +9,8 @@ const (
|
||||
|
||||
// MaxLabelSize is the longest label that can be used when Instantiating a contract
|
||||
MaxLabelSize = 128
|
||||
|
||||
// BuildTagRegexp is a docker image regexp.
|
||||
// We only support max 128 characters, with at least one organization name (subset of all legal names).
|
||||
//
|
||||
// Details from https://docs.docker.com/engine/reference/commandline/tag/#extended-description :
|
||||
//
|
||||
// An image name is made up of slash-separated name components (optionally prefixed by a registry hostname).
|
||||
// Name components may contain lowercase characters, digits and separators.
|
||||
// A separator is defined as a period, one or two underscores, or one or more dashes. A name component may not start or end with a separator.
|
||||
//
|
||||
// A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes.
|
||||
// A tag name may not start with a period or a dash and may contain a maximum of 128 characters.
|
||||
BuildTagRegexp = "^[a-z0-9][a-z0-9._-]*[a-z0-9](/[a-z0-9][a-z0-9._-]*[a-z0-9])+:[a-zA-Z0-9_][a-zA-Z0-9_.-]*$"
|
||||
|
||||
MaxBuildTagSize = 128
|
||||
)
|
||||
|
||||
func validateSourceURL(source string) error {
|
||||
if source != "" {
|
||||
u, err := url.Parse(source)
|
||||
if err != nil {
|
||||
return sdkerrors.Wrap(ErrInvalid, "not an url")
|
||||
}
|
||||
if !u.IsAbs() {
|
||||
return sdkerrors.Wrap(ErrInvalid, "not an absolute url")
|
||||
}
|
||||
if u.Scheme != "https" {
|
||||
return sdkerrors.Wrap(ErrInvalid, "must use https")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateBuilder(buildTag string) error {
|
||||
if len(buildTag) > MaxBuildTagSize {
|
||||
return sdkerrors.Wrap(ErrLimit, "longer than 128 characters")
|
||||
}
|
||||
|
||||
if buildTag != "" {
|
||||
ok, err := regexp.MatchString(BuildTagRegexp, buildTag)
|
||||
if err != nil || !ok {
|
||||
return ErrInvalid
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateWasmCode(s []byte) error {
|
||||
if len(s) == 0 {
|
||||
return sdkerrors.Wrap(ErrEmpty, "is required")
|
||||
|
||||
Reference in New Issue
Block a user