@agoric/cosmos 0.34.2-dev-376e47d.0 → 0.34.2-dev-75ef233.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app/app.go CHANGED
@@ -866,18 +866,17 @@ func normalizeModuleAccount(ctx sdk.Context, ak authkeeper.AccountKeeper, name s
866
866
  }
867
867
 
868
868
  type cosmosInitAction struct {
869
- Type string `json:"type"`
870
- ChainID string `json:"chainID"`
871
- BlockTime int64 `json:"blockTime,omitempty"`
872
- IsBootstrap bool `json:"isBootstrap"`
873
- Params swingset.Params `json:"params"`
874
- SupplyCoins sdk.Coins `json:"supplyCoins"`
875
- UpgradePlan *upgradetypes.Plan `json:"upgradePlan,omitempty"`
876
- LienPort int `json:"lienPort"`
877
- StoragePort int `json:"storagePort"`
878
- SwingsetPort int `json:"swingsetPort"`
879
- VbankPort int `json:"vbankPort"`
880
- VibcPort int `json:"vibcPort"`
869
+ vm.ActionHeader `actionType:"AG_COSMOS_INIT"`
870
+ ChainID string `json:"chainID"`
871
+ IsBootstrap bool `json:"isBootstrap"`
872
+ Params swingset.Params `json:"params"`
873
+ SupplyCoins sdk.Coins `json:"supplyCoins"`
874
+ UpgradePlan *upgradetypes.Plan `json:"upgradePlan,omitempty"`
875
+ LienPort int `json:"lienPort"`
876
+ StoragePort int `json:"storagePort"`
877
+ SwingsetPort int `json:"swingsetPort"`
878
+ VbankPort int `json:"vbankPort"`
879
+ VibcPort int `json:"vibcPort"`
881
880
  }
882
881
 
883
882
  // Name returns the name of the App
