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.

829 lines
22 KiB

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