From ce7f2fc6be104fe2a82f9d871d0c90e8f08e17a2 Mon Sep 17 00:00:00 2001 From: BiPhan4 Date: Sat, 26 Mar 2022 20:56:27 -0400 Subject: [PATCH] non working changes --- contracts/counter/src/contract.rs | 13 ++++++++++++- contracts/counter/src/msg.rs | 1 + contracts/counter/src/state.rs | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/contracts/counter/src/contract.rs b/contracts/counter/src/contract.rs index 4d0fa6b..4b9dd18 100644 --- a/contracts/counter/src/contract.rs +++ b/contracts/counter/src/contract.rs @@ -5,7 +5,7 @@ use cw2::set_contract_version; use crate::error::ContractError; use crate::msg::{CountResponse, ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::state::{State, STATE}; +use crate::state::{State, User, STATE, CUSTOMERS}; // version info for migration info const CONTRACT_NAME: &str = "crates.io:counter"; @@ -41,9 +41,20 @@ pub fn execute( match msg { ExecuteMsg::Increment {} => try_increment(deps), ExecuteMsg::Reset { count } => try_reset(deps, info, count), + //ExecuteMsg::EnterCustomer {} => try_enter_address(deps, info), } } +pub fn try_enter_address(deps: DepsMut, info: MessageInfo, entering_address: String) -> Result{ + + let entry_address = deps.api.addr_validate(&entering_address)?; + + //load and save with extra key argument + let empty = CUSTOMERS.may_load(deps.storage, &str.to_string()); + Ok(Response::new()) +} + + pub fn try_increment(deps: DepsMut) -> Result { STATE.update(deps.storage, |mut state| -> Result<_, ContractError> { state.count += 1; diff --git a/contracts/counter/src/msg.rs b/contracts/counter/src/msg.rs index 380c8a2..dc8875f 100644 --- a/contracts/counter/src/msg.rs +++ b/contracts/counter/src/msg.rs @@ -11,6 +11,7 @@ pub struct InstantiateMsg { pub enum ExecuteMsg { Increment {}, Reset { count: i32 }, + EnterCustomer { entering_address: String} //we will get user address and names. Then divide bill. Then take money from users and put into our own contract. // } diff --git a/contracts/counter/src/state.rs b/contracts/counter/src/state.rs index f37a2c9..1c4599f 100644 --- a/contracts/counter/src/state.rs +++ b/contracts/counter/src/state.rs @@ -2,7 +2,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use cosmwasm_std::Addr; -use cw_storage_plus::Item; //import map and figure out how to use it +use cw_storage_plus::{Item, Map}; //import map and figure out how to use it #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct State { @@ -10,8 +10,14 @@ pub struct State { pub owner: Addr, } +pub struct User { + pub name: String, + pub address: Addr, +} + pub const STATE: Item = Item::new("state"); +pub const CUSTOMERS: Map<&str, User> = Map::new("customers"); /* add states: