mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 19:29:39 +00:00
cli: return numWordsRead from GetDataFromContext
It's needed when we have extra args after the 'data' argument. Then these args are started right from numWordsRead offset.
This commit is contained in:
parent
2ab420ed18
commit
d12ae0998f
2 changed files with 14 additions and 9 deletions
|
@ -828,7 +828,7 @@ func contractDeploy(ctx *cli.Context) error {
|
||||||
return cli.NewExitError(fmt.Errorf("failed to restore manifest file: %w", err), 1)
|
return cli.NewExitError(fmt.Errorf("failed to restore manifest file: %w", err), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
data, extErr := GetDataFromContext(ctx)
|
_, data, extErr := GetDataFromContext(ctx)
|
||||||
if extErr != nil {
|
if extErr != nil {
|
||||||
return extErr
|
return extErr
|
||||||
}
|
}
|
||||||
|
@ -889,23 +889,28 @@ func contractDeploy(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDataFromContext returns data parameter from context args.
|
// GetDataFromContext returns data parameter from context args.
|
||||||
func GetDataFromContext(ctx *cli.Context) (interface{}, *cli.ExitError) {
|
func GetDataFromContext(ctx *cli.Context) (int, interface{}, *cli.ExitError) {
|
||||||
var data interface{}
|
var (
|
||||||
|
data interface{}
|
||||||
|
offset int
|
||||||
|
params []smartcontract.Parameter
|
||||||
|
err error
|
||||||
|
)
|
||||||
args := ctx.Args()
|
args := ctx.Args()
|
||||||
if args.Present() {
|
if args.Present() {
|
||||||
_, params, err := ParseParams(args, true)
|
offset, params, err = ParseParams(args, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cli.NewExitError(fmt.Errorf("unable to parse 'data' parameter: %w", err), 1)
|
return offset, nil, cli.NewExitError(fmt.Errorf("unable to parse 'data' parameter: %w", err), 1)
|
||||||
}
|
}
|
||||||
if len(params) != 1 {
|
if len(params) != 1 {
|
||||||
return nil, cli.NewExitError("'data' should be represented as a single parameter", 1)
|
return offset, nil, cli.NewExitError("'data' should be represented as a single parameter", 1)
|
||||||
}
|
}
|
||||||
data, err = smartcontract.ExpandParameterToEmitable(params[0])
|
data, err = smartcontract.ExpandParameterToEmitable(params[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cli.NewExitError(fmt.Sprintf("failed to convert 'data' to emitable type: %s", err.Error()), 1)
|
return offset, nil, cli.NewExitError(fmt.Sprintf("failed to convert 'data' to emitable type: %s", err.Error()), 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data, nil
|
return offset, data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseContractConfig reads contract configuration file (.yaml) and returns unmarshalled ProjectConfig.
|
// ParseContractConfig reads contract configuration file (.yaml) and returns unmarshalled ProjectConfig.
|
||||||
|
|
|
@ -461,7 +461,7 @@ func transferNEP17(ctx *cli.Context) error {
|
||||||
return cli.NewExitError(fmt.Errorf("invalid amount: %w", err), 1)
|
return cli.NewExitError(fmt.Errorf("invalid amount: %w", err), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
data, extErr := smartcontractcli.GetDataFromContext(ctx)
|
_, data, extErr := smartcontractcli.GetDataFromContext(ctx)
|
||||||
if extErr != nil {
|
if extErr != nil {
|
||||||
return extErr
|
return extErr
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue