mirror of
https://github.com/BiPhan4/DefiHackathon-2022.git
synced 2025-04-02 10:41:42 -04:00
trying to deploy
This commit is contained in:
parent
4c00cbf7ec
commit
7e8771557e
8 changed files with 38 additions and 56 deletions
|
@ -1 +1 @@
|
||||||
9c11206ae9184a6c56fea84d97c362971ebfce471c080a45b435a002146e18e1 counter.wasm
|
e82335a5bc6a618e7e7d5a70b7581475af25e434cc69dd10744d20a72730e929 counter.wasm
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
08e18ced1337e3a64711dc4ecbeecb8abb5fc677ba99167697248450bff6d0f5 ./target/wasm32-unknown-unknown/release/counter.wasm
|
919f0f03ccd5dcf907d768d9691034204ba89c7fc6322c7ef0af03297232870d ./target/wasm32-unknown-unknown/release/counter.wasm
|
||||||
|
|
Binary file not shown.
|
@ -3,7 +3,7 @@ use std::fs::create_dir_all;
|
||||||
|
|
||||||
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
|
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;
|
use counter::state::State;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -16,5 +16,5 @@ fn main() {
|
||||||
export_schema(&schema_for!(ExecuteMsg), &out_dir);
|
export_schema(&schema_for!(ExecuteMsg), &out_dir);
|
||||||
export_schema(&schema_for!(QueryMsg), &out_dir);
|
export_schema(&schema_for!(QueryMsg), &out_dir);
|
||||||
export_schema(&schema_for!(State), &out_dir);
|
export_schema(&schema_for!(State), &out_dir);
|
||||||
export_schema(&schema_for!(CountResponse), &out_dir);
|
export_schema(&schema_for!(totalPayersResponse), &out_dir);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
#[cfg(not(feature = "library"))]
|
#[cfg(not(feature = "library"))]
|
||||||
use cosmwasm_std::entry_point;
|
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 cw2::set_contract_version;
|
||||||
|
|
||||||
use cw20::Cw20Coin;
|
|
||||||
|
|
||||||
|
|
||||||
use crate::error::ContractError;
|
use crate::error::ContractError;
|
||||||
use crate::msg::{CountResponse, ExecuteMsg, InstantiateMsg, QueryMsg};
|
use crate::msg::{ExecuteMsg, InstantiateMsg, totalPayersResponse, QueryMsg};
|
||||||
use crate::state::{State, STATE, BALANCES, PAYERS};
|
use crate::state::{State, STATE, BALANCES};
|
||||||
|
|
||||||
// version info for migration info
|
// version info for migration info
|
||||||
const CONTRACT_NAME: &str = "crates.io:counter";
|
const CONTRACT_NAME: &str = "crates.io:counter";
|
||||||
|
@ -23,18 +20,10 @@ pub fn instantiate(
|
||||||
) -> Result<Response, ContractError> {
|
) -> Result<Response, ContractError> {
|
||||||
let state = State {
|
let state = State {
|
||||||
storeowner: info.sender.clone(),
|
storeowner: info.sender.clone(),
|
||||||
bill: msg.bill
|
bill: msg.bill,
|
||||||
/*logic to split the bill
|
TotalPayers: 0,
|
||||||
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)?;
|
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
|
||||||
STATE.save(deps.storage, &state)?;
|
STATE.save(deps.storage, &state)?;
|
||||||
|
|
||||||
|
@ -53,18 +42,16 @@ pub fn execute(
|
||||||
) -> Result<Response, ContractError> {
|
) -> Result<Response, ContractError> {
|
||||||
match msg {
|
match msg {
|
||||||
ExecuteMsg::Payup {} => try_payup(deps, info),
|
ExecuteMsg::Payup {} => try_payup(deps, info),
|
||||||
|
ExecuteMsg::Createaccounts {} => create_accounts(deps, info),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_accounts(deps: &mut DepsMut, accounts: &[Cw20Coin]) -> StdResult<Uint128> {
|
pub fn create_accounts(deps: DepsMut, info: MessageInfo) -> Result<Response, ContractError> {
|
||||||
let mut total_supply = Uint128::zero();
|
let paid = false;
|
||||||
for row in accounts {
|
let address = deps.api.addr_validate(&info.sender.to_string())?;
|
||||||
let address = deps.api.addr_validate(&row.address)?;
|
BALANCES.save(deps.storage, &address, &paid)?;
|
||||||
BALANCES.save(deps.storage, &address, &row.amount)?;
|
Ok(Response::new())
|
||||||
total_supply += row.amount;
|
|
||||||
}
|
|
||||||
Ok(total_supply)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_payup(deps: DepsMut, info: MessageInfo) -> Result<Response, ContractError> {
|
pub fn try_payup(deps: DepsMut, info: MessageInfo) -> Result<Response, ContractError> {
|
||||||
|
@ -73,23 +60,10 @@ pub fn try_payup(deps: DepsMut, info: MessageInfo) -> Result<Response, ContractE
|
||||||
.range(deps.storage, None, None, Order::Ascending)
|
.range(deps.storage, None, None, Order::Ascending)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let payers = all.iter().len();
|
STATE.update(deps.storage, |mut state| -> Result<_, ContractError> {
|
||||||
|
state.TotalPayers += all.iter().len();
|
||||||
/*
|
Ok(state)
|
||||||
//- 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 config = STATE.load(deps.storage)?;
|
||||||
let deposit_amount: Uint128 = info
|
let deposit_amount: Uint128 = info
|
||||||
|
@ -118,6 +92,12 @@ pub fn try_payup(deps: DepsMut, info: MessageInfo) -> Result<Response, ContractE
|
||||||
Ok(Response::new().add_message(msg))
|
Ok(Response::new().add_message(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn QueryPayers(deps: Deps) -> StdResult<totalPayersResponse> {
|
||||||
|
let state = STATE.load(deps.storage)?;
|
||||||
|
Ok(totalPayersResponse { payers: state.TotalPayers})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//pub createorder(deps: DepsMut, info: MessageInfo: i32) -> Result<Response, ContractError>{
|
//pub createorder(deps: DepsMut, info: MessageInfo: i32) -> Result<Response, ContractError>{
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ pub struct InstantiateMsg {
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum ExecuteMsg {
|
pub enum ExecuteMsg {
|
||||||
Payup {}
|
Payup {},
|
||||||
|
Createaccounts{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,12 +19,14 @@ pub enum ExecuteMsg {
|
||||||
pub enum QueryMsg {
|
pub enum QueryMsg {
|
||||||
// GetCount returns the current count as a json-encoded number
|
// GetCount returns the current count as a json-encoded number
|
||||||
GetCount {},
|
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)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||||
pub struct CountResponse {
|
pub struct totalPayersResponse {
|
||||||
pub count: i32,
|
pub payers: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
//initiate balances?
|
//initiate balances?
|
|
@ -4,16 +4,15 @@ use serde::{Deserialize, Serialize};
|
||||||
use cosmwasm_std::{Uint128, Addr};
|
use cosmwasm_std::{Uint128, Addr};
|
||||||
use cw_storage_plus::{Item, Map};
|
use cw_storage_plus::{Item, Map};
|
||||||
|
|
||||||
use crate::msg;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
pub storeowner: Addr,
|
pub storeowner: Addr,
|
||||||
pub bill: i32,
|
pub bill: i32,
|
||||||
|
pub TotalPayers: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub const STATE: Item<State> = Item::new("state");
|
pub const STATE: Item<State> = 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<Uint128> = Item::new("payers");
|
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"localterra": {
|
"localterra": {
|
||||||
"counter": {
|
"counter": {
|
||||||
"codeId": "6",
|
"codeId": "7",
|
||||||
"contractAddresses": {
|
"contractAddresses": {
|
||||||
"default": "terra1xzlgeyuuyqje79ma6vllregprkmgwgavjx2h6m"
|
"default": "terra1y45vkh0n6kplaeqw6ratuertapxupz53wdg6vd"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue