Skip to content

Commit

Permalink
Remove wrapper response types for single value queries (#225)
Browse files Browse the repository at this point in the history
* Use QueryResponses

* Use QueryResponses for name mitner

* Use QueryResponses for name whitelist

* Remove ParamResponse

* Use single value queries for Name Marketplace

* Update schema

* Upgraded ts-codegen
  • Loading branch information
shanev authored Dec 7, 2022
1 parent 3a150ec commit 2e6e681
Show file tree
Hide file tree
Showing 36 changed files with 800 additions and 1,184 deletions.
298 changes: 89 additions & 209 deletions contracts/marketplace/schema/name-marketplace.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions contracts/marketplace/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
msg::{BidResponse, ExecuteMsg, QueryMsg},
msg::{ExecuteMsg, QueryMsg},
state::Bid,
};
use cosmwasm_schema::cw_serde;
Expand Down Expand Up @@ -34,14 +34,14 @@ impl NameMarketplaceContract {
}

pub fn highest_bid(&self, querier: &QuerierWrapper, token_id: &str) -> StdResult<Option<Bid>> {
let res: BidResponse = querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
let res: Option<Bid> = querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: self.addr().into(),
msg: to_binary(&QueryMsg::HighestBid {
token_id: token_id.to_string(),
})?,
}))?;

Ok(res.bid)
Ok(res)
}

// contract needs approval from nft owner before accepting bid
Expand Down
58 changes: 14 additions & 44 deletions contracts/marketplace/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,64 +109,64 @@ impl BidOffset {
#[derive(QueryResponses)]
pub enum QueryMsg {
/// Get the current ask for specific name
#[returns(AskResponse)]
#[returns(Option<Ask>)]
Ask { token_id: TokenId },
/// Get all asks for a collection
#[returns(AsksResponse)]
#[returns(Vec<Ask>)]
Asks {
start_after: Option<Id>,
limit: Option<u32>,
},
/// Get all asks in reverse
#[returns(AsksResponse)]
#[returns(Vec<Ask>)]
ReverseAsks {
start_before: Option<Id>,
limit: Option<u32>,
},
/// Count of all asks
#[returns(AskCountResponse)]
#[returns(u64)]
AskCount {},
/// Get all asks by seller
#[returns(AsksResponse)]
#[returns(Vec<Ask>)]
AsksBySeller {
seller: Seller,
start_after: Option<TokenId>,
limit: Option<u32>,
},
/// Get data for a specific bid
#[returns(BidResponse)]
#[returns(Option<Bid>)]
Bid { token_id: TokenId, bidder: Bidder },
/// Get all bids by a bidder
#[returns(BidsResponse)]
#[returns(Vec<Bid>)]
BidsByBidder {
bidder: Bidder,
start_after: Option<TokenId>,
limit: Option<u32>,
},
/// Get all bids for a specific NFT
#[returns(BidsResponse)]
#[returns(Vec<Bid>)]
Bids {
token_id: TokenId,
start_after: Option<Bidder>,
limit: Option<u32>,
},
/// Get all bids for a collection, sorted by price
#[returns(BidsResponse)]
#[returns(Vec<Bid>)]
BidsSortedByPrice {
start_after: Option<BidOffset>,
limit: Option<u32>,
},
/// Get all bids for a collection, sorted by price in reverse
#[returns(BidsResponse)]
#[returns(Vec<Bid>)]
ReverseBidsSortedByPrice {
start_before: Option<BidOffset>,
limit: Option<u32>,
},
/// Get all bids for a specific account
#[returns(BidsResponse)]
#[returns(Vec<Bid>)]
BidsForSeller { seller: String },
/// Get the highest bid for a name
#[returns(BidResponse)]
#[returns(Option<Bid>)]
HighestBid { token_id: TokenId },
/// Show all registered ask hooks
#[returns(HooksResponse)]
Expand All @@ -178,10 +178,10 @@ pub enum QueryMsg {
#[returns(HooksResponse)]
SaleHooks {},
/// Get the config for the contract
#[returns(ParamsResponse)]
#[returns(SudoParams)]
Params {},
/// Get the renewal queue for a specific time
#[returns(AsksResponse)]
#[returns(Vec<Ask>)]
RenewalQueue { time: Timestamp },
/// Get the minter and collection
#[returns(ConfigResponse)]
Expand All @@ -194,36 +194,6 @@ pub struct ConfigResponse {
pub collection: Addr,
}

#[cw_serde]
pub struct AskResponse {
pub ask: Option<Ask>,
}

#[cw_serde]
pub struct AsksResponse {
pub asks: Vec<Ask>,
}

#[cw_serde]
pub struct AskCountResponse {
pub count: u32,
}

#[cw_serde]
pub struct BidResponse {
pub bid: Option<Bid>,
}

#[cw_serde]
pub struct BidsResponse {
pub bids: Vec<Bid>,
}

#[cw_serde]
pub struct ParamsResponse {
pub params: SudoParams,
}

#[cw_serde]
pub struct SaleHookMsg {
pub token_id: String,
Expand Down
Loading

0 comments on commit 2e6e681

Please sign in to comment.