@@ -900,16 +899,9 @@ func (app *GaiaApp) initController(ctx sdk.Context, bootstrap bool) {
900
899
  app.CheckControllerInited(false)
901
900
  app.controllerInited = true
902
901
 
903
- var blockTime int64 = 0
904
- if bootstrap || app.upgradePlan != nil {
905
- blockTime = ctx.BlockTime().Unix()
906
- }
907
-
908
902
  // Begin initializing the controller here.
909
903
  action := &cosmosInitAction{
910
- Type: "AG_COSMOS_INIT",
911
904
  ChainID: ctx.ChainID(),
912
- BlockTime: blockTime,
913
905
  IsBootstrap: bootstrap,
914
906
  Params: app.SwingSetKeeper.GetParams(ctx),
915
907
  SupplyCoins: sdk.NewCoins(app.BankKeeper.GetSupply(ctx, "uist")),
@@ -920,7 +912,11 @@ func (app *GaiaApp) initController(ctx sdk.Context, bootstrap bool) {
920
912
  VbankPort: app.vbankPort,
921
913
  VibcPort: app.vibcPort,
922
914
  }
923
- // This really abuses `BlockingSend` to get back at `sendToController`
915
+ // This uses `BlockingSend` as a friendly wrapper for `sendToController`
916
+ //
917
+ // CAVEAT: we are restarting after an in-consensus halt or just because this
918
+ // node felt like it. The controller must be able to handle either case
919
+ // (inConsensus := action.IsBootstrap || action.UpgradePlan != nil).
924
920
  out, err := app.SwingSetKeeper.BlockingSend(ctx, action)
925
921
 
926
922
  // fmt.Fprintf(os.Stderr, "AG_COSMOS_INIT Returned from SwingSet: %s, %v\n", out, err)
package/git-revision.txt CHANGED
@@ -1 +1 @@
1
- 376e47d
1
+ 75ef233
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/cosmos",
3
- "version": "0.34.2-dev-376e47d.0+376e47d",
3
+ "version": "0.34.2-dev-75ef233.0+75ef233",
4
4
  "description": "Connect JS to the Cosmos blockchain SDK",
5
5
  "parsers": {
6
6
  "js": "mjs"
@@ -38,5 +38,5 @@
38
38
  "typeCoverage": {
39
39
  "atLeast": 0
40
40
  },
41
- "gitHead": "376e47d1b7eba11d1e587778489d8f199d53870f"
41
+ "gitHead": "75ef233cac98f56ca75690fab7d69bdcd16d7683"
42
42
  }
package/vm/action.go ADDED
@@ -0,0 +1,130 @@
1
+ package vm
2
+
3
+ import (
4
+ "reflect"
5
+ "strconv"
6
+ "time"
7
+
8
+ sdk "github.com/cosmos/cosmos-sdk/types"
9
+ )
10
+
11
+ var (
12
+ zeroTime = time.Time{}
13
+ actionHeaderType = reflect.TypeOf(ActionHeader{})
14
+ _ Action = &ActionHeader{}
15
+ )
16
+
17
+ // Jsonable is a value, j, that can be passed through json.Marshal(j).
18
+ type Jsonable interface{}
19
+
20
+ type Action interface {
21
+ GetActionHeader() ActionHeader
22
+ }
23
+
24
+ // ActionPusher enqueues data for later consumption by the controller.
25
+ type ActionPusher func(ctx sdk.Context, action Action) error
26
+
27
+ // ActionHeader should be embedded in all actions. It is populated by PopulateAction.
28
+ type ActionHeader struct {
29
+ // Type defaults to the `actionType:"..."` tag of the embedder's ActionHeader field.
30
+ Type string `json:"type"`
31
+ // BlockHeight defaults to sdk.Context.BlockHeight().
32
+ BlockHeight int64 `json:"blockHeight,omitempty"`
33
+ // BlockTime defaults to sdk.Context.BlockTime().Unix().
34
+ BlockTime int64 `json:"blockTime,omitempty"`
35
+ }
36
+
37
+ func (ah ActionHeader) GetActionHeader() ActionHeader {
38
+ return ah
39
+ }
40
+
41
+ // SetActionHeaderFromContext provides defaults to an ActionHeader.
42
+ func SetActionHeaderFromContext(ctx sdk.Context, actionType string, ah *ActionHeader) {
43
+ // Default the action type.
44
+ if len(ah.Type) == 0 {
45
+ ah.Type = actionType
46
+ }
47
+
48
+ // Default the block height.
49
+ if ah.BlockHeight == 0 {
50
+ ah.BlockHeight = ctx.BlockHeight()
51
+ }
52
+
53
+ if ah.BlockTime == 0 {
54
+ // Only default to a non-zero block time.
55
+ if blockTime := ctx.BlockTime(); blockTime != zeroTime {
56
+ ah.BlockTime = blockTime.Unix()
57
+ }
58
+ }
59
+ }
60
+
61
+ // PopulateAction interprets `default:"..."` tags and specially handles an
62
+ // embedded ActionHeader struct.
63
+ func PopulateAction(ctx sdk.Context, action Action) Action {
64
+ oldRv := reflect.Indirect(reflect.ValueOf(action))
65
+ if oldRv.Kind() != reflect.Struct {
66
+ return action
67
+ }
68
+
69
+ // Shallow copy to a new value.
70
+ rp := reflect.New(oldRv.Type())
71
+ rv := reflect.Indirect(rp)
72
+ for i := 0; i < rv.NumField(); i++ {
73
+ oldField := oldRv.Field(i)
74
+ field := rv.Field(i)
75
+ fieldType := rv.Type().Field(i)
76
+ if !field.CanSet() {
77
+ continue
78
+ }
79
+
80
+ // Copy from original.
81
+ field.Set(oldField)
82
+
83
+ // Populate any ActionHeader struct.
84
+ var ahp *ActionHeader
85
+ if fieldType.Type == actionHeaderType {
86
+ ahp = field.Addr().Interface().(*ActionHeader)
87
+ } else if fieldType.Type == reflect.PtrTo(actionHeaderType) {
88
+ if field.IsNil() {
89
+ ahp = &ActionHeader{}
90
+ } else {
91
+ ahp = field.Interface().(*ActionHeader)
92
+ }
93
+ }
94
+ if ahp != nil {
95
+ actionTypeTag, _ := fieldType.Tag.Lookup("actionType")
96
+ ah := *ahp
97
+ SetActionHeaderFromContext(ctx, actionTypeTag, &ah)
98
+ if field.Kind() == reflect.Ptr {
99
+ field.Set(reflect.ValueOf(&ah))
100
+ } else {
101
+ field.Set(reflect.ValueOf(ah))
102
+ }
103
+ continue
104
+ }
105
+
106
+ // Still zero value, try default struct field tag.
107
+ defaultTag, _ := fieldType.Tag.Lookup("default")
108
+ if !field.IsZero() || len(defaultTag) == 0 {
109
+ continue
110
+ }
111
+
112
+ switch field.Kind() {
113
+ case reflect.String:
114
+ field.SetString(defaultTag)
115
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
116
+ if val, err := strconv.ParseInt(defaultTag, 0, 64); err == nil {
117
+ field.SetInt(val)
118
+ }
119
+ case reflect.Bool:
120
+ if val, err := strconv.ParseBool(defaultTag); err == nil {
121
+ field.SetBool(val)
122
+ }
123
+ case reflect.Float32, reflect.Float64:
124
+ if val, err := strconv.ParseFloat(defaultTag, 64); err == nil {
125
+ field.SetFloat(val)
126
+ }
127
+ }
128
+ }
129
+ return rv.Interface().(Action)
130
+ }
@@ -0,0 +1,129 @@
1
+ package vm_test
2
+
3
+ import (
4
+ "encoding/json"
5
+ "testing"
6
+ "time"
7
+
8
+ "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
9
+ sdk "github.com/cosmos/cosmos-sdk/types"
10
+ )
11
+
12
+ var (
13
+ _ vm.Action = &Trivial{}
14
+ _ vm.Action = &Defaults{}
15
+ _ vm.Action = &dataAction{}
16
+ )
17
+
18
+ type Trivial struct {
19
+ vm.ActionHeader
20
+ Abc int
21
+ def string
22
+ }
23
+
24
+ type Defaults struct {
25
+ String string `default:"abc"`
26
+ Int int `default:"123"`
27
+ Float float64 `default:"4.56"`
28
+ Bool bool `default:"true"`
29
+ Any interface{}
30
+ }
31
+
32
+ func (d Defaults) GetActionHeader() vm.ActionHeader {
33
+ return vm.ActionHeader{}
34
+ }
35
+
36
+ type dataAction struct {
37
+ *vm.ActionHeader `actionType:"DATA_ACTION"`
38
+ Data []byte
39
+ }
40
+
41
+ func TestActionContext(t *testing.T) {
42
+ emptyCtx := sdk.Context{}
43
+
44
+ testCases := []struct {
45
+ name string
46
+ ctx sdk.Context
47
+ in vm.Action
48
+ expectedOut interface{}
49
+ }{
50
+ {"nil", emptyCtx, nil, nil},
51
+ {"no context", emptyCtx,
52
+ &Trivial{Abc: 123, def: "zot"},
53
+ &Trivial{Abc: 123, def: "zot"},
54
+ },
55
+ {"block height",
56
+ emptyCtx.WithBlockHeight(998),
57
+ &Trivial{Abc: 123, def: "zot"},
58
+ &Trivial{ActionHeader: vm.ActionHeader{BlockHeight: 998}, Abc: 123, def: "zot"},
59
+ },
60
+ {"block time",
61
+ emptyCtx.WithBlockTime(time.UnixMicro(1_000_000)),
62
+ &Trivial{Abc: 123, def: "zot"},
63
+ &Trivial{Abc: 123, def: "zot", ActionHeader: vm.ActionHeader{BlockTime: 1}},
64
+ },
65
+ {"default tags",
66
+ emptyCtx,
67
+ &Defaults{},
68
+ &Defaults{"abc", 123, 4.56, true, nil},
69
+ },
70
+ {"data action defaults",
71
+ emptyCtx.WithBlockHeight(998).WithBlockTime(time.UnixMicro(1_000_000)),
72
+ &dataAction{Data: []byte("hello")},
73
+ &dataAction{Data: []byte("hello"),
74
+ ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION", BlockHeight: 998, BlockTime: 1}},
75
+ },
76
+ {"data action override Type",
77
+ emptyCtx.WithBlockHeight(998).WithBlockTime(time.UnixMicro(1_000_000)),
78
+ &dataAction{Data: []byte("hello2"),
79
+ ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION2"}},
80
+ &dataAction{Data: []byte("hello2"),
81
+ ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION2", BlockHeight: 998, BlockTime: 1}},
82
+ },
83
+ {"data action override BlockHeight",
84
+ emptyCtx.WithBlockHeight(998).WithBlockTime(time.UnixMicro(1_000_000)),
85
+ &dataAction{Data: []byte("hello2"),
86
+ ActionHeader: &vm.ActionHeader{BlockHeight: 999}},
87
+ &dataAction{Data: []byte("hello2"),
88
+ ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION", BlockHeight: 999, BlockTime: 1}},
89
+ },
90
+ {"data action override BlockTime",
91
+ emptyCtx.WithBlockHeight(998).WithBlockTime(time.UnixMicro(1_000_000)),
92
+ &dataAction{Data: []byte("hello2"),
93
+ ActionHeader: &vm.ActionHeader{BlockTime: 2}},
94
+ &dataAction{Data: []byte("hello2"),
95
+ ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION", BlockHeight: 998, BlockTime: 2}},
96
+ },
97
+ {"data action override all defaults",
98
+ emptyCtx.WithBlockHeight(998).WithBlockTime(time.UnixMicro(1_000_000)),
99
+ &dataAction{Data: []byte("hello2"),
100
+ ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION2", BlockHeight: 999, BlockTime: 2}},
101
+ &dataAction{Data: []byte("hello2"),
102
+ ActionHeader: &vm.ActionHeader{Type: "DATA_ACTION2", BlockHeight: 999, BlockTime: 2}},
103
+ },
104
+ }
105
+
106
+ for _, tc := range testCases {
107
+ tc := tc
108
+ t.Run(tc.name, func(t *testing.T) {
109
+ jstr := func(in interface{}) string {
110
+ bz, err := json.Marshal(in)
111
+ if err != nil {
112
+ t.Fatal(err)
113
+ }
114
+ return string(bz)
115
+ }
116
+ jsonIn := jstr(tc.in)
117
+ out := vm.PopulateAction(tc.ctx, tc.in)
118
+ jsonIn2 := jstr(tc.in)
119
+ if jsonIn != jsonIn2 {
120
+ t.Errorf("unexpected mutated input: %s to %s", jsonIn, jsonIn2)
121
+ }
122
+ jsonOut := jstr(out)
123
+ jsonExpectedOut := jstr(tc.expectedOut)
124
+ if jsonOut != jsonExpectedOut {
125
+ t.Errorf("expected %s, got %s", jsonExpectedOut, jsonOut)
126
+ }
127
+ })
128
+ }
129
+ }
package/vm/controller.go CHANGED
@@ -20,12 +20,6 @@ type ControllerAdmissionMsg interface {
20
20
  IsHighPriority(sdk.Context, interface{}) (bool, error)
21
21
  }
22
22
 
23
- // Jsonable is a value, j, that can be passed through json.Marshal(j).
24
- type Jsonable interface{}
25
-
26
- // ActionPusher enqueues data for later consumption by the controller.
27
- type ActionPusher func(ctx sdk.Context, action Jsonable) error
28
-
29
23
  var wrappedEmptySDKContext = sdk.WrapSDKContext(
30
24
  sdk.Context{}.WithContext(context.Background()),
31
25
  )
@@ -112,7 +112,7 @@ func makeTestKit() testKit {
112
112
  sk := stakingkeeper.NewKeeper(cdc, stakingStoreKey, wak, bk, stakingSpace)
113
113
 
114
114
  // lien keeper
115
- pushAction := func(sdk.Context, vm.Jsonable) error {
115
+ pushAction := func(sdk.Context, vm.Action) error {
116
116
  return nil
117
117
  }
118
118
  keeper := NewKeeper(cdc, lienStoreKey, wak, bk, sk, pushAction)
@@ -10,38 +10,34 @@ import (
10
10
  sdk "github.com/cosmos/cosmos-sdk/types"
11
11
  abci "github.com/tendermint/tendermint/abci/types"
12
12
 
13
+ "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
13
14
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
14
15
  )
15
16
 
16
17
  type beginBlockAction struct {
17
- Type string `json:"type"`
18
- BlockHeight int64 `json:"blockHeight"`
19
- BlockTime int64 `json:"blockTime"`
20
- ChainID string `json:"chainID"`
21
- Params types.Params `json:"params"`
18
+ vm.ActionHeader `actionType:"BEGIN_BLOCK"`
19
+ ChainID string `json:"chainID"`
20
+ Params types.Params `json:"params"`
22
21
  }
23
22
 
24
23
  type endBlockAction struct {
25
- Type string `json:"type"`
26
- BlockHeight int64 `json:"blockHeight"`
27
- BlockTime int64 `json:"blockTime"`
24
+ vm.ActionHeader `actionType:"END_BLOCK"`
28
25
  }
29
26
 
30
27
  type commitBlockAction struct {
31
- Type string `json:"type"`
32
- BlockHeight int64 `json:"blockHeight"`
33
- BlockTime int64 `json:"blockTime"`
28
+ vm.ActionHeader `actionType:"COMMIT_BLOCK"`
29
+ }
30
+
31
+ type afterCommitBlockAction struct {
32
+ vm.ActionHeader `actionType:"AFTER_COMMIT_BLOCK"`
34
33
  }
35
34
 
36
35
  func BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, keeper Keeper) error {
37
36
  defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
38
37
 
39
38
  action := &beginBlockAction{
40
- Type: "BEGIN_BLOCK",
41
- BlockHeight: ctx.BlockHeight(),
42
- BlockTime: ctx.BlockTime().Unix(),
43
- ChainID: ctx.ChainID(),
44
- Params: keeper.GetParams(ctx),
39
+ ChainID: ctx.ChainID(),
40
+ Params: keeper.GetParams(ctx),
45
41
  }
46
42
  _, err := keeper.BlockingSend(ctx, action)
47
43
  // fmt.Fprintf(os.Stderr, "BEGIN_BLOCK Returned from SwingSet: %s, %v\n", out, err)
@@ -60,11 +56,7 @@ var endBlockTime int64
60
56
  func EndBlock(ctx sdk.Context, req abci.RequestEndBlock, keeper Keeper) ([]abci.ValidatorUpdate, error) {
61
57
  defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
62
58
 
63
- action := &endBlockAction{
64
- Type: "END_BLOCK",
65
- BlockHeight: ctx.BlockHeight(),
66
- BlockTime: ctx.BlockTime().Unix(),
67
- }
59
+ action := &endBlockAction{}
68
60
  _, err := keeper.BlockingSend(ctx, action)
69
61
 
70
62
  // fmt.Fprintf(os.Stderr, "END_BLOCK Returned from SwingSet: %s, %v\n", out, err)
@@ -81,15 +73,18 @@ func EndBlock(ctx sdk.Context, req abci.RequestEndBlock, keeper Keeper) ([]abci.
81
73
  return []abci.ValidatorUpdate{}, nil
82
74
  }
83
75
 
76
+ func getEndBlockContext() sdk.Context {
77
+ return sdk.Context{}.
78
+ WithContext(context.Background()).
79
+ WithBlockHeight(endBlockHeight).
80
+ WithBlockTime(time.Unix(endBlockTime, 0))
81
+ }
82
+
84
83
  func CommitBlock(keeper Keeper) error {
85
84
  defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), "commit_blocker")
86
85
 
87
- action := &commitBlockAction{
88
- Type: "COMMIT_BLOCK",
89
- BlockHeight: endBlockHeight,
90
- BlockTime: endBlockTime,
91
- }
92
- _, err := keeper.BlockingSend(sdk.Context{}.WithContext(context.Background()), action)
86
+ action := &commitBlockAction{}
87
+ _, err := keeper.BlockingSend(getEndBlockContext(), action)
93
88
 
94
89
  // fmt.Fprintf(os.Stderr, "COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
95
90
  if err != nil {
@@ -103,12 +98,8 @@ func CommitBlock(keeper Keeper) error {
103
98
  func AfterCommitBlock(keeper Keeper) error {
104
99
  // defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), "commit_blocker")
105
100
 
106
- action := &commitBlockAction{
107
- Type: "AFTER_COMMIT_BLOCK",
108
- BlockHeight: endBlockHeight,
109
- BlockTime: endBlockTime,
110
- }
111
- _, err := keeper.BlockingSend(sdk.Context{}.WithContext(context.Background()), action)
101
+ action := &afterCommitBlockAction{}
102
+ _, err := keeper.BlockingSend(getEndBlockContext(), action)
112
103
 
113
104
  // fmt.Fprintf(os.Stderr, "AFTER_COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
114
105
  if err != nil {
@@ -110,6 +110,16 @@ func NewKeeper(
110
110
  }
111
111
  }
112
112
 
113
+ func populateAction(ctx sdk.Context, action vm.Action) (vm.Action, error) {
114
+ action = vm.PopulateAction(ctx, action)
115
+ ah := action.GetActionHeader()
116
+ if len(ah.Type) == 0 {
117
+ return nil, fmt.Errorf("action %q cannot have an empty ActionHeader.Type", action)
118
+ }
119
+
120
+ return action, nil
121
+ }
122
+
113
123
  // pushAction appends an action to the controller's specified inbound queue.
114
124
  // The queue is kept in the kvstore so that changes are properly reverted if the
115
125
  // kvstore is rolled back. By the time the block manager runs, it can commit
@@ -118,7 +128,11 @@ func NewKeeper(
118
128
  //
119
129
  // The inbound queue's format is documented by `makeChainQueue` in
120
130
  // `packages/cosmic-swingset/src/helpers/make-queue.js`.
121
- func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.Jsonable) error {
131
+ func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.Action) error {
132
+ action, err := populateAction(ctx, action)
133
+ if err != nil {
134
+ return err
135
+ }
122
136
  txHash, txHashOk := ctx.Context().Value(baseapp.TxHashContextKey).(string)
123
137
  if !txHashOk {
124
138
  txHash = "unknown"
@@ -143,12 +157,12 @@ func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.J
143
157
  }
144
158
 
145
159
  // PushAction appends an action to the controller's actionQueue.
146
- func (k Keeper) PushAction(ctx sdk.Context, action vm.Jsonable) error {
160
+ func (k Keeper) PushAction(ctx sdk.Context, action vm.Action) error {
147
161
  return k.pushAction(ctx, StoragePathActionQueue, action)
148
162
  }
149
163
 
150
164
  // PushAction appends an action to the controller's highPriorityQueue.
151
- func (k Keeper) PushHighPriorityAction(ctx sdk.Context, action vm.Jsonable) error {
165
+ func (k Keeper) PushHighPriorityAction(ctx sdk.Context, action vm.Action) error {
152
166
  return k.pushAction(ctx, StoragePathHighPriorityQueue, action)
153
167
  }
154
168
 
@@ -234,7 +248,11 @@ func (k Keeper) UpdateQueueAllowed(ctx sdk.Context) error {
234
248
  // until the response. It is orthogonal to PushAction, and should only be used
235
249
  // by SwingSet to perform block lifecycle events (BEGIN_BLOCK, END_BLOCK,
236
250
  // COMMIT_BLOCK).
237
- func (k Keeper) BlockingSend(ctx sdk.Context, action vm.Jsonable) (string, error) {
251
+ func (k Keeper) BlockingSend(ctx sdk.Context, action vm.Action) (string, error) {
252
+ action, err := populateAction(ctx, action)
253
+ if err != nil {
254
+ return "", err
255
+ }
238
256
  bz, err := json.Marshal(action)
239
257
  if err != nil {
240
258
  return "", err
@@ -21,15 +21,13 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {
21
21
  var _ types.MsgServer = msgServer{}
22
22
 
23
23
  type deliverInboundAction struct {
24
- Type string `json:"type"`
25
- Peer string `json:"peer"`
26
- Messages [][]interface{} `json:"messages"`
27
- Ack uint64 `json:"ack"`
28
- BlockHeight int64 `json:"blockHeight"`
29
- BlockTime int64 `json:"blockTime"`
24
+ vm.ActionHeader `actionType:"DELIVER_INBOUND"`
25
+ Peer string `json:"peer"`
26
+ Messages [][]interface{} `json:"messages"`
27
+ Ack uint64 `json:"ack"`
30
28
  }
31
29
 
32
- func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionMsg, action vm.Jsonable) error {
30
+ func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionMsg, action vm.Action) error {
33
31
  isHighPriority, err := msg.IsHighPriority(ctx, keeper)
34
32
  if err != nil {
35
33
  return err
@@ -51,12 +49,9 @@ func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeli
51
49
  messages[i] = []interface{}{msg.Nums[i], message}
52
50
  }
53
51
  action := &deliverInboundAction{
54
- Type: "DELIVER_INBOUND",
55
- Peer: msg.Submitter.String(),
56
- Messages: messages,
57
- Ack: msg.Ack,
58
- BlockHeight: ctx.BlockHeight(),
59
- BlockTime: ctx.BlockTime().Unix(),
52
+ Peer: msg.Submitter.String(),
53
+ Messages: messages,
54
+ Ack: msg.Ack,
60
55
  }
61
56
 
62
57
  err := keeper.routeAction(ctx, msg, action)
@@ -68,11 +63,9 @@ func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeli
68
63
  }
69
64
 
70
65
  type walletAction struct {
71
- Type string `json:"type"` // WALLET_ACTION
72
- Owner string `json:"owner"`
73
- Action string `json:"action"`
74
- BlockHeight int64 `json:"blockHeight"`
75
- BlockTime int64 `json:"blockTime"`
66
+ vm.ActionHeader `actionType:"WALLET_ACTION"`
67
+ Owner string `json:"owner"`
68
+ Action string `json:"action"`
76
69
  }
77
70
 
78
71
  func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWalletAction) (*types.MsgWalletActionResponse, error) {
@@ -84,11 +77,8 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet
84
77
  }
85
78
 
86
79
  action := &walletAction{
87
- Type: "WALLET_ACTION",
88
- Owner: msg.Owner.String(),
89
- Action: msg.Action,
90
- BlockHeight: ctx.BlockHeight(),
91
- BlockTime: ctx.BlockTime().Unix(),
80
+ Owner: msg.Owner.String(),
81
+ Action: msg.Action,
92
82
  }
93
83
  // fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
94
84
 
@@ -101,11 +91,9 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet
101
91
  }
102
92
 
103
93
  type walletSpendAction struct {
104
- Type string `json:"type"` // WALLET_SPEND_ACTION
105
- Owner string `json:"owner"`
106
- SpendAction string `json:"spendAction"`
107
- BlockHeight int64 `json:"blockHeight"`
108
- BlockTime int64 `json:"blockTime"`
94
+ vm.ActionHeader `actionType:"WALLET_SPEND_ACTION"`
95
+ Owner string `json:"owner"`
96
+ SpendAction string `json:"spendAction"`
109
97
  }
110
98
 
111
99
  func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgWalletSpendAction) (*types.MsgWalletSpendActionResponse, error) {
@@ -117,11 +105,8 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW
117
105
  }
118
106
 
119
107
  action := &walletSpendAction{
120
- Type: "WALLET_SPEND_ACTION",
121
108
  Owner: msg.Owner.String(),
122
109
  SpendAction: msg.SpendAction,
123
- BlockHeight: ctx.BlockHeight(),
124
- BlockTime: ctx.BlockTime().Unix(),
125
110
  }
126
111
  // fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
127
112
  err = keeper.routeAction(ctx, msg, action)
@@ -132,11 +117,9 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW
132
117
  }
133
118
 
134
119
  type provisionAction struct {
120
+ vm.ActionHeader `actionType:"PLEASE_PROVISION"`
135
121
  *types.MsgProvision
136
- Type string `json:"type"` // PLEASE_PROVISION
137
- BlockHeight int64 `json:"blockHeight"`
138
- BlockTime int64 `json:"blockTime"`
139
- AutoProvision bool `json:"autoProvision"`
122
+ AutoProvision bool `json:"autoProvision"`
140
123
  }
141
124
 
142
125
  // provisionIfNeeded generates a provision action if no smart wallet is already
@@ -160,9 +143,6 @@ func (keeper msgServer) provisionIfNeeded(ctx sdk.Context, owner sdk.AccAddress)
160
143
 
161
144
  action := &provisionAction{
162
145
  MsgProvision: msg,
163
- Type: "PLEASE_PROVISION",
164
- BlockHeight: ctx.BlockHeight(),
165
- BlockTime: ctx.BlockTime().Unix(),
166
146
  AutoProvision: true,
167
147
  }
168
148
 
@@ -185,9 +165,6 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision
185
165
 
186
166
  action := &provisionAction{
187
167
  MsgProvision: msg,
188
- Type: "PLEASE_PROVISION",
189
- BlockHeight: ctx.BlockHeight(),
190
- BlockTime: ctx.BlockTime().Unix(),
191
168
  }
192
169
 
193
170
  // Create the account, if it doesn't already exist.
@@ -207,10 +184,8 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision
207
184
  }
208
185
 
209
186
  type installBundleAction struct {
187
+ vm.ActionHeader `actionType:"INSTALL_BUNDLE"`
210
188
  *types.MsgInstallBundle
211
- Type string `json:"type"` // INSTALL_BUNDLE
212
- BlockHeight int64 `json:"blockHeight"`
213
- BlockTime int64 `json:"blockTime"`
214
189
  }
215
190
 
216
191
  func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInstallBundle) (*types.MsgInstallBundleResponse, error) {
@@ -222,9 +197,6 @@ func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInsta
222
197
  }
223
198
  action := &installBundleAction{
224
199
  MsgInstallBundle: msg,
225
- Type: "INSTALL_BUNDLE",
226
- BlockHeight: ctx.BlockHeight(),
227
- BlockTime: ctx.BlockTime().Unix(),
228
200
  }
229
201
 
230
202
  err = keeper.routeAction(ctx, msg, action)
@@ -3,23 +3,19 @@ package keeper
3
3
  import (
4
4
  sdk "github.com/cosmos/cosmos-sdk/types"
5
5
 
6
+ "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
6
7
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
7
8
  )
8
9
 
9
10
  type coreEvalAction struct {
10
- Type string `json:"type"` // CORE_EVAL
11
- Evals []types.CoreEval `json:"evals"`
12
- BlockHeight int64 `json:"blockHeight"`
13
- BlockTime int64 `json:"blockTime"`
11
+ vm.ActionHeader `actionType:"CORE_EVAL"`
12
+ Evals []types.CoreEval `json:"evals"`
14
13
  }
15
14
 
16
15
  // CoreEvalProposal tells SwingSet to evaluate the given JS code.
17
16
  func (k Keeper) CoreEvalProposal(ctx sdk.Context, p *types.CoreEvalProposal) error {
18
17
  action := &coreEvalAction{
19
- Type: "CORE_EVAL",
20
- Evals: p.Evals,
21
- BlockHeight: ctx.BlockHeight(),
22
- BlockTime: ctx.BlockTime().Unix(),
18
+ Evals: p.Evals,
23
19
  }
24
20
 
25
21
  return k.PushHighPriorityAction(ctx, action)
package/x/vbank/vbank.go CHANGED
@@ -68,15 +68,15 @@ func (vbu vbankManyBalanceUpdates) Swap(i int, j int) {
68
68
  }
69
69
 
70
70
  type vbankBalanceUpdate struct {
71
- Nonce uint64 `json:"nonce"`
72
- Type string `json:"type"`
73
- Updated vbankManyBalanceUpdates `json:"updated"`
71
+ vm.ActionHeader `actionType:"VBANK_BALANCE_UPDATE"`
72
+ Nonce uint64 `json:"nonce"`
73
+ Updated vbankManyBalanceUpdates `json:"updated"`
74
74
  }
75
75
 
76
76
  // getBalanceUpdate returns a bridge message containing the current bank balance
77
77
  // for the given addresses each for the specified denominations. Coins are used
78
78
  // only to track the set of denoms, not for the particular nonzero amounts.
79
- func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string]sdk.Coins) vm.Jsonable {
79
+ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string]sdk.Coins) vm.Action {
80
80
  nentries := len(addressToUpdate)
81
81
  if nentries == 0 {
82
82
  return nil
@@ -84,7 +84,6 @@ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string
84
84
 
85
85
  nonce := keeper.GetNextSequence(ctx)
86
86
  event := vbankBalanceUpdate{
87
- Type: "VBANK_BALANCE_UPDATE",
88
87
  Nonce: nonce,
89
88
  Updated: make([]vbankSingleBalanceUpdate, 0, nentries),
90
89
  }
@@ -111,7 +110,9 @@ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string
111
110
 
112
111
  // Ensure we have a deterministic order of updates.
113
112
  sort.Sort(event.Updated)
114
- return event
113
+
114
+ // Populate the event default fields (even though event does not embed vm.ActionHeader)
115
+ return vm.PopulateAction(ctx, event)
115
116
  }
116
117
 
117
118
  func marshal(event vm.Jsonable) ([]byte, error) {
@@ -243,7 +244,7 @@ func (ch portHandler) Receive(cctx context.Context, str string) (ret string, err
243
244
  return
244
245
  }
245
246
 
246
- func (am AppModule) PushAction(ctx sdk.Context, action vm.Jsonable) error {
247
+ func (am AppModule) PushAction(ctx sdk.Context, action vm.Action) error {
247
248
  // vbank actions are not triggered by a swingset message in a transaction, so we need to
248
249
  // synthesize unique context information.
249
250
  // We use a fixed placeholder value for the txHash context, and can simply use `0` for the
@@ -250,7 +250,7 @@ func (b *mockBank) SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, re
250
250
  func makeTestKit(account types.AccountKeeper, bank types.BankKeeper) (Keeper, sdk.Context) {
251
251
  encodingConfig := params.MakeEncodingConfig()
252
252
  cdc := encodingConfig.Marshaler
253
- pushAction := func(ctx sdk.Context, action vm.Jsonable) error {
253
+ pushAction := func(ctx sdk.Context, action vm.Action) error {
254
254
  return nil
255
255
  }
256
256
 
@@ -517,16 +517,16 @@ func Test_EndBlock_Events(t *testing.T) {
517
517
  }}
518
518
  acct := &mockAuthKeeper{
519
519
  accounts: map[string]authtypes.AccountI{
520
- addr1: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{ Address: addr1 }},
521
- addr2: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{ Address: addr2 }},
522
- addr3: &authtypes.BaseAccount{ Address: addr3 },
520
+ addr1: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{Address: addr1}},
521
+ addr2: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{Address: addr2}},
522
+ addr3: &authtypes.BaseAccount{Address: addr3},
523
523
  },
524
524
  }
525
525
  keeper, ctx := makeTestKit(acct, bank)
526
526
  // Turn off rewards.
527
527
  keeper.SetParams(ctx, types.Params{PerEpochRewardFraction: sdk.ZeroDec()})
528
528
  msgsSent := []string{}
529
- keeper.PushAction = func(ctx sdk.Context, action vm.Jsonable) error {
529
+ keeper.PushAction = func(ctx sdk.Context, action vm.Action) error {
530
530
  bz, err := json.Marshal(action)
531
531
  if err != nil {
532
532
  return err
@@ -630,7 +630,7 @@ func Test_EndBlock_Rewards(t *testing.T) {
630
630
  }
631
631
  keeper, ctx := makeTestKit(nil, bank)
632
632
  msgsSent := []string{}
633
- keeper.PushAction = func(ctx sdk.Context, action vm.Jsonable) error {
633
+ keeper.PushAction = func(ctx sdk.Context, action vm.Action) error {
634
634
  bz, err := json.Marshal(action)
635
635
  if err != nil {
636
636
  return err
@@ -746,7 +746,7 @@ func Test_EndBlock_Rewards(t *testing.T) {
746
746
  }
747
747
  }
748
748
 
749
- type mockAuthKeeper struct{
749
+ type mockAuthKeeper struct {
750
750
  accounts map[string]authtypes.AccountI
751
751
  modAddrs map[string]string
752
752
  }
@@ -754,11 +754,11 @@ type mockAuthKeeper struct{
754
754
  func (ma mockAuthKeeper) GetModuleAccount(ctx sdk.Context, name string) authtypes.ModuleAccountI {
755
755
  addr, ok := ma.modAddrs[name]
756
756
  if !ok {
757
- return nil
757
+ return nil
758
758
  }
759
759
  acct, ok := ma.accounts[addr]
760
760
  if !ok {
761
- panic("missing module account")
761
+ panic("missing module account")
762
762
  }
763
763
  return acct.(authtypes.ModuleAccountI)
764
764
  }
@@ -778,7 +778,7 @@ func Test_Module_Account(t *testing.T) {
778
778
  acct := &mockAuthKeeper{
779
779
  accounts: map[string]authtypes.AccountI{
780
780
  moduleBech32: authtypes.NewEmptyModuleAccount("vbank/reserve"),
781
- addr1: authtypes.NewBaseAccountWithAddress(sdk.MustAccAddressFromBech32(addr1)),
781
+ addr1: authtypes.NewBaseAccountWithAddress(sdk.MustAccAddressFromBech32(addr1)),
782
782
  },
783
783
  modAddrs: map[string]string{
784
784
  "vbank/reserve": moduleBech32,
package/x/vibc/handler.go CHANGED
@@ -3,6 +3,7 @@ package vibc
3
3
  import (
4
4
  "fmt"
5
5
 
6
+ "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
6
7
  sdk "github.com/cosmos/cosmos-sdk/types"
7
8
  sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
8
9
  )
@@ -23,10 +24,8 @@ func NewHandler(keeper Keeper) sdk.Handler {
23
24
 
24
25
  type sendPacketAction struct {
25
26
  *MsgSendPacket
26
- Type string `json:"type"` // IBC_EVENT
27
- Event string `json:"event"` // sendPacket
28
- BlockHeight int64 `json:"blockHeight"`
29
- BlockTime int64 `json:"blockTime"`
27
+ vm.ActionHeader `actionType:"IBC_EVENT"`
28
+ Event string `json:"event" default:"sendPacket"`
30
29
  }
31
30
 
32
31
  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
41
40
 
42
41
  action := &sendPacketAction{
43
42
  MsgSendPacket: msg,
44
- Type: "IBC_EVENT",
45
- Event: "sendPacket",
46
- BlockHeight: ctx.BlockHeight(),
47
- BlockTime: ctx.BlockTime().Unix(),
48
43
  }
49
44
  // fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
50
45
 
package/x/vibc/ibc.go CHANGED
@@ -153,7 +153,7 @@ func (ch IBCModule) Receive(cctx context.Context, str string) (ret string, err e
153
153
  return
154
154
  }
155
155
 
156
- func (im IBCModule) PushAction(ctx sdk.Context, action vm.Jsonable) error {
156
+ func (im IBCModule) PushAction(ctx sdk.Context, action vm.Action) error {
157
157
  // fmt.Println("ibc.go upcall", send)
158
158
  return im.keeper.PushAction(ctx, action)
159
159
  // fmt.Println("ibc.go upcall reply", reply, err)
@@ -177,16 +177,14 @@ func (im IBCModule) OnChanOpenInit(
177
177
  }
178
178
 
179
179
  type channelOpenTryEvent struct {
180
- Type string `json:"type"` // IBC
181
- Event string `json:"event"` // channelOpenTry
182
- Order string `json:"order"`
183
- ConnectionHops []string `json:"connectionHops"`
184
- PortID string `json:"portID"`
185
- ChannelID string `json:"channelID"`
186
- Counterparty channeltypes.Counterparty `json:"counterparty"`
187
- Version string `json:"version"`
188
- BlockHeight int64 `json:"blockHeight"`
189
- BlockTime int64 `json:"blockTime"`
180
+ vm.ActionHeader `actionType:"IBC_EVENT"`
181
+ Event string `json:"event" default:"channelOpenTry"`
182
+ Order string `json:"order"`
183
+ ConnectionHops []string `json:"connectionHops"`
184
+ PortID string `json:"portID"`
185
+ ChannelID string `json:"channelID"`
186
+ Counterparty channeltypes.Counterparty `json:"counterparty"`
187
+ Version string `json:"version"`
190
188
  }
191
189
 
192
190
  func (im IBCModule) OnChanOpenTry(
@@ -200,16 +198,12 @@ func (im IBCModule) OnChanOpenTry(
200
198
  counterpartyVersion string,
201
199
  ) (string, error) {
202
200
  event := channelOpenTryEvent{
203
- Type: "IBC_EVENT",
204
- Event: "channelOpenTry",
205
201
  Order: orderToString(order),
206
202
  ConnectionHops: connectionHops,
207
203
  PortID: portID,
208
204
  ChannelID: channelID,
209
205
  Counterparty: counterparty,
210
206
  Version: counterpartyVersion, // TODO: don't just use the counterparty version
211
- BlockHeight: ctx.BlockHeight(),
212
- BlockTime: ctx.BlockTime().Unix(),
213
207
  }
214
208
 
215
209
  err := im.PushAction(ctx, event)
@@ -226,15 +220,13 @@ func (im IBCModule) OnChanOpenTry(
226
220
  }
227
221
 
228
222
  type channelOpenAckEvent struct {
229
- Type string `json:"type"` // IBC
230
- Event string `json:"event"` // channelOpenAck
223
+ vm.ActionHeader `actionType:"IBC_EVENT"`
224
+ Event string `json:"event" default:"channelOpenAck"`
231
225
  PortID string `json:"portID"`
232
226
  ChannelID string `json:"channelID"`
233
227
  CounterpartyVersion string `json:"counterpartyVersion"`
234
228
  Counterparty channeltypes.Counterparty `json:"counterparty"`
235
229
  ConnectionHops []string `json:"connectionHops"`
236
- BlockHeight int64 `json:"blockHeight"`
237
- BlockTime int64 `json:"blockTime"`
238
230
  }
239
231
 
240
232
  func (im IBCModule) OnChanOpenAck(
@@ -250,27 +242,21 @@ func (im IBCModule) OnChanOpenAck(
250
242
 
251
243
  channel.Counterparty.ChannelId = counterpartyChannelID
252
244
  event := channelOpenAckEvent{
253
- Type: "IBC_EVENT",
254
- Event: "channelOpenAck",
255
245
  PortID: portID,
256
246
  ChannelID: channelID,
257
247
  CounterpartyVersion: counterpartyVersion,
258
248
  Counterparty: channel.Counterparty,
259
249
  ConnectionHops: channel.ConnectionHops,
260
- BlockHeight: ctx.BlockHeight(),
261
- BlockTime: ctx.BlockTime().Unix(),
262
250
  }
263
251
 
264
252
  return im.PushAction(ctx, event)
265
253
  }
266
254
 
267
255
  type channelOpenConfirmEvent struct {
268
- Type string `json:"type"` // IBC
269
- Event string `json:"event"` // channelOpenConfirm
270
- PortID string `json:"portID"`
271
- ChannelID string `json:"channelID"`
272
- BlockHeight int64 `json:"blockHeight"`
273
- BlockTime int64 `json:"blockTime"`
256
+ vm.ActionHeader `actionType:"IBC_EVENT"`
257
+ Event string `json:"event" default:"channelOpenConfirm"`
258
+ PortID string `json:"portID"`
259
+ ChannelID string `json:"channelID"`
274
260
  }
275
261
 
276
262
  func (im IBCModule) OnChanOpenConfirm(
@@ -279,24 +265,18 @@ func (im IBCModule) OnChanOpenConfirm(
279
265
  channelID string,
280
266
  ) error {
281
267
  event := channelOpenConfirmEvent{
282
- Type: "IBC_EVENT",
283
- Event: "channelOpenConfirm",
284
- PortID: portID,
285
- ChannelID: channelID,
286
- BlockHeight: ctx.BlockHeight(),
287
- BlockTime: ctx.BlockTime().Unix(),
268
+ PortID: portID,
269
+ ChannelID: channelID,
288
270
  }
289
271
 
290
272
  return im.PushAction(ctx, event)
291
273
  }
292
274
 
293
275
  type channelCloseInitEvent struct {
294
- Type string `json:"type"` // IBC
295
- Event string `json:"event"` // channelCloseInit
296
- PortID string `json:"portID"`
297
- ChannelID string `json:"channelID"`
298
- BlockHeight int64 `json:"blockHeight"`
299
- BlockTime int64 `json:"blockTime"`
276
+ vm.ActionHeader `actionType:"IBC_EVENT"`
277
+ Event string `json:"event" default:"channelCloseInit"`
278
+ PortID string `json:"portID"`
279
+ ChannelID string `json:"channelID"`
300
280
  }
301
281
 
302
282
  func (im IBCModule) OnChanCloseInit(
@@ -305,12 +285,8 @@ func (im IBCModule) OnChanCloseInit(
305
285
  channelID string,
306
286
  ) error {
307
287
  event := channelCloseInitEvent{
308
- Type: "IBC_EVENT",
309
- Event: "channelCloseInit",
310
- PortID: portID,
311
- ChannelID: channelID,
312
- BlockHeight: ctx.BlockHeight(),
313
- BlockTime: ctx.BlockTime().Unix(),
288
+ PortID: portID,
289
+ ChannelID: channelID,
314
290
  }
315
291
 
316
292
  err := im.PushAction(ctx, event)
@@ -318,12 +294,10 @@ func (im IBCModule) OnChanCloseInit(
318
294
  }
319
295
 
320
296
  type channelCloseConfirmEvent struct {
321
- Type string `json:"type"` // IBC
322
- Event string `json:"event"` // channelCloseConfirm
323
- PortID string `json:"portID"`
324
- ChannelID string `json:"channelID"`
325
- BlockHeight int64 `json:"blockHeight"`
326
- BlockTime int64 `json:"blockTime"`
297
+ vm.ActionHeader `actionType:"IBC_EVENT"`
298
+ Event string `json:"event" default:"channelCloseConfirm"`
299
+ PortID string `json:"portID"`
300
+ ChannelID string `json:"channelID"`
327
301
  }
328
302
 
329
303
  func (im IBCModule) OnChanCloseConfirm(
@@ -332,12 +306,8 @@ func (im IBCModule) OnChanCloseConfirm(
332
306
  channelID string,
333
307
  ) error {
334
308
  event := channelCloseConfirmEvent{
335
- Type: "IBC_EVENT",
336
- Event: "channelCloseConfirm",
337
- PortID: portID,
338
- ChannelID: channelID,
339
- BlockHeight: ctx.BlockHeight(),
340
- BlockTime: ctx.BlockTime().Unix(),
309
+ PortID: portID,
310
+ ChannelID: channelID,
341
311
  }
342
312
 
343
313
  err := im.PushAction(ctx, event)
@@ -345,11 +315,9 @@ func (im IBCModule) OnChanCloseConfirm(
345
315
  }
346
316
 
347
317
  type receivePacketEvent struct {
348
- Type string `json:"type"` // IBC
349
- Event string `json:"event"` // receivePacket
350
- Packet channeltypes.Packet `json:"packet"`
351
- BlockHeight int64 `json:"blockHeight"`
352
- BlockTime int64 `json:"blockTime"`
318
+ vm.ActionHeader `actionType:"IBC_EVENT"`
319
+ Event string `json:"event" default:"receivePacket"`
320
+ Packet channeltypes.Packet `json:"packet"`
353
321
  }
354
322
 
355
323
  func (im IBCModule) OnRecvPacket(
@@ -366,11 +334,7 @@ func (im IBCModule) OnRecvPacket(
366
334
  // the same packets.
367
335
 
368
336
  event := receivePacketEvent{
369
- Type: "IBC_EVENT",
370
- Event: "receivePacket",
371
- Packet: packet,
372
- BlockHeight: ctx.BlockHeight(),
373
- BlockTime: ctx.BlockTime().Unix(),
337
+ Packet: packet,
374
338
  }
375
339
 
376
340
  err := im.PushAction(ctx, event)
@@ -382,12 +346,10 @@ func (im IBCModule) OnRecvPacket(
382
346
  }
383
347
 
384
348
  type acknowledgementPacketEvent struct {
385
- Type string `json:"type"` // IBC
386
- Event string `json:"event"` // acknowledgementPacket
349
+ vm.ActionHeader `actionType:"IBC_EVENT"`
350
+ Event string `json:"event" default:"acknowledgementPacket"`
387
351
  Packet channeltypes.Packet `json:"packet"`
388
352
  Acknowledgement []byte `json:"acknowledgement"`
389
- BlockHeight int64 `json:"blockHeight"`
390
- BlockTime int64 `json:"blockTime"`
391
353
  }
392
354
 
393
355
  func (im IBCModule) OnAcknowledgementPacket(
@@ -397,12 +359,8 @@ func (im IBCModule) OnAcknowledgementPacket(
397
359
  relayer sdk.AccAddress,
398
360
  ) error {
399
361
  event := acknowledgementPacketEvent{
400
- Type: "IBC_EVENT",
401
- Event: "acknowledgementPacket",
402
362
  Packet: packet,
403
363
  Acknowledgement: acknowledgement,
404
- BlockHeight: ctx.BlockHeight(),
405
- BlockTime: ctx.BlockTime().Unix(),
406
364
  }
407
365
 
408
366
  err := im.PushAction(ctx, event)
@@ -414,11 +372,9 @@ func (im IBCModule) OnAcknowledgementPacket(
414
372
  }
415
373
 
416
374
  type timeoutPacketEvent struct {
417
- Type string `json:"type"` // IBC
418
- Event string `json:"event"` // timeoutPacket
419
- Packet channeltypes.Packet `json:"packet"`
420
- BlockHeight int64 `json:"blockHeight"`
421
- BlockTime int64 `json:"blockTime"`
375
+ vm.ActionHeader `actionType:"IBC_EVENT"`
376
+ Event string `json:"event" default:"timeoutPacket"`
377
+ Packet channeltypes.Packet `json:"packet"`
422
378
  }
423
379
 
424
380
  func (im IBCModule) OnTimeoutPacket(
@@ -427,11 +383,7 @@ func (im IBCModule) OnTimeoutPacket(
427
383
  relayer sdk.AccAddress,
428
384
  ) error {
429
385
  event := timeoutPacketEvent{
430
- Type: "IBC_EVENT",
431
- Event: "timeoutPacket",
432
- Packet: packet,
433
- BlockHeight: ctx.BlockHeight(),
434
- BlockTime: ctx.BlockTime().Unix(),
386
+ Packet: packet,
435
387
  }
436
388
 
437
389
  err := im.PushAction(ctx, event)