Merge branch 'master' into hulatown/adr-043-nft

This commit is contained in:
billy rennekamp 2021-07-09 12:39:55 +02:00 committed by GitHub
commit afc66804e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
65 changed files with 16371 additions and 365 deletions

View File

@ -7,6 +7,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: gaurav-nelson/github-action-markdown-link-check@1.0.12
- uses: gaurav-nelson/github-action-markdown-link-check@1.0.13
with:
folder-path: "docs"

View File

@ -53,9 +53,11 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#9246](https://github.com/cosmos/cosmos-sdk/pull/9246) The `New` method for the network package now returns an error.
* (codec) [\#9521](https://github.com/cosmos/cosmos-sdk/pull/9521) Removed deprecated `clientCtx.JSONCodec` from `client.Context`.
* (codec) [\#9521](https://github.com/cosmos/cosmos-sdk/pull/9521) Rename `EncodingConfig.Marshaler` to `Codec`.
* [\#9418](https://github.com/cosmos/cosmos-sdk/pull/9418) `sdk.Msg`'s `GetSigners()` method updated to return `[]string`.
* [\#9594](https://github.com/cosmos/cosmos-sdk/pull/9594) `RESTHandlerFn` argument is removed from the `gov/NewProposalHandler`.
* [\#9594](https://github.com/cosmos/cosmos-sdk/pull/9594) `types/rest` package moved to `testutil/rest`.
* [\#9432](https://github.com/cosmos/cosmos-sdk/pull/9432) `ConsensusParamsKeyTable` moved from `params/keeper` to `params/types`
* [\#9576](https://github.com/cosmos/cosmos-sdk/pull/9576) Add debug error message to `sdkerrors.QueryResult` when enabled
### Client Breaking Changes
@ -73,6 +75,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes
* [\#9639](https://github.com/cosmos/cosmos-sdk/pull/9639) Check store keys length before accessing them by making sure that `key` is of length `m+1` (for `key[n:m]`)
* (types) [\#9627](https://github.com/cosmos/cosmos-sdk/pull/9627) Fix nil pointer panic on `NewBigIntFromInt`
* (x/genutil) [\#9574](https://github.com/cosmos/cosmos-sdk/pull/9575) Actually use the `gentx` client tx flags (like `--keyring-dir`)
* (x/distribution) [\#9599](https://github.com/cosmos/cosmos-sdk/pull/9599) Withdraw rewards event now includes a value attribute even if there are 0 rewards (due to situations like 100% commission).
@ -212,7 +215,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes
* (x/gov) [\#8813](https://github.com/cosmos/cosmos-sdk/pull/8813) fix `GET /cosmos/gov/v1beta1/proposals/{proposal_id}/deposits` to include initial deposit
* (x/gov) [\#8813](https://github.com/cosmos/cosmos-sdk/pull/8813) fix `{appd} q gov deposits [proposal-id]`, `GET /gov/proposals/{proposal_id}/deposits` to include initial deposit.
* (gRPC) [\#8945](https://github.com/cosmos/cosmos-sdk/pull/8945) gRPC reflection now works correctly.
* (keyring) [#\8635](https://github.com/cosmos/cosmos-sdk/issues/8635) Remove hardcoded default passphrase value on `NewMnemonic`
* (x/bank) [\#8434](https://github.com/cosmos/cosmos-sdk/pull/8434) Fix legacy REST API `GET /bank/total` and `GET /bank/total/{denom}` in swagger

View File

@ -405,7 +405,7 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
// ref: https://github.com/cosmos/cosmos-sdk/pull/8039
defer func() {
if r := recover(); r != nil {
res = sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrPanic, "%v", r))
res = sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrPanic, "%v", r), app.trace)
}
}()
@ -422,7 +422,7 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
path := splitPath(req.Path)
if len(path) == 0 {
sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "no query path provided"))
sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "no query path provided"), app.trace)
}
switch path[0] {
@ -440,7 +440,7 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
return handleQueryCustom(app, path, req)
}
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown query path"))
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown query path"), app.trace)
}
// ListSnapshots implements the ABCI interface. It delegates to app.snapshotManager if set.
@ -570,12 +570,12 @@ func (app *BaseApp) ApplySnapshotChunk(req abci.RequestApplySnapshotChunk) abci.
func (app *BaseApp) handleQueryGRPC(handler GRPCQueryHandler, req abci.RequestQuery) abci.ResponseQuery {
ctx, err := app.createQueryContext(req.Height, req.Prove)
if err != nil {
return sdkerrors.QueryResult(err)
return sdkerrors.QueryResult(err, app.trace)
}
res, err := handler(ctx, req)
if err != nil {
res = sdkerrors.QueryResult(gRPCErrorToSDKError(err))
res = sdkerrors.QueryResult(gRPCErrorToSDKError(err), app.trace)
res.Height = req.Height
return res
}
@ -746,7 +746,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res
gInfo, res, err := app.Simulate(txBytes)
if err != nil {
return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to simulate tx"))
return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to simulate tx"), app.trace)
}
simRes := &sdk.SimulationResponse{
@ -756,7 +756,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res
bz, err := codec.ProtoMarshalJSON(simRes, app.interfaceRegistry)
if err != nil {
return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to JSON encode simulation response"))
return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to JSON encode simulation response"), app.trace)
}
return abci.ResponseQuery{
@ -773,7 +773,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res
}
default:
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query: %s", path))
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query: %s", path), app.trace)
}
}
@ -781,15 +781,14 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res
sdkerrors.Wrap(
sdkerrors.ErrUnknownRequest,
"expected second parameter to be either 'simulate' or 'version', neither was present",
),
)
), app.trace)
}
func handleQueryStore(app *BaseApp, path []string, req abci.RequestQuery) abci.ResponseQuery {
// "/store" prefix for store queries
queryable, ok := app.cms.(sdk.Queryable)
if !ok {
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "multistore doesn't support queries"))
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "multistore doesn't support queries"), app.trace)
}
req.Path = "/" + strings.Join(path[1:], "/")
@ -799,8 +798,7 @@ func handleQueryStore(app *BaseApp, path []string, req abci.RequestQuery) abci.R
sdkerrors.Wrap(
sdkerrors.ErrInvalidRequest,
"cannot query with proof when height <= 1; please provide a valid height",
),
)
), app.trace)
}
resp := queryable.Query(req)
@ -815,8 +813,7 @@ func handleQueryP2P(app *BaseApp, path []string) abci.ResponseQuery {
return sdkerrors.QueryResult(
sdkerrors.Wrap(
sdkerrors.ErrUnknownRequest, "path should be p2p filter <addr|id> <parameter>",
),
)
), app.trace)
}
var resp abci.ResponseQuery
@ -833,7 +830,7 @@ func handleQueryP2P(app *BaseApp, path []string) abci.ResponseQuery {
}
default:
resp = sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'"))
resp = sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'"), app.trace)
}
return resp
@ -846,17 +843,17 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) abci.
// The QueryRouter routes using path[1]. For example, in the path
// "custom/gov/proposal", QueryRouter routes using "gov".
if len(path) < 2 || path[1] == "" {
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "no route for custom query specified"))
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "no route for custom query specified"), app.trace)
}
querier := app.queryRouter.Route(path[1])
if querier == nil {
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "no custom querier found for route %s", path[1]))
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "no custom querier found for route %s", path[1]), app.trace)
}
ctx, err := app.createQueryContext(req.Height, req.Prove)
if err != nil {
return sdkerrors.QueryResult(err)
return sdkerrors.QueryResult(err, app.trace)
}
// Passes the rest of the path as an argument to the querier.
@ -865,7 +862,7 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) abci.
// []string{"proposal", "test"} as the path.
resBytes, err := querier(ctx, path[2:], req)
if err != nil {
res := sdkerrors.QueryResult(err)
res := sdkerrors.QueryResult(err, app.trace)
res.Height = req.Height
return res
}

View File

