rpc, cli: remove invoke RPC-call

part of #1036
This commit is contained in:
Anna Shaleva 2020-06-10 11:31:01 +03:00
parent c044bdc731
commit 0af5b9339d
4 changed files with 10 additions and 137 deletions

View file

@ -132,23 +132,6 @@ func NewCommands() []cli.Command {
gasFlag,
},
},
{
Name: "invoke",
Usage: "invoke deployed contract on the blockchain",
UsageText: "neo-go contract invoke -e endpoint -w wallet [-a address] [-g gas] scripthash [arguments...]",
Description: `Executes given (as a script hash) deployed script with the given arguments.
See testinvoke documentation for the details about parameters. It differs
from testinvoke in that this command sends an invocation transaction to
the network.
`,
Action: invoke,
Flags: []cli.Flag{
endpointFlag,
walletFlag,
addressFlag,
gasFlag,
},
},
{
Name: "invokefunction",
Usage: "invoke deployed contract on the blockchain",
@ -166,26 +149,6 @@ func NewCommands() []cli.Command {
gasFlag,
},
},
{
Name: "testinvoke",
Usage: "invoke deployed contract on the blockchain (test mode)",
UsageText: "neo-go contract testinvoke -e endpoint scripthash [arguments...]",
Description: `Executes given (as a script hash) deployed script with the given arguments.
It's very similar to the tesinvokefunction command, but differs in the way
arguments are being passed. This invoker does not accept method parameter
and it passes all given parameters as plain values to the contract, not
wrapping them them into array like testinvokefunction does. For arguments
syntax please refer to the testinvokefunction command help.
Most of the time (if your contract follows the standard convention of
method with array of values parameters) you want to use testinvokefunction
command instead of testinvoke.
`,
Action: testInvoke,
Flags: []cli.Flag{
endpointFlag,
},
},
{
Name: "testinvokefunction",
Usage: "invoke deployed contract on the blockchain (test mode)",
@ -389,23 +352,15 @@ func contractCompile(ctx *cli.Context) error {
return nil
}
func testInvoke(ctx *cli.Context) error {
return invokeInternal(ctx, false, false)
}
func testInvokeFunction(ctx *cli.Context) error {
return invokeInternal(ctx, true, false)
}
func invoke(ctx *cli.Context) error {
return invokeInternal(ctx, false, true)
return invokeInternal(ctx, false)
}
func invokeFunction(ctx *cli.Context) error {
return invokeInternal(ctx, true, true)
return invokeInternal(ctx, true)
}
func invokeInternal(ctx *cli.Context, withMethod bool, signAndPush bool) error {
func invokeInternal(ctx *cli.Context, signAndPush bool) error {
var (
err error
gas util.Fixed8
@ -426,13 +381,13 @@ func invokeInternal(ctx *cli.Context, withMethod bool, signAndPush bool) error {
return cli.NewExitError(errNoScriptHash, 1)
}
script := args[0]
if withMethod {
if len(args) <= 1 {
return cli.NewExitError(errNoMethod, 1)
}
operation = args[1]
paramsStart++
if len(args) <= 1 {
return cli.NewExitError(errNoMethod, 1)
}
operation = args[1]
paramsStart++
if len(args) > paramsStart {
for k, s := range args[paramsStart:] {
param, err := smartcontract.NewParameterFromString(s)
@ -455,11 +410,7 @@ func invokeInternal(ctx *cli.Context, withMethod bool, signAndPush bool) error {
return cli.NewExitError(err, 1)
}
if withMethod {
resp, err = c.InvokeFunction(script, operation, params)
} else {
resp, err = c.Invoke(script, params)
}
resp, err = c.InvokeFunction(script, operation, params)
if err != nil {
return cli.NewExitError(err, 1)
}

View file

@ -363,19 +363,6 @@ func (c *Client) InvokeFunction(script, operation string, params []smartcontract
return resp, nil
}
// Invoke returns the results after calling the smart contract scripthash
// with the given parameters.
func (c *Client) Invoke(script string, params []smartcontract.Parameter) (*result.Invoke, error) {
var (
p = request.NewRawParams(script, params)
resp = &result.Invoke{}
)
if err := c.performRequest("invoke", p, resp); err != nil {
return nil, err
}
return resp, nil
}
// SendRawTransaction broadcasts a transaction over the NEO network.
// The given hex string needs to be signed with a keypair.
// When the result of the response object is true, the TX has successfully

View file

@ -98,7 +98,6 @@ var rpcHandlers = map[string]func(*Server, request.Params) (interface{}, *respon
"getunclaimedgas": (*Server).getUnclaimedGas,
"getvalidators": (*Server).getValidators,
"getversion": (*Server).getVersion,
"invoke": (*Server).invoke,
"invokefunction": (*Server).invokeFunction,
"invokescript": (*Server).invokescript,
"sendrawtransaction": (*Server).sendrawtransaction,
@ -855,31 +854,6 @@ func (s *Server) getValidators(_ request.Params) (interface{}, *response.Error)
return res, nil
}
// invoke implements the `invoke` RPC call.
func (s *Server) invoke(reqParams request.Params) (interface{}, *response.Error) {
scriptHashHex, ok := reqParams.ValueWithType(0, request.StringT)
if !ok {
return nil, response.ErrInvalidParams
}
scriptHash, err := scriptHashHex.GetUint160FromHex()
if err != nil {
return nil, response.ErrInvalidParams
}
sliceP, ok := reqParams.ValueWithType(1, request.ArrayT)
if !ok {
return nil, response.ErrInvalidParams
}
slice, err := sliceP.GetArray()
if err != nil {
return nil, response.ErrInvalidParams
}
script, err := request.CreateInvocationScript(scriptHash, slice)
if err != nil {
return nil, response.NewInternalServerError("can't create invocation script", err)
}
return s.runScriptInVM(script), nil
}
// invokescript implements the `invokescript` RPC call.
func (s *Server) invokeFunction(reqParams request.Params) (interface{}, *response.Error) {
scriptHashHex, ok := reqParams.ValueWithType(0, request.StringT)

View file

@ -573,45 +573,6 @@ var rpcTestCases = map[string][]rpcTestCase{
},
},
},
"invoke": {
{
name: "positive",
params: `["50befd26fdf6e4d957c11e078b24ebce6291456f", [{"type": "String", "value": "qwerty"}]]`,
result: func(e *executor) interface{} { return &result.Invoke{} },
check: func(t *testing.T, e *executor, inv interface{}) {
res, ok := inv.(*result.Invoke)
require.True(t, ok)
assert.Equal(t, "0c067177657274790c146f459162ceeb248b071ec157d9e4f6fd26fdbe5041627d5b52", res.Script)
assert.NotEqual(t, "", res.State)
assert.NotEqual(t, 0, res.GasConsumed)
},
},
{
name: "no params",
params: `[]`,
fail: true,
},
{
name: "not a string",
params: `[42, []]`,
fail: true,
},
{
name: "not a scripthash",
params: `["qwerty", []]`,
fail: true,
},
{
name: "not an array",
params: `["50befd26fdf6e4d957c11e078b24ebce6291456f", 42]`,
fail: true,
},
{
name: "bad params",
params: `["50befd26fdf6e4d957c11e078b24ebce6291456f", [{"type": "Integer", "value": "qwerty"}]]`,
fail: true,
},
},
"invokefunction": {
{
name: "positive",