cosmos-sdk/wire/wire.go

38 lines
656 B
Go
Raw Normal View History

2018-03-02 01:24:07 -08:00
package wire
import (
2018-04-09 10:32:19 -07:00
"bytes"
"encoding/json"
2018-04-06 16:20:14 -07:00
"github.com/tendermint/go-amino"
2018-04-06 17:25:08 -07:00
"github.com/tendermint/go-crypto"
2018-03-02 01:24:07 -08:00
)
2018-04-18 21:49:24 -07:00
// amino codec to marshal/unmarshal
2018-04-06 16:20:14 -07:00
type Codec = amino.Codec
2018-03-02 01:24:07 -08:00
func NewCodec() *Codec {
2018-04-06 16:20:14 -07:00
cdc := amino.NewCodec()
return cdc
2018-03-02 01:24:07 -08:00
}
2018-04-06 17:25:08 -07:00
2018-04-18 21:49:24 -07:00
// Register the go-crypto to the codec
2018-04-06 17:25:08 -07:00
func RegisterCrypto(cdc *Codec) {
crypto.RegisterAmino(cdc)
}
2018-04-09 10:32:19 -07:00
2018-04-18 21:49:24 -07:00
// attempt to make some pretty json
2018-04-09 10:32:19 -07:00
func MarshalJSONIndent(cdc *Codec, obj interface{}) ([]byte, error) {
bz, err := cdc.MarshalJSON(obj)
if err != nil {
return nil, err
}
var out bytes.Buffer
err = json.Indent(&out, bz, "", " ")
if err != nil {
return nil, err
}
return out.Bytes(), nil
}