github.com/uuosio/chaintester@v0.0.0-20230731100329-1f6fad7372e5/interfaces/i_p_c_chain_tester-remote/i_p_c_chain_tester-remote.go (about) 1 // Code generated by Thrift Compiler (0.15.0). DO NOT EDIT. 2 3 package main 4 5 import ( 6 "context" 7 "flag" 8 "fmt" 9 "math" 10 "net" 11 "net/url" 12 "os" 13 "strconv" 14 "strings" 15 thrift "github.com/apache/thrift/lib/go/thrift" 16 "interfaces" 17 ) 18 19 var _ = interfaces.GoUnusedProtection__ 20 21 func Usage() { 22 fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") 23 flag.PrintDefaults() 24 fmt.Fprintln(os.Stderr, "\nFunctions:") 25 fmt.Fprintln(os.Stderr, " void init_vm_api()") 26 fmt.Fprintln(os.Stderr, " void init_apply_request()") 27 fmt.Fprintln(os.Stderr, " bool set_native_contract(i32 id, string contract, string dylib)") 28 fmt.Fprintln(os.Stderr, " void enable_debugging(bool enable)") 29 fmt.Fprintln(os.Stderr, " void enable_debug_contract(i32 id, string contract, bool enable)") 30 fmt.Fprintln(os.Stderr, " bool is_debug_contract_enabled(i32 id, string contract)") 31 fmt.Fprintln(os.Stderr, " string pack_abi(string abi)") 32 fmt.Fprintln(os.Stderr, " string pack_action_args(i32 id, string contract, string action, string action_args)") 33 fmt.Fprintln(os.Stderr, " string unpack_action_args(i32 id, string contract, string action, string raw_args)") 34 fmt.Fprintln(os.Stderr, " i32 new_chain(bool initialize)") 35 fmt.Fprintln(os.Stderr, " i32 free_chain(i32 id)") 36 fmt.Fprintln(os.Stderr, " string get_info(i32 id)") 37 fmt.Fprintln(os.Stderr, " string create_key(string key_type)") 38 fmt.Fprintln(os.Stderr, " string get_account(i32 id, string account)") 39 fmt.Fprintln(os.Stderr, " string create_account(i32 id, string creator, string account, string owner_key, string active_key, i64 ram_bytes, i64 stake_net, i64 stake_cpu)") 40 fmt.Fprintln(os.Stderr, " bool import_key(i32 id, string pub_key, string priv_key)") 41 fmt.Fprintln(os.Stderr, " string get_required_keys(i32 id, string transaction, available_keys)") 42 fmt.Fprintln(os.Stderr, " void produce_block(i32 id, i64 next_block_skip_seconds)") 43 fmt.Fprintln(os.Stderr, " string push_action(i32 id, string account, string action, ActionArguments arguments, string permissions)") 44 fmt.Fprintln(os.Stderr, " string push_actions(i32 id, actions)") 45 fmt.Fprintln(os.Stderr, " string deploy_contract(i32 id, string account, string wasm, string abi)") 46 fmt.Fprintln(os.Stderr, " string get_table_rows(i32 id, bool json, string code, string scope, string table, string lower_bound, string upper_bound, i64 limit, string key_type, string index_position, string encode_type, bool reverse, bool show_payer)") 47 fmt.Fprintln(os.Stderr) 48 os.Exit(0) 49 } 50 51 type httpHeaders map[string]string 52 53 func (h httpHeaders) String() string { 54 var m map[string]string = h 55 return fmt.Sprintf("%s", m) 56 } 57 58 func (h httpHeaders) Set(value string) error { 59 parts := strings.Split(value, ": ") 60 if len(parts) != 2 { 61 return fmt.Errorf("header should be of format 'Key: Value'") 62 } 63 h[parts[0]] = parts[1] 64 return nil 65 } 66 67 func main() { 68 flag.Usage = Usage 69 var host string 70 var port int 71 var protocol string 72 var urlString string 73 var framed bool 74 var useHttp bool 75 headers := make(httpHeaders) 76 var parsedUrl *url.URL 77 var trans thrift.TTransport 78 _ = strconv.Atoi 79 _ = math.Abs 80 flag.Usage = Usage 81 flag.StringVar(&host, "h", "localhost", "Specify host and port") 82 flag.IntVar(&port, "p", 9090, "Specify port") 83 flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") 84 flag.StringVar(&urlString, "u", "", "Specify the url") 85 flag.BoolVar(&framed, "framed", false, "Use framed transport") 86 flag.BoolVar(&useHttp, "http", false, "Use http") 87 flag.Var(headers, "H", "Headers to set on the http(s) request (e.g. -H \"Key: Value\")") 88 flag.Parse() 89 90 if len(urlString) > 0 { 91 var err error 92 parsedUrl, err = url.Parse(urlString) 93 if err != nil { 94 fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) 95 flag.Usage() 96 } 97 host = parsedUrl.Host 98 useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" || parsedUrl.Scheme == "https" 99 } else if useHttp { 100 _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) 101 if err != nil { 102 fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) 103 flag.Usage() 104 } 105 } 106 107 cmd := flag.Arg(0) 108 var err error 109 var cfg *thrift.TConfiguration = nil 110 if useHttp { 111 trans, err = thrift.NewTHttpClient(parsedUrl.String()) 112 if len(headers) > 0 { 113 httptrans := trans.(*thrift.THttpClient) 114 for key, value := range headers { 115 httptrans.SetHeader(key, value) 116 } 117 } 118 } else { 119 portStr := fmt.Sprint(port) 120 if strings.Contains(host, ":") { 121 host, portStr, err = net.SplitHostPort(host) 122 if err != nil { 123 fmt.Fprintln(os.Stderr, "error with host:", err) 124 os.Exit(1) 125 } 126 } 127 trans = thrift.NewTSocketConf(net.JoinHostPort(host, portStr), cfg) 128 if err != nil { 129 fmt.Fprintln(os.Stderr, "error resolving address:", err) 130 os.Exit(1) 131 } 132 if framed { 133 trans = thrift.NewTFramedTransportConf(trans, cfg) 134 } 135 } 136 if err != nil { 137 fmt.Fprintln(os.Stderr, "Error creating transport", err) 138 os.Exit(1) 139 } 140 defer trans.Close() 141 var protocolFactory thrift.TProtocolFactory 142 switch protocol { 143 case "compact": 144 protocolFactory = thrift.NewTCompactProtocolFactoryConf(cfg) 145 break 146 case "simplejson": 147 protocolFactory = thrift.NewTSimpleJSONProtocolFactoryConf(cfg) 148 break 149 case "json": 150 protocolFactory = thrift.NewTJSONProtocolFactory() 151 break 152 case "binary", "": 153 protocolFactory = thrift.NewTBinaryProtocolFactoryConf(cfg) 154 break 155 default: 156 fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) 157 Usage() 158 os.Exit(1) 159 } 160 iprot := protocolFactory.GetProtocol(trans) 161 oprot := protocolFactory.GetProtocol(trans) 162 client := interfaces.NewIPCChainTesterClient(thrift.NewTStandardClient(iprot, oprot)) 163 if err := trans.Open(); err != nil { 164 fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) 165 os.Exit(1) 166 } 167 168 switch cmd { 169 case "init_vm_api": 170 if flag.NArg() - 1 != 0 { 171 fmt.Fprintln(os.Stderr, "InitVMAPI requires 0 args") 172 flag.Usage() 173 } 174 fmt.Print(client.InitVMAPI(context.Background())) 175 fmt.Print("\n") 176 break 177 case "init_apply_request": 178 if flag.NArg() - 1 != 0 { 179 fmt.Fprintln(os.Stderr, "InitApplyRequest requires 0 args") 180 flag.Usage() 181 } 182 fmt.Print(client.InitApplyRequest(context.Background())) 183 fmt.Print("\n") 184 break 185 case "set_native_contract": 186 if flag.NArg() - 1 != 3 { 187 fmt.Fprintln(os.Stderr, "SetNativeContract requires 3 args") 188 flag.Usage() 189 } 190 tmp0, err66 := (strconv.Atoi(flag.Arg(1))) 191 if err66 != nil { 192 Usage() 193 return 194 } 195 argvalue0 := int32(tmp0) 196 value0 := argvalue0 197 argvalue1 := flag.Arg(2) 198 value1 := argvalue1 199 argvalue2 := flag.Arg(3) 200 value2 := argvalue2 201 fmt.Print(client.SetNativeContract(context.Background(), value0, value1, value2)) 202 fmt.Print("\n") 203 break 204 case "enable_debugging": 205 if flag.NArg() - 1 != 1 { 206 fmt.Fprintln(os.Stderr, "EnableDebugging requires 1 args") 207 flag.Usage() 208 } 209 argvalue0 := flag.Arg(1) == "true" 210 value0 := argvalue0 211 fmt.Print(client.EnableDebugging(context.Background(), value0)) 212 fmt.Print("\n") 213 break 214 case "enable_debug_contract": 215 if flag.NArg() - 1 != 3 { 216 fmt.Fprintln(os.Stderr, "EnableDebugContract requires 3 args") 217 flag.Usage() 218 } 219 tmp0, err70 := (strconv.Atoi(flag.Arg(1))) 220 if err70 != nil { 221 Usage() 222 return 223 } 224 argvalue0 := int32(tmp0) 225 value0 := argvalue0 226 argvalue1 := flag.Arg(2) 227 value1 := argvalue1 228 argvalue2 := flag.Arg(3) == "true" 229 value2 := argvalue2 230 fmt.Print(client.EnableDebugContract(context.Background(), value0, value1, value2)) 231 fmt.Print("\n") 232 break 233 case "is_debug_contract_enabled": 234 if flag.NArg() - 1 != 2 { 235 fmt.Fprintln(os.Stderr, "IsDebugContractEnabled requires 2 args") 236 flag.Usage() 237 } 238 tmp0, err73 := (strconv.Atoi(flag.Arg(1))) 239 if err73 != nil { 240 Usage() 241 return 242 } 243 argvalue0 := int32(tmp0) 244 value0 := argvalue0 245 argvalue1 := flag.Arg(2) 246 value1 := argvalue1 247 fmt.Print(client.IsDebugContractEnabled(context.Background(), value0, value1)) 248 fmt.Print("\n") 249 break 250 case "pack_abi": 251 if flag.NArg() - 1 != 1 { 252 fmt.Fprintln(os.Stderr, "PackAbi requires 1 args") 253 flag.Usage() 254 } 255 argvalue0 := flag.Arg(1) 256 value0 := argvalue0 257 fmt.Print(client.PackAbi(context.Background(), value0)) 258 fmt.Print("\n") 259 break 260 case "pack_action_args": 261 if flag.NArg() - 1 != 4 { 262 fmt.Fprintln(os.Stderr, "PackActionArgs_ requires 4 args") 263 flag.Usage() 264 } 265 tmp0, err76 := (strconv.Atoi(flag.Arg(1))) 266 if err76 != nil { 267 Usage() 268 return 269 } 270 argvalue0 := int32(tmp0) 271 value0 := argvalue0 272 argvalue1 := flag.Arg(2) 273 value1 := argvalue1 274 argvalue2 := flag.Arg(3) 275 value2 := argvalue2 276 argvalue3 := flag.Arg(4) 277 value3 := argvalue3 278 fmt.Print(client.PackActionArgs_(context.Background(), value0, value1, value2, value3)) 279 fmt.Print("\n") 280 break 281 case "unpack_action_args": 282 if flag.NArg() - 1 != 4 { 283 fmt.Fprintln(os.Stderr, "UnpackActionArgs_ requires 4 args") 284 flag.Usage() 285 } 286 tmp0, err80 := (strconv.Atoi(flag.Arg(1))) 287 if err80 != nil { 288 Usage() 289 return 290 } 291 argvalue0 := int32(tmp0) 292 value0 := argvalue0 293 argvalue1 := flag.Arg(2) 294 value1 := argvalue1 295 argvalue2 := flag.Arg(3) 296 value2 := argvalue2 297 argvalue3 := []byte(flag.Arg(4)) 298 value3 := argvalue3 299 fmt.Print(client.UnpackActionArgs_(context.Background(), value0, value1, value2, value3)) 300 fmt.Print("\n") 301 break 302 case "new_chain": 303 if flag.NArg() - 1 != 1 { 304 fmt.Fprintln(os.Stderr, "NewChain_ requires 1 args") 305 flag.Usage() 306 } 307 argvalue0 := flag.Arg(1) == "true" 308 value0 := argvalue0 309 fmt.Print(client.NewChain_(context.Background(), value0)) 310 fmt.Print("\n") 311 break 312 case "free_chain": 313 if flag.NArg() - 1 != 1 { 314 fmt.Fprintln(os.Stderr, "FreeChain requires 1 args") 315 flag.Usage() 316 } 317 tmp0, err85 := (strconv.Atoi(flag.Arg(1))) 318 if err85 != nil { 319 Usage() 320 return 321 } 322 argvalue0 := int32(tmp0) 323 value0 := argvalue0 324 fmt.Print(client.FreeChain(context.Background(), value0)) 325 fmt.Print("\n") 326 break 327 case "get_info": 328 if flag.NArg() - 1 != 1 { 329 fmt.Fprintln(os.Stderr, "GetInfo requires 1 args") 330 flag.Usage() 331 } 332 tmp0, err86 := (strconv.Atoi(flag.Arg(1))) 333 if err86 != nil { 334 Usage() 335 return 336 } 337 argvalue0 := int32(tmp0) 338 value0 := argvalue0 339 fmt.Print(client.GetInfo(context.Background(), value0)) 340 fmt.Print("\n") 341 break 342 case "create_key": 343 if flag.NArg() - 1 != 1 { 344 fmt.Fprintln(os.Stderr, "CreateKey requires 1 args") 345 flag.Usage() 346 } 347 argvalue0 := flag.Arg(1) 348 value0 := argvalue0 349 fmt.Print(client.CreateKey(context.Background(), value0)) 350 fmt.Print("\n") 351 break 352 case "get_account": 353 if flag.NArg() - 1 != 2 { 354 fmt.Fprintln(os.Stderr, "GetAccount requires 2 args") 355 flag.Usage() 356 } 357 tmp0, err88 := (strconv.Atoi(flag.Arg(1))) 358 if err88 != nil { 359 Usage() 360 return 361 } 362 argvalue0 := int32(tmp0) 363 value0 := argvalue0 364 argvalue1 := flag.Arg(2) 365 value1 := argvalue1 366 fmt.Print(client.GetAccount(context.Background(), value0, value1)) 367 fmt.Print("\n") 368 break 369 case "create_account": 370 if flag.NArg() - 1 != 8 { 371 fmt.Fprintln(os.Stderr, "CreateAccount requires 8 args") 372 flag.Usage() 373 } 374 tmp0, err90 := (strconv.Atoi(flag.Arg(1))) 375 if err90 != nil { 376 Usage() 377 return 378 } 379 argvalue0 := int32(tmp0) 380 value0 := argvalue0 381 argvalue1 := flag.Arg(2) 382 value1 := argvalue1 383 argvalue2 := flag.Arg(3) 384 value2 := argvalue2 385 argvalue3 := flag.Arg(4) 386 value3 := argvalue3 387 argvalue4 := flag.Arg(5) 388 value4 := argvalue4 389 argvalue5, err95 := (strconv.ParseInt(flag.Arg(6), 10, 64)) 390 if err95 != nil { 391 Usage() 392 return 393 } 394 value5 := argvalue5 395 argvalue6, err96 := (strconv.ParseInt(flag.Arg(7), 10, 64)) 396 if err96 != nil { 397 Usage() 398 return 399 } 400 value6 := argvalue6 401 argvalue7, err97 := (strconv.ParseInt(flag.Arg(8), 10, 64)) 402 if err97 != nil { 403 Usage() 404 return 405 } 406 value7 := argvalue7 407 fmt.Print(client.CreateAccount(context.Background(), value0, value1, value2, value3, value4, value5, value6, value7)) 408 fmt.Print("\n") 409 break 410 case "import_key": 411 if flag.NArg() - 1 != 3 { 412 fmt.Fprintln(os.Stderr, "ImportKey requires 3 args") 413 flag.Usage() 414 } 415 tmp0, err98 := (strconv.Atoi(flag.Arg(1))) 416 if err98 != nil { 417 Usage() 418 return 419 } 420 argvalue0 := int32(tmp0) 421 value0 := argvalue0 422 argvalue1 := flag.Arg(2) 423 value1 := argvalue1 424 argvalue2 := flag.Arg(3) 425 value2 := argvalue2 426 fmt.Print(client.ImportKey(context.Background(), value0, value1, value2)) 427 fmt.Print("\n") 428 break 429 case "get_required_keys": 430 if flag.NArg() - 1 != 3 { 431 fmt.Fprintln(os.Stderr, "GetRequiredKeys requires 3 args") 432 flag.Usage() 433 } 434 tmp0, err101 := (strconv.Atoi(flag.Arg(1))) 435 if err101 != nil { 436 Usage() 437 return 438 } 439 argvalue0 := int32(tmp0) 440 value0 := argvalue0 441 argvalue1 := flag.Arg(2) 442 value1 := argvalue1 443 arg103 := flag.Arg(3) 444 mbTrans104 := thrift.NewTMemoryBufferLen(len(arg103)) 445 defer mbTrans104.Close() 446 _, err105 := mbTrans104.WriteString(arg103) 447 if err105 != nil { 448 Usage() 449 return 450 } 451 factory106 := thrift.NewTJSONProtocolFactory() 452 jsProt107 := factory106.GetProtocol(mbTrans104) 453 containerStruct2 := interfaces.NewIPCChainTesterGetRequiredKeysArgs() 454 err108 := containerStruct2.ReadField3(context.Background(), jsProt107) 455 if err108 != nil { 456 Usage() 457 return 458 } 459 argvalue2 := containerStruct2.AvailableKeys 460 value2 := argvalue2 461 fmt.Print(client.GetRequiredKeys(context.Background(), value0, value1, value2)) 462 fmt.Print("\n") 463 break 464 case "produce_block": 465 if flag.NArg() - 1 != 2 { 466 fmt.Fprintln(os.Stderr, "ProduceBlock requires 2 args") 467 flag.Usage() 468 } 469 tmp0, err109 := (strconv.Atoi(flag.Arg(1))) 470 if err109 != nil { 471 Usage() 472 return 473 } 474 argvalue0 := int32(tmp0) 475 value0 := argvalue0 476 argvalue1, err110 := (strconv.ParseInt(flag.Arg(2), 10, 64)) 477 if err110 != nil { 478 Usage() 479 return 480 } 481 value1 := argvalue1 482 fmt.Print(client.ProduceBlock(context.Background(), value0, value1)) 483 fmt.Print("\n") 484 break 485 case "push_action": 486 if flag.NArg() - 1 != 5 { 487 fmt.Fprintln(os.Stderr, "PushAction requires 5 args") 488 flag.Usage() 489 } 490 tmp0, err111 := (strconv.Atoi(flag.Arg(1))) 491 if err111 != nil { 492 Usage() 493 return 494 } 495 argvalue0 := int32(tmp0) 496 value0 := argvalue0 497 argvalue1 := flag.Arg(2) 498 value1 := argvalue1 499 argvalue2 := flag.Arg(3) 500 value2 := argvalue2 501 arg114 := flag.Arg(4) 502 mbTrans115 := thrift.NewTMemoryBufferLen(len(arg114)) 503 defer mbTrans115.Close() 504 _, err116 := mbTrans115.WriteString(arg114) 505 if err116 != nil { 506 Usage() 507 return 508 } 509 factory117 := thrift.NewTJSONProtocolFactory() 510 jsProt118 := factory117.GetProtocol(mbTrans115) 511 argvalue3 := interfaces.NewActionArguments() 512 err119 := argvalue3.Read(context.Background(), jsProt118) 513 if err119 != nil { 514 Usage() 515 return 516 } 517 value3 := argvalue3 518 argvalue4 := flag.Arg(5) 519 value4 := argvalue4 520 fmt.Print(client.PushAction(context.Background(), value0, value1, value2, value3, value4)) 521 fmt.Print("\n") 522 break 523 case "push_actions": 524 if flag.NArg() - 1 != 2 { 525 fmt.Fprintln(os.Stderr, "PushActions requires 2 args") 526 flag.Usage() 527 } 528 tmp0, err121 := (strconv.Atoi(flag.Arg(1))) 529 if err121 != nil { 530 Usage() 531 return 532 } 533 argvalue0 := int32(tmp0) 534 value0 := argvalue0 535 arg122 := flag.Arg(2) 536 mbTrans123 := thrift.NewTMemoryBufferLen(len(arg122)) 537 defer mbTrans123.Close() 538 _, err124 := mbTrans123.WriteString(arg122) 539 if err124 != nil { 540 Usage() 541 return 542 } 543 factory125 := thrift.NewTJSONProtocolFactory() 544 jsProt126 := factory125.GetProtocol(mbTrans123) 545 containerStruct1 := interfaces.NewIPCChainTesterPushActionsArgs() 546 err127 := containerStruct1.ReadField2(context.Background(), jsProt126) 547 if err127 != nil { 548 Usage() 549 return 550 } 551 argvalue1 := containerStruct1.Actions 552 value1 := argvalue1 553 fmt.Print(client.PushActions(context.Background(), value0, value1)) 554 fmt.Print("\n") 555 break 556 case "deploy_contract": 557 if flag.NArg() - 1 != 4 { 558 fmt.Fprintln(os.Stderr, "DeployContract requires 4 args") 559 flag.Usage() 560 } 561 tmp0, err128 := (strconv.Atoi(flag.Arg(1))) 562 if err128 != nil { 563 Usage() 564 return 565 } 566 argvalue0 := int32(tmp0) 567 value0 := argvalue0 568 argvalue1 := flag.Arg(2) 569 value1 := argvalue1 570 argvalue2 := flag.Arg(3) 571 value2 := argvalue2 572 argvalue3 := flag.Arg(4) 573 value3 := argvalue3 574 fmt.Print(client.DeployContract(context.Background(), value0, value1, value2, value3)) 575 fmt.Print("\n") 576 break 577 case "get_table_rows": 578 if flag.NArg() - 1 != 13 { 579 fmt.Fprintln(os.Stderr, "GetTableRows requires 13 args") 580 flag.Usage() 581 } 582 tmp0, err132 := (strconv.Atoi(flag.Arg(1))) 583 if err132 != nil { 584 Usage() 585 return 586 } 587 argvalue0 := int32(tmp0) 588 value0 := argvalue0 589 argvalue1 := flag.Arg(2) == "true" 590 value1 := argvalue1 591 argvalue2 := flag.Arg(3) 592 value2 := argvalue2 593 argvalue3 := flag.Arg(4) 594 value3 := argvalue3 595 argvalue4 := flag.Arg(5) 596 value4 := argvalue4 597 argvalue5 := flag.Arg(6) 598 value5 := argvalue5 599 argvalue6 := flag.Arg(7) 600 value6 := argvalue6 601 argvalue7, err139 := (strconv.ParseInt(flag.Arg(8), 10, 64)) 602 if err139 != nil { 603 Usage() 604 return 605 } 606 value7 := argvalue7 607 argvalue8 := flag.Arg(9) 608 value8 := argvalue8 609 argvalue9 := flag.Arg(10) 610 value9 := argvalue9 611 argvalue10 := flag.Arg(11) 612 value10 := argvalue10 613 argvalue11 := flag.Arg(12) == "true" 614 value11 := argvalue11 615 argvalue12 := flag.Arg(13) == "true" 616 value12 := argvalue12 617 fmt.Print(client.GetTableRows(context.Background(), value0, value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12)) 618 fmt.Print("\n") 619 break 620 case "": 621 Usage() 622 break 623 default: 624 fmt.Fprintln(os.Stderr, "Invalid function ", cmd) 625 } 626 }