RPC invocation parameters (#106)

* added rpc.invoke and parameters marshalling

* removed debug output

* stringer and marshalling corrections

* version
This commit is contained in:
aprasolova 2018-11-26 18:57:53 +03:00 committed by Anthony De Meulemeester
parent 6ccb518ab0
commit de45c58551
2 changed files with 42 additions and 0 deletions

View file

@ -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 (

View file

@ -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 {