diff --git a/contracts/neutron_interchain_queries/src/testing/tests.rs b/contracts/neutron_interchain_queries/src/testing/tests.rs index 66909321..ef04ab9d 100644 --- a/contracts/neutron_interchain_queries/src/testing/tests.rs +++ b/contracts/neutron_interchain_queries/src/testing/tests.rs @@ -19,7 +19,9 @@ use cosmwasm_std::testing::{message_info, mock_env, MockApi, MockStorage}; use cosmwasm_std::{ from_json, Addr, Binary, Coin, Decimal, Env, MessageInfo, OwnedDeps, StdError, Uint128, }; -use neutron_sdk::interchain_queries::helpers::{decode_and_convert, kv_key_from_string}; +use neutron_sdk::interchain_queries::helpers::{ + decode_and_convert, decode_hex, kv_key_from_string, +}; use neutron_sdk::interchain_queries::types::{ QueryType, TransactionFilterItem, TransactionFilterOp, TransactionFilterValue, }; @@ -39,7 +41,6 @@ use neutron_std::types::neutron::interchainqueries::{ RegisteredQuery, StorageValue, }; -use neutron_sdk::interchain_queries::hex::decode_hex; use neutron_sdk::interchain_queries::v047::queries::{ BalanceResponse, DelegatorDelegationsResponse, FeePoolResponse, ProposalResponse, TotalSupplyResponse, ValidatorResponse, ValidatorSigningInfoResponse, diff --git a/contracts/neutron_interchain_txs/src/contract.rs b/contracts/neutron_interchain_txs/src/contract.rs index 1548f76e..9a55abe7 100644 --- a/contracts/neutron_interchain_txs/src/contract.rs +++ b/contracts/neutron_interchain_txs/src/contract.rs @@ -6,11 +6,11 @@ use crate::storage::{ }; use cosmos_sdk_proto::traits::Message; use cosmwasm_std::{ - to_json_binary, Addr, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, MessageInfo, Reply, + to_json_binary, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult, SubMsg, }; use cw2::set_contract_version; -use neutron_sdk::interchain_txs::helpers::register_interchain_account; +use neutron_sdk::interchain_txs::helpers::{register_interchain_account, submit_tx}; use neutron_sdk::{ interchain_txs::helpers::{decode_message_response, get_port_id}, interchain_txs::v047::helpers::decode_acknowledgement_response, @@ -25,9 +25,7 @@ use neutron_std::types::cosmos::staking::v1beta1::{ }; use neutron_std::types::ibc::core::channel::v1::Order; use neutron_std::types::neutron::feerefunder::{Fee, FeerefunderQuerier}; -use neutron_std::types::neutron::interchaintxs::v1::{ - InterchaintxsQuerier, MsgSubmitTx, MsgSubmitTxResponse, -}; +use neutron_std::types::neutron::interchaintxs::v1::{InterchaintxsQuerier, MsgSubmitTxResponse}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -272,27 +270,6 @@ fn execute_delegate( Ok(Response::default().add_submessages(vec![submsg])) } -fn submit_tx( - contract: Addr, - connection_id: String, - interchain_account_id: String, - msgs: Vec, - memo: String, - timeout: u64, - fee: Fee, -) -> CosmosMsg { - MsgSubmitTx { - from_address: contract.to_string(), - interchain_account_id, - connection_id, - msgs, - memo, - timeout, - fee: Some(fee), - } - .into() -} - fn execute_undelegate( mut deps: DepsMut, env: Env, diff --git a/packages/neutron-sdk/src/interchain_queries/helpers.rs b/packages/neutron-sdk/src/interchain_queries/helpers.rs index 41bd1d2a..b26c97c0 100644 --- a/packages/neutron-sdk/src/interchain_queries/helpers.rs +++ b/packages/neutron-sdk/src/interchain_queries/helpers.rs @@ -1,5 +1,4 @@ use crate::errors::error::{NeutronError, NeutronResult}; -use crate::interchain_queries::hex::decode_hex; use crate::interchain_queries::types::{ AddressBytes, QueryPayload, QueryType, TransactionFilterItem, MAX_ADDR_LEN, }; @@ -9,6 +8,7 @@ use neutron_std::types::neutron::interchainqueries::{ MsgUpdateInterchainQueryRequest, }; use serde_json_wasm::to_string; +use std::fmt::Write as _; /// Decodes a bech32 encoded string and converts to base64 encoded bytes /// @@ -47,6 +47,8 @@ pub fn uint256_to_u128(value: Uint256) -> Result { } /// Basic helper to define a register interchain query message: +/// * **contract** is a contract address that registers the interchain query. +/// Must be equal to the contract that sends the message. /// * **query** is a query type identifier ('tx' or 'kv' for now) with a payload: /// - when the query enum is 'kv' then payload is the KV-storage keys for which we want to get /// values from remote chain; @@ -83,6 +85,8 @@ pub fn register_interchain_query( } /// Basic helper to define a update interchain query message: +/// * **contract** is a contract address that updates the interchain query. +/// Must be equal to the contract that sends the message. /// * **query_id** is ID of the query we want to update; /// * **new_keys** is encoded keys to query; /// * **new_update_period** is used to say how often (in neutron blocks) the query must be updated. @@ -102,7 +106,6 @@ pub fn update_interchain_query( Some(filters) => { to_string(&filters).map_err(|e| StdError::generic_err(e.to_string()))? } - // TODO: check if passing empty string is correct None => "".to_string(), }, } @@ -110,6 +113,8 @@ pub fn update_interchain_query( } /// Basic helper to define a remove interchain query message: +/// * **contract** is a contract address that removes the interchain query. +/// Must be equal to the contract that sends the message. /// * **query_id** is ID of the query we want to remove. pub fn remove_interchain_query(contract: Addr, query_id: u64) -> NeutronResult { Ok(MsgRemoveInterchainQueryRequest { @@ -132,3 +137,20 @@ pub fn kv_key_from_string>(s: S) -> Option { key: decode_hex(split[1])?, }) } + +/// Encodes bytes slice into hex string +pub fn encode_hex(bytes: &[u8]) -> String { + let mut s = String::with_capacity(bytes.len() * 2); + for &b in bytes { + let _ = write!(s, "{:02x}", b); + } + s +} + +/// Decodes hex string into bytes vec +pub fn decode_hex(s: &str) -> Option> { + (0..s.len()) + .step_by(2) + .map(|i| u8::from_str_radix(&s[i..i + 2], 16).ok()) + .collect() +} diff --git a/packages/neutron-sdk/src/interchain_queries/hex.rs b/packages/neutron-sdk/src/interchain_queries/hex.rs deleted file mode 100644 index 11de7aeb..00000000 --- a/packages/neutron-sdk/src/interchain_queries/hex.rs +++ /dev/null @@ -1,18 +0,0 @@ -use std::fmt::Write as _; - -/// Encodes bytes slice into hex string -pub fn encode_hex(bytes: &[u8]) -> String { - let mut s = String::with_capacity(bytes.len() * 2); - for &b in bytes { - let _ = write!(s, "{:02x}", b); - } - s -} - -/// Decodes hex string into bytes vec -pub fn decode_hex(s: &str) -> Option> { - (0..s.len()) - .step_by(2) - .map(|i| u8::from_str_radix(&s[i..i + 2], 16).ok()) - .collect() -} diff --git a/packages/neutron-sdk/src/interchain_queries/mod.rs b/packages/neutron-sdk/src/interchain_queries/mod.rs index 1bda93e4..507603ea 100644 --- a/packages/neutron-sdk/src/interchain_queries/mod.rs +++ b/packages/neutron-sdk/src/interchain_queries/mod.rs @@ -1,5 +1,4 @@ pub mod helpers; -pub mod hex; pub mod queries; pub mod types; pub mod v045; diff --git a/packages/neutron-sdk/src/interchain_txs/helpers.rs b/packages/neutron-sdk/src/interchain_txs/helpers.rs index 67e0e867..de07ad53 100644 --- a/packages/neutron-sdk/src/interchain_txs/helpers.rs +++ b/packages/neutron-sdk/src/interchain_txs/helpers.rs @@ -27,6 +27,11 @@ pub fn get_port_id>(contract_address: R, interchain_account_id: R) + interchain_account_id.as_ref() } +/// Basic helper to define a register interchain account message: +/// * **contract** is a contract that registers ICA. Must be the contract address that sends this message. +/// * **connection_id** is an IBC connection identifier between Neutron and remote chain; +/// * **interchain_account_id** is an identifier of your new interchain account. Can be any string. +/// * **ordering** is an ordering of ICA channel. Set to ORDERED if not specified pub fn register_interchain_account( contract: Addr, connection_id: String,