From 1534b62d8de7dbc2d0411fd8820aef513238c30f Mon Sep 17 00:00:00 2001 From: Nikhil Suri Date: Fri, 24 Mar 2023 21:25:06 +0000 Subject: [PATCH 1/8] types: Add AllDenomMetadata BankQuery --- internal/api/lib_test.go | 2 +- types/queries.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/api/lib_test.go b/internal/api/lib_test.go index f00924db2..1f5e37d0d 100644 --- a/internal/api/lib_test.go +++ b/internal/api/lib_test.go @@ -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 diff --git a/types/queries.go b/types/queries.go index db7e01ecd..acf79a1ce 100644 --- a/types/queries.go +++ b/types/queries.go @@ -90,9 +90,10 @@ 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"` + AllDenomMetadata *AllDenomMetadataQuery `json:"all_denom_metadata,omitempty"` } type SupplyQuery struct { @@ -123,6 +124,8 @@ type AllBalancesResponse struct { Amount Coins `json:"amount"` } +type AllDenomMetadataQuery struct{} + // 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 { From 3013e81d2cb9018fe979a93d958abde509182e1b Mon Sep 17 00:00:00 2001 From: Nikhil Suri Date: Wed, 29 Mar 2023 21:24:53 +0000 Subject: [PATCH 2/8] types: Add DenomMetadata BankQuery and response type for AllDenomMetadata BankQuery --- types/queries.go | 19 +++++++++++++- types/types.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/types/queries.go b/types/queries.go index acf79a1ce..cf712b112 100644 --- a/types/queries.go +++ b/types/queries.go @@ -93,6 +93,7 @@ type BankQuery struct { Supply *SupplyQuery `json:"supply,omitempty"` Balance *BalanceQuery `json:"balance,omitempty"` AllBalances *AllBalancesQuery `json:"all_balances,omitempty"` + DenomMetadata *DenomMetadataQuery `json:"get_denom_metadata,omitempty"` AllDenomMetadata *AllDenomMetadataQuery `json:"all_denom_metadata,omitempty"` } @@ -124,7 +125,23 @@ type AllBalancesResponse struct { Amount Coins `json:"amount"` } -type AllDenomMetadataQuery struct{} +type DenomMetadataQuery struct { + Denom string `json:"denom"` +} + +type DenomMetadataResponse struct { + Metadata DenomMetadata `json:"metadata"` +} + +type AllDenomMetadataQuery struct { + // optional argument + // default pagination will be used if this is omitted + Pagination *PageRequest `json:"pagination,omitempty"` +} + +type AllDenomMetadataResponse struct { + Metadata []DenomMetadata `json:"metadata"` +} // 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). diff --git a/types/types.go b/types/types.go index f67b566de..929d9ff93 100644 --- a/types/types.go +++ b/types/types.go @@ -50,6 +50,74 @@ func (c *Coins) UnmarshalJSON(data []byte) error { return nil } +// Replicating the cosmos-sdk bank module Metadata type +type DenomMetadata struct { + Description string `json:"description"` + // denom_units represents the list of DenomUnit's 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"` +} + +// Replicating the PageRequest type for pagination from the cosmos-sdk +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"` + // offset is a numeric offset that can be used when key is unavailable. + // It is less efficient than using key. Only one of offset or key should + // be set. + Offset uint64 `json:"offset"` + // 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 uint64 `json:"limit"` + // count_total is set to true to indicate that the result set should include + // a count of the total number of items available for pagination in UIs. + // count_total is only respected when offset is used. It is ignored when key + // is set. + CountTotal bool `json:"count_total"` + // reverse is set to true if results are to be returned in the descending order. + // + // Since: cosmos-sdk 0.43 + Reverse bool `json:"reverse"` +} + type OutOfGasError struct{} var _ error = OutOfGasError{} From 9825f43d91b228c122e6d9b1d4b63ad15850fdd0 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 31 May 2023 16:18:46 +0200 Subject: [PATCH 3/8] Use simplified pagination type --- types/types.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/types/types.go b/types/types.go index 929d9ff93..b903254ef 100644 --- a/types/types.go +++ b/types/types.go @@ -94,24 +94,15 @@ type DenomUnit struct { Aliases []string `json:"aliases"` } -// Replicating the PageRequest type for pagination from the cosmos-sdk +// 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"` - // offset is a numeric offset that can be used when key is unavailable. - // It is less efficient than using key. Only one of offset or key should - // be set. - Offset uint64 `json:"offset"` // 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 uint64 `json:"limit"` - // count_total is set to true to indicate that the result set should include - // a count of the total number of items available for pagination in UIs. - // count_total is only respected when offset is used. It is ignored when key - // is set. - CountTotal bool `json:"count_total"` // reverse is set to true if results are to be returned in the descending order. // // Since: cosmos-sdk 0.43 From b572c1d9491c8f56e870f5b5c6e0b8f2699653d3 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 31 May 2023 16:19:19 +0200 Subject: [PATCH 4/8] Return next key in paginated metadata response --- types/queries.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/queries.go b/types/queries.go index cf712b112..2b271ba0c 100644 --- a/types/queries.go +++ b/types/queries.go @@ -141,6 +141,10 @@ type AllDenomMetadataQuery struct { type AllDenomMetadataResponse struct { Metadata []DenomMetadata `json:"metadata"` + // next_key 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. From 6f1bef7ca29eb180db91e693fac232d2ef79a82e Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 9 Jun 2023 10:34:49 +0200 Subject: [PATCH 5/8] Use uint32 for pagination limit --- types/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/types.go b/types/types.go index b903254ef..31b2bddb7 100644 --- a/types/types.go +++ b/types/types.go @@ -102,7 +102,7 @@ type PageRequest struct { 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 uint64 `json:"limit"` + Limit uint32 `json:"limit"` // reverse is set to true if results are to be returned in the descending order. // // Since: cosmos-sdk 0.43 From 590fae2f3cf3a2f392f7767cf0949ef5514731d2 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 12 Jun 2023 09:34:57 +0200 Subject: [PATCH 6/8] Apply pr feedback --- types/queries.go | 6 +++--- types/types.go | 24 +++++++++++------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/types/queries.go b/types/queries.go index 2b271ba0c..9144fa4d0 100644 --- a/types/queries.go +++ b/types/queries.go @@ -134,14 +134,14 @@ type DenomMetadataResponse struct { } type AllDenomMetadataQuery struct { - // optional argument - // default pagination will be used if this is omitted + // 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"` - // next_key is the key to be passed to PageRequest.key to + // 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"` diff --git a/types/types.go b/types/types.go index 31b2bddb7..07d829b63 100644 --- a/types/types.go +++ b/types/types.go @@ -53,18 +53,18 @@ func (c *Coins) UnmarshalJSON(data []byte) error { // Replicating the cosmos-sdk bank module Metadata type type DenomMetadata struct { Description string `json:"description"` - // denom_units represents the list of DenomUnit's for a given coin + // 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 represents the base denom (should be the DenomUnit with exponent = 0). Base string `json:"base"` - // display indicates the suggested denom that should be + // 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) + // 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 + // Symbol is the token symbol usually shown on exchanges (eg: ATOM). This can // be the same as the display. // // Since: cosmos-sdk 0.43 @@ -82,30 +82,28 @@ type DenomMetadata struct { // 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 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 + // 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 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 + // 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. + // 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. - // - // Since: cosmos-sdk 0.43 + // Reverse is set to true if results are to be returned in the descending order. Reverse bool `json:"reverse"` } From 0618fb1d06f685b935295f253ebc17edcc867dd5 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 5 Jul 2023 10:39:00 +0200 Subject: [PATCH 7/8] Fix DenomMetadata json key --- types/queries.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/queries.go b/types/queries.go index 9144fa4d0..9b0c963e5 100644 --- a/types/queries.go +++ b/types/queries.go @@ -93,7 +93,7 @@ type BankQuery struct { Supply *SupplyQuery `json:"supply,omitempty"` Balance *BalanceQuery `json:"balance,omitempty"` AllBalances *AllBalancesQuery `json:"all_balances,omitempty"` - DenomMetadata *DenomMetadataQuery `json:"get_denom_metadata,omitempty"` + DenomMetadata *DenomMetadataQuery `json:"denom_metadata,omitempty"` AllDenomMetadata *AllDenomMetadataQuery `json:"all_denom_metadata,omitempty"` } From b39e91de903a655d54815edc4a4356acd4622ca3 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 5 Jul 2023 11:30:28 +0200 Subject: [PATCH 8/8] Remove pointer --- types/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/types.go b/types/types.go index 07d829b63..aa2cecdac 100644 --- a/types/types.go +++ b/types/types.go @@ -54,7 +54,7 @@ func (c *Coins) UnmarshalJSON(data []byte) error { type DenomMetadata struct { Description string `json:"description"` // DenomUnits represents the list of DenomUnits for a given coin - DenomUnits []*DenomUnit `json:"denom_units"` + 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