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 query for registred validator queries #105

Merged
merged 5 commits into from
Sep 14, 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
4 changes: 2 additions & 2 deletions artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
f3f06c36a664d7e1c6b2992ffc7e1b1175830eef4c29ebc476dc2f320666ca10 hydro.wasm
3b2eb51bbf8ec9da85d20751341b3c659f050f430f8c08674af0cfd91e870637 tribute.wasm
5e958ba7eabde84bacbf1f0338594849f29576a476858e5c185216f4990ed8f3 hydro.wasm
0320254a30298260030dda411339b131f570003f4adf7db566df865d2797f2e2 tribute.wasm
Binary file modified artifacts/hydro.wasm
Binary file not shown.
Binary file modified artifacts/tribute.wasm
Binary file not shown.
40 changes: 40 additions & 0 deletions contracts/hydro/schema/hydro_full_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,46 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"registered_validator_queries"
],
"properties": {
"registered_validator_queries": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"validator_power_ratio"
],
"properties": {
"validator_power_ratio": {
"type": "object",
"required": [
"round_id",
"validator"
],
"properties": {
"round_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"validator": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
]
},
Expand Down
40 changes: 40 additions & 0 deletions contracts/hydro/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,46 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"registered_validator_queries"
],
"properties": {
"registered_validator_queries": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"validator_power_ratio"
],
"properties": {
"validator_power_ratio": {
"type": "object",
"required": [
"round_id",
"validator"
],
"properties": {
"round_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"validator": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
31 changes: 27 additions & 4 deletions contracts/hydro/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use crate::lsm_integration::{
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, TrancheInfo};
use crate::query::{
AllUserLockupsResponse, ConstantsResponse, CurrentRoundResponse, ExpiredUserLockupsResponse,
LockEntryWithPower, ProposalResponse, QueryMsg, RoundEndResponse, RoundProposalsResponse,
RoundTotalVotingPowerResponse, TopNProposalsResponse, TotalLockedTokensResponse,
TranchesResponse, UserVoteResponse, UserVotingPowerResponse, ValidatorPowerRatioResponse,
WhitelistAdminsResponse, WhitelistResponse,
LockEntryWithPower, ProposalResponse, QueryMsg, RegisteredValidatorQueriesResponse,
RoundEndResponse, RoundProposalsResponse, RoundTotalVotingPowerResponse, TopNProposalsResponse,
TotalLockedTokensResponse, TranchesResponse, UserVoteResponse, UserVotingPowerResponse,
ValidatorPowerRatioResponse, WhitelistAdminsResponse, WhitelistResponse,
};
use crate::score_keeper::{
add_validator_shares_to_proposal, get_total_power_for_proposal,
Expand Down Expand Up @@ -1109,6 +1109,9 @@ pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: QueryMsg) -> StdResult<Bin
QueryMsg::Whitelist {} => to_json_binary(&query_whitelist(deps)?),
QueryMsg::WhitelistAdmins {} => to_json_binary(&query_whitelist_admins(deps)?),
QueryMsg::TotalLockedTokens {} => to_json_binary(&query_total_locked_tokens(deps)?),
QueryMsg::RegisteredValidatorQueries {} => {
to_json_binary(&query_registered_validator_queries(deps)?)
}
QueryMsg::ValidatorPowerRatio {
validator,
round_id,
Expand Down Expand Up @@ -1437,6 +1440,26 @@ pub fn query_total_locked_tokens(deps: Deps<NeutronQuery>) -> StdResult<TotalLoc
})
}

// Returns all the validator queries that are registered
// by the contract right now, for each query returning the address of the validator it is
// associated with, plus its query id.
pub fn query_registered_validator_queries(
deps: Deps<NeutronQuery>,
) -> StdResult<RegisteredValidatorQueriesResponse> {
let query_ids = VALIDATOR_TO_QUERY_ID
.range(deps.storage, None, None, Order::Ascending)
.filter_map(|l| {
if l.is_err() {
deps.api
.debug(&format!("Error when querying validator query id: {:?}", l));
}
l.ok()
})
.collect();

Ok(RegisteredValidatorQueriesResponse { query_ids })
}

pub fn query_validators_info(
deps: Deps<NeutronQuery>,
round_id: u64,
Expand Down
10 changes: 10 additions & 0 deletions contracts/hydro/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ pub enum QueryMsg {
#[returns(TotalLockedTokensResponse)]
TotalLockedTokens {},

#[returns(RegisteredValidatorQueriesResponse)]
RegisteredValidatorQueries {},

#[returns(ValidatorPowerRatioResponse)]
ValidatorPowerRatio { validator: String, round_id: u64 },
}
Expand Down Expand Up @@ -167,6 +170,13 @@ pub struct RoundProposalsResponse {
pub proposals: Vec<Proposal>,
}

// A vector containing tuples, where each tuple contains a validator address
// and the id of the interchain query associated with that validator.
#[cw_serde]
pub struct RegisteredValidatorQueriesResponse {
pub query_ids: Vec<(String, u64)>,
}

#[cw_serde]
pub struct ValidatorPowerRatioResponse {
pub ratio: Decimal,
Expand Down
Loading