2018-03-04 13:56:49 +00:00
|
|
|
package smartcontract
|
|
|
|
|
2018-04-15 16:56:18 +00:00
|
|
|
import "github.com/CityOfZion/neo-go/pkg/util"
|
2018-03-04 13:56:49 +00:00
|
|
|
|
|
|
|
// ParamType represent the Type of the contract parameter
|
2019-09-30 16:52:16 +00:00
|
|
|
type ParamType byte
|
2018-03-04 13:56:49 +00:00
|
|
|
|
|
|
|
// A list of supported smart contract parameter types.
|
|
|
|
const (
|
|
|
|
SignatureType ParamType = iota
|
|
|
|
BoolType
|
|
|
|
IntegerType
|
|
|
|
Hash160Type
|
|
|
|
Hash256Type
|
|
|
|
ByteArrayType
|
|
|
|
PublicKeyType
|
|
|
|
StringType
|
|
|
|
ArrayType
|
|
|
|
)
|
|
|
|
|
2019-10-10 14:56:58 +00:00
|
|
|
// PropertyState represents contract properties (flags).
|
|
|
|
type PropertyState byte
|
|
|
|
|
|
|
|
// List of supported properties.
|
|
|
|
const (
|
|
|
|
NoProperties = 0
|
|
|
|
HasStorage PropertyState = 1 << iota
|
|
|
|
HasDynamicInvoke
|
|
|
|
IsPayable
|
|
|
|
)
|
|
|
|
|
2018-03-04 13:56:49 +00:00
|
|
|
// Parameter represents a smart contract parameter.
|
|
|
|
type Parameter struct {
|
|
|
|
// Type of the parameter
|
2018-05-04 17:15:35 +00:00
|
|
|
Type ParamType `json:"type"`
|
2018-03-04 13:56:49 +00:00
|
|
|
// The actual value of the parameter.
|
2018-05-04 17:15:35 +00:00
|
|
|
Value interface{} `json:"value"`
|
2018-03-04 13:56:49 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 15:57:53 +00:00
|
|
|
func (pt ParamType) String() string {
|
2019-01-25 11:20:35 +00:00
|
|
|
switch pt {
|
|
|
|
case SignatureType:
|
|
|
|
return "Signature"
|
|
|
|
case BoolType:
|
|
|
|
return "Boolean"
|
|
|
|
case IntegerType:
|
|
|
|
return "Integer"
|
|
|
|
case Hash160Type:
|
|
|
|
return "Hash160"
|
|
|
|
case Hash256Type:
|
|
|
|
return "Hash256"
|
|
|
|
case ByteArrayType:
|
|
|
|
return "ByteArray"
|
|
|
|
case PublicKeyType:
|
|
|
|
return "PublicKey"
|
|
|
|
case StringType:
|
|
|
|
return "String"
|
|
|
|
case ArrayType:
|
|
|
|
return "Array"
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
2018-11-26 15:57:53 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// MarshalJSON implements the json.Marshaler interface.
|
2018-11-26 15:57:53 +00:00
|
|
|
func (pt ParamType) MarshalJSON() ([]byte, error) {
|
2019-01-25 11:20:35 +00:00
|
|
|
return []byte(`"` + pt.String() + `"`), nil
|
2018-11-26 15:57:53 +00:00
|
|
|
}
|
|
|
|
|
2018-03-04 13:56:49 +00:00
|
|
|
// NewParameter returns a Parameter with proper initialized Value
|
|
|
|
// of the given ParamType.
|
|
|
|
func NewParameter(t ParamType) Parameter {
|
|
|
|
return Parameter{
|
|
|
|
Type: t,
|
|
|
|
Value: nil,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContextItem represents a transaction context item.
|
|
|
|
type ContextItem struct {
|
|
|
|
Script util.Uint160
|
|
|
|
Parameters []Parameter
|
|
|
|
Signatures []Signature
|
|
|
|
}
|
|
|
|
|
|
|
|
// Signature represents a transaction signature.
|
|
|
|
type Signature struct {
|
|
|
|
Data []byte
|
|
|
|
PublicKey []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParameterContext holds the parameter context.
|
|
|
|
type ParameterContext struct{}
|