Skip to content

Commit

Permalink
chore(cosmos): make ActionHeader a mutable pointer target
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Mar 5, 2024
1 parent b89aaca commit c2b36dc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 49 deletions.
20 changes: 10 additions & 10 deletions golang/cosmos/x/swingset/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ import (
)

type beginBlockAction struct {
vm.ActionHeader `actionType:"BEGIN_BLOCK"`
ChainID string `json:"chainID"`
Params types.Params `json:"params"`
*vm.ActionHeader `actionType:"BEGIN_BLOCK"`
ChainID string `json:"chainID"`
Params types.Params `json:"params"`
}

type endBlockAction struct {
vm.ActionHeader `actionType:"END_BLOCK"`
*vm.ActionHeader `actionType:"END_BLOCK"`
}

type commitBlockAction struct {
vm.ActionHeader `actionType:"COMMIT_BLOCK"`
*vm.ActionHeader `actionType:"COMMIT_BLOCK"`
}

type afterCommitBlockAction struct {
vm.ActionHeader `actionType:"AFTER_COMMIT_BLOCK"`
*vm.ActionHeader `actionType:"AFTER_COMMIT_BLOCK"`
}

func BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, keeper Keeper) error {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)

action := &beginBlockAction{
action := beginBlockAction{
ChainID: ctx.ChainID(),
Params: keeper.GetParams(ctx),
}
Expand All @@ -56,7 +56,7 @@ var endBlockTime int64
func EndBlock(ctx sdk.Context, req abci.RequestEndBlock, keeper Keeper) ([]abci.ValidatorUpdate, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)

action := &endBlockAction{}
action := endBlockAction{}
_, err := keeper.BlockingSend(ctx, action)

// fmt.Fprintf(os.Stderr, "END_BLOCK Returned from SwingSet: %s, %v\n", out, err)
Expand All @@ -83,7 +83,7 @@ func getEndBlockContext() sdk.Context {
func CommitBlock(keeper Keeper) error {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), "commit_blocker")

action := &commitBlockAction{}
action := commitBlockAction{}
_, err := keeper.BlockingSend(getEndBlockContext(), action)

// fmt.Fprintf(os.Stderr, "COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
Expand All @@ -98,7 +98,7 @@ func CommitBlock(keeper Keeper) error {
func AfterCommitBlock(keeper Keeper) error {
// defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), "commit_blocker")

action := &afterCommitBlockAction{}
action := afterCommitBlockAction{}
_, err := keeper.BlockingSend(getEndBlockContext(), action)

// fmt.Fprintf(os.Stderr, "AFTER_COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
Expand Down
36 changes: 18 additions & 18 deletions golang/cosmos/x/swingset/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {
var _ types.MsgServer = msgServer{}

type deliverInboundAction struct {
vm.ActionHeader `actionType:"DELIVER_INBOUND"`
Peer string `json:"peer"`
Messages [][]interface{} `json:"messages"`
Ack uint64 `json:"ack"`
*vm.ActionHeader `actionType:"DELIVER_INBOUND"`
Peer string `json:"peer"`
Messages [][]interface{} `json:"messages"`
Ack uint64 `json:"ack"`
}

func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionMsg, action vm.Action) error {
Expand All @@ -48,7 +48,7 @@ func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeli
for i, message := range msg.Messages {
messages[i] = []interface{}{msg.Nums[i], message}
}
action := &deliverInboundAction{
action := deliverInboundAction{
Peer: msg.Submitter.String(),
Messages: messages,
Ack: msg.Ack,
Expand All @@ -63,9 +63,9 @@ func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeli
}

type walletAction struct {
vm.ActionHeader `actionType:"WALLET_ACTION"`
Owner string `json:"owner"`
Action string `json:"action"`
*vm.ActionHeader `actionType:"WALLET_ACTION"`
Owner string `json:"owner"`
Action string `json:"action"`
}

func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWalletAction) (*types.MsgWalletActionResponse, error) {
Expand All @@ -76,7 +76,7 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet
return nil, err
}

action := &walletAction{
action := walletAction{
Owner: msg.Owner.String(),
Action: msg.Action,
}
Expand All @@ -91,9 +91,9 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet
}

type walletSpendAction struct {
vm.ActionHeader `actionType:"WALLET_SPEND_ACTION"`
Owner string `json:"owner"`
SpendAction string `json:"spendAction"`
*vm.ActionHeader `actionType:"WALLET_SPEND_ACTION"`
Owner string `json:"owner"`
SpendAction string `json:"spendAction"`
}

func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgWalletSpendAction) (*types.MsgWalletSpendActionResponse, error) {
Expand All @@ -104,7 +104,7 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW
return nil, err
}

action := &walletSpendAction{
action := walletSpendAction{
Owner: msg.Owner.String(),
SpendAction: msg.SpendAction,
}
Expand All @@ -117,7 +117,7 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW
}

type provisionAction struct {
vm.ActionHeader `actionType:"PLEASE_PROVISION"`
*vm.ActionHeader `actionType:"PLEASE_PROVISION"`
*types.MsgProvision
AutoProvision bool `json:"autoProvision"`
}
Expand All @@ -141,7 +141,7 @@ func (keeper msgServer) provisionIfNeeded(ctx sdk.Context, owner sdk.AccAddress)
PowerFlags: []string{types.PowerFlagSmartWallet},
}

action := &provisionAction{
action := provisionAction{
MsgProvision: msg,
AutoProvision: true,
}
Expand All @@ -163,7 +163,7 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision
return nil, err
}

action := &provisionAction{
action := provisionAction{
MsgProvision: msg,
}

Expand All @@ -184,7 +184,7 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision
}

type installBundleAction struct {
vm.ActionHeader `actionType:"INSTALL_BUNDLE"`
*vm.ActionHeader `actionType:"INSTALL_BUNDLE"`
*types.MsgInstallBundle
}

Expand All @@ -195,7 +195,7 @@ func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInsta
if err != nil {
return nil, err
}
action := &installBundleAction{
action := installBundleAction{
MsgInstallBundle: msg,
}

Expand Down
6 changes: 3 additions & 3 deletions golang/cosmos/x/swingset/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
)

type coreEvalAction struct {
vm.ActionHeader `actionType:"CORE_EVAL"`
Evals []types.CoreEval `json:"evals"`
*vm.ActionHeader `actionType:"CORE_EVAL"`
Evals []types.CoreEval `json:"evals"`
}

// CoreEvalProposal tells SwingSet to evaluate the given JS code.
func (k Keeper) CoreEvalProposal(ctx sdk.Context, p *types.CoreEvalProposal) error {
action := &coreEvalAction{
action := coreEvalAction{
Evals: p.Evals,
}

Expand Down
6 changes: 3 additions & 3 deletions golang/cosmos/x/vibc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func NewHandler(keeper Keeper, bankKeeper types.BankKeeper) sdk.Handler {
}

type sendPacketAction struct {
vm.ActionHeader `actionType:"IBC_EVENT"`
Event string `json:"event" default:"sendPacket"`
*vm.ActionHeader `actionType:"IBC_EVENT"`
Event string `json:"event" default:"sendPacket"`
*MsgSendPacket
}

Expand All @@ -45,7 +45,7 @@ func handleMsgSendPacket(
)
}

action := &sendPacketAction{
action := sendPacketAction{
MsgSendPacket: msg,
}
// fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
Expand Down
35 changes: 20 additions & 15 deletions golang/cosmos/x/vibc/types/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ func NewIBCModule(impl IBCModuleImpl) IBCModule {
}
}

type channelOpenInitEvent struct {
type ChannelOpenInitEvent struct {
*vm.ActionHeader `actionType:"IBC_EVENT"`
Event string `json:"event" default:"channelOpenInit"`
Target string `json:"target,omitempty"`
Order string `json:"order"`
ConnectionHops []string `json:"connectionHops"`
PortID string `json:"portID"`
Expand All @@ -65,7 +66,7 @@ func (im IBCModule) OnChanOpenInit(
counterparty channeltypes.Counterparty,
version string,
) (string, error) {
event := channelOpenInitEvent{
event := ChannelOpenInitEvent{
Order: orderToString(order),
ConnectionHops: connectionHops,
PortID: portID,
Expand Down Expand Up @@ -93,9 +94,10 @@ func (im IBCModule) OnChanOpenInit(
return "", nil
}

type channelOpenTryEvent struct {
type ChannelOpenTryEvent struct {
*vm.ActionHeader `actionType:"IBC_EVENT"`
Event string `json:"event" default:"channelOpenTry"`
Target string `json:"target,omitempty"`
Order string `json:"order"`
ConnectionHops []string `json:"connectionHops"`
PortID string `json:"portID"`
Expand All @@ -115,7 +117,7 @@ func (im IBCModule) OnChanOpenTry(
counterparty channeltypes.Counterparty,
counterpartyVersion string,
) (string, error) {
event := channelOpenTryEvent{
event := ChannelOpenTryEvent{
Order: orderToString(order),
ConnectionHops: connectionHops,
PortID: portID,
Expand Down Expand Up @@ -145,7 +147,7 @@ func (im IBCModule) OnChanOpenTry(
return "", nil
}

type channelOpenAckEvent struct {
type ChannelOpenAckEvent struct {
*vm.ActionHeader `actionType:"IBC_EVENT"`
Event string `json:"event" default:"channelOpenAck"`
PortID string `json:"portID"`
Expand All @@ -167,7 +169,7 @@ func (im IBCModule) OnChanOpenAck(
channel, _ := im.impl.GetChannel(ctx, portID, channelID)

channel.Counterparty.ChannelId = counterpartyChannelID
event := channelOpenAckEvent{
event := ChannelOpenAckEvent{
PortID: portID,
ChannelID: channelID,
CounterpartyVersion: counterpartyVersion,
Expand All @@ -178,9 +180,10 @@ func (im IBCModule) OnChanOpenAck(
return im.impl.PushAction(ctx, event)
}

type channelOpenConfirmEvent struct {
type ChannelOpenConfirmEvent struct {
*vm.ActionHeader `actionType:"IBC_EVENT"`
Event string `json:"event" default:"channelOpenConfirm"`
Target string `json:"target,omitempty"`
PortID string `json:"portID"`
ChannelID string `json:"channelID"`
}
Expand All @@ -190,17 +193,18 @@ func (im IBCModule) OnChanOpenConfirm(
portID,
channelID string,
) error {
event := channelOpenConfirmEvent{
event := ChannelOpenConfirmEvent{
PortID: portID,
ChannelID: channelID,
}

return im.impl.PushAction(ctx, event)
}

type channelCloseInitEvent struct {
type ChannelCloseInitEvent struct {
*vm.ActionHeader `actionType:"IBC_EVENT"`
Event string `json:"event" default:"channelCloseInit"`
Target string `json:"target,omitempty"`
PortID string `json:"portID"`
ChannelID string `json:"channelID"`
}
Expand All @@ -210,7 +214,7 @@ func (im IBCModule) OnChanCloseInit(
portID,
channelID string,
) error {
event := channelCloseInitEvent{
event := ChannelCloseInitEvent{
PortID: portID,
ChannelID: channelID,
}
Expand All @@ -219,9 +223,10 @@ func (im IBCModule) OnChanCloseInit(
return err
}

type channelCloseConfirmEvent struct {
type ChannelCloseConfirmEvent struct {
*vm.ActionHeader `actionType:"IBC_EVENT"`
Event string `json:"event" default:"channelCloseConfirm"`
Target string `json:"target,omitempty"`
PortID string `json:"portID"`
ChannelID string `json:"channelID"`
}
Expand All @@ -231,7 +236,7 @@ func (im IBCModule) OnChanCloseConfirm(
portID,
channelID string,
) error {
event := channelCloseConfirmEvent{
event := ChannelCloseConfirmEvent{
PortID: portID,
ChannelID: channelID,
}
Expand All @@ -243,7 +248,7 @@ func (im IBCModule) OnChanCloseConfirm(
type ReceivePacketEvent struct {
*vm.ActionHeader `actionType:"IBC_EVENT"`
Event string `json:"event" default:"receivePacket"`
Target string `json:"target"`
Target string `json:"target,omitempty"`
Packet channeltypes.Packet `json:"packet"`
Relayer sdk.AccAddress `json:"relayer"`
}
Expand Down Expand Up @@ -277,7 +282,7 @@ func (im IBCModule) OnRecvPacket(
type AcknowledgementPacketEvent struct {
*vm.ActionHeader `actionType:"IBC_EVENT"`
Event string `json:"event" default:"acknowledgementPacket"`
Target string `json:"target"`
Target string `json:"target,omitempty"`
Packet channeltypes.Packet `json:"packet"`
Acknowledgement []byte `json:"acknowledgement"`
Relayer sdk.AccAddress `json:"relayer"`
Expand Down Expand Up @@ -306,7 +311,7 @@ func (im IBCModule) OnAcknowledgementPacket(
type TimeoutPacketEvent struct {
*vm.ActionHeader `actionType:"IBC_EVENT"`
Event string `json:"event" default:"timeoutPacket"`
Target string `json:"target"`
Target string `json:"target,omitempty"`
Packet channeltypes.Packet `json:"packet"`
Relayer sdk.AccAddress `json:"relayer"`
}
Expand Down

0 comments on commit c2b36dc

Please sign in to comment.