@ -19,6 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/store/rootmulti"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)
@ -449,6 +450,8 @@ func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp *abci.ConsensusPara
app.paramStore.Set(ctx, ParamStoreKeyBlockParams, cp.Block)
app.paramStore.Set(ctx, ParamStoreKeyEvidenceParams, cp.Evidence)
app.paramStore.Set(ctx, ParamStoreKeyValidatorParams, cp.Validator)
// We're explicitly not storing the Tendermint app_version in the param store. It's
// stored instead in the x/upgrade store, with its own bump logic.
}
// getMaximumBlockGas gets the maximum gas from the consensus params. It panics
@ -508,7 +511,7 @@ func validateBasicTxMsgs(msgs []sdk.Msg) error {
}
for _, msg := range msgs {
err := msg.ValidateBasic()
err := sdktx.ValidateMsg(msg)
if err != nil {
return err
}

View File

@ -717,10 +717,10 @@ func (msg msgCounter) String() string { return "TODO" }
func (msg msgCounter) ProtoMessage() {}
// Implements Msg
func (msg msgCounter) Route() string { return routeMsgCounter }
func (msg msgCounter) Type() string { return "counter1" }
func (msg msgCounter) GetSignBytes() []byte { return nil }
func (msg msgCounter) GetSigners() []sdk.AccAddress { return nil }
func (msg msgCounter) Route() string { return routeMsgCounter }
func (msg msgCounter) Type() string { return "counter1" }
func (msg msgCounter) GetSignBytes() []byte { return nil }
func (msg msgCounter) GetSigners() []string { return nil }
func (msg msgCounter) ValidateBasic() error {
if msg.Counter >= 0 {
return nil
@ -762,10 +762,10 @@ func (msg msgCounter2) String() string { return "TODO" }
func (msg msgCounter2) ProtoMessage() {}
// Implements Msg
func (msg msgCounter2) Route() string { return routeMsgCounter2 }
func (msg msgCounter2) Type() string { return "counter2" }
func (msg msgCounter2) GetSignBytes() []byte { return nil }
func (msg msgCounter2) GetSigners() []sdk.AccAddress { return nil }
func (msg msgCounter2) Route() string { return routeMsgCounter2 }
func (msg msgCounter2) Type() string { return "counter2" }
func (msg msgCounter2) GetSignBytes() []byte { return nil }
func (msg msgCounter2) GetSigners() []string { return nil }
func (msg msgCounter2) ValidateBasic() error {
if msg.Counter >= 0 {
return nil
@ -779,13 +779,13 @@ type msgKeyValue struct {
Value []byte
}
func (msg msgKeyValue) Reset() {}
func (msg msgKeyValue) String() string { return "TODO" }
func (msg msgKeyValue) ProtoMessage() {}
func (msg msgKeyValue) Route() string { return routeMsgKeyValue }
func (msg msgKeyValue) Type() string { return "keyValue" }
func (msg msgKeyValue) GetSignBytes() []byte { return nil }
func (msg msgKeyValue) GetSigners() []sdk.AccAddress { return nil }
func (msg msgKeyValue) Reset() {}
func (msg msgKeyValue) String() string { return "TODO" }
func (msg msgKeyValue) ProtoMessage() {}
func (msg msgKeyValue) Route() string { return routeMsgKeyValue }
func (msg msgKeyValue) Type() string { return "keyValue" }
func (msg msgKeyValue) GetSignBytes() []byte { return nil }
func (msg msgKeyValue) GetSigners() []string { return nil }
func (msg msgKeyValue) ValidateBasic() error {
if msg.Key == nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "key cannot be nil")

View File

@ -35,7 +35,7 @@ func GenerateOrBroadcastTxWithFactory(clientCtx client.Context, txf Factory, msg
// Right now, we're factorizing that call inside this function.
// ref: https://github.com/cosmos/cosmos-sdk/pull/9236#discussion_r623803504
for _, msg := range msgs {
if err := msg.ValidateBasic(); err != nil {
if err := tx.ValidateMsg(msg); err != nil {
return err
}
}

File diff suppressed because it is too large Load Diff

2
go.mod
View File

@ -37,7 +37,7 @@ require (
github.com/regen-network/cosmos-proto v0.3.1
github.com/rs/zerolog v1.23.0
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v1.1.3
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.8.1
github.com/stretchr/testify v1.7.0

6
go.sum
View File

@ -702,8 +702,8 @@ github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw=
github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t68Nk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
@ -874,7 +874,6 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@ -1092,7 +1091,6 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -0,0 +1,244 @@
syntax = "proto3";
package cosmos.group.v1beta1;
import "cosmos/group/v1beta1/types.proto";
import "gogoproto/gogo.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
option go_package = "github.com/cosmos/cosmos-sdk/x/group";
// Query is the cosmos.group.v1beta1 Query service.
service Query {
// GroupInfo queries group info based on group id.
rpc GroupInfo(QueryGroupInfoRequest) returns (QueryGroupInfoResponse);
// GroupAccountInfo queries group account info based on group account address.
rpc GroupAccountInfo(QueryGroupAccountInfoRequest) returns (QueryGroupAccountInfoResponse);
// GroupMembers queries members of a group
rpc GroupMembers(QueryGroupMembersRequest) returns (QueryGroupMembersResponse);
// GroupsByAdmin queries groups by admin address.
rpc GroupsByAdmin(QueryGroupsByAdminRequest) returns (QueryGroupsByAdminResponse);
// GroupAccountsByGroup queries group accounts by group id.
rpc GroupAccountsByGroup(QueryGroupAccountsByGroupRequest) returns (QueryGroupAccountsByGroupResponse);
// GroupsByAdmin queries group accounts by admin address.
rpc GroupAccountsByAdmin(QueryGroupAccountsByAdminRequest) returns (QueryGroupAccountsByAdminResponse);
// Proposal queries a proposal based on proposal id.
rpc Proposal(QueryProposalRequest) returns (QueryProposalResponse);
// ProposalsByGroupAccount queries proposals based on group account address.
rpc ProposalsByGroupAccount(QueryProposalsByGroupAccountRequest) returns (QueryProposalsByGroupAccountResponse);
// VoteByProposalVoter queries a vote by proposal id and voter.
rpc VoteByProposalVoter(QueryVoteByProposalVoterRequest) returns (QueryVoteByProposalVoterResponse);
// VotesByProposal queries a vote by proposal.
rpc VotesByProposal(QueryVotesByProposalRequest) returns (QueryVotesByProposalResponse);
// VotesByVoter queries a vote by voter.
rpc VotesByVoter(QueryVotesByVoterRequest) returns (QueryVotesByVoterResponse);
}
// QueryGroupInfoRequest is the Query/GroupInfo request type.
message QueryGroupInfoRequest {
// group_id is the unique ID of the group.
uint64 group_id = 1;
}
// QueryGroupInfoResponse is the Query/GroupInfo response type.
message QueryGroupInfoResponse {
// info is the GroupInfo for the group.
GroupInfo info = 1;
}
// QueryGroupAccountInfoRequest is the Query/GroupAccountInfo request type.
message QueryGroupAccountInfoRequest {
// address is the account address of the group account.
string address = 1;
}
// QueryGroupAccountInfoResponse is the Query/GroupAccountInfo response type.
message QueryGroupAccountInfoResponse {
// info is the GroupAccountInfo for the group account.
GroupAccountInfo info = 1;
}
// QueryGroupMembersRequest is the Query/GroupMembersRequest request type.
message QueryGroupMembersRequest {
// group_id is the unique ID of the group.
uint64 group_id = 1;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// QueryGroupMembersResponse is the Query/GroupMembersResponse response type.
message QueryGroupMembersResponse {
// members are the members of the group with given group_id.
repeated GroupMember members = 1;
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryGroupsByAdminRequest is the Query/GroupsByAdminRequest request type.
message QueryGroupsByAdminRequest {
// admin is the account address of a group's admin.
string admin = 1;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// QueryGroupsByAdminResponse is the Query/GroupsByAdminResponse response type.
message QueryGroupsByAdminResponse {
// groups are the groups info with the provided admin.
repeated GroupInfo groups = 1;
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryGroupAccountsByGroupRequest is the Query/GroupAccountsByGroup request type.
message QueryGroupAccountsByGroupRequest {
// group_id is the unique ID of the group account's group.
uint64 group_id = 1;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// QueryGroupAccountsByGroupResponse is the Query/GroupAccountsByGroup response type.
message QueryGroupAccountsByGroupResponse {
// group_accounts are the group accounts info associated with the provided group.
repeated GroupAccountInfo group_accounts = 1;
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryGroupAccountsByAdminRequest is the Query/GroupAccountsByAdmin request type.
message QueryGroupAccountsByAdminRequest {
// admin is the admin address of the group account.
string admin = 1;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// QueryGroupAccountsByAdminResponse is the Query/GroupAccountsByAdmin response type.
message QueryGroupAccountsByAdminResponse {
// group_accounts are the group accounts info with provided admin.
repeated GroupAccountInfo group_accounts = 1;
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryProposalRequest is the Query/Proposal request type.
message QueryProposalRequest {
// proposal_id is the unique ID of a proposal.
uint64 proposal_id = 1;
}
// QueryProposalResponse is the Query/Proposal response type.
message QueryProposalResponse {
// proposal is the proposal info.
Proposal proposal = 1;
}
// QueryProposalsByGroupAccountRequest is the Query/ProposalByGroupAccount request type.
message QueryProposalsByGroupAccountRequest {
// address is the group account address related to proposals.
string address = 1;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// QueryProposalsByGroupAccountResponse is the Query/ProposalByGroupAccount response type.
message QueryProposalsByGroupAccountResponse {
// proposals are the proposals with given group account.
repeated Proposal proposals = 1;
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryVoteByProposalVoterResponse is the Query/VoteByProposalVoter request type.
message QueryVoteByProposalVoterRequest {
// proposal_id is the unique ID of a proposal.
uint64 proposal_id = 1;
// voter is a proposal voter account address.
string voter = 2;
}
// QueryVoteByProposalVoterResponse is the Query/VoteByProposalVoter response type.
message QueryVoteByProposalVoterResponse {
// vote is the vote with given proposal_id and voter.
Vote vote = 1;
}
// QueryVotesByProposalResponse is the Query/VotesByProposal request type.
message QueryVotesByProposalRequest {
// proposal_id is the unique ID of a proposal.
uint64 proposal_id = 1;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// QueryVotesByProposalResponse is the Query/VotesByProposal response type.
message QueryVotesByProposalResponse {
// votes are the list of votes for given proposal_id.
repeated Vote votes = 1;
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryVotesByVoterResponse is the Query/VotesByVoter request type.
message QueryVotesByVoterRequest {
// voter is a proposal voter account address.
string voter = 1;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// QueryVotesByVoterResponse is the Query/VotesByVoter response type.
message QueryVotesByVoterResponse {
// votes are the list of votes by given voter.
repeated Vote votes = 1;
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

View File

@ -0,0 +1,281 @@
syntax = "proto3";
package cosmos.group.v1beta1;
option go_package = "github.com/cosmos/cosmos-sdk/x/group";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "google/protobuf/any.proto";
import "cosmos/group/v1beta1/types.proto";
// Msg is the cosmos.group.v1beta1 Msg service.
service Msg {
// CreateGroup creates a new group with an admin account address, a list of members and some optional metadata.
rpc CreateGroup(MsgCreateGroupRequest) returns (MsgCreateGroupResponse);
// UpdateGroupMembers updates the group members with given group id and admin address.
rpc UpdateGroupMembers(MsgUpdateGroupMembersRequest) returns (MsgUpdateGroupMembersResponse);
// UpdateGroupAdmin updates the group admin with given group id and previous admin address.
rpc UpdateGroupAdmin(MsgUpdateGroupAdminRequest) returns (MsgUpdateGroupAdminResponse);
// UpdateGroupMetadata updates the group metadata with given group id and admin address.
rpc UpdateGroupMetadata(MsgUpdateGroupMetadataRequest) returns (MsgUpdateGroupMetadataResponse);
// CreateGroupAccount creates a new group account using given DecisionPolicy.
rpc CreateGroupAccount(MsgCreateGroupAccountRequest) returns (MsgCreateGroupAccountResponse);
// UpdateGroupAccountAdmin updates a group account admin.
rpc UpdateGroupAccountAdmin(MsgUpdateGroupAccountAdminRequest) returns (MsgUpdateGroupAccountAdminResponse);
// UpdateGroupAccountDecisionPolicy allows a group account decision policy to be updated.
rpc UpdateGroupAccountDecisionPolicy(MsgUpdateGroupAccountDecisionPolicyRequest) returns (MsgUpdateGroupAccountDecisionPolicyResponse);
// UpdateGroupAccountMetadata updates a group account metadata.
rpc UpdateGroupAccountMetadata(MsgUpdateGroupAccountMetadataRequest) returns (MsgUpdateGroupAccountMetadataResponse);
// CreateProposal submits a new proposal.
rpc CreateProposal(MsgCreateProposalRequest) returns (MsgCreateProposalResponse);
// Vote allows a voter to vote on a proposal.
rpc Vote(MsgVoteRequest) returns (MsgVoteResponse);
// Exec executes a proposal.
rpc Exec(MsgExecRequest) returns (MsgExecResponse);
}
//
// Groups
//
// MsgCreateGroupRequest is the Msg/CreateGroup request type.
message MsgCreateGroupRequest {
// admin is the account address of the group admin.
string admin = 1;
// members defines the group members.
repeated Member members = 2 [(gogoproto.nullable) = false];
// metadata is any arbitrary metadata to attached to the group.
bytes metadata = 3;
}
// MsgCreateGroupResponse is the Msg/CreateGroup response type.
message MsgCreateGroupResponse {
// group_id is the unique ID of the newly created group.
uint64 group_id = 1;
}
// MsgUpdateGroupMembersRequest is the Msg/UpdateGroupMembers request type.
message MsgUpdateGroupMembersRequest {
// admin is the account address of the group admin.
string admin = 1;
// group_id is the unique ID of the group.
uint64 group_id = 2;
// member_updates is the list of members to update,
// set weight to 0 to remove a member.
repeated Member member_updates = 3 [(gogoproto.nullable) = false];
}
// MsgUpdateGroupMembersResponse is the Msg/UpdateGroupMembers response type.
message MsgUpdateGroupMembersResponse { }
// MsgUpdateGroupAdminRequest is the Msg/UpdateGroupAdmin request type.
message MsgUpdateGroupAdminRequest {
// admin is the current account address of the group admin.
string admin = 1;
// group_id is the unique ID of the group.
uint64 group_id = 2;
// new_admin is the group new admin account address.
string new_admin = 3;
}
// MsgUpdateGroupAdminResponse is the Msg/UpdateGroupAdmin response type.
message MsgUpdateGroupAdminResponse { }
// MsgUpdateGroupMetadataRequest is the Msg/UpdateGroupMetadata request type.
message MsgUpdateGroupMetadataRequest {
// admin is the account address of the group admin.
string admin = 1;
// group_id is the unique ID of the group.
uint64 group_id = 2;
// metadata is the updated group's metadata.
bytes metadata = 3;
}
// MsgUpdateGroupMetadataResponse is the Msg/UpdateGroupMetadata response type.
message MsgUpdateGroupMetadataResponse { }
//
// Group Accounts
//
// MsgCreateGroupAccountRequest is the Msg/CreateGroupAccount request type.
message MsgCreateGroupAccountRequest {
option (gogoproto.goproto_getters) = false;
// admin is the account address of the group admin.
string admin = 1;
// group_id is the unique ID of the group.
uint64 group_id = 2;
// metadata is any arbitrary metadata to attached to the group account.
bytes metadata = 3;
// decision_policy specifies the group account's decision policy.
google.protobuf.Any decision_policy = 4 [(cosmos_proto.accepts_interface) = "DecisionPolicy"];
}
// MsgCreateGroupAccountResponse is the Msg/CreateGroupAccount response type.
message MsgCreateGroupAccountResponse {
// address is the account address of the newly created group account.
string address = 1;
}
// MsgUpdateGroupAccountAdminRequest is the Msg/UpdateGroupAccountAdmin request type.
message MsgUpdateGroupAccountAdminRequest {
// admin is the account address of the group admin.
string admin = 1;
// address is the group account address.
string address = 2;
// new_admin is the new group account admin.
string new_admin = 3;
}
// MsgUpdateGroupAccountAdminResponse is the Msg/UpdateGroupAccountAdmin response type.
message MsgUpdateGroupAccountAdminResponse { }
// MsgUpdateGroupAccountDecisionPolicyRequest is the Msg/UpdateGroupAccountDecisionPolicy request type.
message MsgUpdateGroupAccountDecisionPolicyRequest {
option (gogoproto.goproto_getters) = false;
// admin is the account address of the group admin.
string admin = 1;
// address is the group account address.
string address = 2;
// decision_policy is the updated group account decision policy.
google.protobuf.Any decision_policy = 3 [(cosmos_proto.accepts_interface) = "DecisionPolicy"];
}
// MsgUpdateGroupAccountDecisionPolicyResponse is the Msg/UpdateGroupAccountDecisionPolicy response type.
message MsgUpdateGroupAccountDecisionPolicyResponse { }
// MsgUpdateGroupAccountMetadataRequest is the Msg/UpdateGroupAccountMetadata request type.
message MsgUpdateGroupAccountMetadataRequest {
// admin is the account address of the group admin.
string admin = 1;
// address is the group account address.
string address = 2;
// metadata is the updated group account metadata.
bytes metadata = 3;
}
// MsgUpdateGroupAccountMetadataResponse is the Msg/UpdateGroupAccountMetadata response type.
message MsgUpdateGroupAccountMetadataResponse { }
//
// Proposals and Voting
//
// Exec defines modes of execution of a proposal on creation or on new vote.
enum Exec {
// An empty value means that there should be a separate
// MsgExec request for the proposal to execute.
EXEC_UNSPECIFIED = 0;
// Try to execute the proposal immediately.
// If the proposal is not allowed per the DecisionPolicy,
// the proposal will still be open and could
// be executed at a later point.
EXEC_TRY = 1;
}
// MsgCreateProposalRequest is the Msg/CreateProposal request type.
message MsgCreateProposalRequest {
option (gogoproto.goproto_getters) = false;
// address is the group account address.
string address = 1;
// proposers are the account addresses of the proposers.
// Proposers signatures will be counted as yes votes.
repeated string proposers = 2;
// metadata is any arbitrary metadata to attached to the proposal.
bytes metadata = 3;
// msgs is a list of Msgs that will be executed if the proposal passes.
repeated google.protobuf.Any msgs = 4;
// exec defines the mode of execution of the proposal,
// whether it should be executed immediately on creation or not.
// If so, proposers signatures are considered as Yes votes.
Exec exec = 5;
}
// MsgCreateProposalResponse is the Msg/CreateProposal response type.
message MsgCreateProposalResponse {
// proposal is the unique ID of the proposal.
uint64 proposal_id = 1;
}
// MsgVoteRequest is the Msg/Vote request type.
message MsgVoteRequest {
// proposal is the unique ID of the proposal.
uint64 proposal_id = 1;
// voter is the voter account address.
string voter = 2;
// choice is the voter's choice on the proposal.
Choice choice = 3;
// metadata is any arbitrary metadata to attached to the vote.
bytes metadata = 4;
// exec defines whether the proposal should be executed
// immediately after voting or not.
Exec exec = 5;
}
// MsgVoteResponse is the Msg/Vote response type.
message MsgVoteResponse { }
// MsgExecRequest is the Msg/Exec request type.
message MsgExecRequest {
// proposal is the unique ID of the proposal.
uint64 proposal_id = 1;
// signer is the account address used to execute the proposal.
string signer = 2;
}
// MsgExecResponse is the Msg/Exec request type.
message MsgExecResponse { }

View File

@ -0,0 +1,272 @@
syntax = "proto3";
package cosmos.group.v1beta1;
option go_package = "github.com/cosmos/cosmos-sdk/x/group";
import "gogoproto/gogo.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "cosmos_proto/cosmos.proto";
import "google/protobuf/any.proto";
// Member represents a group member with an account address,
// non-zero weight and metadata.
message Member {
// address is the member's account address.
string address = 1;
// weight is the member's voting weight that should be greater than 0.
string weight = 2;
// metadata is any arbitrary metadata to attached to the member.
bytes metadata = 3;
}
// Members defines a repeated slice of Member objects.
message Members {
// members is the list of members.
repeated Member members = 1 [(gogoproto.nullable) = false];
}
// ThresholdDecisionPolicy implements the DecisionPolicy interface
message ThresholdDecisionPolicy {
option (cosmos_proto.implements_interface) = "DecisionPolicy";
// threshold is the minimum weighted sum of yes votes that must be met or exceeded for a proposal to succeed.
string threshold = 1;
// timeout is the duration from submission of a proposal to the end of voting period
// Within this times votes and exec messages can be submitted.
google.protobuf.Duration timeout = 2 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
}
// Choice defines available types of choices for voting.
enum Choice {
// CHOICE_UNSPECIFIED defines a no-op voting choice.
CHOICE_UNSPECIFIED = 0;
// CHOICE_NO defines a no voting choice.
CHOICE_NO = 1;
// CHOICE_YES defines a yes voting choice.
CHOICE_YES = 2;
// CHOICE_ABSTAIN defines an abstaining voting choice.
CHOICE_ABSTAIN = 3;
// CHOICE_VETO defines a voting choice with veto.
CHOICE_VETO = 4;
}
//
// State
//
// GroupInfo represents the high-level on-chain information for a group.
message GroupInfo {
// group_id is the unique ID of the group.
uint64 group_id = 1;
// admin is the account address of the group's admin.
string admin = 2;
// metadata is any arbitrary metadata to attached to the group.
bytes metadata = 3;
// version is used to track changes to a group's membership structure that
// would break existing proposals. Whenever any members weight is changed,
// or any member is added or removed this version is incremented and will
// cause proposals based on older versions of this group to fail
uint64 version = 4;
// total_weight is the sum of the group members' weights.
string total_weight = 5;
}
// GroupMember represents the relationship between a group and a member.
message GroupMember {
// group_id is the unique ID of the group.
uint64 group_id = 1;
// member is the member data.
Member member = 2;
}
// GroupAccountInfo represents the high-level on-chain information for a group account.
message GroupAccountInfo {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
// address is the group account address.
string address = 1;
// group_id is the unique ID of the group.
uint64 group_id = 2;
// admin is the account address of the group admin.
string admin = 3;
// metadata is any arbitrary metadata to attached to the group account.
bytes metadata = 4;
// version is used to track changes to a group's GroupAccountInfo structure that
// would create a different result on a running proposal.
uint64 version = 5;
// decision_policy specifies the group account's decision policy.
google.protobuf.Any decision_policy = 6 [(cosmos_proto.accepts_interface) = "DecisionPolicy"];
// derivation_key is the "derivation" key of the group account,
// which is needed to derive the group root module key and execute proposals.
bytes derivation_key = 7;
}
// Proposal defines a group proposal. Any member of a group can submit a proposal
// for a group account to decide upon.
// A proposal consists of a set of `sdk.Msg`s that will be executed if the proposal
// passes as well as some optional metadata associated with the proposal.
message Proposal {
option (gogoproto.goproto_getters) = false;
// proposal_id is the unique id of the proposal.
uint64 proposal_id = 1;
// address is the group account address.
string address = 2;
// metadata is any arbitrary metadata to attached to the proposal.
bytes metadata = 3;
// proposers are the account addresses of the proposers.
repeated string proposers = 4;
// submitted_at is a timestamp specifying when a proposal was submitted.
google.protobuf.Timestamp submitted_at = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// group_version tracks the version of the group that this proposal corresponds to.
// When group membership is changed, existing proposals from previous group versions will become invalid.
uint64 group_version = 6;
// group_account_version tracks the version of the group account that this proposal corresponds to.
// When a decision policy is changed, existing proposals from previous policy versions will become invalid.
uint64 group_account_version = 7;
// Status defines proposal statuses.
enum Status {
option (gogoproto.goproto_enum_prefix) = false;
// An empty value is invalid and not allowed.
STATUS_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "ProposalStatusInvalid"];
// Initial status of a proposal when persisted.
STATUS_SUBMITTED = 1 [(gogoproto.enumvalue_customname) = "ProposalStatusSubmitted"];
// Final status of a proposal when the final tally was executed.
STATUS_CLOSED = 2 [(gogoproto.enumvalue_customname) = "ProposalStatusClosed"];
// Final status of a proposal when the group was modified before the final tally.
STATUS_ABORTED = 3 [(gogoproto.enumvalue_customname) = "ProposalStatusAborted"];
// TODO: do we want to support a withdrawn operation?
// A proposal can be deleted before the voting start time by the owner. When this happens the final status
// is Withdrawn.
// STATUS_WITHDRAWN = 4 [(gogoproto.enumvalue_customname) = "Withdrawn"];
}
// Status represents the high level position in the life cycle of the proposal. Initial value is Submitted.
Status status = 8;
// Result defines types of proposal results.
enum Result {
option (gogoproto.goproto_enum_prefix) = false;
// An empty value is invalid and not allowed
RESULT_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "ProposalResultInvalid"];
// Until a final tally has happened the status is unfinalized
RESULT_UNFINALIZED = 1 [(gogoproto.enumvalue_customname) = "ProposalResultUnfinalized"];
// Final result of the tally
RESULT_ACCEPTED = 2 [(gogoproto.enumvalue_customname) = "ProposalResultAccepted"];
// Final result of the tally
RESULT_REJECTED = 3 [(gogoproto.enumvalue_customname) = "ProposalResultRejected"];
}
// result is the final result based on the votes and election rule. Initial value is unfinalized.
// The result is persisted so that clients can always rely on this state and not have to replicate the logic.
Result result = 9;
// vote_state contains the sums of all weighted votes for this proposal.
Tally vote_state = 10 [(gogoproto.nullable) = false];
// timeout is the timestamp of the block where the proposal execution times out. Header times of the votes and execution messages
// must be before this end time to be included in the election. After the timeout timestamp the proposal can not be
// executed anymore and should be considered pending delete.
google.protobuf.Timestamp timeout = 11 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// ExecutorResult defines types of proposal executor results.
enum ExecutorResult {
option (gogoproto.goproto_enum_prefix) = false;
// An empty value is not allowed.
EXECUTOR_RESULT_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "ProposalExecutorResultInvalid"];
// We have not yet run the executor.
EXECUTOR_RESULT_NOT_RUN = 1 [(gogoproto.enumvalue_customname) = "ProposalExecutorResultNotRun"];
// The executor was successful and proposed action updated state.
EXECUTOR_RESULT_SUCCESS = 2 [(gogoproto.enumvalue_customname) = "ProposalExecutorResultSuccess"];
// The executor returned an error and proposed action didn't update state.
EXECUTOR_RESULT_FAILURE = 3 [(gogoproto.enumvalue_customname) = "ProposalExecutorResultFailure"];
}
// executor_result is the final result based on the votes and election rule. Initial value is NotRun.
ExecutorResult executor_result = 12;
// msgs is a list of Msgs that will be executed if the proposal passes.
repeated google.protobuf.Any msgs = 13;
}
// Tally represents the sum of weighted votes.
message Tally {
option (gogoproto.goproto_getters) = false;
// yes_count is the weighted sum of yes votes.
string yes_count = 1;
// no_count is the weighted sum of no votes.
string no_count = 2;
// abstain_count is the weighted sum of abstainers
string abstain_count = 3;
// veto_count is the weighted sum of vetoes.
string veto_count = 4;
}
// Vote represents a vote for a proposal.
message Vote {
// proposal is the unique ID of the proposal.
uint64 proposal_id = 1;
// voter is the account address of the voter.
string voter = 2;
// choice is the voter's choice on the proposal.
Choice choice = 3;
// metadata is any arbitrary metadata to attached to the vote.
bytes metadata = 4;
// submitted_at is the timestamp when the vote was submitted.
google.protobuf.Timestamp submitted_at = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
}

View File

@ -58,7 +58,7 @@ func (tx kvstoreTx) ValidateBasic() error {
return nil
}
func (tx kvstoreTx) GetSigners() []sdk.AccAddress {
func (tx kvstoreTx) GetSigners() []string {
return nil
}

View File

@ -254,7 +254,7 @@ func (c converter) Ops(status string, msg sdk.Msg) ([]*rosettatypes.Operation, e
op := &rosettatypes.Operation{
Type: opName,
Status: &status,
Account: &rosettatypes.AccountIdentifier{Address: signer.String()},
Account: &rosettatypes.AccountIdentifier{Address: signer},
Metadata: meta,
}

View File

@ -224,7 +224,7 @@ func NewSimApp(
app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
// set the BaseApp's parameter store
bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()))
bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()))
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])

View File

@ -279,7 +279,7 @@ func (st *Store) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
defer telemetry.MeasureSince(time.Now(), "store", "iavl", "query")
if len(req.Data) == 0 {
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrTxDecode, "query cannot be zero length"))
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrTxDecode, "query cannot be zero length"), false)
}
tree := st.tree
@ -339,7 +339,7 @@ func (st *Store) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
res.Value = bz
default:
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unexpected query path: %v", req.Path))
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unexpected query path: %v", req.Path), false)
}
return res

View File

@ -529,17 +529,17 @@ func (rs *Store) Query(req abci.RequestQuery) abci.ResponseQuery {
path := req.Path
storeName, subpath, err := parsePath(path)
if err != nil {
return sdkerrors.QueryResult(err)
return sdkerrors.QueryResult(err, false)
}
store := rs.getStoreByName(storeName)
if store == nil {
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "no such store: %s", storeName))
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "no such store: %s", storeName), false)
}
queryable, ok := store.(types.Queryable)
if !ok {
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "store %s (type %T) doesn't support queries", storeName, store))
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "store %s (type %T) doesn't support queries", storeName, store), false)
}
// trim the path and make the query
@ -551,7 +551,7 @@ func (rs *Store) Query(req abci.RequestQuery) abci.ResponseQuery {
}
if res.ProofOps == nil || len(res.ProofOps.Ops) == 0 {
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "proof is unexpectedly empty; ensure height has not been pruned"))
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "proof is unexpectedly empty; ensure height has not been pruned"), false)
}
// If the request's height is the latest height we've committed, then utilize
@ -564,7 +564,7 @@ func (rs *Store) Query(req abci.RequestQuery) abci.ResponseQuery {
} else {
commitInfo, err = getCommitInfo(rs.db, res.Height)
if err != nil {
return sdkerrors.QueryResult(err)
return sdkerrors.QueryResult(err, false)
}
}

