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

Add AllDenomMetadata BankQuery #430

Merged
merged 8 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

const (
TESTING_CAPABILITIES = "staking,stargate,iterator,cosmwasm_1_1,cosmwasm_1_2"
TESTING_CAPABILITIES = "staking,stargate,iterator,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3"
TESTING_PRINT_DEBUG = false
TESTING_GAS_LIMIT = uint64(500_000_000_000) // ~0.5ms
TESTING_MEMORY_LIMIT = 32 // MiB
Expand Down
30 changes: 27 additions & 3 deletions types/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ type QueryRequest struct {
}

type BankQuery struct {
Supply *SupplyQuery `json:"supply,omitempty"`
Balance *BalanceQuery `json:"balance,omitempty"`
AllBalances *AllBalancesQuery `json:"all_balances,omitempty"`
Supply *SupplyQuery `json:"supply,omitempty"`
Balance *BalanceQuery `json:"balance,omitempty"`
AllBalances *AllBalancesQuery `json:"all_balances,omitempty"`
DenomMetadata *DenomMetadataQuery `json:"denom_metadata,omitempty"`
AllDenomMetadata *AllDenomMetadataQuery `json:"all_denom_metadata,omitempty"`
}

type SupplyQuery struct {
Expand Down Expand Up @@ -123,6 +125,28 @@ type AllBalancesResponse struct {
Amount Coins `json:"amount"`
}

type DenomMetadataQuery struct {
Denom string `json:"denom"`
}

type DenomMetadataResponse struct {
Metadata DenomMetadata `json:"metadata"`
}

type AllDenomMetadataQuery struct {
// Pagination is an optional argument.
// Default pagination will be used if this is omitted
Pagination *PageRequest `json:"pagination,omitempty"`
}

type AllDenomMetadataResponse struct {
Metadata []DenomMetadata `json:"metadata"`
// NextKey is the key to be passed to PageRequest.key to
// query the next page most efficiently. It will be empty if
// there are no more results.
NextKey []byte `json:"next_key,omitempty"`
}

// IBCQuery defines a query request from the contract into the chain.
// This is the counterpart of [IbcQuery](https://github.com/CosmWasm/cosmwasm/blob/v0.14.0-beta1/packages/std/src/ibc.rs#L61-L83).
type IBCQuery struct {
Expand Down
57 changes: 57 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,63 @@ func (c *Coins) UnmarshalJSON(data []byte) error {
return nil
}

// Replicating the cosmos-sdk bank module Metadata type
type DenomMetadata struct {
Description string `json:"description"`
// DenomUnits represents the list of DenomUnits for a given coin
DenomUnits []DenomUnit `json:"denom_units"`
// Base represents the base denom (should be the DenomUnit with exponent = 0).
Base string `json:"base"`
// Display indicates the suggested denom that should be
// displayed in clients.
Display string `json:"display"`
// Name defines the name of the token (eg: Cosmos Atom)
//
// Since: cosmos-sdk 0.43
Name string `json:"name"`
// Symbol is the token symbol usually shown on exchanges (eg: ATOM). This can
// be the same as the display.
//
// Since: cosmos-sdk 0.43
Symbol string `json:"symbol"`
// URI to a document (on or off-chain) that contains additional information. Optional.
//
// Since: cosmos-sdk 0.46
URI string `json:"uri"`
// URIHash is a sha256 hash of a document pointed by URI. It's used to verify that
// the document didn't change. Optional.
//
// Since: cosmos-sdk 0.46
URIHash string `json:"uri_hash"`
}

// Replicating the cosmos-sdk bank module DenomUnit type
type DenomUnit struct {
// Denom represents the string name of the given denom unit (e.g uatom).
Denom string `json:"denom"`
// Exponent represents power of 10 exponent that one must
// raise the base_denom to in order to equal the given DenomUnit's denom
// 1 denom = 10^exponent base_denom
// (e.g. with a base_denom of uatom, one can create a DenomUnit of 'atom' with
// exponent = 6, thus: 1 atom = 10^6 uatom).
Exponent uint32 `json:"exponent"`
// Aliases is a list of string aliases for the given denom
Aliases []string `json:"aliases"`
}

// Simplified version of the cosmos-sdk PageRequest type
type PageRequest struct {
// Key is a value returned in PageResponse.next_key to begin
// querying the next page most efficiently. Only one of offset or key
// should be set.
Key []byte `json:"key"`
// Limit is the total number of results to be returned in the result page.
// If left empty it will default to a value to be set by each app.
Limit uint32 `json:"limit"`
// Reverse is set to true if results are to be returned in the descending order.
Reverse bool `json:"reverse"`
}

type OutOfGasError struct{}

var _ error = OutOfGasError{}
Expand Down