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.

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