diff --git a/golang/cosmos/app/app.go b/golang/cosmos/app/app.go index 26bb7c922af..100e04ed440 100644 --- a/golang/cosmos/app/app.go +++ b/golang/cosmos/app/app.go @@ -865,18 +865,17 @@ func normalizeModuleAccount(ctx sdk.Context, ak authkeeper.AccountKeeper, name s } type cosmosInitAction struct { - Type string `json:"type"` - ChainID string `json:"chainID"` - BlockTime int64 `json:"blockTime,omitempty"` - IsBootstrap bool `json:"isBootstrap"` - Params swingset.Params `json:"params"` - SupplyCoins sdk.Coins `json:"supplyCoins"` - UpgradePlan *upgradetypes.Plan `json:"upgradePlan,omitempty"` - LienPort int `json:"lienPort"` - StoragePort int `json:"storagePort"` - SwingsetPort int `json:"swingsetPort"` - VbankPort int `json:"vbankPort"` - VibcPort int `json:"vibcPort"` + vm.ActionHeader `actionType:"AG_COSMOS_INIT"` + ChainID string `json:"chainID"` + IsBootstrap bool `json:"isBootstrap"` + Params swingset.Params `json:"params"` + SupplyCoins sdk.Coins `json:"supplyCoins"` + UpgradePlan *upgradetypes.Plan `json:"upgradePlan,omitempty"` + LienPort int `json:"lienPort"` + StoragePort int `json:"storagePort"` + SwingsetPort int `json:"swingsetPort"` + VbankPort int `json:"vbankPort"` + VibcPort int `json:"vibcPort"` } // Name returns the name of the App @@ -899,16 +898,9 @@ func (app *GaiaApp) initController(ctx sdk.Context, bootstrap bool) { app.CheckControllerInited(false) app.controllerInited = true - var blockTime int64 = 0 - if bootstrap || app.upgradePlan != nil { - blockTime = ctx.BlockTime().Unix() - } - // Begin initializing the controller here. action := &cosmosInitAction{ - Type: "AG_COSMOS_INIT", ChainID: ctx.ChainID(), - BlockTime: blockTime, IsBootstrap: bootstrap, Params: app.SwingSetKeeper.GetParams(ctx), SupplyCoins: sdk.NewCoins(app.BankKeeper.GetSupply(ctx, "uist")), @@ -919,7 +911,11 @@ func (app *GaiaApp) initController(ctx sdk.Context, bootstrap bool) { VbankPort: app.vbankPort, VibcPort: app.vibcPort, } - // This really abuses `BlockingSend` to get back at `sendToController` + // This uses `BlockingSend` as a friendly wrapper for `sendToController` + // + // CAVEAT: we are restarting after an in-consensus halt or just because this + // node felt like it. The controller must be able to handle either case + // (inConsensus := action.IsBootstrap || action.UpgradePlan != nil). out, err := app.SwingSetKeeper.BlockingSend(ctx, action) // fmt.Fprintf(os.Stderr, "AG_COSMOS_INIT Returned from SwingSet: %s, %v\n", out, err) diff --git a/golang/cosmos/x/lien/keeper/keeper_test.go b/golang/cosmos/x/lien/keeper/keeper_test.go index f4673661172..31d662fb7df 100644 --- a/golang/cosmos/x/lien/keeper/keeper_test.go +++ b/golang/cosmos/x/lien/keeper/keeper_test.go @@ -112,7 +112,7 @@ func makeTestKit() testKit { sk := stakingkeeper.NewKeeper(cdc, stakingStoreKey, wak, bk, stakingSpace) // lien keeper - pushAction := func(sdk.Context, vm.Jsonable) error { + pushAction := func(sdk.Context, vm.Action) error { return nil } keeper := NewKeeper(cdc, lienStoreKey, wak, bk, sk, pushAction) diff --git a/golang/cosmos/x/swingset/abci.go b/golang/cosmos/x/swingset/abci.go index 567975c995f..df6e360c472 100644 --- a/golang/cosmos/x/swingset/abci.go +++ b/golang/cosmos/x/swingset/abci.go @@ -2,6 +2,7 @@ package swingset import ( // "os" + "context" "fmt" "time" @@ -9,38 +10,34 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" + "github.com/Agoric/agoric-sdk/golang/cosmos/vm" "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types" ) type beginBlockAction struct { - Type string `json:"type"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` - 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 { - Type string `json:"type"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + vm.ActionHeader `actionType:"END_BLOCK"` } type commitBlockAction struct { - Type string `json:"type"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + vm.ActionHeader `actionType:"COMMIT_BLOCK"` +} + +type afterCommitBlockAction struct { + 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{ - Type: "BEGIN_BLOCK", - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), - ChainID: ctx.ChainID(), - Params: keeper.GetParams(ctx), + ChainID: ctx.ChainID(), + Params: keeper.GetParams(ctx), } _, err := keeper.BlockingSend(ctx, action) // fmt.Fprintf(os.Stderr, "BEGIN_BLOCK Returned from SwingSet: %s, %v\n", out, err) @@ -59,11 +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{ - Type: "END_BLOCK", - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), - } + action := &endBlockAction{} _, err := keeper.BlockingSend(ctx, action) // fmt.Fprintf(os.Stderr, "END_BLOCK Returned from SwingSet: %s, %v\n", out, err) @@ -80,15 +73,18 @@ func EndBlock(ctx sdk.Context, req abci.RequestEndBlock, keeper Keeper) ([]abci. return []abci.ValidatorUpdate{}, nil } +func getEndBlockContext() sdk.Context { + return sdk.Context{}. + WithContext(context.Background()). + WithBlockHeight(endBlockHeight). + WithBlockTime(time.Unix(endBlockTime, 0)) +} + func CommitBlock(keeper Keeper) error { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), "commit_blocker") - action := &commitBlockAction{ - Type: "COMMIT_BLOCK", - BlockHeight: endBlockHeight, - BlockTime: endBlockTime, - } - _, err := keeper.BlockingSend(sdk.Context{}, action) + action := &commitBlockAction{} + _, err := keeper.BlockingSend(getEndBlockContext(), action) // fmt.Fprintf(os.Stderr, "COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err) if err != nil { @@ -102,12 +98,8 @@ func CommitBlock(keeper Keeper) error { func AfterCommitBlock(keeper Keeper) error { // defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), "commit_blocker") - action := &commitBlockAction{ - Type: "AFTER_COMMIT_BLOCK", - BlockHeight: endBlockHeight, - BlockTime: endBlockTime, - } - _, err := keeper.BlockingSend(sdk.Context{}, action) + action := &afterCommitBlockAction{} + _, err := keeper.BlockingSend(getEndBlockContext(), action) // fmt.Fprintf(os.Stderr, "AFTER_COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err) if err != nil { diff --git a/golang/cosmos/x/swingset/keeper/msg_server.go b/golang/cosmos/x/swingset/keeper/msg_server.go index e418bf7b3fb..0543661e5c2 100644 --- a/golang/cosmos/x/swingset/keeper/msg_server.go +++ b/golang/cosmos/x/swingset/keeper/msg_server.go @@ -21,15 +21,13 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer { var _ types.MsgServer = msgServer{} type deliverInboundAction struct { - Type string `json:"type"` - Peer string `json:"peer"` - Messages [][]interface{} `json:"messages"` - Ack uint64 `json:"ack"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + 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.Jsonable) error { +func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionMsg, action vm.Action) error { isHighPriority, err := msg.IsHighPriority(ctx, keeper) if err != nil { return err @@ -53,12 +51,9 @@ func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeli } action := &deliverInboundAction{ - Type: "DELIVER_INBOUND", - Peer: msg.Submitter.String(), - Messages: messages, - Ack: msg.Ack, - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), + Peer: msg.Submitter.String(), + Messages: messages, + Ack: msg.Ack, } err := keeper.routeAction(ctx, msg, action) @@ -70,11 +65,9 @@ func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeli } type walletAction struct { - Type string `json:"type"` // WALLET_ACTION - Owner string `json:"owner"` - Action string `json:"action"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + 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) { @@ -86,11 +79,8 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet } action := &walletAction{ - Type: "WALLET_ACTION", - Owner: msg.Owner.String(), - Action: msg.Action, - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), + Owner: msg.Owner.String(), + Action: msg.Action, } // fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx) @@ -103,11 +93,9 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet } type walletSpendAction struct { - Type string `json:"type"` // WALLET_SPEND_ACTION - Owner string `json:"owner"` - SpendAction string `json:"spendAction"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + 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) { @@ -119,11 +107,8 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW } action := &walletSpendAction{ - Type: "WALLET_SPEND_ACTION", Owner: msg.Owner.String(), SpendAction: msg.SpendAction, - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), } // fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx) err = keeper.routeAction(ctx, msg, action) @@ -134,11 +119,9 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW } type provisionAction struct { + vm.ActionHeader `actionType:"PLEASE_PROVISION"` *types.MsgProvision - Type string `json:"type"` // PLEASE_PROVISION - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` - AutoProvision bool `json:"autoProvision"` + AutoProvision bool `json:"autoProvision"` } // provisionIfNeeded generates a provision action if no smart wallet is already @@ -162,9 +145,6 @@ func (keeper msgServer) provisionIfNeeded(ctx sdk.Context, owner sdk.AccAddress) action := &provisionAction{ MsgProvision: msg, - Type: "PLEASE_PROVISION", - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), AutoProvision: true, } @@ -187,9 +167,6 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision action := &provisionAction{ MsgProvision: msg, - Type: "PLEASE_PROVISION", - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), } // Create the account, if it doesn't already exist. @@ -209,10 +186,8 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision } type installBundleAction struct { + vm.ActionHeader `actionType:"INSTALL_BUNDLE"` *types.MsgInstallBundle - Type string `json:"type"` // INSTALL_BUNDLE - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` } func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInstallBundle) (*types.MsgInstallBundleResponse, error) { @@ -224,9 +199,6 @@ func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInsta } action := &installBundleAction{ MsgInstallBundle: msg, - Type: "INSTALL_BUNDLE", - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), } err = keeper.routeAction(ctx, msg, action) diff --git a/golang/cosmos/x/swingset/keeper/proposal.go b/golang/cosmos/x/swingset/keeper/proposal.go index 82d3155b2c4..203a190b6d8 100644 --- a/golang/cosmos/x/swingset/keeper/proposal.go +++ b/golang/cosmos/x/swingset/keeper/proposal.go @@ -3,23 +3,19 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/Agoric/agoric-sdk/golang/cosmos/vm" "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types" ) type coreEvalAction struct { - Type string `json:"type"` // CORE_EVAL - Evals []types.CoreEval `json:"evals"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + 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{ - Type: "CORE_EVAL", - Evals: p.Evals, - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), + Evals: p.Evals, } return k.PushHighPriorityAction(ctx, action) diff --git a/golang/cosmos/x/vbank/vbank.go b/golang/cosmos/x/vbank/vbank.go index cdd3527a2e4..bd4b83908ca 100644 --- a/golang/cosmos/x/vbank/vbank.go +++ b/golang/cosmos/x/vbank/vbank.go @@ -68,15 +68,15 @@ func (vbu vbankManyBalanceUpdates) Swap(i int, j int) { } type vbankBalanceUpdate struct { - Nonce uint64 `json:"nonce"` - Type string `json:"type"` - Updated vbankManyBalanceUpdates `json:"updated"` + vm.ActionHeader `actionType:"VBANK_BALANCE_UPDATE"` + Nonce uint64 `json:"nonce"` + Updated vbankManyBalanceUpdates `json:"updated"` } // getBalanceUpdate returns a bridge message containing the current bank balance // for the given addresses each for the specified denominations. Coins are used // only to track the set of denoms, not for the particular nonzero amounts. -func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string]sdk.Coins) vm.Jsonable { +func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string]sdk.Coins) vm.Action { nentries := len(addressToUpdate) if nentries == 0 { return nil @@ -84,7 +84,6 @@ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string nonce := keeper.GetNextSequence(ctx) event := vbankBalanceUpdate{ - Type: "VBANK_BALANCE_UPDATE", Nonce: nonce, Updated: make([]vbankSingleBalanceUpdate, 0, nentries), } @@ -111,7 +110,9 @@ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string // Ensure we have a deterministic order of updates. sort.Sort(event.Updated) - return event + + // Populate the event default fields (even though event does not embed vm.ActionHeader) + return vm.PopulateAction(ctx, event) } func marshal(event vm.Jsonable) ([]byte, error) { @@ -242,7 +243,7 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string return } -func (am AppModule) PushAction(ctx sdk.Context, action vm.Jsonable) error { +func (am AppModule) PushAction(ctx sdk.Context, action vm.Action) error { // vbank actions are not triggered by a swingset message in a transaction, so we need to // synthesize unique context information. // We use a fixed placeholder value for the txHash context, and can simply use `0` for the diff --git a/golang/cosmos/x/vbank/vbank_test.go b/golang/cosmos/x/vbank/vbank_test.go index 250209fb9ae..e6149776062 100644 --- a/golang/cosmos/x/vbank/vbank_test.go +++ b/golang/cosmos/x/vbank/vbank_test.go @@ -250,7 +250,7 @@ func (b *mockBank) SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, re func makeTestKit(account types.AccountKeeper, bank types.BankKeeper) (Keeper, sdk.Context) { encodingConfig := params.MakeEncodingConfig() cdc := encodingConfig.Marshaler - pushAction := func(ctx sdk.Context, action vm.Jsonable) error { + pushAction := func(ctx sdk.Context, action vm.Action) error { return nil } @@ -517,16 +517,16 @@ func Test_EndBlock_Events(t *testing.T) { }} acct := &mockAuthKeeper{ accounts: map[string]authtypes.AccountI{ - addr1: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{ Address: addr1 }}, - addr2: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{ Address: addr2 }}, - addr3: &authtypes.BaseAccount{ Address: addr3 }, + addr1: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{Address: addr1}}, + addr2: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{Address: addr2}}, + addr3: &authtypes.BaseAccount{Address: addr3}, }, } keeper, ctx := makeTestKit(acct, bank) // Turn off rewards. keeper.SetParams(ctx, types.Params{PerEpochRewardFraction: sdk.ZeroDec()}) msgsSent := []string{} - keeper.PushAction = func(ctx sdk.Context, action vm.Jsonable) error { + keeper.PushAction = func(ctx sdk.Context, action vm.Action) error { bz, err := json.Marshal(action) if err != nil { return err @@ -630,7 +630,7 @@ func Test_EndBlock_Rewards(t *testing.T) { } keeper, ctx := makeTestKit(nil, bank) msgsSent := []string{} - keeper.PushAction = func(ctx sdk.Context, action vm.Jsonable) error { + keeper.PushAction = func(ctx sdk.Context, action vm.Action) error { bz, err := json.Marshal(action) if err != nil { return err @@ -746,7 +746,7 @@ func Test_EndBlock_Rewards(t *testing.T) { } } -type mockAuthKeeper struct{ +type mockAuthKeeper struct { accounts map[string]authtypes.AccountI modAddrs map[string]string } @@ -754,11 +754,11 @@ type mockAuthKeeper struct{ func (ma mockAuthKeeper) GetModuleAccount(ctx sdk.Context, name string) authtypes.ModuleAccountI { addr, ok := ma.modAddrs[name] if !ok { - return nil + return nil } acct, ok := ma.accounts[addr] if !ok { - panic("missing module account") + panic("missing module account") } return acct.(authtypes.ModuleAccountI) } @@ -778,7 +778,7 @@ func Test_Module_Account(t *testing.T) { acct := &mockAuthKeeper{ accounts: map[string]authtypes.AccountI{ moduleBech32: authtypes.NewEmptyModuleAccount("vbank/reserve"), - addr1: authtypes.NewBaseAccountWithAddress(sdk.MustAccAddressFromBech32(addr1)), + addr1: authtypes.NewBaseAccountWithAddress(sdk.MustAccAddressFromBech32(addr1)), }, modAddrs: map[string]string{ "vbank/reserve": moduleBech32, diff --git a/golang/cosmos/x/vibc/handler.go b/golang/cosmos/x/vibc/handler.go index 5f22a103d6e..74cc0da6ff0 100644 --- a/golang/cosmos/x/vibc/handler.go +++ b/golang/cosmos/x/vibc/handler.go @@ -3,6 +3,7 @@ package vibc import ( "fmt" + "github.com/Agoric/agoric-sdk/golang/cosmos/vm" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -23,10 +24,8 @@ func NewHandler(keeper Keeper) sdk.Handler { type sendPacketAction struct { *MsgSendPacket - Type string `json:"type"` // IBC_EVENT - Event string `json:"event"` // sendPacket - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + vm.ActionHeader `actionType:"IBC_EVENT"` + Event string `json:"event" default:"sendPacket"` } func handleMsgSendPacket(ctx sdk.Context, keeper Keeper, msg *MsgSendPacket) (*sdk.Result, error) { @@ -41,10 +40,6 @@ func handleMsgSendPacket(ctx sdk.Context, keeper Keeper, msg *MsgSendPacket) (*s action := &sendPacketAction{ MsgSendPacket: msg, - Type: "IBC_EVENT", - Event: "sendPacket", - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), } // fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx) diff --git a/golang/cosmos/x/vibc/ibc.go b/golang/cosmos/x/vibc/ibc.go index 4590b294a85..929b5997232 100644 --- a/golang/cosmos/x/vibc/ibc.go +++ b/golang/cosmos/x/vibc/ibc.go @@ -151,7 +151,7 @@ func (ch IBCModule) Receive(ctx *vm.ControllerContext, str string) (ret string, return } -func (im IBCModule) PushAction(ctx sdk.Context, action vm.Jsonable) error { +func (im IBCModule) PushAction(ctx sdk.Context, action vm.Action) error { // fmt.Println("ibc.go upcall", send) return im.keeper.PushAction(ctx, action) // fmt.Println("ibc.go upcall reply", reply, err) @@ -175,16 +175,14 @@ func (im IBCModule) OnChanOpenInit( } type channelOpenTryEvent struct { - Type string `json:"type"` // IBC - Event string `json:"event"` // channelOpenTry - Order string `json:"order"` - ConnectionHops []string `json:"connectionHops"` - PortID string `json:"portID"` - ChannelID string `json:"channelID"` - Counterparty channeltypes.Counterparty `json:"counterparty"` - Version string `json:"version"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + vm.ActionHeader `actionType:"IBC_EVENT"` + Event string `json:"event" default:"channelOpenTry"` + Order string `json:"order"` + ConnectionHops []string `json:"connectionHops"` + PortID string `json:"portID"` + ChannelID string `json:"channelID"` + Counterparty channeltypes.Counterparty `json:"counterparty"` + Version string `json:"version"` } func (im IBCModule) OnChanOpenTry( @@ -198,16 +196,12 @@ func (im IBCModule) OnChanOpenTry( counterpartyVersion string, ) (string, error) { event := channelOpenTryEvent{ - Type: "IBC_EVENT", - Event: "channelOpenTry", Order: orderToString(order), ConnectionHops: connectionHops, PortID: portID, ChannelID: channelID, Counterparty: counterparty, Version: counterpartyVersion, // TODO: don't just use the counterparty version - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), } err := im.PushAction(ctx, event) @@ -224,15 +218,13 @@ func (im IBCModule) OnChanOpenTry( } type channelOpenAckEvent struct { - Type string `json:"type"` // IBC - Event string `json:"event"` // channelOpenAck + vm.ActionHeader `actionType:"IBC_EVENT"` + Event string `json:"event" default:"channelOpenAck"` PortID string `json:"portID"` ChannelID string `json:"channelID"` CounterpartyVersion string `json:"counterpartyVersion"` Counterparty channeltypes.Counterparty `json:"counterparty"` ConnectionHops []string `json:"connectionHops"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` } func (im IBCModule) OnChanOpenAck( @@ -248,27 +240,21 @@ func (im IBCModule) OnChanOpenAck( channel.Counterparty.ChannelId = counterpartyChannelID event := channelOpenAckEvent{ - Type: "IBC_EVENT", - Event: "channelOpenAck", PortID: portID, ChannelID: channelID, CounterpartyVersion: counterpartyVersion, Counterparty: channel.Counterparty, ConnectionHops: channel.ConnectionHops, - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), } return im.PushAction(ctx, event) } type channelOpenConfirmEvent struct { - Type string `json:"type"` // IBC - Event string `json:"event"` // channelOpenConfirm - PortID string `json:"portID"` - ChannelID string `json:"channelID"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + vm.ActionHeader `actionType:"IBC_EVENT"` + Event string `json:"event" default:"channelOpenConfirm"` + PortID string `json:"portID"` + ChannelID string `json:"channelID"` } func (im IBCModule) OnChanOpenConfirm( @@ -277,24 +263,18 @@ func (im IBCModule) OnChanOpenConfirm( channelID string, ) error { event := channelOpenConfirmEvent{ - Type: "IBC_EVENT", - Event: "channelOpenConfirm", - PortID: portID, - ChannelID: channelID, - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), + PortID: portID, + ChannelID: channelID, } return im.PushAction(ctx, event) } type channelCloseInitEvent struct { - Type string `json:"type"` // IBC - Event string `json:"event"` // channelCloseInit - PortID string `json:"portID"` - ChannelID string `json:"channelID"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + vm.ActionHeader `actionType:"IBC_EVENT"` + Event string `json:"event" default:"channelCloseInit"` + PortID string `json:"portID"` + ChannelID string `json:"channelID"` } func (im IBCModule) OnChanCloseInit( @@ -303,12 +283,8 @@ func (im IBCModule) OnChanCloseInit( channelID string, ) error { event := channelCloseInitEvent{ - Type: "IBC_EVENT", - Event: "channelCloseInit", - PortID: portID, - ChannelID: channelID, - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), + PortID: portID, + ChannelID: channelID, } err := im.PushAction(ctx, event) @@ -316,12 +292,10 @@ func (im IBCModule) OnChanCloseInit( } type channelCloseConfirmEvent struct { - Type string `json:"type"` // IBC - Event string `json:"event"` // channelCloseConfirm - PortID string `json:"portID"` - ChannelID string `json:"channelID"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + vm.ActionHeader `actionType:"IBC_EVENT"` + Event string `json:"event" default:"channelCloseConfirm"` + PortID string `json:"portID"` + ChannelID string `json:"channelID"` } func (im IBCModule) OnChanCloseConfirm( @@ -330,12 +304,8 @@ func (im IBCModule) OnChanCloseConfirm( channelID string, ) error { event := channelCloseConfirmEvent{ - Type: "IBC_EVENT", - Event: "channelCloseConfirm", - PortID: portID, - ChannelID: channelID, - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), + PortID: portID, + ChannelID: channelID, } err := im.PushAction(ctx, event) @@ -343,11 +313,9 @@ func (im IBCModule) OnChanCloseConfirm( } type receivePacketEvent struct { - Type string `json:"type"` // IBC - Event string `json:"event"` // receivePacket - Packet channeltypes.Packet `json:"packet"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + vm.ActionHeader `actionType:"IBC_EVENT"` + Event string `json:"event" default:"receivePacket"` + Packet channeltypes.Packet `json:"packet"` } func (im IBCModule) OnRecvPacket( @@ -364,11 +332,7 @@ func (im IBCModule) OnRecvPacket( // the same packets. event := receivePacketEvent{ - Type: "IBC_EVENT", - Event: "receivePacket", - Packet: packet, - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), + Packet: packet, } err := im.PushAction(ctx, event) @@ -380,12 +344,10 @@ func (im IBCModule) OnRecvPacket( } type acknowledgementPacketEvent struct { - Type string `json:"type"` // IBC - Event string `json:"event"` // acknowledgementPacket + vm.ActionHeader `actionType:"IBC_EVENT"` + Event string `json:"event" default:"acknowledgementPacket"` Packet channeltypes.Packet `json:"packet"` Acknowledgement []byte `json:"acknowledgement"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` } func (im IBCModule) OnAcknowledgementPacket( @@ -395,12 +357,8 @@ func (im IBCModule) OnAcknowledgementPacket( relayer sdk.AccAddress, ) error { event := acknowledgementPacketEvent{ - Type: "IBC_EVENT", - Event: "acknowledgementPacket", Packet: packet, Acknowledgement: acknowledgement, - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), } err := im.PushAction(ctx, event) @@ -412,11 +370,9 @@ func (im IBCModule) OnAcknowledgementPacket( } type timeoutPacketEvent struct { - Type string `json:"type"` // IBC - Event string `json:"event"` // timeoutPacket - Packet channeltypes.Packet `json:"packet"` - BlockHeight int64 `json:"blockHeight"` - BlockTime int64 `json:"blockTime"` + vm.ActionHeader `actionType:"IBC_EVENT"` + Event string `json:"event" default:"timeoutPacket"` + Packet channeltypes.Packet `json:"packet"` } func (im IBCModule) OnTimeoutPacket( @@ -425,11 +381,7 @@ func (im IBCModule) OnTimeoutPacket( relayer sdk.AccAddress, ) error { event := timeoutPacketEvent{ - Type: "IBC_EVENT", - Event: "timeoutPacket", - Packet: packet, - BlockHeight: ctx.BlockHeight(), - BlockTime: ctx.BlockTime().Unix(), + Packet: packet, } err := im.PushAction(ctx, event)