From 789408d6e44bbe30508e0cc78886bd08139b61f2 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Sun, 6 Mar 2022 22:29:24 -0500 Subject: [PATCH 1/2] Change Addr to String in response --- contracts/minter/src/contract.rs | 6 +++--- contracts/minter/src/contract_tests.rs | 4 ++-- contracts/minter/src/msg.rs | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/contracts/minter/src/contract.rs b/contracts/minter/src/contract.rs index c8facfbe7..137962bf9 100644 --- a/contracts/minter/src/contract.rs +++ b/contracts/minter/src/contract.rs @@ -545,15 +545,15 @@ fn query_config(deps: Deps) -> StdResult { let sg721_address = SG721_ADDRESS.load(deps.storage)?; Ok(ConfigResponse { - admin: config.admin, + admin: config.admin.to_string(), base_token_uri: config.base_token_uri, - sg721_address, + sg721_address: sg721_address.to_string(), sg721_code_id: config.sg721_code_id, num_tokens: config.num_tokens, start_time: config.start_time, unit_price: config.unit_price, per_address_limit: config.per_address_limit, - whitelist: config.whitelist, + whitelist: config.whitelist.map(|w| w.to_string()), }) } diff --git a/contracts/minter/src/contract_tests.rs b/contracts/minter/src/contract_tests.rs index 76c522690..49b10d1fd 100644 --- a/contracts/minter/src/contract_tests.rs +++ b/contracts/minter/src/contract_tests.rs @@ -537,7 +537,7 @@ fn mint_count_query() { let (creator, buyer) = setup_accounts(&mut router); let num_tokens = 10; let (minter_addr, config) = setup_minter_contract(&mut router, &creator, num_tokens); - let sg721_addr = config.sg721_address; + let sg721_addr = Addr::unchecked(config.sg721_address); let whitelist_addr = setup_whitelist_contract(&mut router, &creator); const EXPIRATION_TIME: Timestamp = Timestamp::from_nanos(GENESIS_MINT_START_TIME + 10_000); @@ -895,7 +895,7 @@ fn whitelist_access_len_add_remove_expiration() { }; let res = router.execute_contract( buyer.clone(), - sg721_addr, + Addr::unchecked(sg721_addr), &transfer_msg, &coins_for_msg(coin(123, NATIVE_DENOM)), ); diff --git a/contracts/minter/src/msg.rs b/contracts/minter/src/msg.rs index af159fbfa..eae3f409a 100644 --- a/contracts/minter/src/msg.rs +++ b/contracts/minter/src/msg.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{Addr, Coin, Timestamp}; +use cosmwasm_std::{Coin, Timestamp}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -39,15 +39,15 @@ pub enum QueryMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct ConfigResponse { - pub admin: Addr, + pub admin: String, pub base_token_uri: String, pub num_tokens: u32, pub per_address_limit: u32, - pub sg721_address: Addr, + pub sg721_address: String, pub sg721_code_id: u64, pub start_time: Timestamp, pub unit_price: Coin, - pub whitelist: Option, + pub whitelist: Option, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] From c55ea7fb4346215fb91d4ea6726a44f6141c6134 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Sun, 6 Mar 2022 22:31:00 -0500 Subject: [PATCH 2/2] Update schema and types --- contracts/minter/schema/config_response.json | 18 +++++------------- types/contracts/minter/config.d.ts | 13 ++++++++++++- types/contracts/minter/config_response.d.ts | 8 ++++---- types/contracts/minter/shared-types.d.ts | 10 ---------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/contracts/minter/schema/config_response.json b/contracts/minter/schema/config_response.json index 91275a306..b400751e2 100644 --- a/contracts/minter/schema/config_response.json +++ b/contracts/minter/schema/config_response.json @@ -14,7 +14,7 @@ ], "properties": { "admin": { - "$ref": "#/definitions/Addr" + "type": "string" }, "base_token_uri": { "type": "string" @@ -30,7 +30,7 @@ "minimum": 0.0 }, "sg721_address": { - "$ref": "#/definitions/Addr" + "type": "string" }, "sg721_code_id": { "type": "integer", @@ -44,21 +44,13 @@ "$ref": "#/definitions/Coin" }, "whitelist": { - "anyOf": [ - { - "$ref": "#/definitions/Addr" - }, - { - "type": "null" - } + "type": [ + "string", + "null" ] } }, "definitions": { - "Addr": { - "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", - "type": "string" - }, "Coin": { "type": "object", "required": [ diff --git a/types/contracts/minter/config.d.ts b/types/contracts/minter/config.d.ts index 5f2009cf7..554f8cf51 100644 --- a/types/contracts/minter/config.d.ts +++ b/types/contracts/minter/config.d.ts @@ -1,4 +1,15 @@ -import { Addr, Coin, Timestamp } from "./shared-types"; +import { Coin, Timestamp } from "./shared-types"; + +/** + * A human readable address. + * + * In Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length. + * + * This type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances. + * + * This type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance. + */ +export type Addr = string export interface Config { admin: Addr diff --git a/types/contracts/minter/config_response.d.ts b/types/contracts/minter/config_response.d.ts index 0be670077..0c2d1d91d 100644 --- a/types/contracts/minter/config_response.d.ts +++ b/types/contracts/minter/config_response.d.ts @@ -1,14 +1,14 @@ -import { Addr, Coin, Timestamp } from "./shared-types"; +import { Coin, Timestamp } from "./shared-types"; export interface ConfigResponse { -admin: Addr +admin: string base_token_uri: string num_tokens: number per_address_limit: number -sg721_address: Addr +sg721_address: string sg721_code_id: number start_time: Timestamp unit_price: Coin -whitelist?: (Addr | null) +whitelist?: (string | null) [k: string]: unknown } diff --git a/types/contracts/minter/shared-types.d.ts b/types/contracts/minter/shared-types.d.ts index e9042488e..cc2d8aeb7 100644 --- a/types/contracts/minter/shared-types.d.ts +++ b/types/contracts/minter/shared-types.d.ts @@ -1,13 +1,3 @@ -/** - * A human readable address. - * - * In Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length. - * - * This type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances. - * - * This type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance. - */ -export type Addr = string; /** * A point in time in nanosecond precision. *