Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add queries needed for the tribute contract #19

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions contracts/atom_wars/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,21 @@ fn create_proposal(
TRANCHE_MAP.load(deps.storage, tranche_id)?;

let round_id = compute_current_round_id(deps.as_ref(), env)?;
let proposal_id = PROP_ID.load(deps.storage)?;

// Create proposal in PropMap
let proposal = Proposal {
round_id,
tranche_id,
proposal_id,
covenant_params,
executed: false,
power: Uint128::zero(),
percentage: Uint128::zero(),
};

let prop_id = PROP_ID.load(deps.storage)?;
PROP_ID.save(deps.storage, &(prop_id + 1))?;
PROPOSAL_MAP.save(deps.storage, (round_id, tranche_id, prop_id), &proposal)?;
PROP_ID.save(deps.storage, &(proposal_id + 1))?;
PROPOSAL_MAP.save(deps.storage, (round_id, tranche_id, proposal_id), &proposal)?;

// load the total voting power for this round and tranche
let total_power_voting = TOTAL_POWER_VOTING.load(deps.storage, (round_id, tranche_id));
Expand Down Expand Up @@ -425,6 +426,11 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::UserVotingPower { address } => {
to_json_binary(&query_user_voting_power(deps, env, address)?)
}
QueryMsg::UserVote {
round_id,
tranche_id,
address,
} => to_json_binary(&query_user_vote(deps, round_id, tranche_id, address)?),
QueryMsg::Proposal {
round_id,
tranche_id,
Expand Down Expand Up @@ -498,6 +504,18 @@ pub fn query_user_voting_power(deps: Deps, env: Env, address: String) -> StdResu
.sum())
}

pub fn query_user_vote(
deps: Deps,
round_id: u64,
tranche_id: u64,
user_address: String,
) -> StdResult<Vote> {
Ok(VOTE_MAP.load(
deps.storage,
(round_id, tranche_id, deps.api.addr_validate(&user_address)?),
)?)
}

pub fn query_round_tranche_proposals(
deps: Deps,
round_id: u64,
Expand Down
5 changes: 5 additions & 0 deletions contracts/atom_wars/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ pub enum QueryMsg {
UserVotingPower {
address: String,
},
UserVote {
round_id: u64,
tranche_id: u64,
address: String,
},
CurrentRound {},
RoundEnd {
round_id: u64,
Expand Down
2 changes: 2 additions & 0 deletions contracts/atom_wars/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct LockEntry {
// PROP_MAP: key(round_id, tranche_id, prop_id) -> Proposal {
// round_id: u64,
// tranche_id: u64,
// proposal_id: u64,
// covenant_params: String,
// executed: bool,
// power: Uint128
Expand All @@ -41,6 +42,7 @@ pub const PROPOSAL_MAP: Map<(u64, u64, u64), Proposal> = Map::new("prop_map");
pub struct Proposal {
pub round_id: u64,
pub tranche_id: u64,
pub proposal_id: u64,
pub covenant_params: String,
pub executed: bool, // TODO: maybe remove in the future
pub power: Uint128,
Expand Down
Loading