(ctx *cli.Context)
| 193 | } |
| 194 | |
| 195 | func invokeCodeContract(ctx *cli.Context) error { |
| 196 | SetRpcPort(ctx) |
| 197 | if !ctx.IsSet(utils.GetFlagName(utils.ContractCodeFileFlag)) { |
| 198 | PrintErrorMsg("Missing %s or %s argument.", utils.ContractCodeFileFlag.Name, utils.ContractNameFlag.Name) |
| 199 | cli.ShowSubcommandHelp(ctx) |
| 200 | return nil |
| 201 | } |
| 202 | |
| 203 | codeFile := ctx.String(utils.GetFlagName(utils.ContractCodeFileFlag)) |
| 204 | if "" == codeFile { |
| 205 | return fmt.Errorf("please specific code file") |
| 206 | } |
| 207 | codeStr, err := ioutil.ReadFile(codeFile) |
| 208 | if err != nil { |
| 209 | return fmt.Errorf("read code:%s error:%s", codeFile, err) |
| 210 | } |
| 211 | code := strings.TrimSpace(string(codeStr)) |
| 212 | c, err := common.HexToBytes(code) |
| 213 | if err != nil { |
| 214 | return fmt.Errorf("contrace code convert hex to bytes error:%s", err) |
| 215 | } |
| 216 | |
| 217 | if ctx.IsSet(utils.GetFlagName(utils.ContractPrepareInvokeFlag)) { |
| 218 | preResult, err := utils.PrepareInvokeCodeNeoVMContract(c) |
| 219 | if err != nil { |
| 220 | return fmt.Errorf("PrepareInvokeCodeNeoVMContract error:%s", err) |
| 221 | } |
| 222 | if preResult.State == 0 { |
| 223 | return fmt.Errorf("contract pre-invoke failed") |
| 224 | } |
| 225 | PrintInfoMsg("Contract pre-invoke successfully") |
| 226 | PrintInfoMsg(" Gas limit:%d", preResult.Gas) |
| 227 | |
| 228 | rawReturnTypes := ctx.String(utils.GetFlagName(utils.ContractReturnTypeFlag)) |
| 229 | if rawReturnTypes == "" { |
| 230 | PrintInfoMsg("Return:%s (raw value)", preResult.Result) |
| 231 | return nil |
| 232 | } |
| 233 | values, err := utils.ParseReturnValue(preResult.Result, rawReturnTypes, payload.NEOVM_TYPE) |
| 234 | if err != nil { |
| 235 | return fmt.Errorf("parseReturnValue values:%+v types:%s error:%s", values, rawReturnTypes, err) |
| 236 | } |
| 237 | switch len(values) { |
| 238 | case 0: |
| 239 | PrintInfoMsg("Return: nil") |
| 240 | case 1: |
| 241 | PrintInfoMsg("Return:%+v", values[0]) |
| 242 | default: |
| 243 | PrintInfoMsg("Return:%+v", values) |
| 244 | } |
| 245 | return nil |
| 246 | } |
| 247 | gasPrice := ctx.Uint64(utils.GetFlagName(utils.TransactionGasPriceFlag)) |
| 248 | gasLimit := ctx.Uint64(utils.GetFlagName(utils.TransactionGasLimitFlag)) |
| 249 | networkId, err := utils.GetNetworkId() |
| 250 | if err != nil { |
| 251 | return err |
| 252 | } |
nothing calls this directly
no test coverage detected