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,
|
||||
) -> Result<Response, ContractError> {
|
||||
let state = State {
|
||||
count: msg.count,
|
||||
owner: info.sender.clone(),
|
||||
storeowner: info.sender.clone(),
|
||||
bill: msg.bill
|
||||
};
|
||||
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
|
||||
STATE.save(deps.storage, &state)?;
|
||||
|
@ -39,9 +39,9 @@ pub fn execute(
|
|||
msg: ExecuteMsg,
|
||||
) -> Result<Response, ContractError> {
|
||||
match msg {
|
||||
ExecuteMsg::Increment {} => try_increment(deps),
|
||||
ExecuteMsg::Reset { count } => try_reset(deps, info, count),
|
||||
ExecuteMsg::Payup {} => try_payup(deps, info),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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"))
|
||||
}
|
||||
pub fn try_reset(deps: DepsMut, info: MessageInfo, count: i32) -> Result<Response, ContractError> {
|
||||
STATE.update(deps.storage, |mut state| -> Result<_, ContractError> {
|
||||
if info.sender != state.owner {
|
||||
return Err(ContractError::Unauthorized {});
|
||||
pub fn try_payup(deps: DepsMut, info: MessageInfo: i32) -> Result<Response, ContractError> {
|
||||
let config = STATE.load(deps.storage)?;
|
||||
let deposit_amount: Uint256 = info
|
||||
.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)
|
||||
})?;
|
||||
Ok(Response::new().add_attribute("method", "reset"))
|
||||
|
||||
let msg = CosmosMsg::Bank(BankMsg::Send {
|
||||
to_address: config.storeowner,
|
||||
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)]
|
||||
|
|
|
@ -8,6 +8,9 @@ pub enum ContractError {
|
|||
|
||||
#[error("Unauthorized")]
|
||||
Unauthorized {},
|
||||
|
||||
#[error("you cant deposit $0")]
|
||||
ZeroDeposit {},
|
||||
// Add any other custom errors you like here.
|
||||
// Look at https://docs.rs/thiserror/1.0.21/thiserror/ for details.
|
||||
}
|
||||
|
|
|
@ -3,4 +3,4 @@ mod error;
|
|||
pub mod msg;
|
||||
pub mod state;
|
||||
|
||||
pub use crate::error::ContractError;
|
||||
pub use crate::error::ContractError;
|
|
@ -9,10 +9,10 @@ pub struct InstantiateMsg {
|
|||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ExecuteMsg {
|
||||
Increment {},
|
||||
Reset { count: i32 },
|
||||
Payup {}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum QueryMsg {
|
||||
|
|
|
@ -6,8 +6,7 @@ use cw_storage_plus::Item;
|
|||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||
pub struct State {
|
||||
pub count: i32,
|
||||
pub owner: Addr,
|
||||
pub storeowner: Addr,
|
||||
}
|
||||
|
||||
pub const STATE: Item<State> = Item::new("state");
|
||||
|
|
Loading…
Add table
Reference in a new issue