Revert "done: wire -> json"

This reverts commit f279a5538d.
This commit is contained in:
mossid 2018-03-15 13:48:52 +01:00
parent df752d52c7
commit a8b343a333
4 changed files with 31 additions and 17 deletions

View File

@ -1,7 +1,6 @@
package commands
import (
"encoding/json"
"fmt"
"github.com/spf13/viper"
@ -9,10 +8,10 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
// wire "github.com/tendermint/go-amino"
wire "github.com/tendermint/go-amino"
)
func buildTx(msg sdk.Msg, name string) ([]byte, error) {
func buildTx(cdc *wire.Codec, msg sdk.Msg, name string) ([]byte, error) {
keybase, err := keys.GetKeyBase()
if err != nil {
return nil, err
@ -37,7 +36,7 @@ func buildTx(msg sdk.Msg, name string) ([]byte, error) {
tx := sdk.NewStdTx(msg, sigs)
txBytes, err := json.Marshal(tx)
txBytes, err := cdc.MarshalBinary(tx)
if err != nil {
return nil, err
}

View File

@ -1,7 +1,6 @@
package commands
import (
"encoding/json"
"fmt"
"time"
@ -11,13 +10,13 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/builder"
//wire "github.com/tendermint/go-amino"
wire "github.com/tendermint/go-amino"
"github.com/cosmos/cosmos-sdk/x/ibc"
)
func IBCRelayCmd() *cobra.Command {
cmdr := relayCommander{"ibc"}
func IBCRelayCmd(cdc *wire.Codec) *cobra.Command {
cmdr := relayCommander{cdc, "ibc"}
cmd := &cobra.Command{
Use: "relay",
@ -28,7 +27,7 @@ func IBCRelayCmd() *cobra.Command {
}
type relayCommander struct {
// cdc *wire.Codec
cdc *wire.Codec
ibcStore string
}
@ -60,7 +59,7 @@ func broadcastTx(id string, tx []byte) error {
func (c relayCommander) refine(bz []byte, sequence int64) []byte {
var packet ibc.IBCPacket
if err := json.Unmarshal(bz, &packet); err != nil {
if err := c.cdc.UnmarshalBinary(bz, &packet); err != nil {
panic(err)
}
@ -72,7 +71,7 @@ func (c relayCommander) refine(bz []byte, sequence int64) []byte {
Relayer: address,
Sequence: sequence,
}
res, err := buildTx(msg, name)
res, err := buildTx(c.cdc, msg, name)
if err != nil {
panic(err)
}
@ -88,7 +87,7 @@ func (c relayCommander) loop(fromID, toID string) {
}
var processed int64
if err = json.Unmarshal(processedbz, &processed); err != nil {
if err = c.cdc.UnmarshalBinary(processedbz, &processed); err != nil {
panic(err)
}
@ -103,7 +102,7 @@ OUTER:
continue OUTER
}
var egressLength int64
if err = json.Unmarshal(egressLengthbz, &egressLength); err != nil {
if err = c.cdc.UnmarshalBinary(egressLengthbz, &egressLength); err != nil {
panic(err)
}

16
x/ibc/commands/root.go Normal file
View File

@ -0,0 +1,16 @@
package commands
import (
"github.com/spf13/cobra"
wire "github.com/tendermint/go-amino"
)
func AddCommands(cmd *cobra.Command) {
cdc := wire.NewCodec()
cmd.AddCommand(
IBCTransferCmd(cdc),
IBCRelayCmd(cdc),
)
}

View File

@ -16,8 +16,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc"
)
func IBCTransferCmd() *cobra.Command {
cmdr := sendCommander{}
func IBCTransferCmd(cdc *wire.Codec) *cobra.Command {
cmdr := sendCommander{cdc}
cmd := &cobra.Command{
Use: "transfer",
@ -37,7 +37,7 @@ func IBCTransferCmd() *cobra.Command {
}
type sendCommander struct {
// cdc *wire.Codec
cdc *wire.Codec
}
func (c sendCommander) runIBCTransfer(cmd *cobra.Command, args []string) error {
@ -49,7 +49,7 @@ func (c sendCommander) runIBCTransfer(cmd *cobra.Command, args []string) error {
return err
}
txBytes, err := buildTx(msg, keyname)
txBytes, err := buildTx(c.cdc, msg, keyname)
if err != nil {
return err
}