* Move distr params to simulation param generator * Cleanup sim params output * Print params when possible instead of entire genesis struct * Update module param simulator keys * Rename module params simulator keys * Add/fix missing module params and implement SimParams * UPdate sim test to accept params file * Allow weights to be provided from file * Create doc.go * Remove TODO * Implement MustMarshalJSONIndent * Use mustMarshalJSONIndent for non-codec * Remove TODO * Fix doc.go * Update points * Update simapp/doc.go Co-Authored-By: Alessio Treglia <quadrispro@ubuntu.com> * Update simapp/doc.go Co-Authored-By: Alessio Treglia <quadrispro@ubuntu.com> * Cleanup appStateFn * Use constants for simulation parameter keys * Update msgs.go * minor formatting
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package codec
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
amino "github.com/tendermint/go-amino"
|
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
|
)
|
|
|
|
// amino codec to marshal/unmarshal
|
|
type Codec = amino.Codec
|
|
|
|
func New() *Codec {
|
|
return amino.NewCodec()
|
|
}
|
|
|
|
// Register the go-crypto to the codec
|
|
func RegisterCrypto(cdc *Codec) {
|
|
cryptoAmino.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
|
|
}
|
|
|
|
// MustMarshalJSONIndent executes MarshalJSONIndent except it panics upon failure.
|
|
func MustMarshalJSONIndent(cdc *Codec, obj interface{}) []byte {
|
|
bz, err := MarshalJSONIndent(cdc, obj)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("failed to marshal JSON: %s", err))
|
|
}
|
|
|
|
return bz
|
|
}
|
|
|
|
//__________________________________________________________________
|
|
|
|
// generic sealed codec to be used throughout sdk
|
|
var Cdc *Codec
|
|
|
|
func init() {
|
|
cdc := New()
|
|
RegisterCrypto(cdc)
|
|
Cdc = cdc.Seal()
|
|
}
|