Documentation ¶
Index ¶
Constants ¶
View Source
const (
// Separator represents the type separator
Separator = ":"
)
Variables ¶
View Source
var ( // DataCoin coin data type definition DataCoin = DataType{ DataType: func(string) string { return "sdk.Coin" }, DefaultTestValue: "10token", ProtoType: func(_, name string, index int) string { return fmt.Sprintf("cosmos.base.v1beta1.Coin %s = %d [(gogoproto.nullable) = false]", name, index) }, GenesisArgs: func(multiformatname.Name, int) string { return "" }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { return fmt.Sprintf(`%s%s, err := sdk.ParseCoinNormalized(args[%d]) if err != nil { return err }`, prefix, name.UpperCamel, argIndex) }, GoCLIImports: []GoImport{{Name: "github.com/cosmos/cosmos-sdk/types", Alias: "sdk"}}, ProtoImports: []string{"gogoproto/gogo.proto", "cosmos/base/v1beta1/coin.proto"}, NonIndex: true, } // DataCoinSlice coin array data type definition DataCoinSlice = DataType{ DataType: func(string) string { return "sdk.Coins" }, DefaultTestValue: "10token,20stake", ProtoType: func(_, name string, index int) string { return fmt.Sprintf("repeated cosmos.base.v1beta1.Coin %s = %d [(gogoproto.nullable) = false]", name, index) }, GenesisArgs: func(multiformatname.Name, int) string { return "" }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { return fmt.Sprintf(`%s%s, err := sdk.ParseCoinsNormalized(args[%d]) if err != nil { return err }`, prefix, name.UpperCamel, argIndex) }, GoCLIImports: []GoImport{{Name: "github.com/cosmos/cosmos-sdk/types", Alias: "sdk"}}, ProtoImports: []string{"gogoproto/gogo.proto", "cosmos/base/v1beta1/coin.proto"}, NonIndex: true, } )
View Source
var ( // DataInt int data type definition DataInt = DataType{ DataType: func(string) string { return "int32" }, DefaultTestValue: "111", ValueLoop: "int32(i)", ValueIndex: "0", ValueInvalidIndex: "100000", ProtoType: func(_, name string, index int) string { return fmt.Sprintf("int32 %s = %d", name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { return fmt.Sprintf("%s: %d,\n", name.UpperCamel, value) }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { return fmt.Sprintf(`%s%s, err := cast.ToInt32E(args[%d]) if err != nil { return err }`, prefix, name.UpperCamel, argIndex) }, ToBytes: func(name string) string { return fmt.Sprintf(`%[1]vBytes := make([]byte, 4) binary.BigEndian.PutUint32(%[1]vBytes, uint32(%[1]v))`, name) }, ToString: func(name string) string { return fmt.Sprintf("strconv.Itoa(int(%s))", name) }, GoCLIImports: []GoImport{{Name: "github.com/spf13/cast"}}, } // DataIntSlice int array data type definition DataIntSlice = DataType{ DataType: func(string) string { return "[]int32" }, DefaultTestValue: "1,2,3,4,5", ProtoType: func(_, name string, index int) string { return fmt.Sprintf("repeated int32 %s = %d", name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { return fmt.Sprintf("%s: []int32{%d},\n", name.UpperCamel, value) }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { return fmt.Sprintf(`%[1]vCast%[2]v := strings.Split(args[%[3]v], listSeparator) %[1]v%[2]v := make([]int32, len(%[1]vCast%[2]v)) for i, arg := range %[1]vCast%[2]v { value, err := cast.ToInt32E(arg) if err != nil { return err } %[1]v%[2]v[i] = value }`, prefix, name.UpperCamel, argIndex) }, GoCLIImports: []GoImport{{Name: "github.com/spf13/cast"}, {Name: "strings"}}, NonIndex: true, } )
View Source
var ( // DataString string data type definition DataString = DataType{ DataType: func(string) string { return "string" }, DefaultTestValue: "xyz", ValueLoop: "strconv.Itoa(i)", ValueIndex: "strconv.Itoa(0)", ValueInvalidIndex: "strconv.Itoa(100000)", ProtoType: func(_, name string, index int) string { return fmt.Sprintf("string %s = %d", name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { return fmt.Sprintf("%s: \"%d\",\n", name.UpperCamel, value) }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { return fmt.Sprintf("%s%s := args[%d]", prefix, name.UpperCamel, argIndex) }, ToBytes: func(name string) string { return fmt.Sprintf("%[1]vBytes := []byte(%[1]v)", name) }, ToString: func(name string) string { return name }, } // DataStringSlice string array data type definition DataStringSlice = DataType{ DataType: func(string) string { return "[]string" }, DefaultTestValue: "abc,xyz", ProtoType: func(_, name string, index int) string { return fmt.Sprintf("repeated string %s = %d", name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { return fmt.Sprintf("%s: []string{\"%d\"},\n", name.UpperCamel, value) }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { return fmt.Sprintf(`%[1]v%[2]v := strings.Split(args[%[3]v], listSeparator)`, prefix, name.UpperCamel, argIndex) }, GoCLIImports: []GoImport{{Name: "strings"}}, NonIndex: true, } )
View Source
var ( // DataUint uint data type definition DataUint = DataType{ DataType: func(string) string { return "uint64" }, DefaultTestValue: "111", ValueLoop: "uint64(i)", ValueIndex: "0", ValueInvalidIndex: "100000", ProtoType: func(_, name string, index int) string { return fmt.Sprintf("uint64 %s = %d", name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { return fmt.Sprintf("%s: %d,\n", name.UpperCamel, value) }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { return fmt.Sprintf(`%s%s, err := cast.ToUint64E(args[%d]) if err != nil { return err }`, prefix, name.UpperCamel, argIndex) }, ToBytes: func(name string) string { return fmt.Sprintf(`%[1]vBytes := make([]byte, 8) binary.BigEndian.PutUint64(%[1]vBytes, %[1]v)`, name) }, ToString: func(name string) string { return fmt.Sprintf("strconv.Itoa(int(%s))", name) }, GoCLIImports: []GoImport{{Name: "github.com/spf13/cast"}}, } // DataUintSlice uint array data type definition DataUintSlice = DataType{ DataType: func(string) string { return "[]uint64" }, DefaultTestValue: "1,2,3,4,5", ProtoType: func(_, name string, index int) string { return fmt.Sprintf("repeated uint64 %s = %d", name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { return fmt.Sprintf("%s: []uint64{%d},\n", name.UpperCamel, value) }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { return fmt.Sprintf(`%[1]vCast%[2]v := strings.Split(args[%[3]v], listSeparator) %[1]v%[2]v := make([]uint64, len(%[1]vCast%[2]v)) for i, arg := range %[1]vCast%[2]v { value, err := cast.ToUint64E(arg) if err != nil { return err } %[1]v%[2]v[i] = value }`, prefix, name.UpperCamel, argIndex) }, GoCLIImports: []GoImport{{Name: "github.com/spf13/cast"}, {Name: "strings"}}, NonIndex: true, } )
View Source
var ( // DataBool bool data type definition DataBool = DataType{ DataType: func(string) string { return "bool" }, DefaultTestValue: "false", ValueLoop: "false", ValueIndex: "false", ValueInvalidIndex: "false", ProtoType: func(_, name string, index int) string { return fmt.Sprintf("bool %s = %d", name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { return fmt.Sprintf("%s: %t,\n", name.UpperCamel, value%2 == 0) }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { return fmt.Sprintf(`%s%s, err := cast.ToBoolE(args[%d]) if err != nil { return err }`, prefix, name.UpperCamel, argIndex) }, ToBytes: func(name string) string { return fmt.Sprintf(`%[1]vBytes := []byte{0} if %[1]v { %[1]vBytes = []byte{1} }`, name) }, ToString: func(name string) string { return fmt.Sprintf("strconv.FormatBool(%s)", name) }, GoCLIImports: []GoImport{{Name: "github.com/spf13/cast"}}, } )
View Source
var ( // DataCustom custom data type definition DataCustom = DataType{ DataType: func(datatype string) string { return fmt.Sprintf("*%s", datatype) }, DefaultTestValue: "null", ProtoType: func(datatype, name string, index int) string { return fmt.Sprintf("%s %s = %d", datatype, name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { return fmt.Sprintf("%s: new(types.%s),\n", name.UpperCamel, name.UpperCamel) }, CLIArgs: func(name multiformatname.Name, datatype, prefix string, argIndex int) string { return fmt.Sprintf(`%[1]v%[2]v := new(types.%[3]v) err = json.Unmarshal([]byte(args[%[4]v]), %[1]v%[2]v) if err != nil { return err }`, prefix, name.UpperCamel, datatype, argIndex) }, GoCLIImports: []GoImport{{Name: "encoding/json"}}, NonIndex: true, } )
View Source
var SupportedTypes = map[Name]DataType{ String: DataString, StringSlice: DataStringSlice, StringSliceAlias: DataStringSlice, Bool: DataBool, Int: DataInt, IntSlice: DataIntSlice, IntSliceAlias: DataIntSlice, Uint: DataUint, UintSlice: DataUintSlice, UintSliceAlias: DataUintSlice, Coin: DataCoin, Coins: DataCoinSlice, CoinSliceAlias: DataCoinSlice, Custom: DataCustom, }
SupportedTypes all support data types and definitions
Functions ¶
This section is empty.
Types ¶
type DataType ¶
type DataType struct { DataType func(datatype string) string ProtoType func(datatype, name string, index int) string GenesisArgs func(name multiformatname.Name, value int) string ProtoImports []string GoCLIImports []GoImport DefaultTestValue string ValueLoop string ValueIndex string ValueInvalidIndex string ToBytes func(name string) string ToString func(name string) string CLIArgs func(name multiformatname.Name, datatype, prefix string, argIndex int) string NonIndex bool }
DataType represents the data types for code replacement
type Name ¶
type Name string
Name represents the Alias Name for the data type
const ( // String represents the string type name String Name = "string" // StringSlice represents the string array type name StringSlice Name = "array.string" // Bool represents the bool type name Bool Name = "bool" // Int represents the int type name Int Name = "int" // IntSlice represents the int array type name IntSlice Name = "array.int" // Uint represents the uint type name Uint Name = "uint" // UintSlice represents the uint array type name UintSlice Name = "array.uint" // Coin represents the coin type name Coin Name = "coin" // Coins represents the coin array type name Coins Name = "array.coin" // Custom represents the custom type name Custom Name = Name(TypeCustom) // StringSliceAlias represents the string array type name alias StringSliceAlias Name = "strings" // IntSliceAlias represents the int array type name alias IntSliceAlias Name = "ints" // UintSliceAlias represents the uint array type name alias UintSliceAlias Name = "uints" // CoinSliceAlias represents the coin array type name alias CoinSliceAlias Name = "coins" // TypeCustom represents the string type name id TypeCustom = "customstarporttype" )
Click to show internal directories.
Click to hide internal directories.