forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wire.go
48 lines (38 loc) · 881 Bytes
/
wire.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package wire
import (
"bytes"
"encoding/json"
amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto"
)
// amino codec to marshal/unmarshal
type Codec = amino.Codec
func NewCodec() *Codec {
cdc := amino.NewCodec()
return cdc
}
// Register the go-crypto to the codec
func RegisterCrypto(cdc *Codec) {
crypto.RegisterAmino(cdc)
}
// attempt to make some pretty json
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
}
//__________________________________________________________________
// generic sealed codec to be used throughout sdk
var Cdc *Codec
func init() {
cdc := NewCodec()
RegisterCrypto(cdc)
Cdc = cdc.Seal()
}