Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add x/authz SendAuthorization AllowList #12648

Merged
merged 26 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ec957e1
wip
likhita-809 Jul 20, 2022
f2a735d
wip
likhita-809 Jul 20, 2022
fb82d55
add cli tests
likhita-809 Jul 20, 2022
cc30409
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 21, 2022
a28e4c7
add changelog
likhita-809 Jul 21, 2022
68681aa
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 21, 2022
0ab505e
add validation for duplicate entry and related tests
likhita-809 Jul 21, 2022
e43a609
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 21, 2022
55df097
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 21, 2022
a26a9f1
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 22, 2022
ff0a2fd
address review comments
likhita-809 Jul 25, 2022
7567182
move account helpers from x/authz cli to auth account types
likhita-809 Jul 25, 2022
72a0004
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 25, 2022
922c69c
address more comments
likhita-809 Jul 25, 2022
90d4ffa
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 25, 2022
759710e
nit
likhita-809 Jul 25, 2022
2941e48
address review comments
likhita-809 Jul 26, 2022
e954aee
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 26, 2022
fd4ac1b
refactor code
likhita-809 Jul 26, 2022
e2ac025
fix tests
likhita-809 Jul 26, 2022
9de416c
address review comments
likhita-809 Jul 27, 2022
ec377e2
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 27, 2022
4ae7b7e
remove unncessary line
likhita-809 Jul 27, 2022
694803b
wip: fix test
likhita-809 Jul 27, 2022
96e705b
revert last changes
likhita-809 Jul 27, 2022
585fbc5
Merge branch 'main' into likhita/add-send-authz-allow-list
julienrbrt Jul 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* (x/authz) [#12648](https://github.com/cosmos/cosmos-sdk/pull/12648) Add an allow list, an optional list of addresses allowed to receive bank assests via authz MsgSend grant.
* (cli) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Add the `tendermint key-migrate` to perform Tendermint v0.35 DB key migration.
* (query) [#12253](https://github.com/cosmos/cosmos-sdk/pull/12253) Add `GenericFilteredPaginate` to the `query` package to improve UX.
* (telemetry) [#12405](https://github.com/cosmos/cosmos-sdk/pull/12405) Add _query_ calls metric to telemetry.
Expand Down Expand Up @@ -73,6 +74,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (x/authz) [#12648](https://github.com/cosmos/cosmos-sdk/pull/12648) Add an allow list, an optional list of addresses allowed to receive bank assests via authz MsgSend grant.
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
* (x/bank) [\#12593](https://github.com/cosmos/cosmos-sdk/pull/12593) Add `SpendableCoin` method to `BaseViewKeeper`
* (x/slashing) [#12581](https://github.com/cosmos/cosmos-sdk/pull/12581) Remove `x/slashing` legacy querier.
* (types) [\#12355](https://github.com/cosmos/cosmos-sdk/pull/12355) Remove the compile-time `types.DBbackend` variable. Removes usage of the same in server/util.go
Expand Down
168 changes: 152 additions & 16 deletions api/cosmos/bank/v1beta1/authz.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions proto/cosmos/bank/v1beta1/authz.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ message SendAuthorization {

repeated cosmos.base.v1beta1.Coin spend_limit = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];

// allow_list specifies the list of addresses to whom the grantee can send tokens on behalf of granter's
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
// account.
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
repeated string allow_list = 2;
}
30 changes: 29 additions & 1 deletion x/authz/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
FlagExpiration = "expiration"
FlagAllowedValidators = "allowed-validators"
FlagDenyValidators = "deny-validators"
FlagAllowList = "allow-list"
delegate = "delegate"
redelegate = "redelegate"
unbond = "unbond"
Expand Down Expand Up @@ -93,7 +94,21 @@ Examples:
return fmt.Errorf("spend-limit should be greater than zero")
}

authorization = bank.NewSendAuthorization(spendLimit)
allowList, err := cmd.Flags().GetStringSlice(FlagAllowList)
if err != nil {
return err
}

allowed, err := bech32toAccountAddresses(allowList)
if err != nil {
return err
}

authorization, err = bank.NewSendAuthorization(allowed, spendLimit)
if err != nil {
return err
}

case "generic":
msgType, err := cmd.Flags().GetString(FlagMsgType)
if err != nil {
Expand Down Expand Up @@ -184,6 +199,7 @@ Examples:
cmd.Flags().String(FlagSpendLimit, "", "SpendLimit for Send Authorization, an array of Coins allowed spend")
cmd.Flags().StringSlice(FlagAllowedValidators, []string{}, "Allowed validators addresses separated by ,")
cmd.Flags().StringSlice(FlagDenyValidators, []string{}, "Deny validators addresses separated by ,")
cmd.Flags().StringSlice(FlagAllowList, []string{}, "Allowed addresses grantee is allowed to send funds separated by ,")
cmd.Flags().Int64(FlagExpiration, 0, "Expire time as Unix timestamp. Set zero (0) for no expiry. Default is 0.")
return cmd
}
Expand Down Expand Up @@ -284,3 +300,15 @@ func bech32toValidatorAddresses(validators []string) ([]sdk.ValAddress, error) {
}
return vals, nil
}

func bech32toAccountAddresses(accAddrs []string) ([]sdk.AccAddress, error) {
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
addrs := make([]sdk.AccAddress, len(accAddrs))
for i, addr := range accAddrs {
accAddr, err := sdk.AccAddressFromBech32(addr)
if err != nil {
return nil, err
}
addrs[i] = accAddr
}
return addrs, nil
}
2 changes: 1 addition & 1 deletion x/authz/client/testutil/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (s *IntegrationTestSuite) TestQueryGranterGrantsGRPC() {
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/granter/%s", val.APIAddress, val.Address.String()),
false,
"",
7,
8,
},
}
for _, tc := range testCases {
Expand Down
15 changes: 13 additions & 2 deletions x/authz/client/testutil/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,18 @@ func (s *IntegrationTestSuite) TestQueryAuthorization() {
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
false,
`{"@type":"/cosmos.bank.v1beta1.SendAuthorization","spend_limit":[{"denom":"stake","amount":"100"}]}`,
`{"@type":"/cosmos.bank.v1beta1.SendAuthorization","spend_limit":[{"denom":"stake","amount":"100"}],"allow_list":[]}`,
},
{
"Valid txn with allowed list (json)",
[]string{
val.Address.String(),
s.grantee[3].String(),
typeMsgSend,
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
false,
fmt.Sprintf(`{"@type":"/cosmos.bank.v1beta1.SendAuthorization","spend_limit":[{"denom":"stake","amount":"88"}],"allow_list":["%s"]}`, s.grantee[4]),
},
}
for _, tc := range testCases {
Expand Down Expand Up @@ -221,7 +232,7 @@ func (s *IntegrationTestSuite) TestQueryGranterGrants() {
},
false,
"",
7,
8,
},
{
"valid case with pagination",
Expand Down
Loading