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.

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