Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- feat: Wildcard in Permissions [(#949)](https://github.com/andromedaprotocol/andromeda-core/pull/949)
- feat: Additional Permission Queries [(#960)](https://github.com/andromedaprotocol/andromeda-core/pull/960)
- feat: Standardized events in ADOS [(#970)](https://github.com/andromedaprotocol/andromeda-core/pull/970)
- feat: Kernel queries for all chains and all channels [(#978)](https://github.com/andromedaprotocol/andromeda-core/pull/978)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/os/andromeda-kernel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "andromeda-kernel"
version = "1.2.5-b.3"
version = "1.2.5-b.4"
authors = ["Connor Barr <crnbarr@gmail.com>"]
edition = "2021"
rust-version = "1.65.0"
Expand Down
20 changes: 16 additions & 4 deletions contracts/os/andromeda-kernel/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,28 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractErr
QueryMsg::ChannelInfo { chain } => encode_binary(&query::channel_info(deps, chain)?),
QueryMsg::Recoveries { addr } => encode_binary(&query::recoveries(deps, addr)?),
QueryMsg::ChainName {} => encode_binary(&query::chain_name(deps)?),
// Base queries
QueryMsg::Version {} => encode_binary(&ADOContract::default().query_version(deps)?),
QueryMsg::AdoType {} => encode_binary(&ADOContract::default().query_type(deps)?),
QueryMsg::Owner {} => encode_binary(&ADOContract::default().query_contract_owner(deps)?),
QueryMsg::ChainNameByChannel { channel } => {
encode_binary(&query::chain_name_by_channel(deps, channel)?)
}
QueryMsg::ListAllChains { start_after, limit } => encode_binary(&query::list_all_chains(
Comment thread
joemonem marked this conversation as resolved.
Outdated
deps,
start_after.as_deref(),
limit,
)?),
QueryMsg::ListAllChannels { start_after, limit } => encode_binary(
Comment thread
joemonem marked this conversation as resolved.
Outdated
&query::list_all_channels(deps, start_after.as_deref(), limit)?,
),
QueryMsg::ListChainsWithChannels { start_after, limit } => encode_binary(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, we need another query that takes chain are argument and returns its channel details (both ics20 and direct). If its not present then it will error with Chain Not Found

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already covered by the ChannelInfo query, i'll adjust it to return an error if it's not found instead of a None value

&query::list_chains_with_channels(deps, start_after.as_deref(), limit)?,
),
QueryMsg::PendingPackets { channel_id } => {
encode_binary(&query::pending_packets(deps, channel_id)?)
}
QueryMsg::GetEnv { variable } => encode_binary(&query::get_env(deps, variable)?),

// Base queries
QueryMsg::Version {} => encode_binary(&ADOContract::default().query_version(deps)?),
QueryMsg::AdoType {} => encode_binary(&ADOContract::default().query_type(deps)?),
QueryMsg::Owner {} => encode_binary(&ADOContract::default().query_contract_owner(deps)?),
}
}
59 changes: 57 additions & 2 deletions contracts/os/andromeda-kernel/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use andromeda_std::{
os::{
aos_querier::AOSQuerier,
kernel::{
ChainNameResponse, ChannelInfoResponse, EnvResponse, PacketInfoAndSequence,
PendingPacketResponse, RecoveriesResponse, VerifyAddressResponse,
ChainChannelInfo, ChainNameResponse, ChannelInfoResponse, EnvResponse,
ListChainsWithChannelsResponse, PacketInfoAndSequence, PendingPacketResponse,
RecoveriesResponse, VerifyAddressResponse,
},
},
};
use cosmwasm_std::{Addr, Deps, Order};
use cw_storage_plus::Bound;

use crate::state::{
CHAIN_TO_CHANNEL, CHANNEL_TO_CHAIN, CHANNEL_TO_EXECUTE_MSG, CURR_CHAIN, ENV_VARIABLES,
Expand Down Expand Up @@ -107,3 +109,56 @@ pub fn get_env(deps: Deps, variable: String) -> Result<EnvResponse, ContractErro
value: ENV_VARIABLES.may_load(deps.storage, &variable.to_ascii_uppercase())?,
})
}

pub fn list_all_chains(
deps: Deps,
start_after: Option<&str>,
limit: Option<u32>,
) -> Result<Vec<String>, ContractError> {
let limit = limit.unwrap_or(50).min(100) as usize;
let start = start_after.map(Bound::exclusive);

let chains = CHAIN_TO_CHANNEL
.keys(deps.storage, start, None, cosmwasm_std::Order::Ascending)
.take(limit)
.collect::<Result<Vec<String>, _>>()?;
Ok(chains)
}

pub fn list_all_channels(
deps: Deps,
start_after: Option<&str>,
limit: Option<u32>,
) -> Result<Vec<String>, ContractError> {
let limit = limit.unwrap_or(50).min(100) as usize;
let start = start_after.map(Bound::exclusive);
let channels = CHANNEL_TO_CHAIN
.keys(deps.storage, start, None, cosmwasm_std::Order::Ascending)
.take(limit)
.collect::<Result<Vec<String>, _>>()?;
Ok(channels)
}

pub fn list_chains_with_channels(
deps: Deps,
start_after: Option<&str>,
limit: Option<u32>,
) -> Result<ListChainsWithChannelsResponse, ContractError> {
let limit = limit.unwrap_or(50).min(100) as usize;
let start = start_after.map(Bound::exclusive);

let chain_channel_info: Vec<ChainChannelInfo> = CHAIN_TO_CHANNEL
.range(deps.storage, start, None, Order::Ascending)
.take(limit)
.filter_map(|item| item.ok())
.map(|(chain, channel_info)| ChainChannelInfo {
chain,
ics20_channel_id: channel_info.ics20_channel_id,
direct_channel_id: channel_info.direct_channel_id,
kernel_address: channel_info.kernel_address,
supported_modules: channel_info.supported_modules,
})
.collect();

Ok(ListChainsWithChannelsResponse { chain_channel_info })
}
39 changes: 39 additions & 0 deletions packages/std/src/os/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,45 @@ pub enum QueryMsg {
PendingPackets { channel_id: Option<String> },
#[returns(EnvResponse)]
GetEnv { variable: String },
#[returns(ListAllChainsResponse)]
ListAllChains {
start_after: Option<String>,
limit: Option<u32>,
},
#[returns(ListAllChannelsResponse)]
ListAllChannels {
start_after: Option<String>,
limit: Option<u32>,
},
#[returns(ListChainsWithChannelsResponse)]
ListChainsWithChannels {
start_after: Option<String>,
limit: Option<u32>,
},
}

#[cw_serde]
pub struct ListAllChainsResponse {
pub chains: Vec<String>,
}

#[cw_serde]
pub struct ListAllChannelsResponse {
pub channels: Vec<String>,
}

#[cw_serde]
pub struct ChainChannelInfo {
pub chain: String,
pub ics20_channel_id: Option<String>,
pub direct_channel_id: Option<String>,
pub kernel_address: String,
pub supported_modules: Vec<String>,
}

#[cw_serde]
pub struct ListChainsWithChannelsResponse {
pub chain_channel_info: Vec<ChainChannelInfo>,
}

#[cw_serde]
Expand Down