mirror of
https://github.com/BiPhan4/DefiHackathon-2022.git
synced 2025-04-02 10:41:42 -04:00
added payup funtion and other stuff related to that in other files
This commit is contained in:
parent
287f2d6c7f
commit
c4e8bd2dae
5 changed files with 37 additions and 17 deletions
|
@ -19,8 +19,8 @@ pub fn instantiate(
|
||||||
msg: InstantiateMsg,
|
msg: InstantiateMsg,
|
||||||
) -> Result<Response, ContractError> {
|
) -> Result<Response, ContractError> {
|
||||||
let state = State {
|
let state = State {
|
||||||
count: msg.count,
|
storeowner: info.sender.clone(),
|
||||||
owner: info.sender.clone(),
|
bill: msg.bill
|
||||||
};
|
};
|
||||||
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
|
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
|
||||||
STATE.save(deps.storage, &state)?;
|
STATE.save(deps.storage, &state)?;
|
||||||
|
@ -39,9 +39,9 @@ pub fn execute(
|
||||||
msg: ExecuteMsg,
|
msg: ExecuteMsg,
|
||||||
) -> Result<Response, ContractError> {
|
) -> Result<Response, ContractError> {
|
||||||
match msg {
|
match msg {
|
||||||
ExecuteMsg::Increment {} => try_increment(deps),
|
ExecuteMsg::Payup {} => try_payup(deps, info),
|
||||||
ExecuteMsg::Reset { count } => try_reset(deps, info, count),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_increment(deps: DepsMut) -> Result<Response, ContractError> {
|
pub fn try_increment(deps: DepsMut) -> Result<Response, ContractError> {
|
||||||
|
@ -52,15 +52,33 @@ pub fn try_increment(deps: DepsMut) -> Result<Response, ContractError> {
|
||||||
|
|
||||||
Ok(Response::new().add_attribute("method", "try_increment"))
|
Ok(Response::new().add_attribute("method", "try_increment"))
|
||||||
}
|
}
|
||||||
pub fn try_reset(deps: DepsMut, info: MessageInfo, count: i32) -> Result<Response, ContractError> {
|
pub fn try_payup(deps: DepsMut, info: MessageInfo: i32) -> Result<Response, ContractError> {
|
||||||
STATE.update(deps.storage, |mut state| -> Result<_, ContractError> {
|
let config = STATE.load(deps.storage)?;
|
||||||
if info.sender != state.owner {
|
let deposit_amount: Uint256 = info
|
||||||
return Err(ContractError::Unauthorized {});
|
.funds
|
||||||
|
.iter()
|
||||||
|
.find(|c| c.denom == "uluna")
|
||||||
|
.map(|c| Uint256::from(c.amount))
|
||||||
|
.unwrap_or_else(Uint256::zero);
|
||||||
|
if deposit_amount.is_zero() {
|
||||||
|
return Err(ContractError::ZeroDeposit());
|
||||||
}
|
}
|
||||||
state.count = count;
|
|
||||||
Ok(state)
|
let msg = CosmosMsg::Bank(BankMsg::Send {
|
||||||
})?;
|
to_address: config.storeowner,
|
||||||
Ok(Response::new().add_attribute("method", "reset"))
|
amount: vec![deduct_tax(
|
||||||
|
deps.as_ref(),
|
||||||
|
Coin {
|
||||||
|
denom: "uusd".to_string(),
|
||||||
|
amount: balance,
|
||||||
|
},
|
||||||
|
)?],
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(Response::new().add_message(msg))
|
||||||
|
}
|
||||||
|
pub createorder(deps: DepsMut, info: MessageInfo: i32) -> Result<Response, ContractError>){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(feature = "library"), entry_point)]
|
#[cfg_attr(not(feature = "library"), entry_point)]
|
||||||
|
|
|
@ -8,6 +8,9 @@ pub enum ContractError {
|
||||||
|
|
||||||
#[error("Unauthorized")]
|
#[error("Unauthorized")]
|
||||||
Unauthorized {},
|
Unauthorized {},
|
||||||
|
|
||||||
|
#[error("you cant deposit $0")]
|
||||||
|
ZeroDeposit {},
|
||||||
// Add any other custom errors you like here.
|
// Add any other custom errors you like here.
|
||||||
// Look at https://docs.rs/thiserror/1.0.21/thiserror/ for details.
|
// Look at https://docs.rs/thiserror/1.0.21/thiserror/ for details.
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@ pub struct InstantiateMsg {
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum ExecuteMsg {
|
pub enum ExecuteMsg {
|
||||||
Increment {},
|
Payup {}
|
||||||
Reset { count: i32 },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum QueryMsg {
|
pub enum QueryMsg {
|
||||||
|
|
|
@ -6,8 +6,7 @@ use cw_storage_plus::Item;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
pub count: i32,
|
pub storeowner: Addr,
|
||||||
pub owner: Addr,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const STATE: Item<State> = Item::new("state");
|
pub const STATE: Item<State> = Item::new("state");
|
||||||
|
|
Loading…
Add table
Reference in a new issue