Skip to content

Commit

Permalink
Merge pull request #1162 from Agoric/mfig/combine-peer-and-submitter
Browse files Browse the repository at this point in the history
fix!: combine peer and submitter for `tx swingset deliver`
  • Loading branch information
michaelfig authored Jun 8, 2020
2 parents e5835f5 + d66756f commit 9cb3050
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 21 deletions.
3 changes: 1 addition & 2 deletions packages/cosmic-swingset/lib/ag-solo/chain-cosmos-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export async function connectToChain(
try {
log(`delivering to chain`, GCI, newMessages, acknum);

// TODO: combine peer and submitter in the message format (i.e. remove
// Peer and submitter are combined in the message format (i.e. we removed
// the extra 'myAddr' after 'tx swingset deliver'). All messages from
// solo vats are "from" the signer, and messages relayed from another
// chain will have other data to demonstrate which chain it comes from
Expand Down Expand Up @@ -369,7 +369,6 @@ export async function connectToChain(
'swingset',
'deliver',
'--keyring-backend=test',
myAddr,
`@${tmpInfo.path}`, // Deliver message over file, as it could be big.
'--gas=auto',
'--gas-adjustment=1.05',
Expand Down
10 changes: 5 additions & 5 deletions packages/cosmic-swingset/x/swingset/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
// GetCmdDeliver is the CLI command for sending a DeliverInbound transaction
func GetCmdDeliver(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "deliver [sender] [json string]",
Use: "deliver [json string]",
Short: "deliver inbound messages",
Args: cobra.ExactArgs(2),
Args: cobra.ExactArgs(1),

RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
cliCtx := context.NewCLIContext().WithCodec(cdc)

txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))

jsonIn := args[1]
jsonIn := args[0]
if jsonIn[0] == '@' {
fname := args[1][1:]
fname := args[0][1:]
if fname == "-" {
// Reading from stdin.
if _, err := fmt.Scanln(&jsonIn); err != nil {
Expand All @@ -69,7 +69,7 @@ func GetCmdDeliver(cdc *codec.Codec) *cobra.Command {
return err
}

msg := types.NewMsgDeliverInbound(args[0], msgs, cliCtx.GetFromAddress())
msg := types.NewMsgDeliverInbound(msgs, cliCtx.GetFromAddress())
if err := msg.ValidateBasic(); err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions packages/cosmic-swingset/x/swingset/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package rest
import (
"net/http"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/Agoric/agoric-sdk/packages/cosmic-swingset/x/swingset/internal/types"
"github.com/cosmos/cosmos-sdk/client/context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"

// "github.com/gorilla/mux"
)

Expand Down Expand Up @@ -47,7 +46,7 @@ func deliverMailboxHandler(cliCtx context.CLIContext) http.HandlerFunc {
return
}

msg := types.NewMsgDeliverInbound(req.Peer, deliver, addr)
msg := types.NewMsgDeliverInbound(deliver, addr)
err = msg.ValidateBasic()
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/x/swingset/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func handleMsgDeliverInbound(ctx sdk.Context, keeper Keeper, msg MsgDeliverInbou

action := &deliverInboundAction{
Type: "DELIVER_INBOUND",
Peer: msg.Peer,
Peer: msg.Submitter.String(),
Messages: messages,
Ack: msg.Ack,
StoragePort: GetPort("controller"),
Expand Down
12 changes: 2 additions & 10 deletions packages/cosmic-swingset/x/swingset/internal/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const RouterKey = ModuleName // this was defined in your key.go file

// MsgDeliverInbound defines a DeliverInbound message
type MsgDeliverInbound struct {
Peer string
Messages []string
Nums []int
Ack int
Expand All @@ -20,9 +19,8 @@ type MsgDeliverInbound struct {

var _ sdk.Msg = &MsgDeliverInbound{}

func NewMsgDeliverInbound(peer string, msgs *Messages, submitter sdk.AccAddress) MsgDeliverInbound {
func NewMsgDeliverInbound(msgs *Messages, submitter sdk.AccAddress) MsgDeliverInbound {
return MsgDeliverInbound{
Peer: peer,
Messages: msgs.Messages,
Nums: msgs.Nums,
Ack: msgs.Ack,
Expand All @@ -34,16 +32,13 @@ func NewMsgDeliverInbound(peer string, msgs *Messages, submitter sdk.AccAddress)
func (msg MsgDeliverInbound) Route() string { return RouterKey }

// Type should return the action
func (msg MsgDeliverInbound) Type() string { return "deliver" }
func (msg MsgDeliverInbound) Type() string { return "eventualSend" }

// ValidateBasic runs stateless checks on the message
func (msg MsgDeliverInbound) ValidateBasic() error {
if msg.Submitter.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Submitter.String())
}
if len(msg.Peer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "Peer cannot be empty")
}
if len(msg.Messages) != len(msg.Nums) {
return sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "Messages and Nums must be the same length")
}
Expand Down Expand Up @@ -155,9 +150,6 @@ func (msg MsgProvision) ValidateBasic() error {
if len(msg.Nickname) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "Nickname cannot be empty")
}
if msg.Address.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Address.String())
}
return nil
}

Expand Down

0 comments on commit 9cb3050

Please sign in to comment.