REST bank transfers fail due to encoding. (#6536)

Bank module REST endpoint bank/accounts/{addr}/transfers
was returning invalid StdTx format.
This commit is contained in:
Jonathan Gimeno
2020-07-02 05:16:39 +02:00
committed by GitHub
parent 37cc04081e
commit 8f96ec0585
4 changed files with 130 additions and 1 deletions
+21
View File
@@ -3,6 +3,7 @@
package rest
import (
"bytes"
"encoding/json"
"errors"
"fmt"
@@ -442,3 +443,23 @@ func GetRequest(url string) ([]byte, error) {
return body, nil
}
// PostRequest defines a wrapper around an HTTP POST request with a provided URL and data.
// An error is returned if the request or reading the body fails.
func PostRequest(url string, contentType string, data []byte) ([]byte, error) {
res, err := http.Post(url, contentType, bytes.NewBuffer(data)) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("error while sending post request: %w", err)
}
bz, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %w", err)
}
if err = res.Body.Close(); err != nil {
return nil, err
}
return bz, nil
}