2018-09-13 11:17:32 -07:00
|
|
|
package codec
|
2018-03-02 01:24:07 -08:00
|
|
|
|
|
|
|
import (
|
2018-04-09 10:32:19 -07:00
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
|
2018-06-28 17:54:47 -07:00
|
|
|
amino "github.com/tendermint/go-amino"
|
2019-04-04 07:36:39 -07:00
|
|
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
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
|
|
|
|
2018-09-13 11:17:32 -07:00
|
|
|
func New() *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) {
|
2018-07-25 13:43:37 -07:00
|
|
|
cryptoAmino.RegisterAmino(cdc)
|
2018-04-06 17:25:08 -07:00
|
|
|
}
|
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
|
|
|
|
}
|
2018-06-26 19:00:12 -07:00
|
|
|
|
|
|
|
//__________________________________________________________________
|
|
|
|
|
|
|
|
// generic sealed codec to be used throughout sdk
|
|
|
|
var Cdc *Codec
|
|
|
|
|
|
|
|
func init() {
|
2018-09-13 11:17:32 -07:00
|
|
|
cdc := New()
|
2018-06-26 19:00:12 -07:00
|
|
|
RegisterCrypto(cdc)
|
2018-07-05 09:04:21 -07:00
|
|
|
Cdc = cdc.Seal()
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|