mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-12 17:16:38 +00:00

* refactor: remove unwanted function in `lib` The `lib` shall always be used with file lock. * refactor: log `txResponse` in `buildSignBroadcastTx` - Move `GetTxResponseFromOut` from `testutil` to `lib` Signed-off-by: Julian Strobl <jmastr@mailbox.org>
27 lines
775 B
Go
27 lines
775 B
Go
package lib
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"regexp"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"sigs.k8s.io/yaml"
|
|
)
|
|
|
|
// GetTxResponseFromOut converts strings to numbers and unmarshalles out into TxResponse struct
|
|
func GetTxResponseFromOut(out *bytes.Buffer) (txResponse sdk.TxResponse, err error) {
|
|
m := regexp.MustCompile(`"([0-9]+?)"`)
|
|
str := m.ReplaceAllString(out.String(), "${1}")
|
|
|
|
// We might have YAML here, so we need to convert to JSON first, because TxResponse struct lacks `yaml:"height,omitempty"`, etc.
|
|
// Since JSON is a subset of YAML, passing JSON through YAMLToJSON is a no-op and the result is the byte array of the JSON again.
|
|
j, err := yaml.YAMLToJSON([]byte(str))
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = json.Unmarshal(j, &txResponse)
|
|
return
|
|
}
|