View File

@ -62,22 +62,12 @@ func (msg *TestMsg) GetSignBytes() []byte {
}
return sdk.MustSortJSON(bz)
}
func (msg *TestMsg) GetSigners() []sdk.AccAddress {
addrs := make([]sdk.AccAddress, len(msg.Signers))
for i, in := range msg.Signers {
addr, err := sdk.AccAddressFromBech32(in)
if err != nil {
panic(err)
}
addrs[i] = addr
}
return addrs
func (msg *TestMsg) GetSigners() []string {
return msg.Signers
}
func (msg *TestMsg) ValidateBasic() error { return nil }
var _ sdk.Msg = &MsgCreateDog{}
func (msg *MsgCreateDog) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{} }
func (msg *MsgCreateDog) ValidateBasic() error { return nil }
func (msg *MsgCreateDog) GetSigners() []string { return []string{} }
func (msg *MsgCreateDog) ValidateBasic() error { return nil }

View File

@ -67,8 +67,8 @@ func ResponseDeliverTx(err error, gw, gu uint64, debug bool) abci.ResponseDelive
// QueryResult returns a ResponseQuery from an error. It will try to parse ABCI
// info from the error.
func QueryResult(err error) abci.ResponseQuery {
space, code, log := ABCIInfo(err, false)
func QueryResult(err error, debug bool) abci.ResponseQuery {
space, code, log := ABCIInfo(err, debug)
return abci.ResponseQuery{
Codespace: space,
Code: code,

17
types/kv/helpers.go Normal file
View File

@ -0,0 +1,17 @@
package kv
import "fmt"
// AssertKeyAtLeastLength panics when store key length is less than the given length.
func AssertKeyAtLeastLength(bz []byte, length int) {
if len(bz) < length {
panic(fmt.Sprintf("expected key of length at least %d, got %d", length, len(bz)))
}
}
// AssertKeyLength panics when store key length is not equal to the given length.
func AssertKeyLength(bz []byte, length int) {
if len(bz) != length {
panic(fmt.Sprintf("unexpected key length; got: %d, expected: %d", len(bz), length))
}
}

47
types/tx/msgs.go Normal file
View File

@ -0,0 +1,47 @@
package tx
import (
fmt "fmt"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// SetMsgs takes a slice of sdk.Msg's and turn them into Any's.
func SetMsgs(msgs []sdk.Msg) ([]*types.Any, error) {
anys := make([]*types.Any, len(msgs))
for i, msg := range msgs {
var err error
anys[i], err = types.NewAnyWithValue(msg)
if err != nil {
return nil, err
}
}
return anys, nil
}
// GetMsgs takes a slice of Any's and turn them into sdk.Msg's.
func GetMsgs(anys []*types.Any, name string) ([]sdk.Msg, error) {
msgs := make([]sdk.Msg, len(anys))
for i, any := range anys {
cached := any.GetCachedValue()
if cached == nil {
return nil, fmt.Errorf("any cached value is nil, %s messages must be correctly packed any values", name)
}
msgs[i] = cached.(sdk.Msg)
}
return msgs, nil
}
// UnpackInterfaces unpacks Any's to sdk.Msg's.
func UnpackInterfaces(unpacker types.AnyUnpacker, anys []*types.Any) error {
for _, any := range anys {
var msg sdk.Msg
err := unpacker.UnpackAny(any, &msg)
if err != nil {
return err
}
}
return nil
}

View File

@ -23,13 +23,9 @@ func (t *Tx) GetMsgs() []sdk.Msg {
}
anys := t.Body.Messages
res := make([]sdk.Msg, len(anys))
for i, any := range anys {
cached := any.GetCachedValue()
if cached == nil {
panic("Any cached value is nil. Transaction messages must be correctly packed Any values.")
}
res[i] = cached.(sdk.Msg)
res, err := GetMsgs(anys, "transaction")
if err != nil {
panic(err)
}
return res
}
@ -101,9 +97,14 @@ func (t *Tx) GetSigners() []sdk.AccAddress {
for _, msg := range t.GetMsgs() {
for _, addr := range msg.GetSigners() {
if !seen[addr.String()] {
signers = append(signers, addr)
seen[addr.String()] = true
if !seen[addr] {
signer, err := sdk.AccAddressFromBech32(addr)
if err != nil {
panic(err)
}
signers = append(signers, signer)
seen[addr] = true
}
}
}
@ -170,15 +171,7 @@ func (t *Tx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
func (m *TxBody) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
for _, any := range m.Messages {
var msg sdk.Msg
err := unpacker.UnpackAny(any, &msg)
if err != nil {
return err
}
}
return nil
return UnpackInterfaces(unpacker, m.Messages)
}
// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
@ -202,3 +195,22 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterInterface("cosmos.tx.v1beta1.Tx", (*sdk.Tx)(nil))
registry.RegisterImplementations((*sdk.Tx)(nil), &Tx{})
}
// ValidateMsg calls the `sdk.Msg.ValidateBasic()`
// also validates all the signers are valid bech32 addresses.
func ValidateMsg(msg sdk.Msg) error {
err := msg.ValidateBasic()
if err != nil {
return err
}
signers := msg.GetSigners()
for _, signer := range signers {
_, err = sdk.AccAddressFromBech32(signer)
if err != nil {
return err
}
}
return nil
}

43
types/tx/types_test.go Normal file
View File

@ -0,0 +1,43 @@
package tx_test
import (
"testing"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/stretchr/testify/suite"
)
type testMsgSuite struct {
suite.Suite
}
func TestValidateMsg(t *testing.T) {
suite.Run(t, new(testMsgSuite))
}
func (s *testMsgSuite) TestMsg() {
cases := []struct {
signer []byte
expErr bool
}{
{
[]byte(""),
true,
},
{
[]byte("validAddress"),
false,
},
}
for _, c := range cases {
msg := testdata.NewTestMsg(c.signer)
err := tx.ValidateMsg(msg)
if c.expErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
}
}
}

View File

@ -15,10 +15,10 @@ type (
// doesn't require access to any other information.
ValidateBasic() error
// Signers returns the addrs of signers that must sign.
// Signers returns the bech32-encoded addrs of signers that must sign.
// CONTRACT: All signatures must be present to be valid.
// CONTRACT: Returns addrs in some deterministic order.
GetSigners() []AccAddress
GetSigners() []string
}
// Fee defines an interface for an application application-defined concrete

View File

@ -23,7 +23,7 @@ func (s *testMsgSuite) TestMsg() {
msg := testdata.NewTestMsg(accAddr)
s.Require().NotNil(msg)
s.Require().Equal([]sdk.AccAddress{accAddr}, msg.GetSigners())
s.Require().Equal([]string{accAddr.String()}, msg.GetSigners())
s.Require().Equal("TestMsg", msg.Route())
s.Require().Equal("Test message", msg.Type())
s.Require().Nil(msg.ValidateBasic())

View File

@ -11,7 +11,8 @@ import (
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
)
// ValidateBasicDecorator will call tx.ValidateBasic and return any non-nil error.
// ValidateBasicDecorator will call tx.ValidateBasic, ValidateMsg(for each msg inside tx)
// and return any non-nil error.
// If ValidateBasic passes, decorator calls next AnteHandler in chain. Note,
// ValidateBasicDecorator decorator will not get executed on ReCheckTx since it
// is not dependent on application state.

View File

@ -143,9 +143,13 @@ func (tx StdTx) GetSigners() []sdk.AccAddress {
for _, msg := range tx.GetMsgs() {
for _, addr := range msg.GetSigners() {
if !seen[addr.String()] {
signers = append(signers, addr)
seen[addr.String()] = true
if !seen[addr] {
signer, err := sdk.AccAddressFromBech32(addr)
if err != nil {
panic(err)
}
signers = append(signers, signer)
seen[addr] = true
}
}
}

View File

@ -200,14 +200,9 @@ func (w *wrapper) GetSignaturesV2() ([]signing.SignatureV2, error) {
}
func (w *wrapper) SetMsgs(msgs ...sdk.Msg) error {
anys := make([]*codectypes.Any, len(msgs))
for i, msg := range msgs {
var err error
anys[i], err = codectypes.NewAnyWithValue(msg)
if err != nil {
return err
}
anys, err := tx.SetMsgs(msgs)
if err != nil {
return err
}
w.tx.Body.Messages = anys

View File

@ -68,10 +68,6 @@ func (msg MsgCreateVestingAccount) GetSignBytes() []byte {
}
// GetSigners returns the expected signers for a MsgCreateVestingAccount.
func (msg MsgCreateVestingAccount) GetSigners() []sdk.AccAddress {
from, err := sdk.AccAddressFromBech32(msg.FromAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{from}
func (msg MsgCreateVestingAccount) GetSigners() []string {
return []string{msg.FromAddress}
}

View File

@ -79,7 +79,10 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs []
if len(signers) != 1 {
return nil, sdkerrors.ErrInvalidRequest.Wrap("authorization can be given to msg with only one signer")
}
granter := signers[0]
granter, err := sdk.AccAddressFromBech32(signers[0])
if err != nil {
return nil, err
}
// if granter != grantee then check authorization.Accept, otherwise we implicitly accept.
if !granter.Equals(grantee) {
authorization, _ := k.GetCleanAuthorization(ctx, grantee, granter, sdk.MsgTypeURL(msg))

View File

@ -4,6 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/internal/conv"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/cosmos/cosmos-sdk/x/authz"
)
@ -38,9 +39,12 @@ func grantStoreKey(grantee sdk.AccAddress, granter sdk.AccAddress, msgType strin
func addressesFromGrantStoreKey(key []byte) (granterAddr, granteeAddr sdk.AccAddress) {
// key is of format:
// 0x01<granterAddressLen (1 Byte)><granterAddress_Bytes><granteeAddressLen (1 Byte)><granteeAddress_Bytes><msgType_Bytes>
kv.AssertKeyAtLeastLength(key, 2)
granterAddrLen := key[1] // remove prefix key
kv.AssertKeyAtLeastLength(key, int(3+granterAddrLen))
granterAddr = sdk.AccAddress(key[2 : 2+granterAddrLen])
granteeAddrLen := int(key[2+granterAddrLen])
kv.AssertKeyAtLeastLength(key, 4+int(granterAddrLen+byte(granteeAddrLen)))
granteeAddr = sdk.AccAddress(key[3+granterAddrLen : 3+granterAddrLen+byte(granteeAddrLen)])
return granterAddr, granteeAddr

View File

@ -42,12 +42,8 @@ func NewMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a Authorization
}
// GetSigners implements Msg
func (msg MsgGrant) GetSigners() []sdk.AccAddress {
granter, err := sdk.AccAddressFromBech32(msg.Granter)
if err != nil {
panic(err)
}
return []sdk.AccAddress{granter}
func (msg MsgGrant) GetSigners() []string {
return []string{msg.Granter}
}
// ValidateBasic implements Msg
@ -130,12 +126,8 @@ func NewMsgRevoke(granter sdk.AccAddress, grantee sdk.AccAddress, msgTypeURL str
}
// GetSigners implements Msg
func (msg MsgRevoke) GetSigners() []sdk.AccAddress {
granter, err := sdk.AccAddressFromBech32(msg.Granter)
if err != nil {
panic(err)
}
return []sdk.AccAddress{granter}
func (msg MsgRevoke) GetSigners() []string {
return []string{msg.Granter}
}
// ValidateBasic implements MsgRequest.ValidateBasic
@ -209,12 +201,8 @@ func (msg MsgExec) GetMessages() ([]sdk.Msg, error) {
}
// GetSigners implements Msg
func (msg MsgExec) GetSigners() []sdk.AccAddress {
grantee, err := sdk.AccAddressFromBech32(msg.Grantee)
if err != nil {
panic(err)
}
return []sdk.AccAddress{grantee}
func (msg MsgExec) GetSigners() []string {
return []string{msg.Grantee}
}
// ValidateBasic implements Msg

View File

@ -3,9 +3,8 @@
package v040
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
v040auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v040"
)
@ -40,10 +39,8 @@ func DenomMetadataKey(denom string) []byte {
// store. The key must not contain the perfix BalancesPrefix as the prefix store
// iterator discards the actual prefix.
func AddressFromBalancesStore(key []byte) sdk.AccAddress {
kv.AssertKeyAtLeastLength(key, 1+v040auth.AddrLen)
addr := key[:v040auth.AddrLen]
if len(addr) != v040auth.AddrLen {
panic(fmt.Sprintf("unexpected account address key length; got: %d, expected: %d", len(addr), v040auth.AddrLen))
}
kv.AssertKeyLength(addr, v040auth.AddrLen)
return sdk.AccAddress(addr)
}

View File

@ -3,6 +3,7 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/types/kv"
)
const (
@ -43,6 +44,7 @@ func AddressFromBalancesStore(key []byte) (sdk.AccAddress, error) {
if len(key) == 0 {
return nil, ErrInvalidKey
}
kv.AssertKeyAtLeastLength(key, 1)
addrLen := key[0]
bound := int(addrLen)
if len(key)-1 < bound {

View File

@ -54,12 +54,8 @@ func (msg MsgSend) GetSignBytes() []byte {
}
// GetSigners Implements Msg.
func (msg MsgSend) GetSigners() []sdk.AccAddress {
from, err := sdk.AccAddressFromBech32(msg.FromAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{from}
func (msg MsgSend) GetSigners() []string {
return []string{msg.FromAddress}
}
var _ sdk.Msg = &MsgMultiSend{}
@ -96,11 +92,10 @@ func (msg MsgMultiSend) GetSignBytes() []byte {
}
// GetSigners Implements Msg.
func (msg MsgMultiSend) GetSigners() []sdk.AccAddress {
addrs := make([]sdk.AccAddress, len(msg.Inputs))
func (msg MsgMultiSend) GetSigners() []string {
addrs := make([]string, len(msg.Inputs))
for i, in := range msg.Inputs {
addr, _ := sdk.AccAddressFromBech32(in.Address)
addrs[i] = addr
addrs[i] = in.Address
}
return addrs

View File

@ -65,13 +65,6 @@ func TestMsgSendGetSignBytes(t *testing.T) {
require.Equal(t, expected, string(res))
}
func TestMsgSendGetSigners(t *testing.T) {
var msg = NewMsgSend(sdk.AccAddress([]byte("input111111111111111")), sdk.AccAddress{}, sdk.NewCoins())
res := msg.GetSigners()
// TODO: fix this !
require.Equal(t, fmt.Sprintf("%v", res), "[696E707574313131313131313131313131313131]")
}
func TestMsgMultiSendRoute(t *testing.T) {
// Construct a MsgSend
addr1 := sdk.AccAddress([]byte("input"))
@ -238,32 +231,22 @@ func TestMsgMultiSendGetSignBytes(t *testing.T) {
}
func TestMsgMultiSendGetSigners(t *testing.T) {
var msg = MsgMultiSend{
Inputs: []Input{
NewInput(sdk.AccAddress([]byte("input111111111111111")), nil),
NewInput(sdk.AccAddress([]byte("input222222222222222")), nil),
NewInput(sdk.AccAddress([]byte("input333333333333333")), nil),
},
addrs := make([]string, 3)
inputs := make([]Input, 3)
for i, v := range []string{"input111111111111111", "input222222222222222", "input333333333333333"} {
addr := sdk.AccAddress([]byte(v))
inputs[i] = NewInput(addr, nil)
addrs[i] = addr.String()
}
var msg = NewMsgMultiSend(inputs, nil)
res := msg.GetSigners()
// TODO: fix this !
require.Equal(t, "[696E707574313131313131313131313131313131 696E707574323232323232323232323232323232 696E707574333333333333333333333333333333]", fmt.Sprintf("%v", res))
require.Equal(t, fmt.Sprintf("%v", addrs), fmt.Sprintf("%v", res))
}
func TestMsgSendSigners(t *testing.T) {
signers := []sdk.AccAddress{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
someCoins := sdk.NewCoins(sdk.NewInt64Coin("atom", 123))
inputs := make([]Input, len(signers))
for i, signer := range signers {
inputs[i] = NewInput(signer, someCoins)
}
tx := NewMsgMultiSend(inputs, nil)
require.Equal(t, signers, tx.GetSigners())
func TestMsgSendGetSigners(t *testing.T) {
from := sdk.AccAddress([]byte("input111111111111111"))
msg := NewMsgSend(from, sdk.AccAddress{}, sdk.NewCoins())
res := msg.GetSigners()
require.Equal(t, fmt.Sprintf("%v", res), fmt.Sprintf("%v", []string{from.String()}))
}

View File

@ -21,9 +21,8 @@ func (msg MsgVerifyInvariant) Route() string { return ModuleName }
func (msg MsgVerifyInvariant) Type() string { return "verify_invariant" }
// get the bytes for the message signer to sign on
func (msg MsgVerifyInvariant) GetSigners() []sdk.AccAddress {
sender, _ := sdk.AccAddressFromBech32(msg.Sender)
return []sdk.AccAddress{sender}
func (msg MsgVerifyInvariant) GetSigners() []string {
return []string{msg.Sender}
}
// GetSignBytes gets the sign bytes for the msg MsgVerifyInvariant

View File

@ -110,12 +110,6 @@ $ %s tx distribution withdraw-rewards %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
msgs = append(msgs, types.NewMsgWithdrawValidatorCommission(valAddr))
}
for _, msg := range msgs {
if err := msg.ValidateBasic(); err != nil {
return err
}
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msgs...)
},
}
@ -169,9 +163,6 @@ $ %s tx distribution withdraw-all-rewards --from mykey
}
msg := types.NewMsgWithdrawDelegatorReward(delAddr, val)
if err := msg.ValidateBasic(); err != nil {
return err
}
msgs = append(msgs, msg)
}

View File

@ -6,6 +6,7 @@ import (
"encoding/binary"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
v040auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v040"
)
@ -58,78 +59,68 @@ var (
// gets an address from a validator's outstanding rewards key
func GetValidatorOutstandingRewardsAddress(key []byte) (valAddr sdk.ValAddress) {
kv.AssertKeyAtLeastLength(key, 2)
addr := key[1:]
if len(addr) != v040auth.AddrLen {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, v040auth.AddrLen)
return sdk.ValAddress(addr)
}
// gets an address from a delegator's withdraw info key
func GetDelegatorWithdrawInfoAddress(key []byte) (delAddr sdk.AccAddress) {
kv.AssertKeyAtLeastLength(key, 2)
addr := key[1:]
if len(addr) != v040auth.AddrLen {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, v040auth.AddrLen)
return sdk.AccAddress(addr)
}
// gets the addresses from a delegator starting info key
func GetDelegatorStartingInfoAddresses(key []byte) (valAddr sdk.ValAddress, delAddr sdk.AccAddress) {
kv.AssertKeyAtLeastLength(key, 2+v040auth.AddrLen)
addr := key[1 : 1+v040auth.AddrLen]
if len(addr) != v040auth.AddrLen {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, v040auth.AddrLen)
valAddr = sdk.ValAddress(addr)
addr = key[1+v040auth.AddrLen:]
if len(addr) != v040auth.AddrLen {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, v040auth.AddrLen)
delAddr = sdk.AccAddress(addr)
return
}
// gets the address & period from a validator's historical rewards key
func GetValidatorHistoricalRewardsAddressPeriod(key []byte) (valAddr sdk.ValAddress, period uint64) {
kv.AssertKeyAtLeastLength(key, 2+v040auth.AddrLen)
addr := key[1 : 1+v040auth.AddrLen]
if len(addr) != v040auth.AddrLen {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, v040auth.AddrLen)
valAddr = sdk.ValAddress(addr)
b := key[1+v040auth.AddrLen:]
if len(b) != 8 {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, 8)
period = binary.LittleEndian.Uint64(b)
return
}
// gets the address from a validator's current rewards key
func GetValidatorCurrentRewardsAddress(key []byte) (valAddr sdk.ValAddress) {
kv.AssertKeyAtLeastLength(key, 2)
addr := key[1:]
if len(addr) != v040auth.AddrLen {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, v040auth.AddrLen)
return sdk.ValAddress(addr)
}
// gets the address from a validator's accumulated commission key
func GetValidatorAccumulatedCommissionAddress(key []byte) (valAddr sdk.ValAddress) {
kv.AssertKeyAtLeastLength(key, 2)
addr := key[1:]
if len(addr) != v040auth.AddrLen {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, v040auth.AddrLen)
return sdk.ValAddress(addr)
}
// gets the height from a validator's slash event key
func GetValidatorSlashEventAddressHeight(key []byte) (valAddr sdk.ValAddress, height uint64) {
kv.AssertKeyAtLeastLength(key, 2+v040auth.AddrLen)
addr := key[1 : 1+v040auth.AddrLen]
if len(addr) != v040auth.AddrLen {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, v040auth.AddrLen)
valAddr = sdk.ValAddress(addr)
startB := 1 + v040auth.AddrLen
kv.AssertKeyAtLeastLength(key, startB+9)
b := key[startB : startB+8] // the next 8 bytes represent the height
height = binary.BigEndian.Uint64(b)
return

View File

@ -5,6 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/types/kv"
)
const (
@ -60,10 +61,9 @@ func GetValidatorOutstandingRewardsAddress(key []byte) (valAddr sdk.ValAddress)
// 0x02<valAddrLen (1 Byte)><valAddr_Bytes>
// Remove prefix and address length.
kv.AssertKeyAtLeastLength(key, 3)
addr := key[2:]
if len(addr) != int(key[1]) {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, int(key[1]))
return sdk.ValAddress(addr)
}
@ -74,10 +74,9 @@ func GetDelegatorWithdrawInfoAddress(key []byte) (delAddr sdk.AccAddress) {
// 0x03<accAddrLen (1 Byte)><accAddr_Bytes>
// Remove prefix and address length.
kv.AssertKeyAtLeastLength(key, 3)
addr := key[2:]
if len(addr) != int(key[1]) {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, int(key[1]))
return sdk.AccAddress(addr)
}
@ -86,13 +85,14 @@ func GetDelegatorWithdrawInfoAddress(key []byte) (delAddr sdk.AccAddress) {
func GetDelegatorStartingInfoAddresses(key []byte) (valAddr sdk.ValAddress, delAddr sdk.AccAddress) {
// key is in the format:
// 0x04<valAddrLen (1 Byte)><valAddr_Bytes><accAddrLen (1 Byte)><accAddr_Bytes>
kv.AssertKeyAtLeastLength(key, 2)
valAddrLen := int(key[1])
kv.AssertKeyAtLeastLength(key, 3+valAddrLen)
valAddr = sdk.ValAddress(key[2 : 2+valAddrLen])
delAddrLen := int(key[2+valAddrLen])
kv.AssertKeyAtLeastLength(key, 4+valAddrLen)
delAddr = sdk.AccAddress(key[3+valAddrLen:])
if len(delAddr.Bytes()) != delAddrLen {
panic("unexpected key length")
}
kv.AssertKeyLength(delAddr.Bytes(), delAddrLen)
return
}
@ -101,12 +101,12 @@ func GetDelegatorStartingInfoAddresses(key []byte) (valAddr sdk.ValAddress, delA
func GetValidatorHistoricalRewardsAddressPeriod(key []byte) (valAddr sdk.ValAddress, period uint64) {
// key is in the format:
// 0x05<valAddrLen (1 Byte)><valAddr_Bytes><period_Bytes>
kv.AssertKeyAtLeastLength(key, 2)
valAddrLen := int(key[1])
kv.AssertKeyAtLeastLength(key, 3+valAddrLen)
valAddr = sdk.ValAddress(key[2 : 2+valAddrLen])
b := key[2+valAddrLen:]
if len(b) != 8 {
panic("unexpected key length")
}
kv.AssertKeyLength(b, 8)
period = binary.LittleEndian.Uint64(b)
return
}
@ -117,10 +117,9 @@ func GetValidatorCurrentRewardsAddress(key []byte) (valAddr sdk.ValAddress) {
// 0x06<valAddrLen (1 Byte)><valAddr_Bytes>: ValidatorCurrentRewards
// Remove prefix and address length.
kv.AssertKeyAtLeastLength(key, 3)
addr := key[2:]
if len(addr) != int(key[1]) {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, int(key[1]))
return sdk.ValAddress(addr)
}
@ -131,10 +130,9 @@ func GetValidatorAccumulatedCommissionAddress(key []byte) (valAddr sdk.ValAddres
// 0x07<valAddrLen (1 Byte)><valAddr_Bytes>: ValidatorCurrentRewards
// Remove prefix and address length.
kv.AssertKeyAtLeastLength(key, 3)
addr := key[2:]
if len(addr) != int(key[1]) {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, int(key[1]))
return sdk.ValAddress(addr)
}
@ -143,9 +141,12 @@ func GetValidatorAccumulatedCommissionAddress(key []byte) (valAddr sdk.ValAddres
func GetValidatorSlashEventAddressHeight(key []byte) (valAddr sdk.ValAddress, height uint64) {
// key is in the format:
// 0x08<valAddrLen (1 Byte)><valAddr_Bytes><height>: ValidatorSlashEvent
kv.AssertKeyAtLeastLength(key, 2)
valAddrLen := int(key[1])
kv.AssertKeyAtLeastLength(key, 3+valAddrLen)
valAddr = key[2 : 2+valAddrLen]
startB := 2 + valAddrLen
kv.AssertKeyAtLeastLength(key, startB+9)
b := key[startB : startB+8] // the next 8 bytes represent the height
height = binary.BigEndian.Uint64(b)
return

View File

@ -27,12 +27,8 @@ func (msg MsgSetWithdrawAddress) Route() string { return ModuleName }
func (msg MsgSetWithdrawAddress) Type() string { return TypeMsgSetWithdrawAddress }
// Return address that must sign over msg.GetSignBytes()
func (msg MsgSetWithdrawAddress) GetSigners() []sdk.AccAddress {
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{delAddr}
func (msg MsgSetWithdrawAddress) GetSigners() []string {
return []string{msg.DelegatorAddress}
}
// get the bytes for the message signer to sign on
@ -64,12 +60,8 @@ func (msg MsgWithdrawDelegatorReward) Route() string { return ModuleName }
func (msg MsgWithdrawDelegatorReward) Type() string { return TypeMsgWithdrawDelegatorReward }
// Return address that must sign over msg.GetSignBytes()
func (msg MsgWithdrawDelegatorReward) GetSigners() []sdk.AccAddress {
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{delAddr}
func (msg MsgWithdrawDelegatorReward) GetSigners() []string {
return []string{msg.DelegatorAddress}
}
// get the bytes for the message signer to sign on
@ -99,12 +91,12 @@ func (msg MsgWithdrawValidatorCommission) Route() string { return ModuleName }
func (msg MsgWithdrawValidatorCommission) Type() string { return TypeMsgWithdrawValidatorCommission }
// Return address that must sign over msg.GetSignBytes()
func (msg MsgWithdrawValidatorCommission) GetSigners() []sdk.AccAddress {
func (msg MsgWithdrawValidatorCommission) GetSigners() []string {
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{valAddr.Bytes()}
return []string{sdk.AccAddress(valAddr).String()}
}
// get the bytes for the message signer to sign on
@ -138,12 +130,8 @@ func (msg MsgFundCommunityPool) Type() string { return TypeMsgFundCommunityPool
// GetSigners returns the signer addresses that are expected to sign the result
// of GetSignBytes.
func (msg MsgFundCommunityPool) GetSigners() []sdk.AccAddress {
depoAddr, err := sdk.AccAddressFromBech32(msg.Depositor)
if err != nil {
panic(err)
}
return []sdk.AccAddress{depoAddr}
func (msg MsgFundCommunityPool) GetSigners() []string {
return []string{msg.Depositor}
}
// GetSignBytes returns the raw bytes for a MsgFundCommunityPool message that

View File

@ -66,13 +66,8 @@ func (m MsgSubmitEvidence) GetSignBytes() []byte {
}
// GetSigners returns the single expected signer for a MsgSubmitEvidence.
func (m MsgSubmitEvidence) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(m.Submitter)
if err != nil {
return nil
}
return []sdk.AccAddress{accAddr}
func (m MsgSubmitEvidence) GetSigners() []string {
return []string{m.Submitter}
}
func (m MsgSubmitEvidence) GetEvidence() exported.Evidence {

View File

@ -54,7 +54,7 @@ func TestMsgSubmitEvidence(t *testing.T) {
require.Equal(t, tc.expectErr, tc.msg.ValidateBasic() != nil, "unexpected result for tc #%d", i)
if !tc.expectErr {
require.Equal(t, tc.msg.GetSigners(), []sdk.AccAddress{tc.submitter}, "unexpected result for tc #%d", i)
require.Equal(t, tc.msg.GetSigners(), []string{tc.submitter.String()}, "unexpected result for tc #%d", i)
}
}
}

View File

@ -57,12 +57,8 @@ func (msg MsgGrantAllowance) ValidateBasic() error {
}
// GetSigners gets the granter account associated with an allowance
func (msg MsgGrantAllowance) GetSigners() []sdk.AccAddress {
granter, err := sdk.AccAddressFromBech32(msg.Granter)
if err != nil {
panic(err)
}
return []sdk.AccAddress{granter}
func (msg MsgGrantAllowance) GetSigners() []string {
return []string{msg.Granter}
}
// Type implements the LegacyMsg.Type method.
@ -120,12 +116,8 @@ func (msg MsgRevokeAllowance) ValidateBasic() error {
// GetSigners gets the granter address associated with an Allowance
// to revoke.
func (msg MsgRevokeAllowance) GetSigners() []sdk.AccAddress {
granter, err := sdk.AccAddressFromBech32(msg.Granter)
if err != nil {
panic(err)
}
return []sdk.AccAddress{granter}
func (msg MsgRevokeAllowance) GetSigners() []string {
return []string{msg.Granter}
}
// Type implements the LegacyMsg.Type method.

View File

@ -64,7 +64,7 @@ func TestMsgGrantAllowance(t *testing.T) {
require.NoError(t, err)
addrSlice := msg.GetSigners()
require.Equal(t, tc.granter.String(), addrSlice[0].String())
require.Equal(t, tc.granter.String(), addrSlice[0])
allowance, err := msg.GetFeeAllowanceI()
require.NoError(t, err)
@ -126,7 +126,7 @@ func TestMsgRevokeAllowance(t *testing.T) {
if tc.valid {
require.NoError(t, err)
addrSlice := msg.GetSigners()
require.Equal(t, tc.granter.String(), addrSlice[0].String())
require.Equal(t, tc.granter.String(), addrSlice[0])
} else {
require.Error(t, err)
}

View File

@ -87,7 +87,7 @@ func (s *IntegrationTestSuite) TestGenTxCmd() {
s.Require().Len(msgs, 1)
s.Require().Equal(sdk.MsgTypeURL(&types.MsgCreateValidator{}), sdk.MsgTypeURL(msgs[0]))
s.Require().Equal([]sdk.AccAddress{val.Address}, msgs[0].GetSigners())
s.Require().Equal([]string{val.Address.String()}, msgs[0].GetSigners())
s.Require().Equal(amount, msgs[0].(*types.MsgCreateValidator).Value)
err = tx.ValidateBasic()
s.Require().NoError(err)

View File

@ -275,11 +275,6 @@ $ %s tx gov weighted-vote 1 yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05 --from
// Build vote message and run basic validation
msg := types.NewMsgVoteWeighted(from, proposalID, options)
err = msg.ValidateBasic()
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

View File

@ -4,10 +4,10 @@ package v040
import (
"encoding/binary"
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
v040auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v040"
)
@ -113,9 +113,7 @@ func VoteKey(proposalID uint64, voterAddr sdk.AccAddress) []byte {
// SplitProposalKey split the proposal key and returns the proposal id
func SplitProposalKey(key []byte) (proposalID uint64) {
if len(key[1:]) != 8 {
panic(fmt.Sprintf("unexpected key length (%d ≠ 8)", len(key[1:])))
}
kv.AssertKeyLength(key[1:], 8)
return GetProposalIDFromBytes(key[1:])
}
@ -143,9 +141,7 @@ func SplitKeyVote(key []byte) (proposalID uint64, voterAddr sdk.AccAddress) {
// private functions
func splitKeyWithTime(key []byte) (proposalID uint64, endTime time.Time) {
if len(key[1:]) != 8+lenTime {
panic(fmt.Sprintf("unexpected key length (%d ≠ %d)", len(key[1:]), lenTime+8))
}
kv.AssertKeyLength(key[1:], 8+lenTime)
endTime, err := sdk.ParseTimeBytes(key[1 : 1+lenTime])
if err != nil {
@ -157,10 +153,9 @@ func splitKeyWithTime(key []byte) (proposalID uint64, endTime time.Time) {
}
func splitKeyWithAddress(key []byte) (proposalID uint64, addr sdk.AccAddress) {
if len(key[1:]) != 8+v040auth.AddrLen {
panic(fmt.Sprintf("unexpected key length (%d ≠ %d)", len(key), 8+v040auth.AddrLen))
}
kv.AssertKeyLength(key[1:], 8+v040auth.AddrLen)
kv.AssertKeyAtLeastLength(key, 10)
proposalID = GetProposalIDFromBytes(key[1:9])
addr = sdk.AccAddress(key[9:])
return

View File

@ -2,11 +2,11 @@ package types
import (
"encoding/binary"
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/types/kv"
)
const (
@ -111,9 +111,7 @@ func VoteKey(proposalID uint64, voterAddr sdk.AccAddress) []byte {
// SplitProposalKey split the proposal key and returns the proposal id
func SplitProposalKey(key []byte) (proposalID uint64) {
if len(key[1:]) != 8 {
panic(fmt.Sprintf("unexpected key length (%d ≠ 8)", len(key[1:])))
}
kv.AssertKeyLength(key[1:], 8)
return GetProposalIDFromBytes(key[1:])
}
@ -141,9 +139,7 @@ func SplitKeyVote(key []byte) (proposalID uint64, voterAddr sdk.AccAddress) {
// private functions
func splitKeyWithTime(key []byte) (proposalID uint64, endTime time.Time) {
if len(key[1:]) != 8+lenTime {
panic(fmt.Sprintf("unexpected key length (%d ≠ %d)", len(key[1:]), lenTime+8))
}
kv.AssertKeyLength(key[1:], 8+lenTime)
endTime, err := sdk.ParseTimeBytes(key[1 : 1+lenTime])
if err != nil {
@ -157,7 +153,9 @@ func splitKeyWithTime(key []byte) (proposalID uint64, endTime time.Time) {
func splitKeyWithAddress(key []byte) (proposalID uint64, addr sdk.AccAddress) {
// Both Vote and Deposit store keys are of format:
// <prefix (1 Byte)><proposalID (8 bytes)><addrLen (1 Byte)><addr_Bytes>
kv.AssertKeyAtLeastLength(key, 10)
proposalID = GetProposalIDFromBytes(key[1:9])
kv.AssertKeyAtLeastLength(key, 11)
addr = sdk.AccAddress(key[10:])
return
}

View File

@ -114,9 +114,8 @@ func (m MsgSubmitProposal) GetSignBytes() []byte {
}
// GetSigners implements Msg
func (m MsgSubmitProposal) GetSigners() []sdk.AccAddress {
proposer, _ := sdk.AccAddressFromBech32(m.Proposer)
return []sdk.AccAddress{proposer}
func (m MsgSubmitProposal) GetSigners() []string {
return []string{m.Proposer}
}
// String implements the Stringer interface
@ -171,9 +170,8 @@ func (msg MsgDeposit) GetSignBytes() []byte {
}
// GetSigners implements Msg
func (msg MsgDeposit) GetSigners() []sdk.AccAddress {
depositor, _ := sdk.AccAddressFromBech32(msg.Depositor)
return []sdk.AccAddress{depositor}
func (msg MsgDeposit) GetSigners() []string {
return []string{msg.Depositor}
}
// NewMsgVote creates a message to cast a vote on an active proposal
@ -214,9 +212,8 @@ func (msg MsgVote) GetSignBytes() []byte {
}
// GetSigners implements Msg
func (msg MsgVote) GetSigners() []sdk.AccAddress {
voter, _ := sdk.AccAddressFromBech32(msg.Voter)
return []sdk.AccAddress{voter}
func (msg MsgVote) GetSigners() []string {
return []string{msg.Voter}
}
// NewMsgVoteWeighted creates a message to cast a vote on an active proposal
@ -278,7 +275,6 @@ func (msg MsgVoteWeighted) GetSignBytes() []byte {
}
// GetSigners implements Msg
func (msg MsgVoteWeighted) GetSigners() []sdk.AccAddress {
voter, _ := sdk.AccAddressFromBech32(msg.Voter)
return []sdk.AccAddress{voter}
func (msg MsgVoteWeighted) GetSigners() []string {
return []string{msg.Voter}
}

16
x/group/errors.go Normal file
View File

@ -0,0 +1,16 @@
package group
import (
"github.com/cosmos/cosmos-sdk/types/errors"
)
var (
ErrEmpty = errors.Register(ModuleName, 2, "value is empty")
ErrDuplicate = errors.Register(ModuleName, 3, "duplicate value")
ErrMaxLimit = errors.Register(ModuleName, 4, "limit exceeded")
ErrType = errors.Register(ModuleName, 5, "invalid type")
ErrInvalid = errors.Register(ModuleName, 6, "invalid value")
ErrUnauthorized = errors.Register(ModuleName, 7, "unauthorized")
ErrModified = errors.Register(ModuleName, 8, "modified")
ErrExpired = errors.Register(ModuleName, 9, "expired")
)

9
x/group/keys.go Normal file
View File

@ -0,0 +1,9 @@
package group
const (
// ModuleName is the module name constant used in many places
ModuleName = "group"
// StoreKey defines the primary module store key
StoreKey = ModuleName
)

29
x/group/proposal.go Normal file
View File

@ -0,0 +1,29 @@
package group
import (
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
)
func (p *Proposal) GetMsgs() []sdk.Msg {
msgs, err := tx.GetMsgs(p.Msgs, "proposal")
if err != nil {
panic(err)
}
return msgs
}
func (p *Proposal) SetMsgs(msgs []sdk.Msg) error {
anys, err := tx.SetMsgs(msgs)
if err != nil {
return err
}
p.Msgs = anys
return nil
}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (p Proposal) UnpackInterfaces(unpacker types.AnyUnpacker) error {
return tx.UnpackInterfaces(unpacker, p.Msgs)
}

5366
x/group/query.pb.go Normal file

File diff suppressed because it is too large Load Diff

5239
x/group/tx.pb.go Normal file

File diff suppressed because it is too large Load Diff

96
x/group/types.go Normal file
View File

@ -0,0 +1,96 @@
package group
import (
"fmt"
"time"
proto "github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/types"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
type DecisionPolicyResult struct {
Allow bool
Final bool
}
// DecisionPolicy is the persistent set of rules to determine the result of election on a proposal.
type DecisionPolicy interface {
codec.ProtoMarshaler
ValidateBasic() error
GetTimeout() types.Duration
Allow(tally Tally, totalPower string, votingDuration time.Duration) (DecisionPolicyResult, error)
Validate(g GroupInfo) error
}
// NewGroupAccountInfo creates a new GroupAccountInfo instance
func NewGroupAccountInfo(address sdk.AccAddress, group uint64, admin sdk.AccAddress, metadata []byte,
version uint64, decisionPolicy DecisionPolicy, derivationKey []byte) (GroupAccountInfo, error) {
p := GroupAccountInfo{
Address: address.String(),
GroupId: group,
Admin: admin.String(),
Metadata: metadata,
Version: version,
DerivationKey: derivationKey,
}
err := p.SetDecisionPolicy(decisionPolicy)
if err != nil {
return GroupAccountInfo{}, err
}
return p, nil
}
func (g *GroupAccountInfo) SetDecisionPolicy(decisionPolicy DecisionPolicy) error {
msg, ok := decisionPolicy.(proto.Message)
if !ok {
return fmt.Errorf("can't proto marshal %T", msg)
}
any, err := codectypes.NewAnyWithValue(msg)
if err != nil {
return err
}
g.DecisionPolicy = any
return nil
}
func (g GroupAccountInfo) GetDecisionPolicy() DecisionPolicy {
decisionPolicy, ok := g.DecisionPolicy.GetCachedValue().(DecisionPolicy)
if !ok {
return nil
}
return decisionPolicy
}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (g GroupAccountInfo) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var decisionPolicy DecisionPolicy
return unpacker.UnpackAny(g.DecisionPolicy, &decisionPolicy)
}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (q QueryGroupAccountsByGroupResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpackGroupAccounts(unpacker, q.GroupAccounts)
}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (q QueryGroupAccountsByAdminResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpackGroupAccounts(unpacker, q.GroupAccounts)
}
func unpackGroupAccounts(unpacker codectypes.AnyUnpacker, accs []*GroupAccountInfo) error {
for _, g := range accs {
err := g.UnpackInterfaces(unpacker)
if err != nil {
return err
}
}
return nil
}

3379
x/group/types.pb.go Normal file

File diff suppressed because it is too large Load Diff

View File

@ -112,6 +112,7 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
// module-specific gRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
proposal.RegisterQueryServer(cfg.QueryServer(), am.keeper)
}
// ProposalContents returns all the params content functions used to

View File

@ -1,11 +1,10 @@
package keeper
package types
import (
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/x/params/types"
)
// ConsensusParamsKeyTable returns an x/params module keyTable to be used in
@ -13,15 +12,15 @@ import (
// standard validation functions. Applications can choose to adopt this KeyTable
// or provider their own when the existing validation functions do not suite their
// needs.
func ConsensusParamsKeyTable() types.KeyTable {
return types.NewKeyTable(
types.NewParamSetPair(
func ConsensusParamsKeyTable() KeyTable {
return NewKeyTable(
NewParamSetPair(
baseapp.ParamStoreKeyBlockParams, abci.BlockParams{}, baseapp.ValidateBlockParams,
),
types.NewParamSetPair(
NewParamSetPair(
baseapp.ParamStoreKeyEvidenceParams, tmproto.EvidenceParams{}, baseapp.ValidateEvidenceParams,
),
types.NewParamSetPair(
NewParamSetPair(
baseapp.ParamStoreKeyValidatorParams, tmproto.ValidatorParams{}, baseapp.ValidateValidatorParams,
),
)

View File

@ -6,6 +6,7 @@ import (
"encoding/binary"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
v040auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v040"
)
@ -44,10 +45,9 @@ func ValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
// ValidatorSigningInfoAddress - extract the address from a validator signing info key
func ValidatorSigningInfoAddress(key []byte) (v sdk.ConsAddress) {
kv.AssertKeyAtLeastLength(key, 2)
addr := key[1:]
if len(addr) != v040auth.AddrLen {
panic("unexpected key length")
}
kv.AssertKeyLength(addr, v040auth.AddrLen)
return sdk.ConsAddress(addr)
}

View File

@ -5,6 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/types/kv"
)
const (
@ -43,6 +44,7 @@ func ValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
// ValidatorSigningInfoAddress - extract the address from a validator signing info key
func ValidatorSigningInfoAddress(key []byte) (v sdk.ConsAddress) {
// Remove prefix and address length.
kv.AssertKeyAtLeastLength(key, 3)
addr := key[2:]
return sdk.ConsAddress(addr)

View File

@ -22,12 +22,12 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) *MsgUnjail {
func (msg MsgUnjail) Route() string { return RouterKey }
func (msg MsgUnjail) Type() string { return TypeMsgUnjail }
func (msg MsgUnjail) GetSigners() []sdk.AccAddress {
func (msg MsgUnjail) GetSigners() []string {
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddr)
if err != nil {
panic(err)
}
return []sdk.AccAddress{valAddr.Bytes()}
return []string{sdk.AccAddress(valAddr).String()}
}
// GetSignBytes gets the bytes for the message signer to sign on

View File

@ -10,6 +10,7 @@ import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
v040auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v040"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
@ -66,6 +67,7 @@ func GetValidatorByConsAddrKey(addr sdk.ConsAddress) []byte {
// Get the validator operator address from LastValidatorPowerKey
func AddressFromLastValidatorPowerKey(key []byte) []byte {
kv.AssertKeyAtLeastLength(key, 2)
return key[1:] // remove prefix bytes
}
@ -112,9 +114,7 @@ func GetLastValidatorPowerKey(operator sdk.ValAddress) []byte {
// parse the validators operator address from power rank key
func ParseValidatorPowerRankKey(key []byte) (operAddr []byte) {
powerBytesLen := 8
if len(key) != 1+powerBytesLen+v040auth.AddrLen {
panic("Invalid validator power rank key length")
}
kv.AssertKeyLength(key, 1+powerBytesLen+v040auth.AddrLen)
operAddr = sdk.CopyBytes(key[powerBytesLen+1:])
@ -196,11 +196,11 @@ func GetUBDByValIndexKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte
// rearranges the ValIndexKey to get the UBDKey
func GetUBDKeyFromValIndexKey(indexKey []byte) []byte {
kv.AssertKeyAtLeastLength(indexKey, 2)
addrs := indexKey[1:] // remove prefix bytes
if len(addrs) != 2*v040auth.AddrLen {
panic("unexpected key length")
}
kv.AssertKeyLength(addrs, 2*v040auth.AddrLen)
kv.AssertKeyAtLeastLength(addrs, v040auth.AddrLen+1)
valAddr := addrs[:v040auth.AddrLen]
delAddr := addrs[v040auth.AddrLen:]
@ -268,9 +268,7 @@ func GetREDByValDstIndexKey(delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.V
// GetREDKeyFromValSrcIndexKey rearranges the ValSrcIndexKey to get the REDKey
func GetREDKeyFromValSrcIndexKey(indexKey []byte) []byte {
// note that first byte is prefix byte
if len(indexKey) != 3*v040auth.AddrLen+1 {
panic("unexpected key length")
}
kv.AssertKeyLength(indexKey, 3*v040auth.AddrLen+1)
valSrcAddr := indexKey[1 : v040auth.AddrLen+1]
delAddr := indexKey[v040auth.AddrLen+1 : 2*v040auth.AddrLen+1]
@ -282,9 +280,7 @@ func GetREDKeyFromValSrcIndexKey(indexKey []byte) []byte {
// GetREDKeyFromValDstIndexKey rearranges the ValDstIndexKey to get the REDKey
func GetREDKeyFromValDstIndexKey(indexKey []byte) []byte {
// note that first byte is prefix byte
if len(indexKey) != 3*v040auth.AddrLen+1 {
panic("unexpected key length")
}
kv.AssertKeyLength(indexKey, 3*v040auth.AddrLen+1)
valDstAddr := indexKey[1 : v040auth.AddrLen+1]
delAddr := indexKey[v040auth.AddrLen+1 : 2*v040auth.AddrLen+1]

View File

@ -9,6 +9,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/types/kv"
)
const (
@ -63,11 +64,13 @@ func GetValidatorByConsAddrKey(addr sdk.ConsAddress) []byte {
// AddressFromValidatorsKey creates the validator operator address from ValidatorsKey
func AddressFromValidatorsKey(key []byte) []byte {
kv.AssertKeyAtLeastLength(key, 3)
return key[2:] // remove prefix bytes and address length
}
// AddressFromLastValidatorPowerKey creates the validator operator address from LastValidatorPowerKey
func AddressFromLastValidatorPowerKey(key []byte) []byte {
kv.AssertKeyAtLeastLength(key, 3)
return key[2:] // remove prefix bytes and address length
}
@ -196,10 +199,13 @@ func GetUBDByValIndexKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte
// GetUBDKeyFromValIndexKey rearranges the ValIndexKey to get the UBDKey
func GetUBDKeyFromValIndexKey(indexKey []byte) []byte {
kv.AssertKeyAtLeastLength(indexKey, 2)
addrs := indexKey[1:] // remove prefix bytes
valAddrLen := addrs[0]
kv.AssertKeyAtLeastLength(addrs, 2+int(valAddrLen))
valAddr := addrs[1 : 1+valAddrLen]
kv.AssertKeyAtLeastLength(addrs, 3+int(valAddrLen))
delAddr := addrs[valAddrLen+2:]
return GetUBDKey(delAddr, valAddr)
@ -273,12 +279,16 @@ func GetREDByValDstIndexKey(delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.V
// GetREDKeyFromValSrcIndexKey rearranges the ValSrcIndexKey to get the REDKey
func GetREDKeyFromValSrcIndexKey(indexKey []byte) []byte {
// note that first byte is prefix byte, which we remove
kv.AssertKeyAtLeastLength(indexKey, 2)
addrs := indexKey[1:]
valSrcAddrLen := addrs[0]
kv.AssertKeyAtLeastLength(addrs, int(valSrcAddrLen)+2)
valSrcAddr := addrs[1 : valSrcAddrLen+1]
delAddrLen := addrs[valSrcAddrLen+1]
kv.AssertKeyAtLeastLength(addrs, int(valSrcAddrLen)+int(delAddrLen)+2)
delAddr := addrs[valSrcAddrLen+2 : valSrcAddrLen+2+delAddrLen]
kv.AssertKeyAtLeastLength(addrs, int(valSrcAddrLen)+int(delAddrLen)+4)
valDstAddr := addrs[valSrcAddrLen+delAddrLen+3:]
return GetREDKey(delAddr, valSrcAddr, valDstAddr)
@ -287,12 +297,16 @@ func GetREDKeyFromValSrcIndexKey(indexKey []byte) []byte {
// GetREDKeyFromValDstIndexKey rearranges the ValDstIndexKey to get the REDKey
func GetREDKeyFromValDstIndexKey(indexKey []byte) []byte {
// note that first byte is prefix byte, which we remove
kv.AssertKeyAtLeastLength(indexKey, 2)
addrs := indexKey[1:]
valDstAddrLen := addrs[0]
kv.AssertKeyAtLeastLength(addrs, int(valDstAddrLen)+2)
valDstAddr := addrs[1 : valDstAddrLen+1]
delAddrLen := addrs[valDstAddrLen+1]
kv.AssertKeyAtLeastLength(addrs, int(valDstAddrLen)+int(delAddrLen)+3)
delAddr := addrs[valDstAddrLen+2 : valDstAddrLen+2+delAddrLen]
kv.AssertKeyAtLeastLength(addrs, int(valDstAddrLen)+int(delAddrLen)+4)
valSrcAddr := addrs[valDstAddrLen+delAddrLen+3:]
return GetREDKey(delAddr, valSrcAddr, valDstAddr)

View File

@ -1,8 +1,6 @@
package types
import (
"bytes"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -62,19 +60,17 @@ func (msg MsgCreateValidator) Type() string { return TypeMsgCreateValidator }
// must sign over msg.GetSignBytes().
// If the validator address is not same as delegator's, then the validator must
// sign the msg as well.
func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress {
func (msg MsgCreateValidator) GetSigners() []string {
// delegator is first signer so delegator pays fees
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddress)
addrs := []string{msg.DelegatorAddress}
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
if err != nil {
panic(err)
}
addrs := []sdk.AccAddress{delAddr}
addr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
if err != nil {
panic(err)
}
if !bytes.Equal(delAddr.Bytes(), addr.Bytes()) {
addrs = append(addrs, sdk.AccAddress(addr))
valAccAddr := sdk.AccAddress(valAddr).String()
if msg.DelegatorAddress != valAccAddr {
addrs = append(addrs, valAccAddr)
}
return addrs
@ -167,12 +163,12 @@ func (msg MsgEditValidator) Route() string { return RouterKey }
func (msg MsgEditValidator) Type() string { return TypeMsgEditValidator }
// GetSigners implements the sdk.Msg interface.
func (msg MsgEditValidator) GetSigners() []sdk.AccAddress {
func (msg MsgEditValidator) GetSigners() []string {
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{valAddr.Bytes()}
return []string{sdk.AccAddress(valAddr).String()}
}
// GetSignBytes implements the sdk.Msg interface.
@ -224,12 +220,8 @@ func (msg MsgDelegate) Route() string { return RouterKey }
func (msg MsgDelegate) Type() string { return TypeMsgDelegate }
// GetSigners implements the sdk.Msg interface.
func (msg MsgDelegate) GetSigners() []sdk.AccAddress {
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{delAddr}
func (msg MsgDelegate) GetSigners() []string {
return []string{msg.DelegatorAddress}
}
// GetSignBytes implements the sdk.Msg interface.
@ -278,12 +270,8 @@ func (msg MsgBeginRedelegate) Route() string { return RouterKey }
func (msg MsgBeginRedelegate) Type() string { return TypeMsgBeginRedelegate }
// GetSigners implements the sdk.Msg interface
func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress {
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{delAddr}
func (msg MsgBeginRedelegate) GetSigners() []string {
return []string{msg.DelegatorAddress}
}
// GetSignBytes implements the sdk.Msg interface.
@ -333,12 +321,8 @@ func (msg MsgUndelegate) Route() string { return RouterKey }
func (msg MsgUndelegate) Type() string { return TypeMsgUndelegate }
// GetSigners implements the sdk.Msg interface.
func (msg MsgUndelegate) GetSigners() []sdk.AccAddress {
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{delAddr}
func (msg MsgUndelegate) GetSigners() []string {
return []string{msg.DelegatorAddress}
}
// GetSignBytes implements the sdk.Msg interface.