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.

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