mirror of
https://github.com/BiPhan4/DefiHackathon-2022.git
synced 2025-04-02 10:41:42 -04:00
attempting bill splitting
This commit is contained in:
parent
c061918f78
commit
4c00cbf7ec
4 changed files with 69 additions and 6 deletions
25
contracts/counter/Cargo.lock
generated
25
contracts/counter/Cargo.lock
generated
|
@ -103,6 +103,7 @@ dependencies = [
|
|||
"cosmwasm-storage",
|
||||
"cw-storage-plus",
|
||||
"cw2",
|
||||
"cw20",
|
||||
"schemars",
|
||||
"serde",
|
||||
"thiserror",
|
||||
|
@ -169,6 +170,18 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cw0"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d759bb5418a3bdf091e1f1be17de2a15d95d2be4fee28045c2e461f4c6d9d1ca"
|
||||
dependencies = [
|
||||
"cosmwasm-std",
|
||||
"schemars",
|
||||
"serde",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cw2"
|
||||
version = "0.8.1"
|
||||
|
@ -181,6 +194,18 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cw20"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac49b013ca1e355fd988cc1926acc9a16d7fd45cfb595ee330455582a788b100"
|
||||
dependencies = [
|
||||
"cosmwasm-std",
|
||||
"cw0",
|
||||
"schemars",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "der"
|
||||
version = "0.4.1"
|
||||
|
|
|
@ -44,6 +44,7 @@ cosmwasm-std = { version = "0.16.2" }
|
|||
cosmwasm-storage = { version = "0.16.0" }
|
||||
cw-storage-plus = "0.8.0"
|
||||
cw2 = "0.8.1"
|
||||
cw20 = "0.9.0"
|
||||
schemars = "0.8.3"
|
||||
serde = { version = "1.0.127", default-features = false, features = ["derive"] }
|
||||
thiserror = { version = "1.0.26" }
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
#[cfg(not(feature = "library"))]
|
||||
use cosmwasm_std::entry_point;
|
||||
use cosmwasm_std::{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};
|
||||
use cw2::set_contract_version;
|
||||
|
||||
use cw20::Cw20Coin;
|
||||
|
||||
|
||||
use crate::error::ContractError;
|
||||
use crate::msg::{CountResponse, ExecuteMsg, InstantiateMsg, QueryMsg};
|
||||
use crate::state::{State, STATE};
|
||||
use crate::state::{State, STATE, BALANCES, PAYERS};
|
||||
|
||||
// version info for migration info
|
||||
const CONTRACT_NAME: &str = "crates.io:counter";
|
||||
|
@ -54,7 +57,40 @@ pub fn execute(
|
|||
|
||||
}
|
||||
|
||||
pub fn create_accounts(deps: &mut DepsMut, accounts: &[Cw20Coin]) -> StdResult<Uint128> {
|
||||
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 try_payup(deps: DepsMut, info: MessageInfo) -> Result<Response, ContractError> {
|
||||
|
||||
let all: StdResult<Vec<_>> = BALANCES
|
||||
.range(deps.storage, None, None, Order::Ascending)
|
||||
.collect();
|
||||
|
||||
let payers = all.iter().len();
|
||||
|
||||
/*
|
||||
//- code below takes entire amount from one user
|
||||
our bill is known, and our total payees is known
|
||||
int each_pays = bill/payers;
|
||||
|
||||
deposit_amount = 0;
|
||||
|
||||
for (i = 0 to payers){
|
||||
address_of_a_payer = BALANCES[i].Addr
|
||||
fund taken out = each_pays
|
||||
deposit_amount += funds taken out
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
let config = STATE.load(deps.storage)?;
|
||||
let deposit_amount: Uint128 = info
|
||||
.funds
|
||||
|
@ -62,6 +98,7 @@ pub fn try_payup(deps: DepsMut, info: MessageInfo) -> Result<Response, ContractE
|
|||
.find(|c| c.denom == "uluna")
|
||||
.map(|c| Uint128::from(c.amount))
|
||||
.unwrap_or_else(Uint128::zero);
|
||||
|
||||
if deposit_amount.is_zero() {
|
||||
return Err(ContractError::ZeroDeposit {});
|
||||
}
|
||||
|
@ -82,7 +119,5 @@ pub fn try_payup(deps: DepsMut, info: MessageInfo) -> Result<Response, ContractE
|
|||
}
|
||||
|
||||
//pub createorder(deps: DepsMut, info: MessageInfo: i32) -> Result<Response, ContractError>{
|
||||
|
||||
|
||||
//}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use cosmwasm_std::Addr;
|
||||
use cosmwasm_std::{Uint128, Addr};
|
||||
use cw_storage_plus::{Item, Map};
|
||||
|
||||
use crate::msg;
|
||||
|
@ -14,4 +14,6 @@ pub struct State {
|
|||
|
||||
pub const STATE: Item<State> = Item::new("state");
|
||||
|
||||
pub const BALANCES: Map<&Addr, bool> = Map::new("balance");
|
||||
pub const BALANCES: Map<&Addr, Uint128> = Map::new("balance");
|
||||
|
||||
pub const PAYERS: Item<Uint128> = Item::new("payers");
|
Loading…
Add table
Reference in a new issue