Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
feat: Add x/authz SendAuthorization AllowList (#12648)
Browse files Browse the repository at this point in the history
## Description

Closes: #12609 



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
likhita-809 authored Jul 27, 2022
1 parent df4339c commit 9f5ee97
Show file tree
Hide file tree
Showing 19 changed files with 514 additions and 59 deletions.
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.
* (sdk.Coins) [#12627](https://github.com/cosmos/cosmos-sdk/pull/12627) Make a Denoms method on sdk.Coins.

Expand All @@ -63,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (x/bank) [#12648](https://github.com/cosmos/cosmos-sdk/pull/12648) `NewSendAuthorization` takes a new argument of an optional list of addresses allowed to receive bank assests via authz MsgSend grant. You can pass `nil` for the same behavior as before, i.e. any recipient is allowed.
* (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
170 changes: 154 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.

6 changes: 6 additions & 0 deletions proto/cosmos/bank/v1beta1/authz.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ 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 an optional list of addresses to whom the grantee can send tokens on behalf of the
// granter. If omitted, any recipient is allowed.
//
// Since: cosmos-sdk 0.47
repeated string allow_list = 2;
}
35 changes: 31 additions & 4 deletions 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,18 @@ 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 := bech32toAccAddresses(allowList)
if err != nil {
return err
}

authorization = bank.NewSendAuthorization(spendLimit, allowed)

case "generic":
msgType, err := cmd.Flags().GetString(FlagMsgType)
if err != nil {
Expand Down Expand Up @@ -140,12 +152,12 @@ Examples:
delegateLimit = &spendLimit
}

allowed, err := bech32toValidatorAddresses(allowValidators)
allowed, err := bech32toValAddresses(allowValidators)
if err != nil {
return err
}

denied, err := bech32toValidatorAddresses(denyValidators)
denied, err := bech32toValAddresses(denyValidators)
if err != nil {
return err
}
Expand Down Expand Up @@ -184,6 +196,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 @@ -273,7 +286,8 @@ Example:
return cmd
}

func bech32toValidatorAddresses(validators []string) ([]sdk.ValAddress, error) {
// bech32toValAddresses returns []ValAddress from a list of Bech32 string addresses.
func bech32toValAddresses(validators []string) ([]sdk.ValAddress, error) {
vals := make([]sdk.ValAddress, len(validators))
for i, validator := range validators {
addr, err := sdk.ValAddressFromBech32(validator)
Expand All @@ -284,3 +298,16 @@ func bech32toValidatorAddresses(validators []string) ([]sdk.ValAddress, error) {
}
return vals, nil
}

// bech32toAccAddresses returns []AccAddress from a list of Bech32 string addresses.
func bech32toAccAddresses(accAddrs []string) ([]sdk.AccAddress, error) {
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
Loading

0 comments on commit 9f5ee97

Please sign in to comment.