cli icon indicating copy to clipboard operation
cli copied to clipboard

add `authz` command set

Open gjermundgaraba opened this issue 3 years ago • 0 comments

Authz is one of those things that creates a whole new set of use cases on Cosmos chains. Validators provide auto-compounding services. You can give your hot wallet permissions to vote with the stake from your cold wallet. The list goes on.

One of pains when using Authz with CLI's in a multi-chain world is that you have to maintain multiple binaries and keyrings (one for each chain).

If the ignite cli could provide a single CLI where you could interact with any authz-enabled cosmos chain (obviously, also including local ones you are developing and testing against) it would be valuable for end-users, validators and anyone wanting to create automation scripts much easier.

The solution is similar to what is outlined for the ignite node bank commands (#2489).

Implement the following commands:

  • ignite node query authz grantee-grants
  • ignite node query authz granter-grants
  • ignite node query authz grants
  • ignite node tx authz exec
  • ignite node tx authz grant
  • ignite node tx authz revoke

All the commands need the --rpc flag. The query commands also need the pagination flags. The tx commands also need gas, keyring and --generate-only flags

Take a look at for instance the gaiad query/tx authz command commands to see which other flags we might need. You can also look at the flags implemented for ignite node query bank balances and ignite node tx bank send to see what some of the basic flags are and how they are implemented.

For the grant and revoke commands, notice especially the --msg-type, --spend-limit, --expiration, --allowed-validators and --deny-validators flags

Please note that we need to define their respective top level commands for the above commands.

In the ignite/cmd package we should create a file for each command (some already exist):

cmd/
    node.go 
    node_query.go
    node_query_authz.go
    node_query_authz_grantee_grants.go
    node_query_authz_granter_grants.go
    node_query_authz_grants.go
    node_tx.go
    node_tx_authz.go
    node_tx_authz_exec.go
    node_tx_authz_grant.go
    node_tx_authz_revoke.go

You need to initialize ignite/pkg/cosmosclient inside ignite/cmd and have all the business logic implement there for these new commands.

So we need to implement the functions inside the cosmosclient package. Look at how this is already done for the bank commands.

These commands should be able to be used for any chain.

Sample usages:

  • ignite node q authz granter-grants [cosmos... / or / account-name ] --node https://rpc.cosmos.network:443
  • ignite node tx authz grant [cosmos... / or / account-name ] generic --msg-type --node https://rpc.cosmos.network:443

account-name above and also the value of --from taken from the account names when you use ignite account command set.

These balances and send commands pretty similar to the ones in gaiad but with an exception that we need to make them compatible with all Cosmos-SDK based chains and make it use accounts from ignite account.

Make sure to add an integration test that will:

  • Scaffold a chain with a custom address prefix
  • Grant different types of grants <authorization_type="send"|"generic"|"delegate"|"unbond"|"redelegate">
  • Query the grants
  • Execute a ignite node tx authz exec command with the output from the ignite node tx bank send command (by using --generate-only and putting the output in a file)
  • Revoke grant
  • Try to execute again and see that it fails

gjermundgaraba avatar May 23 '22 20:05 gjermundgaraba