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.

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