Skip to content

Commit

Permalink
Use vanilla cw721 queries for collection
Browse files Browse the repository at this point in the history
  • Loading branch information
MightOfOaks committed Sep 7, 2023
1 parent 171c41e commit fde6b8c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 38 deletions.
28 changes: 6 additions & 22 deletions contracts/vip/collection/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
use cosmwasm_std::entry_point;
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};

Check warning on line 3 in contracts/vip/collection/src/contract.rs

View workflow job for this annotation

GitHub Actions / Lint

unused import: `to_binary`
use cw2::set_contract_version;
use cw721::Cw721Query;
use cw721::{Cw721Query};

Check warning on line 5 in contracts/vip/collection/src/contract.rs

View workflow job for this annotation

GitHub Actions / Lint

unused import: `Cw721Query`
use cw721_base::InstantiateMsg;

use crate::error::ContractError;
use crate::msg::QueryMsg;
use crate::{ExecuteMsg, VipCollection};
use crate::{ExecuteMsg, QueryMsg, VipCollection};

const CONTRACT_NAME: &str = "crates.io:stargaze-vip-collection";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -59,31 +58,16 @@ pub fn execute(
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Metadata { token_id } => {
to_binary(&VipCollection::default().nft_info(deps, token_id)?.extension)
}
QueryMsg::TotalStaked { owner } => to_binary(&query_total_staked(deps, owner)?),
}
}

/// Total staked is the sum of all staked amounts for a given owner. If
/// an owner has multiple items, it will iterate through all of them and
/// sum the staked amounts.
pub fn query_total_staked(deps: Deps, owner: String) -> StdResult<Binary> {
// TODO: get all tokens by owner of `address` (token_id)
// TODO: iterate through metadata to get total stake weight

todo!()
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
VipCollection::default().query(deps, env, msg)
}

#[cfg(test)]
mod tests {
use cosmwasm_std::Empty;
use cw_multi_test::{Contract, ContractWrapper};
use sg_std::StargazeMsgWrapper;

fn collection_contract() -> Box<dyn Contract<StargazeMsgWrapper>> {
fn collection_contract() -> Box<dyn Contract<Empty>> {
let contract = ContractWrapper::new(
crate::contract::instantiate,
crate::contract::execute,
Expand Down
2 changes: 2 additions & 0 deletions contracts/vip/collection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ mod error;
pub mod msg;
pub mod state;
use cosmwasm_std::Empty;
use schemars::JsonSchema;

Check warning on line 6 in contracts/vip/collection/src/lib.rs

View workflow job for this annotation

GitHub Actions / Lint

unused import: `schemars::JsonSchema`
use state::Metadata;

pub use crate::error::ContractError;

pub type VipCollection<'a> = cw721_base::Cw721Contract<'a, Metadata, Empty, Empty, Empty>;

pub type ExecuteMsg = cw721_base::ExecuteMsg<Metadata, Empty>;
pub type QueryMsg = cw721_base::QueryMsg<Empty>;
3 changes: 0 additions & 3 deletions contracts/vip/collection/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Uint128;

use crate::state::Metadata;

Expand All @@ -8,6 +7,4 @@ use crate::state::Metadata;
pub enum QueryMsg {
#[returns(Metadata)]
Metadata { token_id: String },
#[returns(Uint128)]
TotalStaked { owner: String },
}
21 changes: 8 additions & 13 deletions contracts/vip/minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use std::env;
use cosmwasm_std::entry_point;
use cosmwasm_std::{
ensure, instantiate2_address, to_binary, Addr, Binary, CodeInfoResponse, ContractInfoResponse,
Deps, DepsMut, Env, Event, MessageInfo, StdError, StdResult, Timestamp, Uint128, WasmMsg,
Deps, DepsMut, Env, Event, MessageInfo, Response, StdError, StdResult, Timestamp, Uint128, WasmMsg,
};
use cw2::set_contract_version;
use sg_std::Response;

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
Expand Down Expand Up @@ -252,19 +251,15 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
#[cfg(test)]
mod tests {
use crate::msg::InstantiateMsg;
use crate::sudo;
use cosmwasm_std::{to_binary, Addr, Event, WasmMsg};
use cw_multi_test::{Contract, ContractWrapper, Executor};
use sg_multi_test::StargazeApp;
use sg_std::StargazeMsgWrapper;

fn minter_contract() -> Box<dyn Contract<StargazeMsgWrapper>> {
let contract = ContractWrapper::new(super::instantiate, super::execute, super::query)
.with_sudo(sudo::sudo);
use cosmwasm_std::{to_binary, Addr, Event, WasmMsg, Empty};
use cw_multi_test::{App, Contract, ContractWrapper, Executor};

fn minter_contract() -> Box<dyn Contract<Empty>> {
let contract = ContractWrapper::new(super::instantiate, super::execute, super::query);
Box::new(contract)
}

fn collection_contract() -> Box<dyn Contract<StargazeMsgWrapper>> {
fn collection_contract() -> Box<dyn Contract<Empty>> {
let contract = ContractWrapper::new(
stargaze_vip_collection::contract::execute,
stargaze_vip_collection::contract::instantiate,
Expand All @@ -274,7 +269,7 @@ mod tests {
}
#[test]
fn try_instantiate() {
let mut app = StargazeApp::default();
let mut app = App::default();
let minter_code_id = app.store_code(minter_contract());
let collection_code_id = app.store_code(collection_contract());

Expand Down

0 comments on commit fde6b8c

Please sign in to comment.