diff --git a/contracts/counter/artifacts/checksums.txt b/contracts/counter/artifacts/checksums.txt index 17a0d8e..b6a9b70 100644 --- a/contracts/counter/artifacts/checksums.txt +++ b/contracts/counter/artifacts/checksums.txt @@ -1 +1 @@ -9c11206ae9184a6c56fea84d97c362971ebfce471c080a45b435a002146e18e1 counter.wasm +e82335a5bc6a618e7e7d5a70b7581475af25e434cc69dd10744d20a72730e929 counter.wasm diff --git a/contracts/counter/artifacts/checksums_intermediate.txt b/contracts/counter/artifacts/checksums_intermediate.txt index 14be890..795d552 100644 --- a/contracts/counter/artifacts/checksums_intermediate.txt +++ b/contracts/counter/artifacts/checksums_intermediate.txt @@ -1 +1 @@ -08e18ced1337e3a64711dc4ecbeecb8abb5fc677ba99167697248450bff6d0f5 ./target/wasm32-unknown-unknown/release/counter.wasm +919f0f03ccd5dcf907d768d9691034204ba89c7fc6322c7ef0af03297232870d ./target/wasm32-unknown-unknown/release/counter.wasm diff --git a/contracts/counter/artifacts/counter.wasm b/contracts/counter/artifacts/counter.wasm index f18b383..59f9122 100644 Binary files a/contracts/counter/artifacts/counter.wasm and b/contracts/counter/artifacts/counter.wasm differ diff --git a/contracts/counter/examples/schema.rs b/contracts/counter/examples/schema.rs index fdf606f..0bcc70f 100644 --- a/contracts/counter/examples/schema.rs +++ b/contracts/counter/examples/schema.rs @@ -3,7 +3,7 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; -use counter::msg::{CountResponse, ExecuteMsg, InstantiateMsg, QueryMsg}; +use counter::msg::{totalPayersResponse, ExecuteMsg, InstantiateMsg, QueryMsg}; use counter::state::State; fn main() { @@ -16,5 +16,5 @@ fn main() { export_schema(&schema_for!(ExecuteMsg), &out_dir); export_schema(&schema_for!(QueryMsg), &out_dir); export_schema(&schema_for!(State), &out_dir); - export_schema(&schema_for!(CountResponse), &out_dir); + export_schema(&schema_for!(totalPayersResponse), &out_dir); } diff --git a/contracts/counter/src/contract.rs b/contracts/counter/src/contract.rs index cfecc34..4c674d7 100644 --- a/contracts/counter/src/contract.rs +++ b/contracts/counter/src/contract.rs @@ -1,14 +1,11 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{Order, Uint128, Coin, BankMsg, CosmosMsg, Uint256, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; +use cosmwasm_std::{Order, Uint128, Coin, BankMsg, CosmosMsg, Uint256, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Api, Addr}; use cw2::set_contract_version; -use cw20::Cw20Coin; - - use crate::error::ContractError; -use crate::msg::{CountResponse, ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::state::{State, STATE, BALANCES, PAYERS}; +use crate::msg::{ExecuteMsg, InstantiateMsg, totalPayersResponse, QueryMsg}; +use crate::state::{State, STATE, BALANCES}; // version info for migration info const CONTRACT_NAME: &str = "crates.io:counter"; @@ -23,18 +20,10 @@ pub fn instantiate( ) -> Result { 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 - - */ - + bill: msg.bill, + TotalPayers: 0, }; + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; STATE.save(deps.storage, &state)?; @@ -53,18 +42,16 @@ pub fn execute( ) -> Result { match msg { ExecuteMsg::Payup {} => try_payup(deps, info), + ExecuteMsg::Createaccounts {} => create_accounts(deps, info), } } -pub fn create_accounts(deps: &mut DepsMut, accounts: &[Cw20Coin]) -> StdResult { - let mut total_supply = Uint128::zero(); - for row in accounts { - let address = deps.api.addr_validate(&row.address)?; - BALANCES.save(deps.storage, &address, &row.amount)?; - total_supply += row.amount; - } - Ok(total_supply) +pub fn create_accounts(deps: DepsMut, info: MessageInfo) -> Result { + let paid = false; + let address = deps.api.addr_validate(&info.sender.to_string())?; + BALANCES.save(deps.storage, &address, &paid)?; + Ok(Response::new()) } pub fn try_payup(deps: DepsMut, info: MessageInfo) -> Result { @@ -73,23 +60,10 @@ pub fn try_payup(deps: DepsMut, info: MessageInfo) -> Result Result<_, ContractError> { + state.TotalPayers += all.iter().len(); + Ok(state) + })?; let config = STATE.load(deps.storage)?; let deposit_amount: Uint128 = info @@ -118,6 +92,12 @@ pub fn try_payup(deps: DepsMut, info: MessageInfo) -> Result StdResult { + let state = STATE.load(deps.storage)?; + Ok(totalPayersResponse { payers: state.TotalPayers}) +} + + //pub createorder(deps: DepsMut, info: MessageInfo: i32) -> Result{ //} diff --git a/contracts/counter/src/msg.rs b/contracts/counter/src/msg.rs index fc5b734..651c147 100644 --- a/contracts/counter/src/msg.rs +++ b/contracts/counter/src/msg.rs @@ -9,7 +9,8 @@ pub struct InstantiateMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum ExecuteMsg { - Payup {} + Payup {}, + Createaccounts{} } @@ -18,12 +19,14 @@ pub enum ExecuteMsg { pub enum QueryMsg { // GetCount returns the current count as a json-encoded number GetCount {}, + QueryPayers{}, + } -// We define a custom struct for each query response +//We define a custom struct for each query response #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct CountResponse { - pub count: i32, +pub struct totalPayersResponse { + pub payers: usize, } //initiate balances? \ No newline at end of file diff --git a/contracts/counter/src/state.rs b/contracts/counter/src/state.rs index f9b2aa3..96423f8 100644 --- a/contracts/counter/src/state.rs +++ b/contracts/counter/src/state.rs @@ -4,16 +4,15 @@ use serde::{Deserialize, Serialize}; use cosmwasm_std::{Uint128, Addr}; 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 TotalPayers: usize, } + pub const STATE: Item = Item::new("state"); -pub const BALANCES: Map<&Addr, Uint128> = Map::new("balance"); +pub const BALANCES: Map<&Addr, bool> = Map::new("balance"); -pub const PAYERS: Item = Item::new("payers"); \ No newline at end of file diff --git a/refs.terrain.json b/refs.terrain.json index 4192948..50fc609 100644 --- a/refs.terrain.json +++ b/refs.terrain.json @@ -1,9 +1,9 @@ { "localterra": { "counter": { - "codeId": "6", + "codeId": "7", "contractAddresses": { - "default": "terra1xzlgeyuuyqje79ma6vllregprkmgwgavjx2h6m" + "default": "terra1y45vkh0n6kplaeqw6ratuertapxupz53wdg6vd" } } }