Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
albertandrejev committed Jan 15, 2024
1 parent 01ae762 commit 0913cd5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
20 changes: 12 additions & 8 deletions contracts/strategy/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use cosmwasm_std::{attr, entry_point, to_json_binary, Attribute, Deps, Uint128};
use cosmwasm_std::{Binary, DepsMut, Env, MessageInfo, Response, StdResult};
use cw2::set_contract_version;
Expand Down Expand Up @@ -130,15 +132,17 @@ fn prepare_delegation_data(
)?;

let mut delegations: Vec<lido_staking_base::msg::distribution::Delegation> = Vec::new();
let delegation_validator_map: HashMap<_, _> = account_delegations
.delegations
.iter()
.filter(|delegation| delegation.amount.denom == denom)
.map(|delegation| (delegation.validator.clone(), delegation.amount.amount))
.collect();

for validator in validator_set.iter() {
let validator_denom_delegation = account_delegations
.delegations
.iter()
.find(|delegation| {
delegation.validator == validator.valoper_address
&& delegation.amount.denom == denom
})
.map(|delegation| delegation.amount.amount)
let validator_denom_delegation = delegation_validator_map
.get(&validator.valoper_address)
.copied()
.unwrap_or_default();

let delegation = lido_staking_base::msg::distribution::Delegation {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use cosmwasm_schema::write_api;

use lido_staking_base::{
msg::validatorsstats::{ExecuteMsg, InstantiateMsg, MigrateMsg},
state::validatorsstats::QueryMsg,
};
use lido_staking_base::msg::validatorsstats::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};

fn main() {
write_api! {
Expand Down
6 changes: 3 additions & 3 deletions contracts/validators-stats/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use cosmwasm_std::{
};
use cosmwasm_std::{Binary, DepsMut, Env, MessageInfo, Response, StdResult};
use cw2::set_contract_version;
use lido_staking_base::msg::validatorsstats::{ExecuteMsg, InstantiateMsg, MigrateMsg};
use lido_staking_base::msg::validatorsstats::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use lido_staking_base::state::validatorsstats::{
Config, MissedBlocks, QueryMsg, ValidatorMissedBlocksForPeriod, ValidatorState, CONFIG,
MISSED_BLOCKS, SIGNING_INFO_QUERY_ID, SIGNING_INFO_REPLY_ID, STATE_MAP, VALCONS_TO_VALOPER,
Config, MissedBlocks, ValidatorMissedBlocksForPeriod, ValidatorState, CONFIG, MISSED_BLOCKS,
SIGNING_INFO_QUERY_ID, SIGNING_INFO_REPLY_ID, STATE_MAP, VALCONS_TO_VALOPER,
VALIDATOR_PROFILE_QUERY_ID, VALIDATOR_PROFILE_REPLY_ID,
};
use neutron_sdk::bindings::msg::MsgRegisterInterchainQueryResponse;
Expand Down
13 changes: 12 additions & 1 deletion packages/base/src/msg/validatorsstats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_schema::{cw_serde, QueryResponses};

use crate::state::validatorsstats::{Config, ValidatorState};

#[cw_serde]
pub struct InstantiateMsg {
Expand All @@ -15,5 +17,14 @@ pub enum ExecuteMsg {
RegisterStatsQueries { validators: Vec<String> },
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(Config)]
Config {},
#[returns(Vec<ValidatorState>)]
State {},
}

#[cw_serde]
pub struct MigrateMsg {}
11 changes: 1 addition & 10 deletions packages/base/src/state/validatorsstats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_schema::cw_serde;

use cosmwasm_std::{Addr, Decimal};
use cw_storage_plus::{Item, Map};
Expand Down Expand Up @@ -32,15 +32,6 @@ pub struct State {
pub validators: Vec<ValidatorState>,
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(Config)]
Config {},
#[returns(Vec<ValidatorState>)]
State {},
}

#[cw_serde]
pub struct ValidatorMissedBlocksForPeriod {
pub address: String,
Expand Down

0 comments on commit 0913cd5

Please sign in to comment.