diff --git a/config.terrain.json b/config.terrain.json index bbc25ef..c49c951 100644 --- a/config.terrain.json +++ b/config.terrain.json @@ -17,7 +17,7 @@ } }, "instantiateMsg": { - "count": 0 + "bill": 20000000 } } } diff --git a/contracts/counter/artifacts/checksums.txt b/contracts/counter/artifacts/checksums.txt new file mode 100644 index 0000000..17a0d8e --- /dev/null +++ b/contracts/counter/artifacts/checksums.txt @@ -0,0 +1 @@ +9c11206ae9184a6c56fea84d97c362971ebfce471c080a45b435a002146e18e1 counter.wasm diff --git a/contracts/counter/artifacts/checksums_intermediate.txt b/contracts/counter/artifacts/checksums_intermediate.txt new file mode 100644 index 0000000..14be890 --- /dev/null +++ b/contracts/counter/artifacts/checksums_intermediate.txt @@ -0,0 +1 @@ +08e18ced1337e3a64711dc4ecbeecb8abb5fc677ba99167697248450bff6d0f5 ./target/wasm32-unknown-unknown/release/counter.wasm diff --git a/contracts/counter/artifacts/counter.wasm b/contracts/counter/artifacts/counter.wasm new file mode 100644 index 0000000..f18b383 Binary files /dev/null and b/contracts/counter/artifacts/counter.wasm differ diff --git a/contracts/counter/src/contract.rs b/contracts/counter/src/contract.rs index 9d90809..7243546 100644 --- a/contracts/counter/src/contract.rs +++ b/contracts/counter/src/contract.rs @@ -1,6 +1,6 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; +use cosmwasm_std::{Uint128, Coin, BankMsg, CosmosMsg, Uint256, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; use cw2::set_contract_version; use crate::error::ContractError; @@ -21,6 +21,16 @@ pub fn instantiate( let state = State { storeowner: info.sender.clone(), bill: msg.bill + /*logic to split the bill + put contract callers into + store owner specifies bill amount + and users call join. + Need join function: join function adds their addresses to map + then once everyone joins have the pay up method split bill + based on map length + + */ + }; set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; STATE.save(deps.storage, &state)?; @@ -28,7 +38,7 @@ pub fn instantiate( Ok(Response::new() .add_attribute("method", "instantiate") .add_attribute("owner", info.sender) - .add_attribute("count", msg.count.to_string())) + ) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -44,122 +54,35 @@ pub fn execute( } -pub fn try_increment(deps: DepsMut) -> Result { - STATE.update(deps.storage, |mut state| -> Result<_, ContractError> { - state.count += 1; - Ok(state) - })?; - - Ok(Response::new().add_attribute("method", "try_increment")) -} -pub fn try_payup(deps: DepsMut, info: MessageInfo: i32) -> Result { +pub fn try_payup(deps: DepsMut, info: MessageInfo) -> Result { let config = STATE.load(deps.storage)?; - let deposit_amount: Uint256 = info + let deposit_amount: Uint128 = info .funds .iter() .find(|c| c.denom == "uluna") - .map(|c| Uint256::from(c.amount)) - .unwrap_or_else(Uint256::zero); + .map(|c| Uint128::from(c.amount)) + .unwrap_or_else(Uint128::zero); if deposit_amount.is_zero() { - return Err(ContractError::ZeroDeposit()); + return Err(ContractError::ZeroDeposit {}); } + /*is depost amount 50% of config.bill + */ let msg = CosmosMsg::Bank(BankMsg::Send { - to_address: config.storeowner, - amount: vec![deduct_tax( - deps.as_ref(), + to_address: config.storeowner.to_string(), + amount: vec![ Coin { - denom: "uusd".to_string(), - amount: balance, + denom: "uluna".to_string(), + amount: deposit_amount, }, - )?], + ], }); Ok(Response::new().add_message(msg)) } -pub createorder(deps: DepsMut, info: MessageInfo: i32) -> Result){ -} +//pub createorder(deps: DepsMut, info: MessageInfo: i32) -> Result{ -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - match msg { - QueryMsg::GetCount {} => to_binary(&query_count(deps)?), - } -} -fn query_count(deps: Deps) -> StdResult { - let state = STATE.load(deps.storage)?; - Ok(CountResponse { count: state.count }) -} +//} -#[cfg(test)] -mod tests { - use super::*; - use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; - use cosmwasm_std::{coins, from_binary}; - - #[test] - fn proper_initialization() { - let mut deps = mock_dependencies(&[]); - - let msg = InstantiateMsg { count: 17 }; - let info = mock_info("creator", &coins(1000, "earth")); - - // we can just call .unwrap() to assert this was a success - let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); - assert_eq!(0, res.messages.len()); - - // it worked, let's query the state - let res = query(deps.as_ref(), mock_env(), QueryMsg::GetCount {}).unwrap(); - let value: CountResponse = from_binary(&res).unwrap(); - assert_eq!(17, value.count); - } - - #[test] - fn increment() { - let mut deps = mock_dependencies(&coins(2, "token")); - - let msg = InstantiateMsg { count: 17 }; - let info = mock_info("creator", &coins(2, "token")); - let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); - - // beneficiary can release it - let info = mock_info("anyone", &coins(2, "token")); - let msg = ExecuteMsg::Increment {}; - let _res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); - - // should increase counter by 1 - let res = query(deps.as_ref(), mock_env(), QueryMsg::GetCount {}).unwrap(); - let value: CountResponse = from_binary(&res).unwrap(); - assert_eq!(18, value.count); - } - - #[test] - fn reset() { - let mut deps = mock_dependencies(&coins(2, "token")); - - let msg = InstantiateMsg { count: 17 }; - let info = mock_info("creator", &coins(2, "token")); - let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); - - // beneficiary can release it - let unauth_info = mock_info("anyone", &coins(2, "token")); - let msg = ExecuteMsg::Reset { count: 5 }; - let res = execute(deps.as_mut(), mock_env(), unauth_info, msg); - match res { - Err(ContractError::Unauthorized {}) => {} - _ => panic!("Must return unauthorized error"), - } - - // only the original creator can reset the counter - let auth_info = mock_info("creator", &coins(2, "token")); - let msg = ExecuteMsg::Reset { count: 5 }; - let _res = execute(deps.as_mut(), mock_env(), auth_info, msg).unwrap(); - - // should now be 5 - let res = query(deps.as_ref(), mock_env(), QueryMsg::GetCount {}).unwrap(); - let value: CountResponse = from_binary(&res).unwrap(); - assert_eq!(5, value.count); - } -} diff --git a/contracts/counter/src/msg.rs b/contracts/counter/src/msg.rs index fed76d7..fc5b734 100644 --- a/contracts/counter/src/msg.rs +++ b/contracts/counter/src/msg.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct InstantiateMsg { - pub count: i32, + pub bill: i32, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] @@ -25,3 +25,5 @@ pub enum QueryMsg { pub struct CountResponse { pub count: i32, } + +//initiate balances? \ No newline at end of file diff --git a/contracts/counter/src/state.rs b/contracts/counter/src/state.rs index 893adeb..5ffffbb 100644 --- a/contracts/counter/src/state.rs +++ b/contracts/counter/src/state.rs @@ -2,11 +2,16 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use cosmwasm_std::Addr; -use cw_storage_plus::Item; +use cw_storage_plus::{Item, Map}; + +use crate::msg; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct State { pub storeowner: Addr, + pub bill: i32, } pub const STATE: Item = Item::new("state"); + +pub const BALANCES: Map<&Addr, bool> = Map::new("balance"); \ No newline at end of file diff --git a/keys.terrain.js b/keys.terrain.js index 1cf7900..a0ac290 100644 --- a/keys.terrain.js +++ b/keys.terrain.js @@ -4,6 +4,6 @@ module.exports = { testnet: { mnemonic: - "rose affair garlic decorate awesome round upgrade distance novel strong this congress jelly title also trigger proof stand between humble primary short area people", + "cactus wash reveal certain neck guard finger dash tired injury piece remember never load illness off butter lumber velvet off allow control anger return", }, }; diff --git a/refs.terrain.json b/refs.terrain.json index 9e26dfe..4192948 100644 --- a/refs.terrain.json +++ b/refs.terrain.json @@ -1 +1,10 @@ -{} \ No newline at end of file +{ + "localterra": { + "counter": { + "codeId": "6", + "contractAddresses": { + "default": "terra1xzlgeyuuyqje79ma6vllregprkmgwgavjx2h6m" + } + } + } +}