diff --git a/pkg/rpc/rpc.go b/pkg/rpc/rpc.go index a4d7f32e2..0c336c8b1 100644 --- a/pkg/rpc/rpc.go +++ b/pkg/rpc/rpc.go @@ -57,6 +57,19 @@ func (c *Client) InvokeFunction(script, operation string, params []smartcontract return resp, nil } +// InvokeFunction return the results after calling a the smart contract scripthash +// with the given parameters. +func (c *Client) Invoke(script string, params []smartcontract.Parameter) (*InvokeScriptResponse, error) { + var ( + p = newParams(script, params) + resp = &InvokeScriptResponse{} + ) + if err := c.performRequest("invoke", p, resp); err != nil { + return nil, err + } + return resp, nil +} + // GetRawTransaction queries a transaction by hash. func (c *Client) GetRawTransaction(hash string, verbose bool) (*response, error) { var ( diff --git a/pkg/smartcontract/param_context.go b/pkg/smartcontract/param_context.go index 4344d9644..c8c2504b2 100644 --- a/pkg/smartcontract/param_context.go +++ b/pkg/smartcontract/param_context.go @@ -26,6 +26,35 @@ type Parameter struct { Value interface{} `json:"value"` } +func (pt ParamType) String() string { + 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 "" + } +} + +func (pt ParamType) MarshalJSON() ([]byte, error) { + return []byte(`"` + pt.String() + `"`), nil +} + // NewParameter returns a Parameter with proper initialized Value // of the given ParamType. func NewParameter(t ParamType) Parameter {