Enable proto JSON for genesis (#7000)
* Enable proto JSON for genesis * Test fixes * Cleanup * Cleanup * Cleanup * Update CHANGELOG.md * Protogen Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: SaReN <sahithnarahari@gmail.com>
This commit is contained in:
co-authored by
Federico Kunze
SaReN
parent
1744194e71
commit
20c5ee3624
+5
-6
@@ -3,6 +3,7 @@ package server
|
||||
// DONTCOVER
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -10,9 +11,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/server/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@@ -29,9 +28,6 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
|
||||
Use: "export",
|
||||
Short: "Export state to JSON",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
cdc := clientCtx.JSONMarshaler
|
||||
|
||||
serverCtx := GetServerContextFromCmd(cmd)
|
||||
config := serverCtx.Config
|
||||
|
||||
@@ -94,7 +90,10 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
|
||||
},
|
||||
}
|
||||
|
||||
encoded, err := codec.MarshalJSONIndent(cdc, doc)
|
||||
// NOTE: for now we're just using standard JSON marshaling for the root GenesisDoc.
|
||||
// These types are in Tendermint, don't support proto and as far as we know, don't need it.
|
||||
// All of the protobuf/amino state is inside AppState
|
||||
encoded, err := json.MarshalIndent(doc, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/types/errors"
|
||||
@@ -36,14 +35,14 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
|
||||
}
|
||||
|
||||
db := dbm.NewMemDB()
|
||||
app := simapp.NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, tempDir, 0)
|
||||
app := simapp.NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, tempDir, 0, simapp.MakeEncodingConfig())
|
||||
|
||||
serverCtx := NewDefaultContext()
|
||||
serverCtx.Config.RootDir = tempDir
|
||||
|
||||
clientCtx := client.Context{}.WithJSONMarshaler(app.LegacyAmino())
|
||||
clientCtx := client.Context{}.WithJSONMarshaler(app.AppCodec())
|
||||
|
||||
genDoc := newDefaultGenesisDoc(app.LegacyAmino())
|
||||
genDoc := newDefaultGenesisDoc()
|
||||
err = saveGenesisFile(genDoc, serverCtx.Config.GenesisFile())
|
||||
|
||||
app.InitChain(
|
||||
@@ -71,7 +70,7 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
|
||||
require.NoError(t, cmd.ExecuteContext(ctx))
|
||||
|
||||
var exportedGenDoc tmtypes.GenesisDoc
|
||||
err = app.LegacyAmino().UnmarshalJSON(output.Bytes(), &exportedGenDoc)
|
||||
err = json.Unmarshal(output.Bytes(), &exportedGenDoc)
|
||||
if err != nil {
|
||||
t.Fatalf("error unmarshaling exported genesis doc: %s", err)
|
||||
}
|
||||
@@ -90,10 +89,10 @@ func createConfigFolder(dir string) error {
|
||||
return os.Mkdir(path.Join(dir, "config"), 0700)
|
||||
}
|
||||
|
||||
func newDefaultGenesisDoc(cdc *codec.LegacyAmino) *tmtypes.GenesisDoc {
|
||||
func newDefaultGenesisDoc() *tmtypes.GenesisDoc {
|
||||
genesisState := simapp.NewDefaultGenesisState()
|
||||
|
||||
stateBytes, err := codec.MarshalJSONIndent(cdc, genesisState)
|
||||
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user