@agoric/cosmos 0.34.2-dev-5dc325b.0 → 0.35.0-getting-started-dev-26244e8.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.
@@ -9,18 +9,11 @@ option go_package = "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types
9
9
 
10
10
  // Query defines the gRPC querier service
11
11
  service Query {
12
- // Return the raw string value of an arbitrary vstorage datum.
12
+ // Return an arbitrary vstorage datum.
13
13
  rpc Data(QueryDataRequest) returns (QueryDataResponse) {
14
14
  option (google.api.http).get = "/agoric/vstorage/data/{path}";
15
15
  }
16
16
 
17
- // Return a formatted representation of a vstorage datum that must be
18
- // a valid StreamCell with CapData values, or standalone CapData.
19
- rpc CapData(QueryCapDataRequest)
20
- returns (QueryCapDataResponse) {
21
- option (google.api.http).get = "/agoric/vstorage/capdata/{path}";
22
- }
23
-
24
17
  // Return the children of a given vstorage path.
25
18
  rpc Children(QueryChildrenRequest)
26
19
  returns (QueryChildrenResponse) {
@@ -44,51 +37,6 @@ message QueryDataResponse {
44
37
  ];
45
38
  }
46
39
 
47
- // QueryCapDataRequest contains a path and formatting configuration.
48
- message QueryCapDataRequest {
49
- string path = 1 [
50
- (gogoproto.jsontag) = "path",
51
- (gogoproto.moretags) = "yaml:\"path\""
52
- ];
53
- // mediaType must be an actual media type in the registry at
54
- // https://www.iana.org/assignments/media-types/media-types.xhtml
55
- // or a special value that does not conflict with the media type syntax.
56
- // The only valid value is "JSON Lines", which is also the default.
57
- string media_type = 2 [
58
- (gogoproto.jsontag) = "mediaType",
59
- (gogoproto.moretags) = "yaml:\"mediaType\""
60
- ];
61
- // itemFormat, if present, must be the special value "flat" to indicate that
62
- // the deep structure of each item should be flattened into a single level
63
- // with kebab-case keys (e.g., `{ "metrics": { "min": 0, "max": 88 } }` as
64
- // `{ "metrics-min": 0, "metrics-max": 88 }`).
65
- string item_format = 3 [
66
- (gogoproto.jsontag) = "itemFormat",
67
- (gogoproto.moretags) = "yaml:\"itemFormat\""
68
- ];
69
- // remotableValueFormat indicates how to transform references to opaque but
70
- // distinguishable Remotables into readable embedded representations.
71
- // * "object" represents each Remotable as an `{ id, allegedName }` object, e.g. `{ "id": "board007", "allegedName": "IST brand" }`.
72
- // * "string" represents each Remotable as a string with bracket-wrapped contents including its alleged name and id, e.g. "[Alleged: IST brand <board007>]".
73
- string remotable_value_format = 10 [
74
- (gogoproto.jsontag) = "remotableValueFormat",
75
- (gogoproto.moretags) = "yaml:\"remotableValueFormat\""
76
- ];
77
- }
78
-
79
- // QueryCapDataResponse represents the result with the requested formatting,
80
- // reserving space for future metadata such as media type.
81
- message QueryCapDataResponse {
82
- string block_height = 1 [
83
- (gogoproto.jsontag) = "blockHeight",
84
- (gogoproto.moretags) = "yaml:\"blockHeight\""
85
- ];
86
- string value = 10 [
87
- (gogoproto.jsontag) = "value",
88
- (gogoproto.moretags) = "yaml:\"value\""
89
- ];
90
- }
91
-
92
40
  // QueryChildrenRequest is the vstorage path children query.
93
41
  message QueryChildrenRequest {
94
42
  string path = 1 [
package/vm/controller.go CHANGED
@@ -1,11 +1,16 @@
1
1
  package vm
2
2
 
3
3
  import (
4
- "context"
4
+ "fmt"
5
5
 
6
6
  sdk "github.com/cosmos/cosmos-sdk/types"
7
7
  )
8
8
 
9
+ type ControllerContext struct {
10
+ Context sdk.Context
11
+ IBCChannelHandlerPort int
12
+ }
13
+
9
14
  type ControllerAdmissionMsg interface {
10
15
  sdk.Msg
11
16
  CheckAdmissibility(sdk.Context, interface{}) error
@@ -26,13 +31,10 @@ type Jsonable interface{}
26
31
  // ActionPusher enqueues data for later consumption by the controller.
27
32
  type ActionPusher func(ctx sdk.Context, action Jsonable) error
28
33
 
29
- var wrappedEmptySDKContext = sdk.WrapSDKContext(
30
- sdk.Context{}.WithContext(context.Background()),
31
- )
32
- var controllerContext context.Context = wrappedEmptySDKContext
34
+ var controllerContext ControllerContext
33
35
 
34
36
  type PortHandler interface {
35
- Receive(context.Context, string) (string, error)
37
+ Receive(*ControllerContext, string) (string, error)
36
38
  }
37
39
 
38
40
  var portToHandler = make(map[int]PortHandler)
@@ -43,9 +45,9 @@ var lastPort = 0
43
45
  func SetControllerContext(ctx sdk.Context) func() {
44
46
  // We are only called by the controller, so we assume that it is billing its
45
47
  // own meter usage.
46
- controllerContext = sdk.WrapSDKContext(ctx.WithGasMeter(sdk.NewInfiniteGasMeter()))
48
+ controllerContext.Context = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
47
49
  return func() {
48
- controllerContext = wrappedEmptySDKContext
50
+ controllerContext.Context = sdk.Context{}
49
51
  }
50
52
  }
51
53
 
@@ -67,3 +69,11 @@ func UnregisterPortHandler(portNum int) error {
67
69
  delete(nameToPort, name)
68
70
  return nil
69
71
  }
72
+
73
+ func ReceiveFromController(portNum int, msg string) (string, error) {
74
+ handler := portToHandler[portNum]
75
+ if handler == nil {
76
+ return "", fmt.Errorf("unregistered port %d", portNum)
77
+ }
78
+ return handler.Receive(&controllerContext, msg)
79
+ }
package/x/lien/lien.go CHANGED
@@ -5,7 +5,6 @@
5
5
  package lien
6
6
 
7
7
  import (
8
- "context"
9
8
  "encoding/json"
10
9
  "fmt"
11
10
  "math"
@@ -71,8 +70,7 @@ const (
71
70
  // Receives and processes a bridge message, returning the
72
71
  // JSON-encoded response or error.
73
72
  // See spec/02_messages.md for the messages and responses.
74
- func (ch portHandler) Receive(cctx context.Context, str string) (string, error) {
75
- ctx := sdk.UnwrapSDKContext(cctx)
73
+ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (string, error) {
76
74
  var msg portMessage
77
75
  err := json.Unmarshal([]byte(str), &msg)
78
76
  if err != nil {
@@ -80,13 +78,13 @@ func (ch portHandler) Receive(cctx context.Context, str string) (string, error)
80
78
  }
81
79
  switch msg.Type {
82
80
  case LIEN_GET_ACCOUNT_STATE:
83
- return ch.handleGetAccountState(ctx, msg)
81
+ return ch.handleGetAccountState(ctx.Context, msg)
84
82
 
85
83
  case LIEN_GET_STAKING:
86
- return ch.handleGetStaking(ctx, msg)
84
+ return ch.handleGetStaking(ctx.Context, msg)
87
85
 
88
86
  case LIEN_CHANGE_LIENED:
89
- return ch.handleChangeLiened(ctx, msg)
87
+ return ch.handleChangeLiened(ctx.Context, msg)
90
88
  }
91
89
  return "", fmt.Errorf("unrecognized type %s", msg.Type)
92
90
  }
@@ -1,11 +1,11 @@
1
1
  package lien
2
2
 
3
3
  import (
4
- "context"
5
4
  "encoding/json"
6
5
  "reflect"
7
6
  "testing"
8
7
 
8
+ "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
9
9
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types"
10
10
 
11
11
  "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
@@ -114,8 +114,8 @@ func (m *mockLienKeeper) GetDelegatorDelegations(ctx sdk.Context, delegator sdk.
114
114
  }
115
115
 
116
116
  func TestBadType(t *testing.T) {
117
- ctx := sdk.Context{}.WithContext(context.Background())
118
- ctlCtx := sdk.WrapSDKContext(ctx)
117
+ ctx := sdk.Context{}
118
+ ctlCtx := &vm.ControllerContext{Context: ctx}
119
119
  keeper := mockLienKeeper{
120
120
  states: map[string]types.AccountState{},
121
121
  }
@@ -135,8 +135,8 @@ func TestBadType(t *testing.T) {
135
135
  }
136
136
 
137
137
  func TestGetAccountState(t *testing.T) {
138
- ctx := sdk.Context{}.WithContext(context.Background())
139
- ctlCtx := sdk.WrapSDKContext(ctx)
138
+ ctx := sdk.Context{}
139
+ ctlCtx := &vm.ControllerContext{Context: ctx}
140
140
 
141
141
  keeper := mockLienKeeper{
142
142
  states: map[string]types.AccountState{
@@ -177,9 +177,8 @@ func TestGetAccountState(t *testing.T) {
177
177
  }
178
178
 
179
179
  func TestGetAccountState_badRequest(t *testing.T) {
180
- ctx := sdk.Context{}.WithContext(context.Background())
181
- ctlCtx := sdk.WrapSDKContext(ctx)
182
-
180
+ ctx := sdk.Context{}
181
+ ctlCtx := &vm.ControllerContext{Context: ctx}
183
182
  keeper := mockLienKeeper{
184
183
  states: map[string]types.AccountState{},
185
184
  }
@@ -215,9 +214,8 @@ func TestGetAccountState_badRequest(t *testing.T) {
215
214
  }
216
215
 
217
216
  func TestSetLiened_badAddr(t *testing.T) {
218
- ctx := sdk.Context{}.WithContext(context.Background())
219
- ctlCtx := sdk.WrapSDKContext(ctx)
220
-
217
+ ctx := sdk.Context{}
218
+ ctlCtx := &vm.ControllerContext{Context: ctx}
221
219
  keeper := mockLienKeeper{}
222
220
  ph := NewPortHandler(&keeper)
223
221
  msg := portMessage{
@@ -237,9 +235,8 @@ func TestSetLiened_badAddr(t *testing.T) {
237
235
  }
238
236
 
239
237
  func TestSetLiened_badDenom(t *testing.T) {
240
- ctx := sdk.Context{}.WithContext(context.Background())
241
- ctlCtx := sdk.WrapSDKContext(ctx)
242
-
238
+ ctx := sdk.Context{}
239
+ ctlCtx := &vm.ControllerContext{Context: ctx}
243
240
  keeper := mockLienKeeper{}
244
241
  ph := NewPortHandler(&keeper)
245
242
  msg := portMessage{
@@ -259,9 +256,8 @@ func TestSetLiened_badDenom(t *testing.T) {
259
256
  }
260
257
 
261
258
  func TestSetLiened(t *testing.T) {
262
- ctx := sdk.Context{}.WithContext(context.Background())
263
- ctlCtx := sdk.WrapSDKContext(ctx)
264
-
259
+ ctx := sdk.Context{}
260
+ ctlCtx := &vm.ControllerContext{Context: ctx}
265
261
  keeper := mockLienKeeper{}
266
262
  ph := NewPortHandler(&keeper)
267
263
  msg := portMessage{
@@ -340,8 +336,8 @@ func TestGetStaking(t *testing.T) {
340
336
  keeper.delegations[addr4.String()] = []stakingTypes.Delegation{}
341
337
 
342
338
  ph := NewPortHandler(&keeper)
343
- ctx := sdk.Context{}.WithContext(context.Background())
344
- ctlCtx := sdk.WrapSDKContext(ctx)
339
+ ctx := sdk.Context{}
340
+ ctlCtx := &vm.ControllerContext{Context: ctx}
345
341
 
346
342
  pi := func(x int64) *sdk.Int {
347
343
  n := i(x)
@@ -2,7 +2,6 @@ package swingset
2
2
 
3
3
  import (
4
4
  // "os"
5
- "context"
6
5
  "fmt"
7
6
  "time"
8
7
 
@@ -89,7 +88,7 @@ func CommitBlock(keeper Keeper) error {
89
88
  BlockHeight: endBlockHeight,
90
89
  BlockTime: endBlockTime,
91
90
  }
92
- _, err := keeper.BlockingSend(sdk.Context{}.WithContext(context.Background()), action)
91
+ _, err := keeper.BlockingSend(sdk.Context{}, action)
93
92
 
94
93
  // fmt.Fprintf(os.Stderr, "COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
95
94
  if err != nil {
@@ -108,7 +107,7 @@ func AfterCommitBlock(keeper Keeper) error {
108
107
  BlockHeight: endBlockHeight,
109
108
  BlockTime: endBlockTime,
110
109
  }
111
- _, err := keeper.BlockingSend(sdk.Context{}.WithContext(context.Background()), action)
110
+ _, err := keeper.BlockingSend(sdk.Context{}, action)
112
111
 
113
112
  // fmt.Fprintf(os.Stderr, "AFTER_COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
114
113
  if err != nil {
@@ -1,7 +1,6 @@
1
1
  package swingset
2
2
 
3
3
  import (
4
- "context"
5
4
  "encoding/json"
6
5
  "fmt"
7
6
  "io"
@@ -34,8 +33,7 @@ func NewPortHandler(k Keeper) vm.PortHandler {
34
33
  // Receive implements the vm.PortHandler method.
35
34
  // It receives and processes an inbound message, returning the
36
35
  // JSON-serialized response or an error.
37
- func (ph portHandler) Receive(cctx context.Context, str string) (string, error) {
38
- ctx := sdk.UnwrapSDKContext(cctx)
36
+ func (ph portHandler) Receive(ctx *vm.ControllerContext, str string) (string, error) {
39
37
  var msg swingsetMessage
40
38
  err := json.Unmarshal([]byte(str), &msg)
41
39
  if err != nil {
@@ -44,7 +42,7 @@ func (ph portHandler) Receive(cctx context.Context, str string) (string, error)
44
42
 
45
43
  switch msg.Method {
46
44
  case SwingStoreUpdateExportData:
47
- return ph.handleSwingStoreUpdateExportData(ctx, msg.Args)
45
+ return ph.handleSwingStoreUpdateExportData(ctx.Context, msg.Args)
48
46
 
49
47
  default:
50
48
  return "", fmt.Errorf("unrecognized swingset method %s", msg.Method)
@@ -50,7 +50,7 @@ var (
50
50
  DefaultBeansPerMinFeeDebit = DefaultBeansPerFeeUnit.Quo(sdk.NewUint(5)) // $0.2
51
51
  DefaultBeansPerStorageByte = DefaultBeansPerFeeUnit.Quo(sdk.NewUint(500)) // $0.002
52
52
 
53
- DefaultBootstrapVatConfig = "@agoric/vm-config/decentral-core-config.json"
53
+ DefaultBootstrapVatConfig = "@agoric/vats/decentral-core-config.json"
54
54
 
55
55
  DefaultPowerFlagFees = []PowerFlagFee{
56
56
  NewPowerFlagFee("SMART_WALLET", sdk.NewCoins(sdk.NewInt64Coin("ubld", 10_000_000))),
@@ -433,7 +433,7 @@ type MsgInstallBundle struct {
433
433
  Submitter github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,2,opt,name=submitter,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"submitter" yaml:"submitter"`
434
434
  // Either bundle or compressed_bundle will be set.
435
435
  // Default compression algorithm is gzip.
436
- CompressedBundle []byte `protobuf:"bytes,3,opt,name=compressed_bundle,json=compressedBundle,proto3" json:"compressedBundle" yaml:"compressedBundle"`
436
+ CompressedBundle []byte `protobuf:"bytes,3,opt,name=compressed_bundle,json=compressedBundle,proto3" json:"compressedBundle" yaml:"bcompressedBndle"`
437
437
  // Size in bytes of uncompression of compressed_bundle.
438
438
  UncompressedSize int64 `protobuf:"varint,4,opt,name=uncompressed_size,json=uncompressedSize,proto3" json:"uncompressedSize"`
439
439
  }
@@ -553,7 +553,7 @@ func init() {
553
553
  func init() { proto.RegisterFile("agoric/swingset/msgs.proto", fileDescriptor_788baa062b181a57) }
554
554
 
555
555
  var fileDescriptor_788baa062b181a57 = []byte{
556
- // 788 bytes of a gzipped FileDescriptorProto
556
+ // 789 bytes of a gzipped FileDescriptorProto
557
557
  0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0xcf, 0x6f, 0xe3, 0x44,
558
558
  0x14, 0x8e, 0xe3, 0x50, 0x36, 0xaf, 0xd9, 0x6d, 0x63, 0x95, 0xad, 0xd7, 0x0b, 0x99, 0xac, 0xa5,
559
559
  0x15, 0x01, 0xd4, 0x44, 0xb0, 0xb7, 0xed, 0x29, 0x16, 0x42, 0x5a, 0xa4, 0xa0, 0xc5, 0x2b, 0x84,
@@ -590,20 +590,20 @@ var fileDescriptor_788baa062b181a57 = []byte{
590
590
  0x01, 0x8d, 0x2d, 0xcf, 0x33, 0x66, 0xc1, 0xc4, 0xc3, 0xca, 0x0b, 0xd8, 0x1a, 0xf3, 0x7f, 0xf9,
591
591
  0xe9, 0x3c, 0x4d, 0x18, 0xca, 0x91, 0x94, 0xa1, 0x87, 0xc2, 0x9e, 0x88, 0x75, 0x33, 0x27, 0x96,
592
592
  0x57, 0x56, 0xbf, 0x87, 0x95, 0x29, 0xdf, 0x40, 0xdb, 0x26, 0x7e, 0x98, 0xc1, 0x78, 0x72, 0x9c,
593
- 0x3b, 0x96, 0x79, 0xe7, 0x41, 0xc2, 0xd0, 0x6e, 0x45, 0x1a, 0x85, 0xf7, 0x7d, 0x61, 0x60, 0x95,
594
- 0xd1, 0xcd, 0x35, 0xb1, 0x32, 0x84, 0xf6, 0x2c, 0x58, 0xa8, 0x4f, 0xdd, 0x4b, 0xcc, 0x4f, 0x4c,
595
- 0x36, 0xf6, 0xb2, 0xea, 0x8b, 0xe4, 0x1b, 0xf7, 0x12, 0x9b, 0x6b, 0x88, 0xae, 0x81, 0xba, 0xba,
596
- 0xb7, 0xc5, 0xc6, 0x7f, 0x72, 0x2d, 0x83, 0x3c, 0xa2, 0x8e, 0xf2, 0x2d, 0x3c, 0x5c, 0xde, 0xfc,
597
- 0x67, 0xfd, 0x95, 0xd7, 0x40, 0x7f, 0xb5, 0x86, 0xf6, 0xc1, 0xad, 0x92, 0xa2, 0x8d, 0x72, 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609
609
  // Reference imports to suppress errors if they are not otherwise used.
package/x/vbank/vbank.go CHANGED
@@ -121,9 +121,8 @@ func marshal(event vm.Jsonable) ([]byte, error) {
121
121
  return json.Marshal(event)
122
122
  }
123
123
 
124
- func (ch portHandler) Receive(cctx context.Context, str string) (ret string, err error) {
124
+ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string, err error) {
125
125
  // fmt.Println("vbank.go downcall", str)
126
- ctx := sdk.UnwrapSDKContext(cctx)
127
126
  keeper := ch.keeper
128
127
 
129
128
  var msg portMessage
@@ -141,7 +140,7 @@ func (ch portHandler) Receive(cctx context.Context, str string) (ret string, err
141
140
  if err = sdk.ValidateDenom(msg.Denom); err != nil {
142
141
  return "", fmt.Errorf("invalid denom %s: %s", msg.Denom, err)
143
142
  }
144
- coin := keeper.GetBalance(ctx, addr, msg.Denom)
143
+ coin := keeper.GetBalance(ctx.Context, addr, msg.Denom)
145
144
  packet := coin.Amount.String()
146
145
  if err == nil {
147
146
  bytes, err := json.Marshal(&packet)
@@ -163,12 +162,12 @@ func (ch portHandler) Receive(cctx context.Context, str string) (ret string, err
163
162
  return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
164
163
  }
165
164
  coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
166
- if err := keeper.GrabCoins(ctx, addr, coins); err != nil {
165
+ if err := keeper.GrabCoins(ctx.Context, addr, coins); err != nil {
167
166
  return "", fmt.Errorf("cannot grab %s coins: %s", coins.Sort().String(), err)
168
167
  }
169
168
  addressToBalances := make(map[string]sdk.Coins, 1)
170
169
  addressToBalances[msg.Sender] = sdk.NewCoins(sdk.NewInt64Coin(msg.Denom, 1))
171
- bz, err := marshal(getBalanceUpdate(ctx, keeper, addressToBalances))
170
+ bz, err := marshal(getBalanceUpdate(ctx.Context, keeper, addressToBalances))
172
171
  if err != nil {
173
172
  return "", err
174
173
  }
@@ -191,12 +190,12 @@ func (ch portHandler) Receive(cctx context.Context, str string) (ret string, err
191
190
  return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
192
191
  }
193
192
  coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
194
- if err := keeper.SendCoins(ctx, addr, coins); err != nil {
193
+ if err := keeper.SendCoins(ctx.Context, addr, coins); err != nil {
195
194
  return "", fmt.Errorf("cannot give %s coins: %s", coins.Sort().String(), err)
196
195
  }
197
196
  addressToBalances := make(map[string]sdk.Coins, 1)
198
197
  addressToBalances[msg.Recipient] = sdk.NewCoins(sdk.NewInt64Coin(msg.Denom, 1))
199
- bz, err := marshal(getBalanceUpdate(ctx, keeper, addressToBalances))
198
+ bz, err := marshal(getBalanceUpdate(ctx.Context, keeper, addressToBalances))
200
199
  if err != nil {
201
200
  return "", err
202
201
  }
@@ -212,20 +211,20 @@ func (ch portHandler) Receive(cctx context.Context, str string) (ret string, err
212
211
  return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
213
212
  }
214
213
  coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
215
- if err := keeper.StoreRewardCoins(ctx, coins); err != nil {
214
+ if err := keeper.StoreRewardCoins(ctx.Context, coins); err != nil {
216
215
  return "", fmt.Errorf("cannot store reward %s coins: %s", coins.Sort().String(), err)
217
216
  }
218
217
  if err != nil {
219
218
  return "", err
220
219
  }
221
- state := keeper.GetState(ctx)
220
+ state := keeper.GetState(ctx.Context)
222
221
  state.RewardPool = state.RewardPool.Add(coins...)
223
- keeper.SetState(ctx, state)
222
+ keeper.SetState(ctx.Context, state)
224
223
  // We don't supply the module balance, since the controller shouldn't know.
225
224
  ret = "true"
226
225
 
227
226
  case "VBANK_GET_MODULE_ACCOUNT_ADDRESS":
228
- addr := keeper.GetModuleAccountAddress(ctx, msg.ModuleName).String()
227
+ addr := keeper.GetModuleAccountAddress(ctx.Context, msg.ModuleName).String()
229
228
  if len(addr) == 0 {
230
229
  return "", fmt.Errorf("module account %s not found", msg.ModuleName)
231
230
  }
@@ -284,7 +284,7 @@ func Test_Receive_GetBalance(t *testing.T) {
284
284
  }}
285
285
  keeper, ctx := makeTestKit(nil, bank)
286
286
  ch := NewPortHandler(AppModule{}, keeper)
287
- ctlCtx := sdk.WrapSDKContext(ctx)
287
+ ctlCtx := &vm.ControllerContext{Context: ctx}
288
288
 
289
289
  ret, err := ch.Receive(ctlCtx, `{
290
290
  "type": "VBANK_GET_BALANCE",
@@ -312,7 +312,7 @@ func Test_Receive_Give(t *testing.T) {
312
312
  }}
313
313
  keeper, ctx := makeTestKit(nil, bank)
314
314
  ch := NewPortHandler(AppModule{}, keeper)
315
- ctlCtx := sdk.WrapSDKContext(ctx)
315
+ ctlCtx := &vm.ControllerContext{Context: ctx}
316
316
 
317
317
  ret, err := ch.Receive(ctlCtx, `{
318
318
  "type": "VBANK_GIVE",
@@ -349,7 +349,7 @@ func Test_Receive_GiveToRewardDistributor(t *testing.T) {
349
349
  bank := &mockBank{}
350
350
  keeper, ctx := makeTestKit(nil, bank)
351
351
  ch := NewPortHandler(AppModule{}, keeper)
352
- ctlCtx := sdk.WrapSDKContext(ctx)
352
+ ctlCtx := &vm.ControllerContext{Context: ctx}
353
353
 
354
354
  tests := []struct {
355
355
  name string
@@ -474,7 +474,7 @@ func Test_Receive_Grab(t *testing.T) {
474
474
  }}
475
475
  keeper, ctx := makeTestKit(nil, bank)
476
476
  ch := NewPortHandler(AppModule{}, keeper)
477
- ctlCtx := sdk.WrapSDKContext(ctx)
477
+ ctlCtx := &vm.ControllerContext{Context: ctx}
478
478
 
479
479
  ret, err := ch.Receive(ctlCtx, `{
480
480
  "type": "VBANK_GRAB",
@@ -787,7 +787,7 @@ func Test_Module_Account(t *testing.T) {
787
787
  keeper, ctx := makeTestKit(acct, nil)
788
788
  am := AppModule{keeper: keeper}
789
789
  ch := NewPortHandler(am, keeper)
790
- ctlCtx := sdk.WrapSDKContext(ctx)
790
+ ctlCtx := &vm.ControllerContext{Context: ctx}
791
791
 
792
792
  mod1 := "vbank/reserve"
793
793
  ret, err := ch.Receive(ctlCtx, `{
package/x/vibc/ibc.go CHANGED
@@ -1,7 +1,6 @@
1
1
  package vibc
2
2
 
3
3
  import (
4
- "context"
5
4
  "encoding/json"
6
5
  "fmt"
7
6
 
@@ -64,9 +63,8 @@ func NewIBCModule(keeper Keeper) IBCModule {
64
63
  }
65
64
  }
66
65
 
67
- func (ch IBCModule) Receive(cctx context.Context, str string) (ret string, err error) {
66
+ func (ch IBCModule) Receive(ctx *vm.ControllerContext, str string) (ret string, err error) {
68
67
  // fmt.Println("ibc.go downcall", str)
69
- ctx := sdk.UnwrapSDKContext(cctx)
70
68
  keeper := ch.keeper
71
69
 
72
70
  msg := new(portMessage)
@@ -82,7 +80,7 @@ func (ch IBCModule) Receive(cctx context.Context, str string) (ret string, err e
82
80
  switch msg.Method {
83
81
  case "sendPacket":
84
82
  seq, ok := keeper.GetNextSequenceSend(
85
- ctx,
83
+ ctx.Context,
86
84
  msg.Packet.SourcePort,
87
85
  msg.Packet.SourceChannel,
88
86
  )
@@ -93,7 +91,7 @@ func (ch IBCModule) Receive(cctx context.Context, str string) (ret string, err e
93
91
  timeoutTimestamp := msg.Packet.TimeoutTimestamp
94
92
  if msg.Packet.TimeoutHeight.IsZero() && msg.Packet.TimeoutTimestamp == 0 {
95
93
  // Use the relative timeout if no absolute timeout is specifiied.
96
- timeoutTimestamp = uint64(ctx.BlockTime().UnixNano()) + msg.RelativeTimeoutNs
94
+ timeoutTimestamp = uint64(ctx.Context.BlockTime().UnixNano()) + msg.RelativeTimeoutNs
97
95
  }
98
96
 
99
97
  packet := channeltypes.NewPacket(
@@ -102,7 +100,7 @@ func (ch IBCModule) Receive(cctx context.Context, str string) (ret string, err e
102
100
  msg.Packet.DestinationPort, msg.Packet.DestinationChannel,
103
101
  msg.Packet.TimeoutHeight, timeoutTimestamp,
104
102
  )
105
- err = keeper.SendPacket(ctx, packet)
103
+ err = keeper.SendPacket(ctx.Context, packet)
106
104
  if err == nil {
107
105
  bytes, err := json.Marshal(&packet)
108
106
  if err == nil {
@@ -111,14 +109,14 @@ func (ch IBCModule) Receive(cctx context.Context, str string) (ret string, err e
111
109
  }
112
110
 
113
111
  case "receiveExecuted":
114
- err = keeper.WriteAcknowledgement(ctx, msg.Packet, msg.Ack)
112
+ err = keeper.WriteAcknowledgement(ctx.Context, msg.Packet, msg.Ack)
115
113
  if err == nil {
116
114
  ret = "true"
117
115
  }
118
116
 
119
117
  case "startChannelOpenInit":
120
118
  err = keeper.ChanOpenInit(
121
- ctx, stringToOrder(msg.Order), msg.Hops,
119
+ ctx.Context, stringToOrder(msg.Order), msg.Hops,
122
120
  msg.Packet.SourcePort,
123
121
  msg.Packet.DestinationPort,
124
122
  msg.Version,
@@ -128,19 +126,19 @@ func (ch IBCModule) Receive(cctx context.Context, str string) (ret string, err e
128
126
  }
129
127
 
130
128
  case "startChannelCloseInit":
131
- err = keeper.ChanCloseInit(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel)
129
+ err = keeper.ChanCloseInit(ctx.Context, msg.Packet.SourcePort, msg.Packet.SourceChannel)
132
130
  if err == nil {
133
131
  ret = "true"
134
132
  }
135
133
 
136
134
  case "bindPort":
137
- err = keeper.BindPort(ctx, msg.Packet.SourcePort)
135
+ err = keeper.BindPort(ctx.Context, msg.Packet.SourcePort)
138
136
  if err == nil {
139
137
  ret = "true"
140
138
  }
141
139
 
142
140
  case "timeoutExecuted":
143
- err = keeper.TimeoutExecuted(ctx, msg.Packet)
141
+ err = keeper.TimeoutExecuted(ctx.Context, msg.Packet)
144
142
  if err == nil {
145
143
  ret = "true"
146
144
  }