@agoric/cosmos 0.35.0-u12.0 → 0.35.0-u14.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/CHANGELOG.md +67 -0
- package/Makefile +25 -12
- package/ante/ante.go +7 -5
- package/ante/inbound_test.go +8 -0
- package/app/app.go +139 -108
- package/app/export.go +13 -9
- package/app/sim_test.go +4 -4
- package/cmd/agd/main.go +5 -3
- package/cmd/libdaemon/main.go +5 -2
- package/daemon/cmd/genaccounts.go +13 -9
- package/daemon/cmd/root.go +38 -17
- package/daemon/cmd/root_test.go +1 -1
- package/daemon/cmd/testnet.go +17 -6
- package/daemon/main.go +3 -2
- package/git-revision.txt +1 -1
- package/go.mod +117 -76
- package/go.sum +858 -210
- package/package.json +3 -3
- package/proto/agoric/vstorage/query.proto +53 -1
- package/scripts/protocgen.sh +12 -1
- package/third_party/proto/buf.yaml +1 -0
- package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
- package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
- package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
- package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
- package/third_party/proto/google/api/annotations.proto +1 -1
- package/third_party/proto/google/api/http.proto +181 -120
- package/third_party/proto/google/api/httpbody.proto +9 -6
- package/third_party/proto/google/protobuf/any.proto +1 -7
- package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
- package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
- package/upgradegaia.sh +13 -4
- package/vm/action.go +133 -0
- package/vm/action_test.go +129 -0
- package/vm/controller.go +9 -16
- package/vm/core_proposals.go +31 -0
- package/x/lien/keeper/account.go +16 -11
- package/x/lien/keeper/keeper.go +5 -4
- package/x/lien/keeper/keeper_test.go +9 -9
- package/x/lien/lien.go +6 -4
- package/x/lien/lien_test.go +20 -16
- package/x/swingset/abci.go +25 -33
- package/x/swingset/client/cli/query.go +2 -2
- package/x/swingset/client/cli/tx.go +48 -33
- package/x/swingset/client/proposal_handler.go +2 -17
- package/x/swingset/keeper/keeper.go +69 -15
- package/x/swingset/keeper/keeper_test.go +1 -1
- package/x/swingset/keeper/migrations.go +7 -2
- package/x/swingset/keeper/msg_server.go +66 -49
- package/x/swingset/keeper/proposal.go +14 -8
- package/x/swingset/keeper/querier.go +14 -6
- package/x/swingset/keeper/swing_store_exports_handler.go +5 -1
- package/x/swingset/proposal_handler.go +3 -3
- package/x/swingset/swingset.go +4 -2
- package/x/swingset/types/codec.go +2 -2
- package/x/swingset/types/default-params.go +22 -16
- package/x/swingset/types/expected_keepers.go +11 -0
- package/x/swingset/types/msgs.go +43 -2
- package/x/swingset/types/msgs.pb.go +16 -16
- package/x/swingset/types/params.go +74 -0
- package/x/swingset/types/params_test.go +116 -0
- package/x/swingset/types/proposal.go +5 -5
- package/x/swingset/types/types.go +30 -28
- package/x/vbank/keeper/keeper.go +3 -2
- package/x/vbank/keeper/querier.go +6 -2
- package/x/vbank/keeper/rewards.go +1 -1
- package/x/vbank/vbank.go +19 -17
- package/x/vbank/vbank_test.go +18 -18
- package/x/vibc/handler.go +3 -8
- package/x/vibc/ibc.go +79 -126
- package/x/vibc/keeper/keeper.go +19 -18
- package/x/vibc/types/expected_keepers.go +13 -5
- package/x/vibc/types/msgs.go +1 -1
- package/x/vibc/types/msgs.pb.go +1 -1
- package/x/vstorage/README.md +138 -0
- package/x/vstorage/capdata/capdata.go +298 -0
- package/x/vstorage/capdata/capdata_test.go +352 -0
- package/x/vstorage/client/cli/query.go +51 -4
- package/x/vstorage/keeper/grpc_query.go +221 -0
- package/x/vstorage/keeper/keeper.go +3 -2
- package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
- package/x/vstorage/keeper/keeper_test.go +1 -1
- package/x/vstorage/keeper/querier.go +6 -2
- package/x/vstorage/keeper/querier_test.go +112 -0
- package/x/vstorage/types/query.pb.go +646 -36
- package/x/vstorage/types/query.pb.gw.go +119 -0
- package/x/vstorage/vstorage.go +16 -15
- package/x/vstorage/vstorage_test.go +5 -5
- package/x/swingset/legacy/v32/params.go +0 -37
- package/x/swingset/legacy/v32/params_test.go +0 -133
- /package/{src/index.cjs → index.cjs} +0 -0
|
@@ -163,3 +163,77 @@ func validateQueueMax(i interface{}) error {
|
|
|
163
163
|
}
|
|
164
164
|
return nil
|
|
165
165
|
}
|
|
166
|
+
|
|
167
|
+
// UpdateParams appends any missing params, configuring them to their defaults,
|
|
168
|
+
// then returning the updated params or an error. Existing params are not
|
|
169
|
+
// modified, regardless of their value, and they are not removed if they no
|
|
170
|
+
// longer appear in the defaults.
|
|
171
|
+
func UpdateParams(params Params) (Params, error) {
|
|
172
|
+
newBpu, err := appendMissingDefaultBeansPerUnit(params.BeansPerUnit, DefaultBeansPerUnit())
|
|
173
|
+
if err != nil {
|
|
174
|
+
return params, err
|
|
175
|
+
}
|
|
176
|
+
newPff, err := appendMissingDefaultPowerFlagFees(params.PowerFlagFees, DefaultPowerFlagFees)
|
|
177
|
+
if err != nil {
|
|
178
|
+
return params, err
|
|
179
|
+
}
|
|
180
|
+
newQm, err := appendMissingDefaultQueueSize(params.QueueMax, DefaultQueueMax)
|
|
181
|
+
if err != nil {
|
|
182
|
+
return params, err
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
params.BeansPerUnit = newBpu
|
|
186
|
+
params.PowerFlagFees = newPff
|
|
187
|
+
params.QueueMax = newQm
|
|
188
|
+
return params, nil
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// appendMissingDefaultBeansPerUnit appends the default beans per unit entries
|
|
192
|
+
// not in the list of bean costs already, returning the possibly-updated list,
|
|
193
|
+
// or an error.
|
|
194
|
+
func appendMissingDefaultBeansPerUnit(bpu []StringBeans, defaultBpu []StringBeans) ([]StringBeans, error) {
|
|
195
|
+
existingBpu := make(map[string]struct{}, len(bpu))
|
|
196
|
+
for _, ob := range bpu {
|
|
197
|
+
existingBpu[ob.Key] = struct{}{}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
for _, b := range defaultBpu {
|
|
201
|
+
if _, exists := existingBpu[b.Key]; !exists {
|
|
202
|
+
bpu = append(bpu, b)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return bpu, nil
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// appendMissingDefaultPowerFlagFees appends the default power flag fee entries
|
|
209
|
+
// not in the list of power flags already, returning the possibly-updated list,
|
|
210
|
+
// or an error.
|
|
211
|
+
func appendMissingDefaultPowerFlagFees(pff []PowerFlagFee, defaultPff []PowerFlagFee) ([]PowerFlagFee, error) {
|
|
212
|
+
existingPff := make(map[string]struct{}, len(pff))
|
|
213
|
+
for _, of := range pff {
|
|
214
|
+
existingPff[of.PowerFlag] = struct{}{}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
for _, f := range defaultPff {
|
|
218
|
+
if _, exists := existingPff[f.PowerFlag]; !exists {
|
|
219
|
+
pff = append(pff, f)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return pff, nil
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// appendMissingDefaultQueueSize appends the default queue size entries not in
|
|
226
|
+
// the list of sizes already, returning the possibly-updated list, or an error.
|
|
227
|
+
func appendMissingDefaultQueueSize(qs []QueueSize, defaultQs []QueueSize) ([]QueueSize, error) {
|
|
228
|
+
existingQs := make(map[string]struct{}, len(qs))
|
|
229
|
+
for _, os := range qs {
|
|
230
|
+
existingQs[os.Key] = struct{}{}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
for _, s := range defaultQs {
|
|
234
|
+
if _, exists := existingQs[s.Key]; !exists {
|
|
235
|
+
qs = append(qs, s)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return qs, nil
|
|
239
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
package types
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"reflect"
|
|
5
|
+
"testing"
|
|
6
|
+
|
|
7
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
type beans = StringBeans
|
|
11
|
+
|
|
12
|
+
func TestAddStorageBeanCost(t *testing.T) {
|
|
13
|
+
var defaultStorageCost beans
|
|
14
|
+
for _, b := range DefaultParams().BeansPerUnit {
|
|
15
|
+
if b.Key == BeansPerStorageByte {
|
|
16
|
+
defaultStorageCost = b
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if defaultStorageCost.Key == "" {
|
|
20
|
+
t.Fatalf("no beans per storage byte in default params")
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
for _, tt := range []struct {
|
|
24
|
+
name string
|
|
25
|
+
in []beans
|
|
26
|
+
want []beans
|
|
27
|
+
}{
|
|
28
|
+
{
|
|
29
|
+
name: "empty",
|
|
30
|
+
in: []beans{},
|
|
31
|
+
want: []beans{defaultStorageCost},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "already_only_same",
|
|
35
|
+
in: []beans{defaultStorageCost},
|
|
36
|
+
want: []beans{defaultStorageCost},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "already_only_different",
|
|
40
|
+
in: []beans{NewStringBeans(BeansPerStorageByte, sdk.NewUint(123))},
|
|
41
|
+
want: []beans{NewStringBeans(BeansPerStorageByte, sdk.NewUint(123))},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "already_same",
|
|
45
|
+
in: []beans{
|
|
46
|
+
NewStringBeans("foo", sdk.NewUint(123)),
|
|
47
|
+
defaultStorageCost,
|
|
48
|
+
NewStringBeans("bar", sdk.NewUint(456)),
|
|
49
|
+
},
|
|
50
|
+
want: []beans{
|
|
51
|
+
NewStringBeans("foo", sdk.NewUint(123)),
|
|
52
|
+
defaultStorageCost,
|
|
53
|
+
NewStringBeans("bar", sdk.NewUint(456)),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "already_different",
|
|
58
|
+
in: []beans{
|
|
59
|
+
NewStringBeans("foo", sdk.NewUint(123)),
|
|
60
|
+
NewStringBeans(BeansPerStorageByte, sdk.NewUint(789)),
|
|
61
|
+
NewStringBeans("bar", sdk.NewUint(456)),
|
|
62
|
+
},
|
|
63
|
+
want: []beans{
|
|
64
|
+
NewStringBeans("foo", sdk.NewUint(123)),
|
|
65
|
+
NewStringBeans(BeansPerStorageByte, sdk.NewUint(789)),
|
|
66
|
+
NewStringBeans("bar", sdk.NewUint(456)),
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "missing",
|
|
71
|
+
in: []beans{
|
|
72
|
+
NewStringBeans("foo", sdk.NewUint(123)),
|
|
73
|
+
NewStringBeans("bar", sdk.NewUint(456)),
|
|
74
|
+
},
|
|
75
|
+
want: []beans{
|
|
76
|
+
NewStringBeans("foo", sdk.NewUint(123)),
|
|
77
|
+
NewStringBeans("bar", sdk.NewUint(456)),
|
|
78
|
+
defaultStorageCost,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
} {
|
|
82
|
+
t.Run(tt.name, func(t *testing.T) {
|
|
83
|
+
got, err := appendMissingDefaultBeansPerUnit(tt.in, []StringBeans{defaultStorageCost})
|
|
84
|
+
if err != nil {
|
|
85
|
+
t.Errorf("got error %v", err)
|
|
86
|
+
} else if !reflect.DeepEqual(got, tt.want) {
|
|
87
|
+
t.Errorf("want %v, got %v", tt.want, got)
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
func TestUpdateParams(t *testing.T) {
|
|
94
|
+
|
|
95
|
+
in := Params{
|
|
96
|
+
BeansPerUnit: []beans{},
|
|
97
|
+
BootstrapVatConfig: "baz",
|
|
98
|
+
FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)),
|
|
99
|
+
PowerFlagFees: []PowerFlagFee{},
|
|
100
|
+
QueueMax: []QueueSize{},
|
|
101
|
+
}
|
|
102
|
+
want := Params{
|
|
103
|
+
BeansPerUnit: DefaultBeansPerUnit(),
|
|
104
|
+
BootstrapVatConfig: "baz",
|
|
105
|
+
FeeUnitPrice: sdk.NewCoins(sdk.NewInt64Coin("denom", 789)),
|
|
106
|
+
PowerFlagFees: DefaultPowerFlagFees,
|
|
107
|
+
QueueMax: DefaultQueueMax,
|
|
108
|
+
}
|
|
109
|
+
got, err := UpdateParams(in)
|
|
110
|
+
if err != nil {
|
|
111
|
+
t.Fatalf("UpdateParam error %v", err)
|
|
112
|
+
}
|
|
113
|
+
if !reflect.DeepEqual(got, want) {
|
|
114
|
+
t.Errorf("got %v, want %v", got, want)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -5,7 +5,7 @@ import (
|
|
|
5
5
|
"strings"
|
|
6
6
|
|
|
7
7
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
8
|
-
|
|
8
|
+
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
const (
|
|
@@ -14,15 +14,15 @@ const (
|
|
|
14
14
|
)
|
|
15
15
|
|
|
16
16
|
var (
|
|
17
|
-
_
|
|
17
|
+
_ govv1beta1.Content = &CoreEvalProposal{}
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
func init() {
|
|
21
|
-
|
|
21
|
+
govv1beta1.RegisterProposalType(ProposalTypeCoreEval)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// NewCoreEvalProposal creates a new core eval proposal.
|
|
25
|
-
func NewCoreEvalProposal(title, description string, evals []CoreEval)
|
|
25
|
+
func NewCoreEvalProposal(title, description string, evals []CoreEval) govv1beta1.Content {
|
|
26
26
|
return &CoreEvalProposal{
|
|
27
27
|
Title: title,
|
|
28
28
|
Description: description,
|
|
@@ -44,7 +44,7 @@ func (cep *CoreEvalProposal) ProposalType() string { return ProposalTypeCoreEval
|
|
|
44
44
|
|
|
45
45
|
// ValidateBasic runs basic stateless validity checks
|
|
46
46
|
func (cep *CoreEvalProposal) ValidateBasic() error {
|
|
47
|
-
err :=
|
|
47
|
+
err := govv1beta1.ValidateAbstract(cep)
|
|
48
48
|
if err != nil {
|
|
49
49
|
return err
|
|
50
50
|
}
|
|
@@ -3,6 +3,7 @@ package types
|
|
|
3
3
|
import (
|
|
4
4
|
"encoding/json"
|
|
5
5
|
"errors"
|
|
6
|
+
"fmt"
|
|
6
7
|
|
|
7
8
|
vstoragetypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
|
|
8
9
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
@@ -25,18 +26,16 @@ func NewEgress(nickname string, peer sdk.AccAddress, powerFlags []string) *Egres
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
//
|
|
29
|
+
// Nat is analogous to @endo/nat
|
|
30
|
+
// https://github.com/endojs/endo/blob/master/packages/nat
|
|
29
31
|
func Nat(num float64) (uint64, error) {
|
|
30
|
-
if num <
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if float64(nat) != num {
|
|
36
|
-
return 0, errors.New("Not a precise integer")
|
|
32
|
+
if 0 <= num && num < (1<<53) {
|
|
33
|
+
nat := uint64(num)
|
|
34
|
+
if float64(nat) == num {
|
|
35
|
+
return nat, nil
|
|
36
|
+
}
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
return nat, nil
|
|
38
|
+
return 0, errors.New("Not a Nat")
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
type Messages struct {
|
|
@@ -45,24 +44,26 @@ type Messages struct {
|
|
|
45
44
|
Ack uint64
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
// UnmarshalMessagesJSON decodes Messages from JSON text.
|
|
48
|
+
// Input must represent an array in which the first element is an array of
|
|
49
|
+
// [messageNum: integer, messageBody: string] pairs and the second element is
|
|
50
|
+
// an "Ack" integer.
|
|
51
|
+
func UnmarshalMessagesJSON(jsonString string) (ret *Messages, err error) {
|
|
52
|
+
packet := [2]interface{}{}
|
|
53
|
+
err = json.Unmarshal([]byte(jsonString), &packet)
|
|
53
54
|
if err != nil {
|
|
54
55
|
return nil, err
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
ret
|
|
58
|
+
ret = &Messages{}
|
|
58
59
|
|
|
59
60
|
ackFloat, ok := packet[1].(float64)
|
|
60
61
|
if !ok {
|
|
61
|
-
return nil, errors.New("Ack is not
|
|
62
|
+
return nil, errors.New("Ack is not a number")
|
|
62
63
|
}
|
|
63
64
|
ret.Ack, err = Nat(ackFloat)
|
|
64
65
|
if err != nil {
|
|
65
|
-
return nil,
|
|
66
|
+
return nil, errors.New("Ack is not a Nat")
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
msgs, ok := packet[0].([]interface{})
|
|
@@ -72,24 +73,25 @@ func UnmarshalMessagesJSON(jsonString string) (*Messages, error) {
|
|
|
72
73
|
|
|
73
74
|
ret.Messages = make([]string, len(msgs))
|
|
74
75
|
ret.Nums = make([]uint64, len(msgs))
|
|
75
|
-
for i,
|
|
76
|
-
|
|
77
|
-
if !ok || len(
|
|
78
|
-
return nil,
|
|
76
|
+
for i, rawMsg := range msgs {
|
|
77
|
+
arrMsg, ok := rawMsg.([]interface{})
|
|
78
|
+
if !ok || len(arrMsg) != 2 {
|
|
79
|
+
return nil, fmt.Errorf("Messages[%d] is not a pair", i)
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
+
|
|
82
|
+
numFloat, ok := arrMsg[0].(float64)
|
|
81
83
|
if !ok {
|
|
82
|
-
return nil,
|
|
84
|
+
return nil, fmt.Errorf("Messages[%d] Num is not a number", i)
|
|
83
85
|
}
|
|
84
86
|
ret.Nums[i], err = Nat(numFloat)
|
|
85
87
|
if err != nil {
|
|
86
|
-
return nil,
|
|
88
|
+
return nil, fmt.Errorf("Messages[%d] Num is not a Nat", i)
|
|
87
89
|
}
|
|
88
|
-
|
|
90
|
+
|
|
91
|
+
ret.Messages[i], ok = arrMsg[1].(string)
|
|
89
92
|
if !ok {
|
|
90
|
-
return nil,
|
|
93
|
+
return nil, fmt.Errorf("Messages[%d] body is not a string", i)
|
|
91
94
|
}
|
|
92
|
-
ret.Messages[i] = msg
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
return ret, nil
|
package/x/vbank/keeper/keeper.go
CHANGED
|
@@ -2,6 +2,7 @@ package keeper
|
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
5
|
+
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
5
6
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
6
7
|
|
|
7
8
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vbank/types"
|
|
@@ -15,7 +16,7 @@ const stateKey string = "state"
|
|
|
15
16
|
|
|
16
17
|
// Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine
|
|
17
18
|
type Keeper struct {
|
|
18
|
-
storeKey
|
|
19
|
+
storeKey storetypes.StoreKey
|
|
19
20
|
cdc codec.Codec
|
|
20
21
|
paramSpace paramtypes.Subspace
|
|
21
22
|
|
|
@@ -27,7 +28,7 @@ type Keeper struct {
|
|
|
27
28
|
|
|
28
29
|
// NewKeeper creates a new vbank Keeper instance
|
|
29
30
|
func NewKeeper(
|
|
30
|
-
cdc codec.Codec, key
|
|
31
|
+
cdc codec.Codec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
|
|
31
32
|
accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper,
|
|
32
33
|
rewardDistributorName string,
|
|
33
34
|
pushAction vm.ActionPusher,
|
|
@@ -11,7 +11,11 @@ import (
|
|
|
11
11
|
|
|
12
12
|
func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
|
13
13
|
return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) {
|
|
14
|
-
|
|
14
|
+
var queryType string
|
|
15
|
+
if len(path) > 0 {
|
|
16
|
+
queryType = path[0]
|
|
17
|
+
}
|
|
18
|
+
switch queryType {
|
|
15
19
|
case types.QueryParams:
|
|
16
20
|
return queryParams(ctx, path[1:], req, k, legacyQuerierCdc)
|
|
17
21
|
|
|
@@ -19,7 +23,7 @@ func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
|
|
19
23
|
return queryState(ctx, path[1:], req, k, legacyQuerierCdc)
|
|
20
24
|
|
|
21
25
|
default:
|
|
22
|
-
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path
|
|
26
|
+
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown vbank query path")
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
}
|
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
|
-
|
|
72
|
-
|
|
73
|
-
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.
|
|
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
|
-
|
|
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) {
|
|
@@ -121,8 +122,9 @@ func marshal(event vm.Jsonable) ([]byte, error) {
|
|
|
121
122
|
return json.Marshal(event)
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
func (ch portHandler) Receive(
|
|
125
|
+
func (ch portHandler) Receive(cctx context.Context, str string) (ret string, err error) {
|
|
125
126
|
// fmt.Println("vbank.go downcall", str)
|
|
127
|
+
ctx := sdk.UnwrapSDKContext(cctx)
|
|
126
128
|
keeper := ch.keeper
|
|
127
129
|
|
|
128
130
|
var msg portMessage
|
|
@@ -140,7 +142,7 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
|
|
|
140
142
|
if err = sdk.ValidateDenom(msg.Denom); err != nil {
|
|
141
143
|
return "", fmt.Errorf("invalid denom %s: %s", msg.Denom, err)
|
|
142
144
|
}
|
|
143
|
-
coin := keeper.GetBalance(ctx
|
|
145
|
+
coin := keeper.GetBalance(ctx, addr, msg.Denom)
|
|
144
146
|
packet := coin.Amount.String()
|
|
145
147
|
if err == nil {
|
|
146
148
|
bytes, err := json.Marshal(&packet)
|
|
@@ -162,12 +164,12 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
|
|
|
162
164
|
return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
|
|
163
165
|
}
|
|
164
166
|
coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
|
|
165
|
-
if err := keeper.GrabCoins(ctx
|
|
167
|
+
if err := keeper.GrabCoins(ctx, addr, coins); err != nil {
|
|
166
168
|
return "", fmt.Errorf("cannot grab %s coins: %s", coins.Sort().String(), err)
|
|
167
169
|
}
|
|
168
170
|
addressToBalances := make(map[string]sdk.Coins, 1)
|
|
169
171
|
addressToBalances[msg.Sender] = sdk.NewCoins(sdk.NewInt64Coin(msg.Denom, 1))
|
|
170
|
-
bz, err := marshal(getBalanceUpdate(ctx
|
|
172
|
+
bz, err := marshal(getBalanceUpdate(ctx, keeper, addressToBalances))
|
|
171
173
|
if err != nil {
|
|
172
174
|
return "", err
|
|
173
175
|
}
|
|
@@ -190,12 +192,12 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
|
|
|
190
192
|
return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
|
|
191
193
|
}
|
|
192
194
|
coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
|
|
193
|
-
if err := keeper.SendCoins(ctx
|
|
195
|
+
if err := keeper.SendCoins(ctx, addr, coins); err != nil {
|
|
194
196
|
return "", fmt.Errorf("cannot give %s coins: %s", coins.Sort().String(), err)
|
|
195
197
|
}
|
|
196
198
|
addressToBalances := make(map[string]sdk.Coins, 1)
|
|
197
199
|
addressToBalances[msg.Recipient] = sdk.NewCoins(sdk.NewInt64Coin(msg.Denom, 1))
|
|
198
|
-
bz, err := marshal(getBalanceUpdate(ctx
|
|
200
|
+
bz, err := marshal(getBalanceUpdate(ctx, keeper, addressToBalances))
|
|
199
201
|
if err != nil {
|
|
200
202
|
return "", err
|
|
201
203
|
}
|
|
@@ -211,20 +213,20 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
|
|
|
211
213
|
return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
|
|
212
214
|
}
|
|
213
215
|
coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
|
|
214
|
-
if err := keeper.StoreRewardCoins(ctx
|
|
216
|
+
if err := keeper.StoreRewardCoins(ctx, coins); err != nil {
|
|
215
217
|
return "", fmt.Errorf("cannot store reward %s coins: %s", coins.Sort().String(), err)
|
|
216
218
|
}
|
|
217
219
|
if err != nil {
|
|
218
220
|
return "", err
|
|
219
221
|
}
|
|
220
|
-
state := keeper.GetState(ctx
|
|
222
|
+
state := keeper.GetState(ctx)
|
|
221
223
|
state.RewardPool = state.RewardPool.Add(coins...)
|
|
222
|
-
keeper.SetState(ctx
|
|
224
|
+
keeper.SetState(ctx, state)
|
|
223
225
|
// We don't supply the module balance, since the controller shouldn't know.
|
|
224
226
|
ret = "true"
|
|
225
227
|
|
|
226
228
|
case "VBANK_GET_MODULE_ACCOUNT_ADDRESS":
|
|
227
|
-
addr := keeper.GetModuleAccountAddress(ctx
|
|
229
|
+
addr := keeper.GetModuleAccountAddress(ctx, msg.ModuleName).String()
|
|
228
230
|
if len(addr) == 0 {
|
|
229
231
|
return "", fmt.Errorf("module account %s not found", msg.ModuleName)
|
|
230
232
|
}
|
|
@@ -242,7 +244,7 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
|
|
|
242
244
|
return
|
|
243
245
|
}
|
|
244
246
|
|
|
245
|
-
func (am AppModule) PushAction(ctx sdk.Context, action vm.
|
|
247
|
+
func (am AppModule) PushAction(ctx sdk.Context, action vm.Action) error {
|
|
246
248
|
// vbank actions are not triggered by a swingset message in a transaction, so we need to
|
|
247
249
|
// synthesize unique context information.
|
|
248
250
|
// We use a fixed placeholder value for the txHash context, and can simply use `0` for the
|
package/x/vbank/vbank_test.go
CHANGED
|
@@ -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.
|
|
253
|
+
pushAction := func(ctx sdk.Context, action vm.Action) error {
|
|
254
254
|
return nil
|
|
255
255
|
}
|
|
256
256
|
|
|
@@ -263,9 +263,9 @@ func makeTestKit(account types.AccountKeeper, bank types.BankKeeper) (Keeper, sd
|
|
|
263
263
|
|
|
264
264
|
db := dbm.NewMemDB()
|
|
265
265
|
ms := store.NewCommitMultiStore(db)
|
|
266
|
-
ms.MountStoreWithDB(vbankStoreKey,
|
|
267
|
-
ms.MountStoreWithDB(paramsStoreKey,
|
|
268
|
-
ms.MountStoreWithDB(paramsTStoreKey,
|
|
266
|
+
ms.MountStoreWithDB(vbankStoreKey, storetypes.StoreTypeIAVL, db)
|
|
267
|
+
ms.MountStoreWithDB(paramsStoreKey, storetypes.StoreTypeIAVL, db)
|
|
268
|
+
ms.MountStoreWithDB(paramsTStoreKey, storetypes.StoreTypeTransient, db)
|
|
269
269
|
err := ms.LoadLatestVersion()
|
|
270
270
|
if err != nil {
|
|
271
271
|
panic(err)
|
|
@@ -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",
|
|
@@ -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{
|
|
521
|
-
addr2: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{
|
|
522
|
-
addr3: &authtypes.BaseAccount{
|
|
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.
|
|
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.
|
|
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
|
-
|
|
757
|
+
return nil
|
|
758
758
|
}
|
|
759
759
|
acct, ok := ma.accounts[addr]
|
|
760
760
|
if !ok {
|
|
761
|
-
|
|
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:
|
|
781
|
+
addr1: authtypes.NewBaseAccountWithAddress(sdk.MustAccAddressFromBech32(addr1)),
|
|
782
782
|
},
|
|
783
783
|
modAddrs: map[string]string{
|
|
784
784
|
"vbank/reserve": moduleBech32,
|
|
@@ -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/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
|
-
|
|
27
|
-
Event
|
|
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
|
|