-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontract.rs
50 lines (46 loc) · 1.5 KB
/
contract.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use cosmwasm_std::{Binary, Deps, DepsMut, entry_point, Env, MessageInfo, Reply, Response, StdResult, SubMsg, SubMsgResult, to_json_binary};
use cw_storage_plus::Item;
use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: InstantiateMsg,
) -> Result<Response, ContractError> {
Ok(Response::new()
.add_attribute("action", "instantiate"))
}
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
let mut res = Response::new();
match msg {
ExecuteMsg::CosmosMsg(cosmos_msg) => {
res.messages.push(SubMsg::new(cosmos_msg));
}
ExecuteMsg::Loop(n) => {
let storage = Item::new("demo");
for i in 0..n {
storage.save(deps.storage, &i.to_string())?;
}
}
}
Ok(res)
}
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> StdResult<Binary> {
Ok(Binary::from(&[]))
}
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(_deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractError> {
match msg.result {
SubMsgResult::Ok(_) => Ok(Response::default()),
SubMsgResult::Err(_) => Err(ContractError::Unauthorized {}),
}
}