diff --git a/benchmarks/codec_test.go b/benchmarks/codec_test.go index 35dc591ea..0e77156cf 100644 --- a/benchmarks/codec_test.go +++ b/benchmarks/codec_test.go @@ -12,10 +12,10 @@ import ( func BenchmarkEncodeStatusWire(b *testing.B) { b.StopTimer() - pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) + pubKey := crypto.GenPrivKeyEd25519().PubKey() status := &ctypes.ResultStatus{ NodeInfo: &p2p.NodeInfo{ - PubKey: pubKey, + PubKey: pubKey.Unwrap().(crypto.PubKeyEd25519), Moniker: "SOMENAME", Network: "SOMENAME", RemoteAddr: "SOMEADDR", @@ -40,7 +40,7 @@ func BenchmarkEncodeStatusWire(b *testing.B) { func BenchmarkEncodeNodeInfoWire(b *testing.B) { b.StopTimer() - pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) + pubKey := crypto.GenPrivKeyEd25519().PubKey().Unwrap().(crypto.PubKeyEd25519) nodeInfo := &p2p.NodeInfo{ PubKey: pubKey, Moniker: "SOMENAME", @@ -61,7 +61,7 @@ func BenchmarkEncodeNodeInfoWire(b *testing.B) { func BenchmarkEncodeNodeInfoBinary(b *testing.B) { b.StopTimer() - pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) + pubKey := crypto.GenPrivKeyEd25519().PubKey().Unwrap().(crypto.PubKeyEd25519) nodeInfo := &p2p.NodeInfo{ PubKey: pubKey, Moniker: "SOMENAME", @@ -83,7 +83,7 @@ func BenchmarkEncodeNodeInfoBinary(b *testing.B) { func BenchmarkEncodeNodeInfoProto(b *testing.B) { b.StopTimer() - pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) + pubKey := crypto.GenPrivKeyEd25519().PubKey().Unwrap().(crypto.PubKeyEd25519) pubKey2 := &proto.PubKey{Ed25519: &proto.PubKeyEd25519{Bytes: pubKey[:]}} nodeInfo := &proto.NodeInfo{ PubKey: pubKey2, diff --git a/cmd/tendermint/commands/show_validator.go b/cmd/tendermint/commands/show_validator.go index 4aa80ae14..0b349f98c 100644 --- a/cmd/tendermint/commands/show_validator.go +++ b/cmd/tendermint/commands/show_validator.go @@ -5,7 +5,7 @@ import ( "github.com/spf13/cobra" - "github.com/tendermint/go-wire" + data "github.com/tendermint/go-data" "github.com/tendermint/tendermint/types" ) @@ -22,5 +22,6 @@ func init() { func showValidator(cmd *cobra.Command, args []string) { privValidatorFile := config.GetString("priv_validator_file") privValidator := types.LoadOrGenPrivValidator(privValidatorFile) - fmt.Println(string(wire.JSONBytesPretty(privValidator.PubKey))) + pubKeyJSONBytes, _ := data.ToJSON(privValidator.PubKey) + fmt.Println(string(pubKeyJSONBytes)) } diff --git a/config/tendermint_test/config.go b/config/tendermint_test/config.go index 9d405dc95..78c3bb337 100644 --- a/config/tendermint_test/config.go +++ b/config/tendermint_test/config.go @@ -137,10 +137,10 @@ var defaultGenesis = `{ "chain_id": "tendermint_test", "validators": [ { - "pub_key": [ - 1, - "3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8" - ], + "pub_key": { + "type": "ed25519", + "data":"3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8" + }, "amount": 10, "name": "" } @@ -150,14 +150,14 @@ var defaultGenesis = `{ var defaultPrivValidator = `{ "address": "D028C9981F7A87F3093672BF0D5B0E2A1B3ED456", - "pub_key": [ - 1, - "3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8" - ], - "priv_key": [ - 1, - "27F82582AEFAE7AB151CFB01C48BB6C1A0DA78F9BDDA979A9F70A84D074EB07D3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8" - ], + "pub_key": { + "type": "ed25519", + "data": "3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8" + }, + "priv_key": { + "type": "ed25519", + "data": "27F82582AEFAE7AB151CFB01C48BB6C1A0DA78F9BDDA979A9F70A84D074EB07D3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8" + }, "last_height": 0, "last_round": 0, "last_step": 0 diff --git a/glide.lock b/glide.lock index a1a29b9db..f49e2d3ad 100644 --- a/glide.lock +++ b/glide.lock @@ -106,7 +106,7 @@ imports: - name: github.com/tendermint/go-merkle version: 714d4d04557fd068a7c2a1748241ce8428015a96 - name: github.com/tendermint/go-p2p - version: e8f33a47846708269d373f9c8080613d6c4f66b2 + version: a163fddbdd2541793d22402afb113e6ccb391774 subpackages: - upnp - name: github.com/tendermint/go-rpc diff --git a/node/node.go b/node/node.go index 990779486..96440e910 100644 --- a/node/node.go +++ b/node/node.go @@ -372,7 +372,7 @@ func (n *Node) makeNodeInfo() *p2p.NodeInfo { } nodeInfo := &p2p.NodeInfo{ - PubKey: n.privKey.PubKey().(crypto.PubKeyEd25519), + PubKey: n.privKey.PubKey().Unwrap().(crypto.PubKeyEd25519), Moniker: n.config.GetString("moniker"), Network: n.config.GetString("chain_id"), Version: version.Version, diff --git a/types/genesis.go b/types/genesis.go index 3a0395488..2e1ebb649 100644 --- a/types/genesis.go +++ b/types/genesis.go @@ -1,11 +1,11 @@ package types import ( + "encoding/json" "time" . "github.com/tendermint/go-common" "github.com/tendermint/go-crypto" - "github.com/tendermint/go-wire" ) //------------------------------------------------------------ @@ -31,14 +31,18 @@ type GenesisDoc struct { // Utility method for saving GenensisDoc as JSON file. func (genDoc *GenesisDoc) SaveAs(file string) error { - genDocBytes := wire.JSONBytesPretty(genDoc) + genDocBytes, err := json.Marshal(genDoc) + if err != nil { + return err + } return WriteFile(file, genDocBytes, 0644) } //------------------------------------------------------------ // Make genesis state from file -func GenesisDocFromJSON(jsonBlob []byte) (genDoc *GenesisDoc, err error) { - wire.ReadJSONPtr(&genDoc, jsonBlob, &err) - return +func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) { + genDoc := GenesisDoc{} + err := json.Unmarshal(jsonBlob, &genDoc) + return &genDoc, err } diff --git a/types/priv_validator.go b/types/priv_validator.go index 8752e430d..905f3bf15 100644 --- a/types/priv_validator.go +++ b/types/priv_validator.go @@ -2,6 +2,7 @@ package types import ( "bytes" + "encoding/json" "errors" "fmt" "io/ioutil" @@ -10,7 +11,6 @@ import ( . "github.com/tendermint/go-common" "github.com/tendermint/go-crypto" - "github.com/tendermint/go-wire" ) const ( @@ -96,13 +96,14 @@ func LoadPrivValidator(filePath string) *PrivValidator { if err != nil { Exit(err.Error()) } - privVal := wire.ReadJSON(&PrivValidator{}, privValJSONBytes, &err).(*PrivValidator) + privVal := PrivValidator{} + err = json.Unmarshal(privValJSONBytes, &privVal) if err != nil { Exit(Fmt("Error reading PrivValidator from %v: %v\n", filePath, err)) } privVal.filePath = filePath privVal.Signer = NewDefaultSigner(privVal.PrivKey) - return privVal + return &privVal } func LoadOrGenPrivValidator(filePath string) *PrivValidator { @@ -136,8 +137,12 @@ func (privVal *PrivValidator) save() { if privVal.filePath == "" { PanicSanity("Cannot save PrivValidator: filePath not set") } - jsonBytes := wire.JSONBytesPretty(privVal) - err := WriteFileAtomic(privVal.filePath, jsonBytes, 0600) + jsonBytes, err := json.Marshal(privVal) + if err != nil { + // `@; BOOM!!! + PanicCrisis(err) + } + err = WriteFileAtomic(privVal.filePath, jsonBytes, 0600) if err != nil { // `@; BOOM!!! PanicCrisis(err)