Skip to content

Commit

Permalink
add view query
Browse files Browse the repository at this point in the history
  • Loading branch information
seiji0411 committed Aug 22, 2024
1 parent 9c06cca commit b24bb63
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions aptosclient/rest_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aptosclient

import (
"bytes"
"context"
"encoding/json"
"io"
Expand Down Expand Up @@ -100,6 +101,34 @@ func (c *RestClient) RawQuery(urlWithoutVersion string, params map[string]string
return
}

func (c *RestClient) ViewQuery(payload map[string]string) (res []byte, err error) {
data, err := json.Marshal(payload)
if err != nil {
return
}
req, err := http.NewRequest("POST", c.GetVersionedRpcUrl()+"/view", bytes.NewReader(data))
if err != nil {
return
}
req.Header["Content-Type"] = []string{"application/json"}

resp, err := c.c.Do(req)
if err != nil {
return
}
res, err = io.ReadAll(resp.Body)
if err != nil {
return
}
if resp.StatusCode >= http.StatusBadRequest {
restError := &aptostypes.RestError{}
json.Unmarshal(res, &restError)
restError.Code = resp.StatusCode
return nil, restError
}
return
}

func (c *RestClient) setChainId() (err error) {
ledger, err := c.LedgerInfo()
if err != nil {
Expand Down

0 comments on commit b24bb63

Please sign in to comment.