You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

828 lines
22 KiB

  1. // File generated by github.com/ebuchman/rpc-gen
  2. package rpc
  3. import (
  4. "fmt"
  5. "github.com/tendermint/tendermint/account"
  6. "github.com/tendermint/tendermint/binary"
  7. "github.com/tendermint/tendermint/rpc/core"
  8. "github.com/tendermint/tendermint/types"
  9. "io/ioutil"
  10. "net/http"
  11. )
  12. type Client interface {
  13. BlockchainInfo(minHeight uint, maxHeight uint) (*core.ResponseBlockchainInfo, error)
  14. BroadcastTx(tx types.Tx) (*core.ResponseBroadcastTx, error)
  15. Call(address []byte, data []byte) (*core.ResponseCall, error)
  16. CallCode(code []byte, data []byte) (*core.ResponseCall, error)
  17. DumpStorage(addr []byte) (*core.ResponseDumpStorage, error)
  18. GenPrivAccount() (*core.ResponseGenPrivAccount, error)
  19. GetAccount(address []byte) (*core.ResponseGetAccount, error)
  20. GetBlock(height uint) (*core.ResponseGetBlock, error)
  21. GetStorage(address []byte, key []byte) (*core.ResponseGetStorage, error)
  22. ListAccounts() (*core.ResponseListAccounts, error)
  23. ListValidators() (*core.ResponseListValidators, error)
  24. NetInfo() (*core.ResponseNetInfo, error)
  25. SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*core.ResponseSignTx, error)
  26. Status() (*core.ResponseStatus, error)
  27. }
  28. func (c *ClientHTTP) BlockchainInfo(minHeight uint, maxHeight uint) (*core.ResponseBlockchainInfo, error) {
  29. values, err := argsToURLValues([]string{"minHeight", "maxHeight"}, minHeight, maxHeight)
  30. if err != nil {
  31. return nil, err
  32. }
  33. resp, err := http.PostForm(c.addr+reverseFuncMap["BlockchainInfo"], values)
  34. if err != nil {
  35. return nil, err
  36. }
  37. defer resp.Body.Close()
  38. body, err := ioutil.ReadAll(resp.Body)
  39. if err != nil {
  40. return nil, err
  41. }
  42. var response struct {
  43. Result *core.ResponseBlockchainInfo `json:"result"`
  44. Error string `json:"error"`
  45. Id string `json:"id"`
  46. JSONRPC string `json:"jsonrpc"`
  47. }
  48. binary.ReadJSON(&response, body, &err)
  49. if err != nil {
  50. return nil, err
  51. }
  52. if response.Error != "" {
  53. return nil, fmt.Errorf(response.Error)
  54. }
  55. return response.Result, nil
  56. }
  57. func (c *ClientHTTP) BroadcastTx(tx types.Tx) (*core.ResponseBroadcastTx, error) {
  58. values, err := argsToURLValues([]string{"tx"}, tx)
  59. if err != nil {
  60. return nil, err
  61. }
  62. resp, err := http.PostForm(c.addr+reverseFuncMap["BroadcastTx"], values)
  63. if err != nil {
  64. return nil, err
  65. }
  66. defer resp.Body.Close()
  67. body, err := ioutil.ReadAll(resp.Body)
  68. if err != nil {
  69. return nil, err
  70. }
  71. var response struct {
  72. Result *core.ResponseBroadcastTx `json:"result"`
  73. Error string `json:"error"`
  74. Id string `json:"id"`
  75. JSONRPC string `json:"jsonrpc"`
  76. }
  77. binary.ReadJSON(&response, body, &err)
  78. if err != nil {
  79. return nil, err
  80. }
  81. if response.Error != "" {
  82. return nil, fmt.Errorf(response.Error)
  83. }
  84. return response.Result, nil
  85. }
  86. func (c *ClientHTTP) Call(address []byte, data []byte) (*core.ResponseCall, error) {
  87. values, err := argsToURLValues([]string{"address", "data"}, address, data)
  88. if err != nil {
  89. return nil, err
  90. }
  91. resp, err := http.PostForm(c.addr+reverseFuncMap["Call"], values)
  92. if err != nil {
  93. return nil, err
  94. }
  95. defer resp.Body.Close()
  96. body, err := ioutil.ReadAll(resp.Body)
  97. if err != nil {
  98. return nil, err
  99. }
  100. var response struct {
  101. Result *core.ResponseCall `json:"result"`
  102. Error string `json:"error"`
  103. Id string `json:"id"`
  104. JSONRPC string `json:"jsonrpc"`
  105. }
  106. binary.ReadJSON(&response, body, &err)
  107. if err != nil {
  108. return nil, err
  109. }
  110. if response.Error != "" {
  111. return nil, fmt.Errorf(response.Error)
  112. }
  113. return response.Result, nil
  114. }
  115. func (c *ClientHTTP) CallCode(code []byte, data []byte) (*core.ResponseCall, error) {
  116. values, err := argsToURLValues([]string{"code", "data"}, code, data)
  117. if err != nil {
  118. return nil, err
  119. }
  120. resp, err := http.PostForm(c.addr+reverseFuncMap["CallCode"], values)
  121. if err != nil {
  122. return nil, err
  123. }
  124. defer resp.Body.Close()
  125. body, err := ioutil.ReadAll(resp.Body)
  126. if err != nil {
  127. return nil, err
  128. }
  129. var response struct {
  130. Result *core.ResponseCall `json:"result"`
  131. Error string `json:"error"`
  132. Id string `json:"id"`
  133. JSONRPC string `json:"jsonrpc"`
  134. }
  135. binary.ReadJSON(&response, body, &err)
  136. if err != nil {
  137. return nil, err
  138. }
  139. if response.Error != "" {
  140. return nil, fmt.Errorf(response.Error)
  141. }
  142. return response.Result, nil
  143. }
  144. func (c *ClientHTTP) DumpStorage(addr []byte) (*core.ResponseDumpStorage, error) {
  145. values, err := argsToURLValues([]string{"addr"}, addr)
  146. if err != nil {
  147. return nil, err
  148. }
  149. resp, err := http.PostForm(c.addr+reverseFuncMap["DumpStorage"], values)
  150. if err != nil {
  151. return nil, err
  152. }
  153. defer resp.Body.Close()
  154. body, err := ioutil.ReadAll(resp.Body)
  155. if err != nil {
  156. return nil, err
  157. }
  158. var response struct {
  159. Result *core.ResponseDumpStorage `json:"result"`
  160. Error string `json:"error"`
  161. Id string `json:"id"`
  162. JSONRPC string `json:"jsonrpc"`
  163. }
  164. binary.ReadJSON(&response, body, &err)
  165. if err != nil {
  166. return nil, err
  167. }
  168. if response.Error != "" {
  169. return nil, fmt.Errorf(response.Error)
  170. }
  171. return response.Result, nil
  172. }
  173. func (c *ClientHTTP) GenPrivAccount() (*core.ResponseGenPrivAccount, error) {
  174. values, err := argsToURLValues(nil)
  175. if err != nil {
  176. return nil, err
  177. }
  178. resp, err := http.PostForm(c.addr+reverseFuncMap["GenPrivAccount"], values)
  179. if err != nil {
  180. return nil, err
  181. }
  182. defer resp.Body.Close()
  183. body, err := ioutil.ReadAll(resp.Body)
  184. if err != nil {
  185. return nil, err
  186. }
  187. var response struct {
  188. Result *core.ResponseGenPrivAccount `json:"result"`
  189. Error string `json:"error"`
  190. Id string `json:"id"`
  191. JSONRPC string `json:"jsonrpc"`
  192. }
  193. binary.ReadJSON(&response, body, &err)
  194. if err != nil {
  195. return nil, err
  196. }
  197. if response.Error != "" {
  198. return nil, fmt.Errorf(response.Error)
  199. }
  200. return response.Result, nil
  201. }
  202. func (c *ClientHTTP) GetAccount(address []byte) (*core.ResponseGetAccount, error) {
  203. values, err := argsToURLValues([]string{"address"}, address)
  204. if err != nil {
  205. return nil, err
  206. }
  207. resp, err := http.PostForm(c.addr+reverseFuncMap["GetAccount"], values)
  208. if err != nil {
  209. return nil, err
  210. }
  211. defer resp.Body.Close()
  212. body, err := ioutil.ReadAll(resp.Body)
  213. if err != nil {
  214. return nil, err
  215. }
  216. var response struct {
  217. Result *core.ResponseGetAccount `json:"result"`
  218. Error string `json:"error"`
  219. Id string `json:"id"`
  220. JSONRPC string `json:"jsonrpc"`
  221. }
  222. binary.ReadJSON(&response, body, &err)
  223. if err != nil {
  224. return nil, err
  225. }
  226. if response.Error != "" {
  227. return nil, fmt.Errorf(response.Error)
  228. }
  229. return response.Result, nil
  230. }
  231. func (c *ClientHTTP) GetBlock(height uint) (*core.ResponseGetBlock, error) {
  232. values, err := argsToURLValues([]string{"height"}, height)
  233. if err != nil {
  234. return nil, err
  235. }
  236. resp, err := http.PostForm(c.addr+reverseFuncMap["GetBlock"], values)
  237. if err != nil {
  238. return nil, err
  239. }
  240. defer resp.Body.Close()
  241. body, err := ioutil.ReadAll(resp.Body)
  242. if err != nil {
  243. return nil, err
  244. }
  245. var response struct {
  246. Result *core.ResponseGetBlock `json:"result"`
  247. Error string `json:"error"`
  248. Id string `json:"id"`
  249. JSONRPC string `json:"jsonrpc"`
  250. }
  251. binary.ReadJSON(&response, body, &err)
  252. if err != nil {
  253. return nil, err
  254. }
  255. if response.Error != "" {
  256. return nil, fmt.Errorf(response.Error)
  257. }
  258. return response.Result, nil
  259. }
  260. func (c *ClientHTTP) GetStorage(address []byte, key []byte) (*core.ResponseGetStorage, error) {
  261. values, err := argsToURLValues([]string{"address", "key"}, address, key)
  262. if err != nil {
  263. return nil, err
  264. }
  265. resp, err := http.PostForm(c.addr+reverseFuncMap["GetStorage"], values)
  266. if err != nil {
  267. return nil, err
  268. }
  269. defer resp.Body.Close()
  270. body, err := ioutil.ReadAll(resp.Body)
  271. if err != nil {
  272. return nil, err
  273. }
  274. var response struct {
  275. Result *core.ResponseGetStorage `json:"result"`
  276. Error string `json:"error"`
  277. Id string `json:"id"`
  278. JSONRPC string `json:"jsonrpc"`
  279. }
  280. binary.ReadJSON(&response, body, &err)
  281. if err != nil {
  282. return nil, err
  283. }
  284. if response.Error != "" {
  285. return nil, fmt.Errorf(response.Error)
  286. }
  287. return response.Result, nil
  288. }
  289. func (c *ClientHTTP) ListAccounts() (*core.ResponseListAccounts, error) {
  290. values, err := argsToURLValues(nil)
  291. if err != nil {
  292. return nil, err
  293. }
  294. resp, err := http.PostForm(c.addr+reverseFuncMap["ListAccounts"], values)
  295. if err != nil {
  296. return nil, err
  297. }
  298. defer resp.Body.Close()
  299. body, err := ioutil.ReadAll(resp.Body)
  300. if err != nil {
  301. return nil, err
  302. }
  303. var response struct {
  304. Result *core.ResponseListAccounts `json:"result"`
  305. Error string `json:"error"`
  306. Id string `json:"id"`
  307. JSONRPC string `json:"jsonrpc"`
  308. }
  309. binary.ReadJSON(&response, body, &err)
  310. if err != nil {
  311. return nil, err
  312. }
  313. if response.Error != "" {
  314. return nil, fmt.Errorf(response.Error)
  315. }
  316. return response.Result, nil
  317. }
  318. func (c *ClientHTTP) ListValidators() (*core.ResponseListValidators, error) {
  319. values, err := argsToURLValues(nil)
  320. if err != nil {
  321. return nil, err
  322. }
  323. resp, err := http.PostForm(c.addr+reverseFuncMap["ListValidators"], values)
  324. if err != nil {
  325. return nil, err
  326. }
  327. defer resp.Body.Close()
  328. body, err := ioutil.ReadAll(resp.Body)
  329. if err != nil {
  330. return nil, err
  331. }
  332. var response struct {
  333. Result *core.ResponseListValidators `json:"result"`
  334. Error string `json:"error"`
  335. Id string `json:"id"`
  336. JSONRPC string `json:"jsonrpc"`
  337. }
  338. binary.ReadJSON(&response, body, &err)
  339. if err != nil {
  340. return nil, err
  341. }
  342. if response.Error != "" {
  343. return nil, fmt.Errorf(response.Error)
  344. }
  345. return response.Result, nil
  346. }
  347. func (c *ClientHTTP) NetInfo() (*core.ResponseNetInfo, error) {
  348. values, err := argsToURLValues(nil)
  349. if err != nil {
  350. return nil, err
  351. }
  352. resp, err := http.PostForm(c.addr+reverseFuncMap["NetInfo"], values)
  353. if err != nil {
  354. return nil, err
  355. }
  356. defer resp.Body.Close()
  357. body, err := ioutil.ReadAll(resp.Body)
  358. if err != nil {
  359. return nil, err
  360. }
  361. var response struct {
  362. Result *core.ResponseNetInfo `json:"result"`
  363. Error string `json:"error"`
  364. Id string `json:"id"`
  365. JSONRPC string `json:"jsonrpc"`
  366. }
  367. binary.ReadJSON(&response, body, &err)
  368. if err != nil {
  369. return nil, err
  370. }
  371. if response.Error != "" {
  372. return nil, fmt.Errorf(response.Error)
  373. }
  374. return response.Result, nil
  375. }
  376. func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*core.ResponseSignTx, error) {
  377. values, err := argsToURLValues([]string{"tx", "priv_accounts"}, tx, privAccounts)
  378. if err != nil {
  379. return nil, err
  380. }
  381. resp, err := http.PostForm(c.addr+reverseFuncMap["SignTx"], values)
  382. if err != nil {
  383. return nil, err
  384. }
  385. defer resp.Body.Close()
  386. body, err := ioutil.ReadAll(resp.Body)
  387. if err != nil {
  388. return nil, err
  389. }
  390. var response struct {
  391. Result *core.ResponseSignTx `json:"result"`
  392. Error string `json:"error"`
  393. Id string `json:"id"`
  394. JSONRPC string `json:"jsonrpc"`
  395. }
  396. binary.ReadJSON(&response, body, &err)
  397. if err != nil {
  398. return nil, err
  399. }
  400. if response.Error != "" {
  401. return nil, fmt.Errorf(response.Error)
  402. }
  403. return response.Result, nil
  404. }
  405. func (c *ClientHTTP) Status() (*core.ResponseStatus, error) {
  406. values, err := argsToURLValues(nil)
  407. if err != nil {
  408. return nil, err
  409. }
  410. resp, err := http.PostForm(c.addr+reverseFuncMap["Status"], values)
  411. if err != nil {
  412. return nil, err
  413. }
  414. defer resp.Body.Close()
  415. body, err := ioutil.ReadAll(resp.Body)
  416. if err != nil {
  417. return nil, err
  418. }
  419. var response struct {
  420. Result *core.ResponseStatus `json:"result"`
  421. Error string `json:"error"`
  422. Id string `json:"id"`
  423. JSONRPC string `json:"jsonrpc"`
  424. }
  425. binary.ReadJSON(&response, body, &err)
  426. if err != nil {
  427. return nil, err
  428. }
  429. if response.Error != "" {
  430. return nil, fmt.Errorf(response.Error)
  431. }
  432. return response.Result, nil
  433. }
  434. func (c *ClientJSON) BlockchainInfo(minHeight uint, maxHeight uint) (*core.ResponseBlockchainInfo, error) {
  435. request := RPCRequest{
  436. JSONRPC: "2.0",
  437. Method: reverseFuncMap["BlockchainInfo"],
  438. Params: []interface{}{minHeight, maxHeight},
  439. Id: 0,
  440. }
  441. body, err := c.RequestResponse(request)
  442. if err != nil {
  443. return nil, err
  444. }
  445. var response struct {
  446. Result *core.ResponseBlockchainInfo `json:"result"`
  447. Error string `json:"error"`
  448. Id string `json:"id"`
  449. JSONRPC string `json:"jsonrpc"`
  450. }
  451. binary.ReadJSON(&response, body, &err)
  452. if err != nil {
  453. return nil, err
  454. }
  455. if response.Error != "" {
  456. return nil, fmt.Errorf(response.Error)
  457. }
  458. return response.Result, nil
  459. }
  460. func (c *ClientJSON) BroadcastTx(tx types.Tx) (*core.ResponseBroadcastTx, error) {
  461. request := RPCRequest{
  462. JSONRPC: "2.0",
  463. Method: reverseFuncMap["BroadcastTx"],
  464. Params: []interface{}{tx},
  465. Id: 0,
  466. }
  467. body, err := c.RequestResponse(request)
  468. if err != nil {
  469. return nil, err
  470. }
  471. var response struct {
  472. Result *core.ResponseBroadcastTx `json:"result"`
  473. Error string `json:"error"`
  474. Id string `json:"id"`
  475. JSONRPC string `json:"jsonrpc"`
  476. }
  477. binary.ReadJSON(&response, body, &err)
  478. if err != nil {
  479. return nil, err
  480. }
  481. if response.Error != "" {
  482. return nil, fmt.Errorf(response.Error)
  483. }
  484. return response.Result, nil
  485. }
  486. func (c *ClientJSON) Call(address []byte, data []byte) (*core.ResponseCall, error) {
  487. request := RPCRequest{
  488. JSONRPC: "2.0",
  489. Method: reverseFuncMap["Call"],
  490. Params: []interface{}{address, data},
  491. Id: 0,
  492. }
  493. body, err := c.RequestResponse(request)
  494. if err != nil {
  495. return nil, err
  496. }
  497. var response struct {
  498. Result *core.ResponseCall `json:"result"`
  499. Error string `json:"error"`
  500. Id string `json:"id"`
  501. JSONRPC string `json:"jsonrpc"`
  502. }
  503. binary.ReadJSON(&response, body, &err)
  504. if err != nil {
  505. return nil, err
  506. }
  507. if response.Error != "" {
  508. return nil, fmt.Errorf(response.Error)
  509. }
  510. return response.Result, nil
  511. }
  512. func (c *ClientJSON) CallCode(code []byte, data []byte) (*core.ResponseCall, error) {
  513. request := RPCRequest{
  514. JSONRPC: "2.0",
  515. Method: reverseFuncMap["CallCode"],
  516. Params: []interface{}{code, data},
  517. Id: 0,
  518. }
  519. body, err := c.RequestResponse(request)
  520. if err != nil {
  521. return nil, err
  522. }
  523. var response struct {
  524. Result *core.ResponseCall `json:"result"`
  525. Error string `json:"error"`
  526. Id string `json:"id"`
  527. JSONRPC string `json:"jsonrpc"`
  528. }
  529. binary.ReadJSON(&response, body, &err)
  530. if err != nil {
  531. return nil, err
  532. }
  533. if response.Error != "" {
  534. return nil, fmt.Errorf(response.Error)
  535. }
  536. return response.Result, nil
  537. }
  538. func (c *ClientJSON) DumpStorage(addr []byte) (*core.ResponseDumpStorage, error) {
  539. request := RPCRequest{
  540. JSONRPC: "2.0",
  541. Method: reverseFuncMap["DumpStorage"],
  542. Params: []interface{}{addr},
  543. Id: 0,
  544. }
  545. body, err := c.RequestResponse(request)
  546. if err != nil {
  547. return nil, err
  548. }
  549. var response struct {
  550. Result *core.ResponseDumpStorage `json:"result"`
  551. Error string `json:"error"`
  552. Id string `json:"id"`
  553. JSONRPC string `json:"jsonrpc"`
  554. }
  555. binary.ReadJSON(&response, body, &err)
  556. if err != nil {
  557. return nil, err
  558. }
  559. if response.Error != "" {
  560. return nil, fmt.Errorf(response.Error)
  561. }
  562. return response.Result, nil
  563. }
  564. func (c *ClientJSON) GenPrivAccount() (*core.ResponseGenPrivAccount, error) {
  565. request := RPCRequest{
  566. JSONRPC: "2.0",
  567. Method: reverseFuncMap["GenPrivAccount"],
  568. Params: []interface{}{},
  569. Id: 0,
  570. }
  571. body, err := c.RequestResponse(request)
  572. if err != nil {
  573. return nil, err
  574. }
  575. var response struct {
  576. Result *core.ResponseGenPrivAccount `json:"result"`
  577. Error string `json:"error"`
  578. Id string `json:"id"`
  579. JSONRPC string `json:"jsonrpc"`
  580. }
  581. binary.ReadJSON(&response, body, &err)
  582. if err != nil {
  583. return nil, err
  584. }
  585. if response.Error != "" {
  586. return nil, fmt.Errorf(response.Error)
  587. }
  588. return response.Result, nil
  589. }
  590. func (c *ClientJSON) GetAccount(address []byte) (*core.ResponseGetAccount, error) {
  591. request := RPCRequest{
  592. JSONRPC: "2.0",
  593. Method: reverseFuncMap["GetAccount"],
  594. Params: []interface{}{address},
  595. Id: 0,
  596. }
  597. body, err := c.RequestResponse(request)
  598. if err != nil {
  599. return nil, err
  600. }
  601. var response struct {
  602. Result *core.ResponseGetAccount `json:"result"`
  603. Error string `json:"error"`
  604. Id string `json:"id"`
  605. JSONRPC string `json:"jsonrpc"`
  606. }
  607. binary.ReadJSON(&response, body, &err)
  608. if err != nil {
  609. return nil, err
  610. }
  611. if response.Error != "" {
  612. return nil, fmt.Errorf(response.Error)
  613. }
  614. return response.Result, nil
  615. }
  616. func (c *ClientJSON) GetBlock(height uint) (*core.ResponseGetBlock, error) {
  617. request := RPCRequest{
  618. JSONRPC: "2.0",
  619. Method: reverseFuncMap["GetBlock"],
  620. Params: []interface{}{height},
  621. Id: 0,
  622. }
  623. body, err := c.RequestResponse(request)
  624. if err != nil {
  625. return nil, err
  626. }
  627. var response struct {
  628. Result *core.ResponseGetBlock `json:"result"`
  629. Error string `json:"error"`
  630. Id string `json:"id"`
  631. JSONRPC string `json:"jsonrpc"`
  632. }
  633. binary.ReadJSON(&response, body, &err)
  634. if err != nil {
  635. return nil, err
  636. }
  637. if response.Error != "" {
  638. return nil, fmt.Errorf(response.Error)
  639. }
  640. return response.Result, nil
  641. }
  642. func (c *ClientJSON) GetStorage(address []byte, key []byte) (*core.ResponseGetStorage, error) {
  643. request := RPCRequest{
  644. JSONRPC: "2.0",
  645. Method: reverseFuncMap["GetStorage"],
  646. Params: []interface{}{address, key},
  647. Id: 0,
  648. }
  649. body, err := c.RequestResponse(request)
  650. if err != nil {
  651. return nil, err
  652. }
  653. var response struct {
  654. Result *core.ResponseGetStorage `json:"result"`
  655. Error string `json:"error"`
  656. Id string `json:"id"`
  657. JSONRPC string `json:"jsonrpc"`
  658. }
  659. binary.ReadJSON(&response, body, &err)
  660. if err != nil {
  661. return nil, err
  662. }
  663. if response.Error != "" {
  664. return nil, fmt.Errorf(response.Error)
  665. }
  666. return response.Result, nil
  667. }
  668. func (c *ClientJSON) ListAccounts() (*core.ResponseListAccounts, error) {
  669. request := RPCRequest{
  670. JSONRPC: "2.0",
  671. Method: reverseFuncMap["ListAccounts"],
  672. Params: []interface{}{},
  673. Id: 0,
  674. }
  675. body, err := c.RequestResponse(request)
  676. if err != nil {
  677. return nil, err
  678. }
  679. var response struct {
  680. Result *core.ResponseListAccounts `json:"result"`
  681. Error string `json:"error"`
  682. Id string `json:"id"`
  683. JSONRPC string `json:"jsonrpc"`
  684. }
  685. binary.ReadJSON(&response, body, &err)
  686. if err != nil {
  687. return nil, err
  688. }
  689. if response.Error != "" {
  690. return nil, fmt.Errorf(response.Error)
  691. }
  692. return response.Result, nil
  693. }
  694. func (c *ClientJSON) ListValidators() (*core.ResponseListValidators, error) {
  695. request := RPCRequest{
  696. JSONRPC: "2.0",
  697. Method: reverseFuncMap["ListValidators"],
  698. Params: []interface{}{},
  699. Id: 0,
  700. }
  701. body, err := c.RequestResponse(request)
  702. if err != nil {
  703. return nil, err
  704. }
  705. var response struct {
  706. Result *core.ResponseListValidators `json:"result"`
  707. Error string `json:"error"`
  708. Id string `json:"id"`
  709. JSONRPC string `json:"jsonrpc"`
  710. }
  711. binary.ReadJSON(&response, body, &err)
  712. if err != nil {
  713. return nil, err
  714. }
  715. if response.Error != "" {
  716. return nil, fmt.Errorf(response.Error)
  717. }
  718. return response.Result, nil
  719. }
  720. func (c *ClientJSON) NetInfo() (*core.ResponseNetInfo, error) {
  721. request := RPCRequest{
  722. JSONRPC: "2.0",
  723. Method: reverseFuncMap["NetInfo"],
  724. Params: []interface{}{},
  725. Id: 0,
  726. }
  727. body, err := c.RequestResponse(request)
  728. if err != nil {
  729. return nil, err
  730. }
  731. var response struct {
  732. Result *core.ResponseNetInfo `json:"result"`
  733. Error string `json:"error"`
  734. Id string `json:"id"`
  735. JSONRPC string `json:"jsonrpc"`
  736. }
  737. binary.ReadJSON(&response, body, &err)
  738. if err != nil {
  739. return nil, err
  740. }
  741. if response.Error != "" {
  742. return nil, fmt.Errorf(response.Error)
  743. }
  744. return response.Result, nil
  745. }
  746. func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*core.ResponseSignTx, error) {
  747. request := RPCRequest{
  748. JSONRPC: "2.0",
  749. Method: reverseFuncMap["SignTx"],
  750. Params: []interface{}{tx, privAccounts},
  751. Id: 0,
  752. }
  753. body, err := c.RequestResponse(request)
  754. if err != nil {
  755. return nil, err
  756. }
  757. var response struct {
  758. Result *core.ResponseSignTx `json:"result"`
  759. Error string `json:"error"`
  760. Id string `json:"id"`
  761. JSONRPC string `json:"jsonrpc"`
  762. }
  763. binary.ReadJSON(&response, body, &err)
  764. if err != nil {
  765. return nil, err
  766. }
  767. if response.Error != "" {
  768. return nil, fmt.Errorf(response.Error)
  769. }
  770. return response.Result, nil
  771. }
  772. func (c *ClientJSON) Status() (*core.ResponseStatus, error) {
  773. request := RPCRequest{
  774. JSONRPC: "2.0",
  775. Method: reverseFuncMap["Status"],
  776. Params: []interface{}{},
  777. Id: 0,
  778. }
  779. body, err := c.RequestResponse(request)
  780. if err != nil {
  781. return nil, err
  782. }
  783. var response struct {
  784. Result *core.ResponseStatus `json:"result"`
  785. Error string `json:"error"`
  786. Id string `json:"id"`
  787. JSONRPC string `json:"jsonrpc"`
  788. }
  789. binary.ReadJSON(&response, body, &err)
  790. if err != nil {
  791. return nil, err
  792. }
  793. if response.Error != "" {
  794. return nil, fmt.Errorf(response.Error)
  795. }
  796. return response.Result, nil
  797. }