Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
foxpy committed May 30, 2023
1 parent b934465 commit e9d4ae2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
10 changes: 10 additions & 0 deletions packages/neutron-sdk/src/interchain_queries/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::errors::error::{NeutronError, NeutronResult};
use crate::interchain_queries::types::{
AddressBytes, BALANCES_PREFIX, DELEGATION_KEY, FEE_POOL_KEY, MAX_ADDR_LEN,
PARAMS_STORE_DELIMITER, PROPOSALS_KEY_PREFIX, SUPPLY_PREFIX, VALIDATORS_KEY,
WASM_CONTRACT_STORE,
};
use cosmos_sdk_proto::cosmos::staking::v1beta1::Commission as ValidatorCommission;
use cosmwasm_std::{Binary, Decimal, Uint128};
Expand Down Expand Up @@ -138,6 +139,15 @@ pub fn create_gov_proposal_key(proposal_id: u64) -> NeutronResult<Vec<u8>> {
Ok(key)
}

/// Creates Cosmos-SDK distribution key for fee pool
/// <https://github.com/cosmos/cosmos-sdk/blob/35ae2c4c72d4aeb33447d5a7af23ca47f786606e/x/distribution/types/keys.go#L46>
pub fn create_wasm_contract_store_key<Key: AsRef<[u8]>>(key: Key) -> NeutronResult<Vec<u8>> {
let mut prefix: Vec<u8> = vec![WASM_CONTRACT_STORE];
prefix.extend_from_slice(length_prefix(key)?.as_slice());

Ok(prefix)
}

/// Returns validator max change rate
pub fn get_max_change_rate(commission: &Option<ValidatorCommission>) -> Option<Decimal> {
let commission_rates = commission.as_ref().map(|v| v.commission_rates.as_ref())?;
Expand Down
32 changes: 28 additions & 4 deletions packages/neutron-sdk/src/interchain_queries/register_queries.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use crate::bindings::query::NeutronQuery;
use crate::interchain_queries::types::{
QueryType, TransactionFilterItem, TransactionFilterOp, TransactionFilterValue, BANK_STORE_KEY,
DISTRIBUTION_STORE_KEY, GOV_STORE_KEY, HEIGHT_FIELD, KEY_BOND_DENOM, PARAMS_STORE_KEY,
RECIPIENT_FIELD, STAKING_STORE_KEY,
RECIPIENT_FIELD, STAKING_STORE_KEY, WASM_STORE_KEY,
};
use crate::{
bindings::{msg::NeutronMsg, types::KVKey},
bindings::{msg::NeutronMsg, query::NeutronQuery, types::KVKey},
errors::error::NeutronResult,
interchain_queries::{
helpers::{
create_account_denom_balance_key, create_delegation_key, create_fee_pool_key,
create_gov_proposal_key, create_params_store_key, create_total_denom_key,
create_validator_key, decode_and_convert,
create_validator_key, create_wasm_contract_store_key, decode_and_convert,
},
types::QueryPayload,
},
Expand Down Expand Up @@ -242,3 +241,28 @@ pub fn new_register_transfers_query_msg(
update_period,
)
}

/// Creates a message to register an Interchain Query to get wasm contract store on remote chain
/// from **wasm** module
///
/// * **connection_id** is an IBC connection identifier between Neutron and remote chain;
/// * **key** is a wasm contract store key
/// * **update_period** is used to say how often the query must be updated.
pub fn new_register_wasm_contract_store_query_msg(
connection_id: String,
key: &str,
update_period: u64,
) -> NeutronResult<NeutronMsg> {
let wasm_key = create_wasm_contract_store_key(key.as_bytes())?;

let kv_key = KVKey {
path: WASM_STORE_KEY.to_string(),
key: Binary(wasm_key),
};

NeutronMsg::register_interchain_query(
QueryPayload::KV(vec![kv_key]),
connection_id,
update_period,
)
}
7 changes: 7 additions & 0 deletions packages/neutron-sdk/src/interchain_queries/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ pub const VALIDATORS_KEY: u8 = 0x21;
/// <https://github.com/cosmos/cosmos-sdk/blob/35ae2c4c72d4aeb33447d5a7af23ca47f786606e/x/distribution/types/keys.go#L46>
pub const FEE_POOL_KEY: u8 = 0x00;

/// Key for Wasm Contract Store in the **wasm** module's storage
/// <https://github.com/CosmWasm/wasmd/blob/e6d451bf9dd96a555b10e72aa3c0f6b820d34684/x/wasm/types/keys.go#L28>
pub const WASM_CONTRACT_STORE: u8 = 0x03;

/// Key for Proposals in the **gov** module's storage
/// <https://github.com/cosmos/cosmos-sdk/blob/35ae2c4c72d4aeb33447d5a7af23ca47f786606e/x/gov/types/keys.go#L41>
pub const PROPOSALS_KEY_PREFIX: u8 = 0x00;
Expand Down Expand Up @@ -77,6 +81,9 @@ pub const PARAMS_STORE_KEY: &str = "params";
/// Default delimiter of **params** Cosmos-SDK module
pub const PARAMS_STORE_DELIMITER: &str = "/";

/// Name of the **wasm** Cosmos module
pub const WASM_STORE_KEY: &str = "wasm";

pub const RECIPIENT_FIELD: &str = "transfer.recipient";
pub const HEIGHT_FIELD: &str = "tx.height";

Expand Down

0 comments on commit e9d4ae2

Please sign in to comment.