Skip to content

Commit

Permalink
one file contract
Browse files Browse the repository at this point in the history
  • Loading branch information
byeongsu-hong committed Oct 6, 2023
1 parent ec87d7d commit 51fc78b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
35 changes: 0 additions & 35 deletions contracts/test-querier/src/contract.rs

This file was deleted.

37 changes: 36 additions & 1 deletion contracts/test-querier/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
#[cfg(not(feature = "library"))]
pub mod contract;
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_vec, ContractResult, Deps, DepsMut, Empty, Env, MessageInfo, QueryRequest, QueryResponse,
Response, StdError, StdResult, SystemResult,
};

pub const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg(not(feature = "library"))]
#[entry_point]
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: Empty,
) -> StdResult<Response> {
cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

Ok(Response::new())
}

#[cfg(not(feature = "library"))]
#[entry_point]
pub fn query(deps: Deps, _env: Env, msg: QueryRequest<Empty>) -> StdResult<QueryResponse> {
let req_bin = to_vec(&msg).map_err(|serialize_err| {
StdError::generic_err(format!("Serializing QueryRequest: {serialize_err}"))
})?;

match deps.querier.raw_query(&req_bin) {
SystemResult::Err(system_err) => Err(StdError::generic_err(format!(
"Querier system error: {system_err}"
))),
SystemResult::Ok(ContractResult::Err(contract_err)) => Err(StdError::generic_err(format!(
"Querier contract error: {contract_err}"
))),
SystemResult::Ok(ContractResult::Ok(value)) => Ok(value),
}
}

0 comments on commit 51fc78b

Please sign in to comment.