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(evmutil): Add DeployedCosmosCoinContracts query #1605

Merged
merged 11 commits into from
Jun 2, 2023

Conversation

pirtleshell
Copy link
Member

Description

  • adds query for enumerating all deployed contract addresses for erc20s representing cosmos coins in the evm
  • includes cli command

this PR isn't as big as it looks, i promise! 😂 its ~200 lines of actual code and 250 lines of tests. the rest is proto generated things.

❯ kava q evmutil deployed-cosmos-coin-contracts --help
Query for deployed ERC20 contract addresses representing cosmos coins in the EVM

Usage:
  kava query evmutil deployed-cosmos-coin-contracts [--denoms denom1,denom2] [flags]

Examples:
Query all:
  kava q evmutil deployed-cosmos-coin-contracts

Query by denom:
  kava q evmutil deployed-cosmos-coin-contracts --denoms denom1,denom2

Flags:
      --count-total        count total number of records in deployed-cosmos-coin-contracts to query for
      --denoms strings     (optional) Cosmos denoms to get addresses for. If no contract is deployed, the result will be omitted. Limit 100 per query.
      --grpc-addr string   the gRPC endpoint to use for this chain
      --grpc-insecure      allow gRPC over insecure channels, if not TLS the server must use TLS
      --height int         Use a specific height to query state at (this can error if the node is pruning state)
  -h, --help               help for deployed-cosmos-coin-contracts
      --limit uint         pagination limit of deployed-cosmos-coin-contracts to query for (default 100)
      --node string        <host>:<port> to Tendermint RPC interface for this chain (default "tcp://localhost:26657")
      --offset uint        pagination offset of deployed-cosmos-coin-contracts to query for
  -o, --output string      Output format (text|json) (default "text")
      --page uint          pagination page of deployed-cosmos-coin-contracts to query for. This sets offset to a multiple of limit (default 1)
      --page-key string    pagination page-key of deployed-cosmos-coin-contracts to query for
      --reverse            results are sorted in descending order

There's no error when empty:

❯ curl -s http://localhost:1317/kava/evmutil/v1beta1/deployed_cosmos_coin_contracts | jq
{
  "deployed_cosmos_coin_contracts": [],
  "pagination": {
    "next_key": null,
    "total": "0"
  }
}

Here's the response with data:

❯ curl -s http://localhost:1317/kava/evmutil/v1beta1/deployed_cosmos_coin_contracts | jq
{
  "deployed_cosmos_coin_contracts": [
    {
      "cosmos_denom": "busd",
      "address": "0x15932E26f5BD4923d46a2b205191C4b5d5f43FE3"
    }
  ],
  "pagination": {
    "next_key": null,
    "total": "1"
  }
}

Checklist

  • Changelog has been updated as necessary.

Base automatically changed from rp-convert-cosmos-coin-events to master May 30, 2023 20:06
func getDeployedCosmosCoinContractsByDenoms(
k *Keeper, ctx sdk.Context, denoms []string,
) (*types.QueryDeployedCosmosCoinContractsResponse, error) {
if len(denoms) > query.DefaultLimit {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice glad this is limited and tested. This is a user parameter that causes a db lookup, so without a limit this endpoint could be used for a denial of service.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation is an interesting problem. It feels like there are cases where a range & filter would be superior over direct lookups, but definitely not for small numbers of filters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, range & filter would allow pagination on this endpoint when requested with a >100 denoms query, too. but i made the tradeoff with the assumption that the most common use cases were either

  1. looking up all contract addresses (no denoms in query)
  2. looking up contract address for only a handful of contracts (limited number of denoms in query)

i think the majority of the time, 2) is going to be more efficient with direct lookups. a larger factor was that this split between a method that paginates all results & a method that only does direct lookups on a list felt easier to read in the code than the single PaginateFilter that handled both cases.
a nice bonus is that denoms that exist are returned in the order they were requested in (though omitting missing denoms mean there's no guarantee that search index == result index)

@pirtleshell pirtleshell merged commit d500cd1 into master Jun 2, 2023
@pirtleshell pirtleshell deleted the rp-query-contract-addrs branch June 2, 2023 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants