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.

768 lines
20 KiB

  1. package rpc
  2. import (
  3. "fmt"
  4. "github.com/tendermint/tendermint/account"
  5. "github.com/tendermint/tendermint/binary"
  6. "github.com/tendermint/tendermint/rpc/core"
  7. "github.com/tendermint/tendermint/types"
  8. "io/ioutil"
  9. "net/http"
  10. )
  11. type Client interface {
  12. BlockchainInfo(minHeight uint) (*core.ResponseBlockchainInfo, error)
  13. BroadcastTx(tx types.Tx) (*core.ResponseBroadcastTx, error)
  14. Call(address []byte) (*core.ResponseCall, error)
  15. DumpStorage(addr []byte) (*core.ResponseDumpStorage, error)
  16. GenPrivAccount() (*core.ResponseGenPrivAccount, error)
  17. GetAccount(address []byte) (*core.ResponseGetAccount, error)
  18. GetBlock(height uint) (*core.ResponseGetBlock, error)
  19. GetStorage(address []byte) (*core.ResponseGetStorage, error)
  20. ListAccounts() (*core.ResponseListAccounts, error)
  21. ListValidators() (*core.ResponseListValidators, error)
  22. NetInfo() (*core.ResponseNetInfo, error)
  23. SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*core.ResponseSignTx, error)
  24. Status() (*core.ResponseStatus, error)
  25. }
  26. func (c *ClientHTTP) BlockchainInfo(minHeight uint) (*core.ResponseBlockchainInfo, error) {
  27. values, err := argsToURLValues([]string{"minHeight"}, minHeight)
  28. if err != nil {
  29. return nil, err
  30. }
  31. resp, err := http.PostForm(c.addr+"blockchain_info", values)
  32. if err != nil {
  33. return nil, err
  34. }
  35. defer resp.Body.Close()
  36. body, err := ioutil.ReadAll(resp.Body)
  37. if err != nil {
  38. return nil, err
  39. }
  40. var response struct {
  41. Result *core.ResponseBlockchainInfo `json:"result"`
  42. Error string `json:"error"`
  43. Id string `json:"id"`
  44. JSONRPC string `json:"jsonrpc"`
  45. }
  46. binary.ReadJSON(&response, body, &err)
  47. if err != nil {
  48. return nil, err
  49. }
  50. if response.Error != "" {
  51. return nil, fmt.Errorf(response.Error)
  52. }
  53. return response.Result, nil
  54. }
  55. func (c *ClientHTTP) BroadcastTx(tx types.Tx) (*core.ResponseBroadcastTx, error) {
  56. values, err := argsToURLValues([]string{"tx"}, tx)
  57. if err != nil {
  58. return nil, err
  59. }
  60. resp, err := http.PostForm(c.addr+"broadcast_tx", values)
  61. if err != nil {
  62. return nil, err
  63. }
  64. defer resp.Body.Close()
  65. body, err := ioutil.ReadAll(resp.Body)
  66. if err != nil {
  67. return nil, err
  68. }
  69. var response struct {
  70. Result *core.ResponseBroadcastTx `json:"result"`
  71. Error string `json:"error"`
  72. Id string `json:"id"`
  73. JSONRPC string `json:"jsonrpc"`
  74. }
  75. binary.ReadJSON(&response, body, &err)
  76. if err != nil {
  77. return nil, err
  78. }
  79. if response.Error != "" {
  80. return nil, fmt.Errorf(response.Error)
  81. }
  82. return response.Result, nil
  83. }
  84. func (c *ClientHTTP) Call(address []byte) (*core.ResponseCall, error) {
  85. values, err := argsToURLValues([]string{"address"}, address)
  86. if err != nil {
  87. return nil, err
  88. }
  89. resp, err := http.PostForm(c.addr+"call", values)
  90. if err != nil {
  91. return nil, err
  92. }
  93. defer resp.Body.Close()
  94. body, err := ioutil.ReadAll(resp.Body)
  95. if err != nil {
  96. return nil, err
  97. }
  98. var response struct {
  99. Result *core.ResponseCall `json:"result"`
  100. Error string `json:"error"`
  101. Id string `json:"id"`
  102. JSONRPC string `json:"jsonrpc"`
  103. }
  104. binary.ReadJSON(&response, body, &err)
  105. if err != nil {
  106. return nil, err
  107. }
  108. if response.Error != "" {
  109. return nil, fmt.Errorf(response.Error)
  110. }
  111. return response.Result, nil
  112. }
  113. func (c *ClientHTTP) DumpStorage(addr []byte) (*core.ResponseDumpStorage, error) {
  114. values, err := argsToURLValues([]string{"addr"}, addr)
  115. if err != nil {
  116. return nil, err
  117. }
  118. resp, err := http.PostForm(c.addr+"dump_storage", values)
  119. if err != nil {
  120. return nil, err
  121. }
  122. defer resp.Body.Close()
  123. body, err := ioutil.ReadAll(resp.Body)
  124. if err != nil {
  125. return nil, err
  126. }
  127. var response struct {
  128. Result *core.ResponseDumpStorage `json:"result"`
  129. Error string `json:"error"`
  130. Id string `json:"id"`
  131. JSONRPC string `json:"jsonrpc"`
  132. }
  133. binary.ReadJSON(&response, body, &err)
  134. if err != nil {
  135. return nil, err
  136. }
  137. if response.Error != "" {
  138. return nil, fmt.Errorf(response.Error)
  139. }
  140. return response.Result, nil
  141. }
  142. func (c *ClientHTTP) GenPrivAccount() (*core.ResponseGenPrivAccount, error) {
  143. values, err := argsToURLValues(nil, nil)
  144. if err != nil {
  145. return nil, err
  146. }
  147. resp, err := http.PostForm(c.addr+"gen_priv_account", values)
  148. if err != nil {
  149. return nil, err
  150. }
  151. defer resp.Body.Close()
  152. body, err := ioutil.ReadAll(resp.Body)
  153. if err != nil {
  154. return nil, err
  155. }
  156. var response struct {
  157. Result *core.ResponseGenPrivAccount `json:"result"`
  158. Error string `json:"error"`
  159. Id string `json:"id"`
  160. JSONRPC string `json:"jsonrpc"`
  161. }
  162. binary.ReadJSON(&response, body, &err)
  163. if err != nil {
  164. return nil, err
  165. }
  166. if response.Error != "" {
  167. return nil, fmt.Errorf(response.Error)
  168. }
  169. return response.Result, nil
  170. }
  171. func (c *ClientHTTP) GetAccount(address []byte) (*core.ResponseGetAccount, error) {
  172. values, err := argsToURLValues([]string{"address"}, address)
  173. if err != nil {
  174. return nil, err
  175. }
  176. resp, err := http.PostForm(c.addr+"get_account", values)
  177. if err != nil {
  178. return nil, err
  179. }
  180. defer resp.Body.Close()
  181. body, err := ioutil.ReadAll(resp.Body)
  182. if err != nil {
  183. return nil, err
  184. }
  185. var response struct {
  186. Result *core.ResponseGetAccount `json:"result"`
  187. Error string `json:"error"`
  188. Id string `json:"id"`
  189. JSONRPC string `json:"jsonrpc"`
  190. }
  191. binary.ReadJSON(&response, body, &err)
  192. if err != nil {
  193. return nil, err
  194. }
  195. if response.Error != "" {
  196. return nil, fmt.Errorf(response.Error)
  197. }
  198. return response.Result, nil
  199. }
  200. func (c *ClientHTTP) GetBlock(height uint) (*core.ResponseGetBlock, error) {
  201. values, err := argsToURLValues([]string{"height"}, height)
  202. if err != nil {
  203. return nil, err
  204. }
  205. resp, err := http.PostForm(c.addr+"get_block", values)
  206. if err != nil {
  207. return nil, err
  208. }
  209. defer resp.Body.Close()
  210. body, err := ioutil.ReadAll(resp.Body)
  211. if err != nil {
  212. return nil, err
  213. }
  214. var response struct {
  215. Result *core.ResponseGetBlock `json:"result"`
  216. Error string `json:"error"`
  217. Id string `json:"id"`
  218. JSONRPC string `json:"jsonrpc"`
  219. }
  220. binary.ReadJSON(&response, body, &err)
  221. if err != nil {
  222. return nil, err
  223. }
  224. if response.Error != "" {
  225. return nil, fmt.Errorf(response.Error)
  226. }
  227. return response.Result, nil
  228. }
  229. func (c *ClientHTTP) GetStorage(address []byte) (*core.ResponseGetStorage, error) {
  230. values, err := argsToURLValues([]string{"address"}, address)
  231. if err != nil {
  232. return nil, err
  233. }
  234. resp, err := http.PostForm(c.addr+"get_storage", values)
  235. if err != nil {
  236. return nil, err
  237. }
  238. defer resp.Body.Close()
  239. body, err := ioutil.ReadAll(resp.Body)
  240. if err != nil {
  241. return nil, err
  242. }
  243. var response struct {
  244. Result *core.ResponseGetStorage `json:"result"`
  245. Error string `json:"error"`
  246. Id string `json:"id"`
  247. JSONRPC string `json:"jsonrpc"`
  248. }
  249. binary.ReadJSON(&response, body, &err)
  250. if err != nil {
  251. return nil, err
  252. }
  253. if response.Error != "" {
  254. return nil, fmt.Errorf(response.Error)
  255. }
  256. return response.Result, nil
  257. }
  258. func (c *ClientHTTP) ListAccounts() (*core.ResponseListAccounts, error) {
  259. values, err := argsToURLValues(nil, nil)
  260. if err != nil {
  261. return nil, err
  262. }
  263. resp, err := http.PostForm(c.addr+"list_accounts", values)
  264. if err != nil {
  265. return nil, err
  266. }
  267. defer resp.Body.Close()
  268. body, err := ioutil.ReadAll(resp.Body)
  269. if err != nil {
  270. return nil, err
  271. }
  272. var response struct {
  273. Result *core.ResponseListAccounts `json:"result"`
  274. Error string `json:"error"`
  275. Id string `json:"id"`
  276. JSONRPC string `json:"jsonrpc"`
  277. }
  278. binary.ReadJSON(&response, body, &err)
  279. if err != nil {
  280. return nil, err
  281. }
  282. if response.Error != "" {
  283. return nil, fmt.Errorf(response.Error)
  284. }
  285. return response.Result, nil
  286. }
  287. func (c *ClientHTTP) ListValidators() (*core.ResponseListValidators, error) {
  288. values, err := argsToURLValues(nil, nil)
  289. if err != nil {
  290. return nil, err
  291. }
  292. resp, err := http.PostForm(c.addr+"list_validators", values)
  293. if err != nil {
  294. return nil, err
  295. }
  296. defer resp.Body.Close()
  297. body, err := ioutil.ReadAll(resp.Body)
  298. if err != nil {
  299. return nil, err
  300. }
  301. var response struct {
  302. Result *core.ResponseListValidators `json:"result"`
  303. Error string `json:"error"`
  304. Id string `json:"id"`
  305. JSONRPC string `json:"jsonrpc"`
  306. }
  307. binary.ReadJSON(&response, body, &err)
  308. if err != nil {
  309. return nil, err
  310. }
  311. if response.Error != "" {
  312. return nil, fmt.Errorf(response.Error)
  313. }
  314. return response.Result, nil
  315. }
  316. func (c *ClientHTTP) NetInfo() (*core.ResponseNetInfo, error) {
  317. values, err := argsToURLValues(nil, nil)
  318. if err != nil {
  319. return nil, err
  320. }
  321. resp, err := http.PostForm(c.addr+"net_info", values)
  322. if err != nil {
  323. return nil, err
  324. }
  325. defer resp.Body.Close()
  326. body, err := ioutil.ReadAll(resp.Body)
  327. if err != nil {
  328. return nil, err
  329. }
  330. var response struct {
  331. Result *core.ResponseNetInfo `json:"result"`
  332. Error string `json:"error"`
  333. Id string `json:"id"`
  334. JSONRPC string `json:"jsonrpc"`
  335. }
  336. binary.ReadJSON(&response, body, &err)
  337. if err != nil {
  338. return nil, err
  339. }
  340. if response.Error != "" {
  341. return nil, fmt.Errorf(response.Error)
  342. }
  343. return response.Result, nil
  344. }
  345. func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*core.ResponseSignTx, error) {
  346. values, err := argsToURLValues([]string{"tx", "privAccounts"}, tx, privAccounts)
  347. if err != nil {
  348. return nil, err
  349. }
  350. resp, err := http.PostForm(c.addr+"sign_tx", values)
  351. if err != nil {
  352. return nil, err
  353. }
  354. defer resp.Body.Close()
  355. body, err := ioutil.ReadAll(resp.Body)
  356. if err != nil {
  357. return nil, err
  358. }
  359. var response struct {
  360. Result *core.ResponseSignTx `json:"result"`
  361. Error string `json:"error"`
  362. Id string `json:"id"`
  363. JSONRPC string `json:"jsonrpc"`
  364. }
  365. binary.ReadJSON(&response, body, &err)
  366. if err != nil {
  367. return nil, err
  368. }
  369. if response.Error != "" {
  370. return nil, fmt.Errorf(response.Error)
  371. }
  372. return response.Result, nil
  373. }
  374. func (c *ClientHTTP) Status() (*core.ResponseStatus, error) {
  375. values, err := argsToURLValues(nil, nil)
  376. if err != nil {
  377. return nil, err
  378. }
  379. resp, err := http.PostForm(c.addr+"status", values)
  380. if err != nil {
  381. return nil, err
  382. }
  383. defer resp.Body.Close()
  384. body, err := ioutil.ReadAll(resp.Body)
  385. if err != nil {
  386. return nil, err
  387. }
  388. var response struct {
  389. Result *core.ResponseStatus `json:"result"`
  390. Error string `json:"error"`
  391. Id string `json:"id"`
  392. JSONRPC string `json:"jsonrpc"`
  393. }
  394. binary.ReadJSON(&response, body, &err)
  395. if err != nil {
  396. return nil, err
  397. }
  398. if response.Error != "" {
  399. return nil, fmt.Errorf(response.Error)
  400. }
  401. return response.Result, nil
  402. }
  403. func (c *ClientJSON) BlockchainInfo(minHeight uint) (*core.ResponseBlockchainInfo, error) {
  404. request := RPCRequest{
  405. JSONRPC: "2.0",
  406. Method: "blockchain_info",
  407. Params: []interface{}{minHeight},
  408. Id: 0,
  409. }
  410. body, err := c.RequestResponse(request)
  411. if err != nil {
  412. return nil, err
  413. }
  414. var response struct {
  415. Result *core.ResponseBlockchainInfo `json:"result"`
  416. Error string `json:"error"`
  417. Id string `json:"id"`
  418. JSONRPC string `json:"jsonrpc"`
  419. }
  420. binary.ReadJSON(&response, body, &err)
  421. if err != nil {
  422. return nil, err
  423. }
  424. if response.Error != "" {
  425. return nil, fmt.Errorf(response.Error)
  426. }
  427. return response.Result, nil
  428. }
  429. func (c *ClientJSON) BroadcastTx(tx types.Tx) (*core.ResponseBroadcastTx, error) {
  430. request := RPCRequest{
  431. JSONRPC: "2.0",
  432. Method: "broadcast_tx",
  433. Params: []interface{}{tx},
  434. Id: 0,
  435. }
  436. body, err := c.RequestResponse(request)
  437. if err != nil {
  438. return nil, err
  439. }
  440. var response struct {
  441. Result *core.ResponseBroadcastTx `json:"result"`
  442. Error string `json:"error"`
  443. Id string `json:"id"`
  444. JSONRPC string `json:"jsonrpc"`
  445. }
  446. binary.ReadJSON(&response, body, &err)
  447. if err != nil {
  448. return nil, err
  449. }
  450. if response.Error != "" {
  451. return nil, fmt.Errorf(response.Error)
  452. }
  453. return response.Result, nil
  454. }
  455. func (c *ClientJSON) Call(address []byte) (*core.ResponseCall, error) {
  456. request := RPCRequest{
  457. JSONRPC: "2.0",
  458. Method: "call",
  459. Params: []interface{}{address},
  460. Id: 0,
  461. }
  462. body, err := c.RequestResponse(request)
  463. if err != nil {
  464. return nil, err
  465. }
  466. var response struct {
  467. Result *core.ResponseCall `json:"result"`
  468. Error string `json:"error"`
  469. Id string `json:"id"`
  470. JSONRPC string `json:"jsonrpc"`
  471. }
  472. binary.ReadJSON(&response, body, &err)
  473. if err != nil {
  474. return nil, err
  475. }
  476. if response.Error != "" {
  477. return nil, fmt.Errorf(response.Error)
  478. }
  479. return response.Result, nil
  480. }
  481. func (c *ClientJSON) DumpStorage(addr []byte) (*core.ResponseDumpStorage, error) {
  482. request := RPCRequest{
  483. JSONRPC: "2.0",
  484. Method: "dump_storage",
  485. Params: []interface{}{addr},
  486. Id: 0,
  487. }
  488. body, err := c.RequestResponse(request)
  489. if err != nil {
  490. return nil, err
  491. }
  492. var response struct {
  493. Result *core.ResponseDumpStorage `json:"result"`
  494. Error string `json:"error"`
  495. Id string `json:"id"`
  496. JSONRPC string `json:"jsonrpc"`
  497. }
  498. binary.ReadJSON(&response, body, &err)
  499. if err != nil {
  500. return nil, err
  501. }
  502. if response.Error != "" {
  503. return nil, fmt.Errorf(response.Error)
  504. }
  505. return response.Result, nil
  506. }
  507. func (c *ClientJSON) GenPrivAccount() (*core.ResponseGenPrivAccount, error) {
  508. request := RPCRequest{
  509. JSONRPC: "2.0",
  510. Method: "gen_priv_account",
  511. Params: []interface{}{nil},
  512. Id: 0,
  513. }
  514. body, err := c.RequestResponse(request)
  515. if err != nil {
  516. return nil, err
  517. }
  518. var response struct {
  519. Result *core.ResponseGenPrivAccount `json:"result"`
  520. Error string `json:"error"`
  521. Id string `json:"id"`
  522. JSONRPC string `json:"jsonrpc"`
  523. }
  524. binary.ReadJSON(&response, body, &err)
  525. if err != nil {
  526. return nil, err
  527. }
  528. if response.Error != "" {
  529. return nil, fmt.Errorf(response.Error)
  530. }
  531. return response.Result, nil
  532. }
  533. func (c *ClientJSON) GetAccount(address []byte) (*core.ResponseGetAccount, error) {
  534. request := RPCRequest{
  535. JSONRPC: "2.0",
  536. Method: "get_account",
  537. Params: []interface{}{address},
  538. Id: 0,
  539. }
  540. body, err := c.RequestResponse(request)
  541. if err != nil {
  542. return nil, err
  543. }
  544. var response struct {
  545. Result *core.ResponseGetAccount `json:"result"`
  546. Error string `json:"error"`
  547. Id string `json:"id"`
  548. JSONRPC string `json:"jsonrpc"`
  549. }
  550. binary.ReadJSON(&response, body, &err)
  551. if err != nil {
  552. return nil, err
  553. }
  554. if response.Error != "" {
  555. return nil, fmt.Errorf(response.Error)
  556. }
  557. return response.Result, nil
  558. }
  559. func (c *ClientJSON) GetBlock(height uint) (*core.ResponseGetBlock, error) {
  560. request := RPCRequest{
  561. JSONRPC: "2.0",
  562. Method: "get_block",
  563. Params: []interface{}{height},
  564. Id: 0,
  565. }
  566. body, err := c.RequestResponse(request)
  567. if err != nil {
  568. return nil, err
  569. }
  570. var response struct {
  571. Result *core.ResponseGetBlock `json:"result"`
  572. Error string `json:"error"`
  573. Id string `json:"id"`
  574. JSONRPC string `json:"jsonrpc"`
  575. }
  576. binary.ReadJSON(&response, body, &err)
  577. if err != nil {
  578. return nil, err
  579. }
  580. if response.Error != "" {
  581. return nil, fmt.Errorf(response.Error)
  582. }
  583. return response.Result, nil
  584. }
  585. func (c *ClientJSON) GetStorage(address []byte) (*core.ResponseGetStorage, error) {
  586. request := RPCRequest{
  587. JSONRPC: "2.0",
  588. Method: "get_storage",
  589. Params: []interface{}{address},
  590. Id: 0,
  591. }
  592. body, err := c.RequestResponse(request)
  593. if err != nil {
  594. return nil, err
  595. }
  596. var response struct {
  597. Result *core.ResponseGetStorage `json:"result"`
  598. Error string `json:"error"`
  599. Id string `json:"id"`
  600. JSONRPC string `json:"jsonrpc"`
  601. }
  602. binary.ReadJSON(&response, body, &err)
  603. if err != nil {
  604. return nil, err
  605. }
  606. if response.Error != "" {
  607. return nil, fmt.Errorf(response.Error)
  608. }
  609. return response.Result, nil
  610. }
  611. func (c *ClientJSON) ListAccounts() (*core.ResponseListAccounts, error) {
  612. request := RPCRequest{
  613. JSONRPC: "2.0",
  614. Method: "list_accounts",
  615. Params: []interface{}{nil},
  616. Id: 0,
  617. }
  618. body, err := c.RequestResponse(request)
  619. if err != nil {
  620. return nil, err
  621. }
  622. var response struct {
  623. Result *core.ResponseListAccounts `json:"result"`
  624. Error string `json:"error"`
  625. Id string `json:"id"`
  626. JSONRPC string `json:"jsonrpc"`
  627. }
  628. binary.ReadJSON(&response, body, &err)
  629. if err != nil {
  630. return nil, err
  631. }
  632. if response.Error != "" {
  633. return nil, fmt.Errorf(response.Error)
  634. }
  635. return response.Result, nil
  636. }
  637. func (c *ClientJSON) ListValidators() (*core.ResponseListValidators, error) {
  638. request := RPCRequest{
  639. JSONRPC: "2.0",
  640. Method: "list_validators",
  641. Params: []interface{}{nil},
  642. Id: 0,
  643. }
  644. body, err := c.RequestResponse(request)
  645. if err != nil {
  646. return nil, err
  647. }
  648. var response struct {
  649. Result *core.ResponseListValidators `json:"result"`
  650. Error string `json:"error"`
  651. Id string `json:"id"`
  652. JSONRPC string `json:"jsonrpc"`
  653. }
  654. binary.ReadJSON(&response, body, &err)
  655. if err != nil {
  656. return nil, err
  657. }
  658. if response.Error != "" {
  659. return nil, fmt.Errorf(response.Error)
  660. }
  661. return response.Result, nil
  662. }
  663. func (c *ClientJSON) NetInfo() (*core.ResponseNetInfo, error) {
  664. request := RPCRequest{
  665. JSONRPC: "2.0",
  666. Method: "net_info",
  667. Params: []interface{}{nil},
  668. Id: 0,
  669. }
  670. body, err := c.RequestResponse(request)
  671. if err != nil {
  672. return nil, err
  673. }
  674. var response struct {
  675. Result *core.ResponseNetInfo `json:"result"`
  676. Error string `json:"error"`
  677. Id string `json:"id"`
  678. JSONRPC string `json:"jsonrpc"`
  679. }
  680. binary.ReadJSON(&response, body, &err)
  681. if err != nil {
  682. return nil, err
  683. }
  684. if response.Error != "" {
  685. return nil, fmt.Errorf(response.Error)
  686. }
  687. return response.Result, nil
  688. }
  689. func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*core.ResponseSignTx, error) {
  690. request := RPCRequest{
  691. JSONRPC: "2.0",
  692. Method: "sign_tx",
  693. Params: []interface{}{tx, privAccounts},
  694. Id: 0,
  695. }
  696. body, err := c.RequestResponse(request)
  697. if err != nil {
  698. return nil, err
  699. }
  700. var response struct {
  701. Result *core.ResponseSignTx `json:"result"`
  702. Error string `json:"error"`
  703. Id string `json:"id"`
  704. JSONRPC string `json:"jsonrpc"`
  705. }
  706. binary.ReadJSON(&response, body, &err)
  707. if err != nil {
  708. return nil, err
  709. }
  710. if response.Error != "" {
  711. return nil, fmt.Errorf(response.Error)
  712. }
  713. return response.Result, nil
  714. }
  715. func (c *ClientJSON) Status() (*core.ResponseStatus, error) {
  716. request := RPCRequest{
  717. JSONRPC: "2.0",
  718. Method: "status",
  719. Params: []interface{}{nil},
  720. Id: 0,
  721. }
  722. body, err := c.RequestResponse(request)
  723. if err != nil {
  724. return nil, err
  725. }
  726. var response struct {
  727. Result *core.ResponseStatus `json:"result"`
  728. Error string `json:"error"`
  729. Id string `json:"id"`
  730. JSONRPC string `json:"jsonrpc"`
  731. }
  732. binary.ReadJSON(&response, body, &err)
  733. if err != nil {
  734. return nil, err
  735. }
  736. if response.Error != "" {
  737. return nil, fmt.Errorf(response.Error)
  738. }
  739. return response.Result, nil
  740. }