@agoric/cosmos 0.34.2-dev-5fcf452.0 → 0.34.2-dev-d355030.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 +5 -4
- package/cmd/agd/agvm.go +42 -0
- package/cmd/agd/main.go +133 -11
- package/cmd/libdaemon/main.go +67 -53
- package/daemon/cmd/root.go +55 -24
- package/daemon/main.go +3 -1
- package/git-revision.txt +1 -1
- package/package.json +2 -2
- package/vm/client.go +113 -0
- package/vm/client_test.go +184 -0
- package/vm/controller.go +8 -18
- package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
- package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
- package/vm/server.go +23 -0
- package/x/lien/lien.go +6 -4
- package/x/lien/lien_test.go +19 -15
- package/x/swingset/abci.go +3 -2
- package/x/swingset/swingset.go +4 -2
- package/x/vbank/vbank.go +11 -10
- package/x/vbank/vbank_test.go +5 -5
- package/x/vibc/ibc.go +11 -9
- package/x/vstorage/vstorage.go +16 -15
- package/x/vstorage/vstorage_test.go +4 -4
package/x/lien/lien_test.go
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
package lien
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
4
5
|
"encoding/json"
|
|
5
6
|
"reflect"
|
|
6
7
|
"testing"
|
|
7
8
|
|
|
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{}
|
|
118
|
-
ctlCtx :=
|
|
117
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
118
|
+
ctlCtx := sdk.WrapSDKContext(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{}
|
|
139
|
-
ctlCtx :=
|
|
138
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
139
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
140
140
|
|
|
141
141
|
keeper := mockLienKeeper{
|
|
142
142
|
states: map[string]types.AccountState{
|
|
@@ -177,8 +177,9 @@ func TestGetAccountState(t *testing.T) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
func TestGetAccountState_badRequest(t *testing.T) {
|
|
180
|
-
ctx := sdk.Context{}
|
|
181
|
-
ctlCtx :=
|
|
180
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
181
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
182
|
+
|
|
182
183
|
keeper := mockLienKeeper{
|
|
183
184
|
states: map[string]types.AccountState{},
|
|
184
185
|
}
|
|
@@ -214,8 +215,9 @@ func TestGetAccountState_badRequest(t *testing.T) {
|
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
func TestSetLiened_badAddr(t *testing.T) {
|
|
217
|
-
ctx := sdk.Context{}
|
|
218
|
-
ctlCtx :=
|
|
218
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
219
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
220
|
+
|
|
219
221
|
keeper := mockLienKeeper{}
|
|
220
222
|
ph := NewPortHandler(&keeper)
|
|
221
223
|
msg := portMessage{
|
|
@@ -235,8 +237,9 @@ func TestSetLiened_badAddr(t *testing.T) {
|
|
|
235
237
|
}
|
|
236
238
|
|
|
237
239
|
func TestSetLiened_badDenom(t *testing.T) {
|
|
238
|
-
ctx := sdk.Context{}
|
|
239
|
-
ctlCtx :=
|
|
240
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
241
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
242
|
+
|
|
240
243
|
keeper := mockLienKeeper{}
|
|
241
244
|
ph := NewPortHandler(&keeper)
|
|
242
245
|
msg := portMessage{
|
|
@@ -256,8 +259,9 @@ func TestSetLiened_badDenom(t *testing.T) {
|
|
|
256
259
|
}
|
|
257
260
|
|
|
258
261
|
func TestSetLiened(t *testing.T) {
|
|
259
|
-
ctx := sdk.Context{}
|
|
260
|
-
ctlCtx :=
|
|
262
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
263
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
264
|
+
|
|
261
265
|
keeper := mockLienKeeper{}
|
|
262
266
|
ph := NewPortHandler(&keeper)
|
|
263
267
|
msg := portMessage{
|
|
@@ -336,8 +340,8 @@ func TestGetStaking(t *testing.T) {
|
|
|
336
340
|
keeper.delegations[addr4.String()] = []stakingTypes.Delegation{}
|
|
337
341
|
|
|
338
342
|
ph := NewPortHandler(&keeper)
|
|
339
|
-
ctx := sdk.Context{}
|
|
340
|
-
ctlCtx :=
|
|
343
|
+
ctx := sdk.Context{}.WithContext(context.Background())
|
|
344
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
341
345
|
|
|
342
346
|
pi := func(x int64) *sdk.Int {
|
|
343
347
|
n := i(x)
|
package/x/swingset/abci.go
CHANGED
|
@@ -2,6 +2,7 @@ package swingset
|
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
// "os"
|
|
5
|
+
"context"
|
|
5
6
|
"fmt"
|
|
6
7
|
"time"
|
|
7
8
|
|
|
@@ -88,7 +89,7 @@ func CommitBlock(keeper Keeper) error {
|
|
|
88
89
|
BlockHeight: endBlockHeight,
|
|
89
90
|
BlockTime: endBlockTime,
|
|
90
91
|
}
|
|
91
|
-
_, err := keeper.BlockingSend(sdk.Context{}, action)
|
|
92
|
+
_, err := keeper.BlockingSend(sdk.Context{}.WithContext(context.Background()), action)
|
|
92
93
|
|
|
93
94
|
// fmt.Fprintf(os.Stderr, "COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
|
|
94
95
|
if err != nil {
|
|
@@ -107,7 +108,7 @@ func AfterCommitBlock(keeper Keeper) error {
|
|
|
107
108
|
BlockHeight: endBlockHeight,
|
|
108
109
|
BlockTime: endBlockTime,
|
|
109
110
|
}
|
|
110
|
-
_, err := keeper.BlockingSend(sdk.Context{}, action)
|
|
111
|
+
_, err := keeper.BlockingSend(sdk.Context{}.WithContext(context.Background()), action)
|
|
111
112
|
|
|
112
113
|
// fmt.Fprintf(os.Stderr, "AFTER_COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
|
|
113
114
|
if err != nil {
|
package/x/swingset/swingset.go
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package swingset
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
4
5
|
"encoding/json"
|
|
5
6
|
"fmt"
|
|
6
7
|
"io"
|
|
@@ -33,7 +34,8 @@ func NewPortHandler(k Keeper) vm.PortHandler {
|
|
|
33
34
|
// Receive implements the vm.PortHandler method.
|
|
34
35
|
// It receives and processes an inbound message, returning the
|
|
35
36
|
// JSON-serialized response or an error.
|
|
36
|
-
func (ph portHandler) Receive(
|
|
37
|
+
func (ph portHandler) Receive(cctx context.Context, str string) (string, error) {
|
|
38
|
+
ctx := sdk.UnwrapSDKContext(cctx)
|
|
37
39
|
var msg swingsetMessage
|
|
38
40
|
err := json.Unmarshal([]byte(str), &msg)
|
|
39
41
|
if err != nil {
|
|
@@ -42,7 +44,7 @@ func (ph portHandler) Receive(ctx *vm.ControllerContext, str string) (string, er
|
|
|
42
44
|
|
|
43
45
|
switch msg.Method {
|
|
44
46
|
case SwingStoreUpdateExportData:
|
|
45
|
-
return ph.handleSwingStoreUpdateExportData(ctx
|
|
47
|
+
return ph.handleSwingStoreUpdateExportData(ctx, msg.Args)
|
|
46
48
|
|
|
47
49
|
default:
|
|
48
50
|
return "", fmt.Errorf("unrecognized swingset method %s", msg.Method)
|
package/x/vbank/vbank.go
CHANGED
|
@@ -121,8 +121,9 @@ func marshal(event vm.Jsonable) ([]byte, error) {
|
|
|
121
121
|
return json.Marshal(event)
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
func (ch portHandler) Receive(
|
|
124
|
+
func (ch portHandler) Receive(cctx context.Context, str string) (ret string, err error) {
|
|
125
125
|
// fmt.Println("vbank.go downcall", str)
|
|
126
|
+
ctx := sdk.UnwrapSDKContext(cctx)
|
|
126
127
|
keeper := ch.keeper
|
|
127
128
|
|
|
128
129
|
var msg portMessage
|
|
@@ -140,7 +141,7 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
|
|
|
140
141
|
if err = sdk.ValidateDenom(msg.Denom); err != nil {
|
|
141
142
|
return "", fmt.Errorf("invalid denom %s: %s", msg.Denom, err)
|
|
142
143
|
}
|
|
143
|
-
coin := keeper.GetBalance(ctx
|
|
144
|
+
coin := keeper.GetBalance(ctx, addr, msg.Denom)
|
|
144
145
|
packet := coin.Amount.String()
|
|
145
146
|
if err == nil {
|
|
146
147
|
bytes, err := json.Marshal(&packet)
|
|
@@ -162,12 +163,12 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
|
|
|
162
163
|
return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
|
|
163
164
|
}
|
|
164
165
|
coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
|
|
165
|
-
if err := keeper.GrabCoins(ctx
|
|
166
|
+
if err := keeper.GrabCoins(ctx, addr, coins); err != nil {
|
|
166
167
|
return "", fmt.Errorf("cannot grab %s coins: %s", coins.Sort().String(), err)
|
|
167
168
|
}
|
|
168
169
|
addressToBalances := make(map[string]sdk.Coins, 1)
|
|
169
170
|
addressToBalances[msg.Sender] = sdk.NewCoins(sdk.NewInt64Coin(msg.Denom, 1))
|
|
170
|
-
bz, err := marshal(getBalanceUpdate(ctx
|
|
171
|
+
bz, err := marshal(getBalanceUpdate(ctx, keeper, addressToBalances))
|
|
171
172
|
if err != nil {
|
|
172
173
|
return "", err
|
|
173
174
|
}
|
|
@@ -190,12 +191,12 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
|
|
|
190
191
|
return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
|
|
191
192
|
}
|
|
192
193
|
coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
|
|
193
|
-
if err := keeper.SendCoins(ctx
|
|
194
|
+
if err := keeper.SendCoins(ctx, addr, coins); err != nil {
|
|
194
195
|
return "", fmt.Errorf("cannot give %s coins: %s", coins.Sort().String(), err)
|
|
195
196
|
}
|
|
196
197
|
addressToBalances := make(map[string]sdk.Coins, 1)
|
|
197
198
|
addressToBalances[msg.Recipient] = sdk.NewCoins(sdk.NewInt64Coin(msg.Denom, 1))
|
|
198
|
-
bz, err := marshal(getBalanceUpdate(ctx
|
|
199
|
+
bz, err := marshal(getBalanceUpdate(ctx, keeper, addressToBalances))
|
|
199
200
|
if err != nil {
|
|
200
201
|
return "", err
|
|
201
202
|
}
|
|
@@ -211,20 +212,20 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
|
|
|
211
212
|
return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
|
|
212
213
|
}
|
|
213
214
|
coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
|
|
214
|
-
if err := keeper.StoreRewardCoins(ctx
|
|
215
|
+
if err := keeper.StoreRewardCoins(ctx, coins); err != nil {
|
|
215
216
|
return "", fmt.Errorf("cannot store reward %s coins: %s", coins.Sort().String(), err)
|
|
216
217
|
}
|
|
217
218
|
if err != nil {
|
|
218
219
|
return "", err
|
|
219
220
|
}
|
|
220
|
-
state := keeper.GetState(ctx
|
|
221
|
+
state := keeper.GetState(ctx)
|
|
221
222
|
state.RewardPool = state.RewardPool.Add(coins...)
|
|
222
|
-
keeper.SetState(ctx
|
|
223
|
+
keeper.SetState(ctx, state)
|
|
223
224
|
// We don't supply the module balance, since the controller shouldn't know.
|
|
224
225
|
ret = "true"
|
|
225
226
|
|
|
226
227
|
case "VBANK_GET_MODULE_ACCOUNT_ADDRESS":
|
|
227
|
-
addr := keeper.GetModuleAccountAddress(ctx
|
|
228
|
+
addr := keeper.GetModuleAccountAddress(ctx, msg.ModuleName).String()
|
|
228
229
|
if len(addr) == 0 {
|
|
229
230
|
return "", fmt.Errorf("module account %s not found", msg.ModuleName)
|
|
230
231
|
}
|
package/x/vbank/vbank_test.go
CHANGED
|
@@ -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 :=
|
|
287
|
+
ctlCtx := sdk.WrapSDKContext(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 :=
|
|
315
|
+
ctlCtx := sdk.WrapSDKContext(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 :=
|
|
352
|
+
ctlCtx := sdk.WrapSDKContext(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 :=
|
|
477
|
+
ctlCtx := sdk.WrapSDKContext(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 :=
|
|
790
|
+
ctlCtx := sdk.WrapSDKContext(ctx)
|
|
791
791
|
|
|
792
792
|
mod1 := "vbank/reserve"
|
|
793
793
|
ret, err := ch.Receive(ctlCtx, `{
|
package/x/vibc/ibc.go
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package vibc
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
4
5
|
"encoding/json"
|
|
5
6
|
"fmt"
|
|
6
7
|
|
|
@@ -63,8 +64,9 @@ func NewIBCModule(keeper Keeper) IBCModule {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
func (ch IBCModule) Receive(
|
|
67
|
+
func (ch IBCModule) Receive(cctx context.Context, str string) (ret string, err error) {
|
|
67
68
|
// fmt.Println("ibc.go downcall", str)
|
|
69
|
+
ctx := sdk.UnwrapSDKContext(cctx)
|
|
68
70
|
keeper := ch.keeper
|
|
69
71
|
|
|
70
72
|
msg := new(portMessage)
|
|
@@ -80,7 +82,7 @@ func (ch IBCModule) Receive(ctx *vm.ControllerContext, str string) (ret string,
|
|
|
80
82
|
switch msg.Method {
|
|
81
83
|
case "sendPacket":
|
|
82
84
|
seq, ok := keeper.GetNextSequenceSend(
|
|
83
|
-
ctx
|
|
85
|
+
ctx,
|
|
84
86
|
msg.Packet.SourcePort,
|
|
85
87
|
msg.Packet.SourceChannel,
|
|
86
88
|
)
|
|
@@ -91,7 +93,7 @@ func (ch IBCModule) Receive(ctx *vm.ControllerContext, str string) (ret string,
|
|
|
91
93
|
timeoutTimestamp := msg.Packet.TimeoutTimestamp
|
|
92
94
|
if msg.Packet.TimeoutHeight.IsZero() && msg.Packet.TimeoutTimestamp == 0 {
|
|
93
95
|
// Use the relative timeout if no absolute timeout is specifiied.
|
|
94
|
-
timeoutTimestamp = uint64(ctx.
|
|
96
|
+
timeoutTimestamp = uint64(ctx.BlockTime().UnixNano()) + msg.RelativeTimeoutNs
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
packet := channeltypes.NewPacket(
|
|
@@ -100,7 +102,7 @@ func (ch IBCModule) Receive(ctx *vm.ControllerContext, str string) (ret string,
|
|
|
100
102
|
msg.Packet.DestinationPort, msg.Packet.DestinationChannel,
|
|
101
103
|
msg.Packet.TimeoutHeight, timeoutTimestamp,
|
|
102
104
|
)
|
|
103
|
-
err = keeper.SendPacket(ctx
|
|
105
|
+
err = keeper.SendPacket(ctx, packet)
|
|
104
106
|
if err == nil {
|
|
105
107
|
bytes, err := json.Marshal(&packet)
|
|
106
108
|
if err == nil {
|
|
@@ -109,14 +111,14 @@ func (ch IBCModule) Receive(ctx *vm.ControllerContext, str string) (ret string,
|
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
case "receiveExecuted":
|
|
112
|
-
err = keeper.WriteAcknowledgement(ctx
|
|
114
|
+
err = keeper.WriteAcknowledgement(ctx, msg.Packet, msg.Ack)
|
|
113
115
|
if err == nil {
|
|
114
116
|
ret = "true"
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
case "startChannelOpenInit":
|
|
118
120
|
err = keeper.ChanOpenInit(
|
|
119
|
-
ctx
|
|
121
|
+
ctx, stringToOrder(msg.Order), msg.Hops,
|
|
120
122
|
msg.Packet.SourcePort,
|
|
121
123
|
msg.Packet.DestinationPort,
|
|
122
124
|
msg.Version,
|
|
@@ -126,19 +128,19 @@ func (ch IBCModule) Receive(ctx *vm.ControllerContext, str string) (ret string,
|
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
case "startChannelCloseInit":
|
|
129
|
-
err = keeper.ChanCloseInit(ctx
|
|
131
|
+
err = keeper.ChanCloseInit(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel)
|
|
130
132
|
if err == nil {
|
|
131
133
|
ret = "true"
|
|
132
134
|
}
|
|
133
135
|
|
|
134
136
|
case "bindPort":
|
|
135
|
-
err = keeper.BindPort(ctx
|
|
137
|
+
err = keeper.BindPort(ctx, msg.Packet.SourcePort)
|
|
136
138
|
if err == nil {
|
|
137
139
|
ret = "true"
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
case "timeoutExecuted":
|
|
141
|
-
err = keeper.TimeoutExecuted(ctx
|
|
143
|
+
err = keeper.TimeoutExecuted(ctx, msg.Packet)
|
|
142
144
|
if err == nil {
|
|
143
145
|
ret = "true"
|
|
144
146
|
}
|
package/x/vstorage/vstorage.go
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package vstorage
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
4
5
|
"encoding/json"
|
|
5
6
|
"errors"
|
|
6
7
|
"fmt"
|
|
@@ -8,7 +9,6 @@ import (
|
|
|
8
9
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
9
10
|
|
|
10
11
|
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
11
|
-
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
12
12
|
)
|
|
13
13
|
|
|
14
14
|
type vstorageHandler struct {
|
|
@@ -41,7 +41,8 @@ func unmarshalSinglePathFromArgs(args []json.RawMessage, path *string) error {
|
|
|
41
41
|
return json.Unmarshal(args[0], path)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
func (sh vstorageHandler) Receive(cctx
|
|
44
|
+
func (sh vstorageHandler) Receive(cctx context.Context, str string) (ret string, err error) {
|
|
45
|
+
ctx := sdk.UnwrapSDKContext(cctx)
|
|
45
46
|
keeper := sh.keeper
|
|
46
47
|
msg := new(vstorageMessage)
|
|
47
48
|
err = json.Unmarshal([]byte(str), &msg)
|
|
@@ -56,7 +57,7 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
56
57
|
case sdk.ErrorOutOfGas:
|
|
57
58
|
err = fmt.Errorf(
|
|
58
59
|
"out of gas in location: %v; gasUsed: %d",
|
|
59
|
-
rType.Descriptor,
|
|
60
|
+
rType.Descriptor, ctx.GasMeter().GasConsumed(),
|
|
60
61
|
)
|
|
61
62
|
default:
|
|
62
63
|
// Not ErrorOutOfGas, so panic again.
|
|
@@ -74,7 +75,7 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
74
75
|
if err != nil {
|
|
75
76
|
return
|
|
76
77
|
}
|
|
77
|
-
keeper.SetStorageAndNotify(
|
|
78
|
+
keeper.SetStorageAndNotify(ctx, entry)
|
|
78
79
|
}
|
|
79
80
|
return "true", nil
|
|
80
81
|
|
|
@@ -89,7 +90,7 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
89
90
|
return
|
|
90
91
|
}
|
|
91
92
|
//fmt.Printf("giving Keeper.SetStorage(%s) %s\n", entry.Path(), entry.Value())
|
|
92
|
-
keeper.LegacySetStorageAndNotify(
|
|
93
|
+
keeper.LegacySetStorageAndNotify(ctx, entry)
|
|
93
94
|
}
|
|
94
95
|
return "true", nil
|
|
95
96
|
|
|
@@ -100,7 +101,7 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
100
101
|
if err != nil {
|
|
101
102
|
return
|
|
102
103
|
}
|
|
103
|
-
keeper.SetStorage(
|
|
104
|
+
keeper.SetStorage(ctx, entry)
|
|
104
105
|
}
|
|
105
106
|
return "true", nil
|
|
106
107
|
|
|
@@ -115,7 +116,7 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
115
116
|
err = fmt.Errorf("no value for append entry with path: %q", entry.Key())
|
|
116
117
|
return
|
|
117
118
|
}
|
|
118
|
-
err = keeper.AppendStorageValueAndNotify(
|
|
119
|
+
err = keeper.AppendStorageValueAndNotify(ctx, entry.Key(), entry.StringValue())
|
|
119
120
|
if err != nil {
|
|
120
121
|
return
|
|
121
122
|
}
|
|
@@ -130,7 +131,7 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
130
131
|
return
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
entry := keeper.GetEntry(
|
|
134
|
+
entry := keeper.GetEntry(ctx, path)
|
|
134
135
|
bz, err := json.Marshal(entry.Value())
|
|
135
136
|
if err != nil {
|
|
136
137
|
return "", err
|
|
@@ -161,7 +162,7 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
161
162
|
if err != nil {
|
|
162
163
|
return
|
|
163
164
|
}
|
|
164
|
-
value := keeper.HasStorage(
|
|
165
|
+
value := keeper.HasStorage(ctx, path)
|
|
165
166
|
if !value {
|
|
166
167
|
return "false", nil
|
|
167
168
|
}
|
|
@@ -174,7 +175,7 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
174
175
|
if err != nil {
|
|
175
176
|
return
|
|
176
177
|
}
|
|
177
|
-
children := keeper.GetChildren(
|
|
178
|
+
children := keeper.GetChildren(ctx, path)
|
|
178
179
|
if children.Children == nil {
|
|
179
180
|
return "[]", nil
|
|
180
181
|
}
|
|
@@ -190,10 +191,10 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
190
191
|
if err != nil {
|
|
191
192
|
return
|
|
192
193
|
}
|
|
193
|
-
children := keeper.GetChildren(
|
|
194
|
+
children := keeper.GetChildren(ctx, path)
|
|
194
195
|
entries := make([]agoric.KVEntry, len(children.Children))
|
|
195
196
|
for i, child := range children.Children {
|
|
196
|
-
entry := keeper.GetEntry(
|
|
197
|
+
entry := keeper.GetEntry(ctx, fmt.Sprintf("%s.%s", path, child))
|
|
197
198
|
if !entry.HasValue() {
|
|
198
199
|
entries[i] = agoric.NewKVEntryWithNoValue(child)
|
|
199
200
|
} else {
|
|
@@ -212,10 +213,10 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
212
213
|
if err != nil {
|
|
213
214
|
return
|
|
214
215
|
}
|
|
215
|
-
children := keeper.GetChildren(
|
|
216
|
+
children := keeper.GetChildren(ctx, path)
|
|
216
217
|
vals := make([]*string, len(children.Children))
|
|
217
218
|
for i, child := range children.Children {
|
|
218
|
-
vals[i] = keeper.GetEntry(
|
|
219
|
+
vals[i] = keeper.GetEntry(ctx, fmt.Sprintf("%s.%s", path, child)).Value()
|
|
219
220
|
}
|
|
220
221
|
bytes, err := json.Marshal(vals)
|
|
221
222
|
if err != nil {
|
|
@@ -229,7 +230,7 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
229
230
|
if err != nil {
|
|
230
231
|
return
|
|
231
232
|
}
|
|
232
|
-
children := keeper.GetChildren(
|
|
233
|
+
children := keeper.GetChildren(ctx, path)
|
|
233
234
|
if children.Children == nil {
|
|
234
235
|
return "0", nil
|
|
235
236
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package vstorage
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
4
5
|
"encoding/json"
|
|
5
6
|
"fmt"
|
|
6
7
|
"reflect"
|
|
@@ -14,7 +15,6 @@ import (
|
|
|
14
15
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
15
16
|
|
|
16
17
|
agorictypes "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
17
|
-
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
18
18
|
"github.com/tendermint/tendermint/libs/log"
|
|
19
19
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
20
20
|
dbm "github.com/tendermint/tm-db"
|
|
@@ -32,7 +32,7 @@ type testKit struct {
|
|
|
32
32
|
keeper Keeper
|
|
33
33
|
handler vstorageHandler
|
|
34
34
|
ctx sdk.Context
|
|
35
|
-
cctx
|
|
35
|
+
cctx context.Context
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
func makeTestKit() testKit {
|
|
@@ -45,14 +45,14 @@ func makeTestKit() testKit {
|
|
|
45
45
|
panic(err)
|
|
46
46
|
}
|
|
47
47
|
ctx := sdk.NewContext(ms, tmproto.Header{}, false, log.NewNopLogger())
|
|
48
|
-
cctx :=
|
|
48
|
+
cctx := sdk.WrapSDKContext(ctx)
|
|
49
49
|
handler := vstorageHandler{keeper}
|
|
50
50
|
return testKit{keeper, handler, ctx, cctx}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
func callReceive(
|
|
54
54
|
handler vstorageHandler,
|
|
55
|
-
cctx
|
|
55
|
+
cctx context.Context,
|
|
56
56
|
method string,
|
|
57
57
|
args []interface{},
|
|
58
58
|
) (string, error) {
|