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.

1121 lines
29 KiB

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