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.

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