diff --git a/Cargo.lock b/Cargo.lock index 12e58da..f80c104 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,21 +13,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "aho-corasick" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a" -dependencies = [ - "memchr", -] - -[[package]] -name = "anyhow" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" - [[package]] name = "base16ct" version = "0.1.1" @@ -76,12 +61,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" - [[package]] name = "cfg-if" version = "1.0.0" @@ -155,21 +134,11 @@ dependencies = [ "hex", "schemars", "serde", - "serde-json-wasm 0.5.0", + "serde-json-wasm", "sha2 0.10.7", "thiserror", ] -[[package]] -name = "cosmwasm-storage" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b52be0d56b78f502f3acb75e40908a0d04d9f265b6beb0f86b36ec2ece048748" -dependencies = [ - "cosmwasm-std", - "serde", -] - [[package]] name = "cpufeatures" version = "0.2.5" @@ -214,25 +183,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "cw-multi-test" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2eb84554bbfa6b66736abcd6a9bfdf237ee0ecb83910f746dff7f799093c80a" -dependencies = [ - "anyhow", - "cosmwasm-std", - "cw-storage-plus", - "cw-utils", - "derivative", - "itertools", - "k256", - "prost", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "cw-storage-plus" version = "1.1.0" @@ -244,21 +194,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cw-utils" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c80e93d1deccb8588db03945016a292c3c631e6325d349ebb35d2db6f4f946f7" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw2", - "schemars", - "semver", - "serde", - "thiserror", -] - [[package]] name = "cw2" version = "1.1.0" @@ -347,12 +282,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "either" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" - [[package]] name = "elliptic-curve" version = "0.12.3" @@ -430,12 +359,6 @@ dependencies = [ "ahash", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "hex" version = "0.4.3" @@ -457,30 +380,13 @@ version = "1.0.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cosmwasm-storage", - "cw-multi-test", "cw-storage-plus", "cw2", "hex", - "regex", - "schemars", - "serde", - "serde-json-wasm 1.0.0", "sha2 0.10.7", - "strum", - "strum_macros", "thiserror", ] -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.5" @@ -505,12 +411,6 @@ version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - [[package]] name = "once_cell" version = "1.17.0" @@ -542,29 +442,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "prost" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001" -dependencies = [ - "bytes", - "prost-derive", -] - -[[package]] -name = "prost-derive" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" -dependencies = [ - "anyhow", - "itertools", - "proc-macro2", - "quote", - "syn 1.0.107", -] - [[package]] name = "quote" version = "1.0.33" @@ -589,35 +466,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "regex" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" - [[package]] name = "rfc6979" version = "0.3.1" @@ -629,12 +477,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - [[package]] name = "ryu" version = "1.0.12" @@ -679,12 +521,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "semver" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" - [[package]] name = "serde" version = "1.0.185" @@ -703,15 +539,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde-json-wasm" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c37d03f3b0f6b5f77c11af1e7c772de1c9af83e50bef7bb6069601900ba67b" -dependencies = [ - "serde", -] - [[package]] name = "serde_derive" version = "1.0.185" @@ -789,25 +616,6 @@ dependencies = [ "der", ] -[[package]] -name = "strum" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" - -[[package]] -name = "strum_macros" -version = "0.25.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad8d03b598d3d0fff69bf533ee3ef19b8eeb342729596df84bcc7e1f96ec4059" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn 2.0.29", -] - [[package]] name = "subtle" version = "2.4.1" diff --git a/Cargo.toml b/Cargo.toml index dbca9d1..fd638d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,29 +32,11 @@ backtraces = ["cosmwasm-std/backtraces"] # use library feature to disable all instantiate/execute/query exports library = [] -[package.metadata.scripts] -optimize = """docker run --rm -v "$(pwd)":/code \ - --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ - --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/rust-optimizer:0.12.12 -""" - [dependencies] cosmwasm-schema = "1.3.3" cosmwasm-std = "1.3.3" -cosmwasm-storage = "1.3.3" cw-storage-plus = "1.1.0" cw2 = "1.1.0" hex = "0.4.3" -regex = "1" -schemars = "0.8.12" -serde = { version = "1.0.185", default-features = false, features = ["derive"] } sha2 = "0.10.7" -thiserror = "1.0.47" -strum = "0.25.0" -strum_macros = "0.25.2" -serde-json-wasm = "1.0.0" - -[dev-dependencies] -cw-multi-test = "0.16.2" - +thiserror = "1.0.47" diff --git a/Makefile b/Makefile index 71feb06..066df81 100644 --- a/Makefile +++ b/Makefile @@ -22,19 +22,19 @@ build-debug: build-optimized: docker run --rm -v "$(CURDIR)":/code \ - --mount type=volume,source="$(notdir $(CURDIR))_cache",target=/code/target \ + --mount type=volume,source="$(notdir $(CURDIR))_cache",target=/target \ --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/rust-optimizer:0.12.13 + cosmwasm/rust-optimizer:0.14.0 validate: cosmwasm-check ./artifacts/ica_oracle.wasm # Uploads the contract to osmosis -store-contract: +store-contract: @STRIDE_HOME=$(STRIDE_HOME) bash scripts/store_contract.sh # Instantiates the contract directly with the osmosis dockernet validator as the admin -instantiate-contract: +instantiate-contract: @STRIDE_HOME=$(STRIDE_HOME) bash scripts/instantiate_contract.sh # Adds a metric directly to the contract from the osmosis dockernet validator diff --git a/src/helpers.rs b/src/helpers.rs index 3d77b1b..814747d 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,8 +1,7 @@ use crate::ContractError; -use regex::Regex; use sha2::{Digest, Sha256}; -const CHANNEL_REGEX: &str = r"^channel-\d+$"; +const CHANNEL_ID_PERFIX: &str = "channel"; const TRANSFER_PORT_ID: &str = "transfer"; /// follows cosmos SDK validation logic where denoms can be 3 - 128 characters long @@ -38,12 +37,24 @@ pub fn validate_native_denom(denom: &str) -> Result<(), ContractError> { // Validates that the channel ID is of the form `channel-N` pub fn validate_channel_id(channel_id: &str) -> Result<(), ContractError> { - let re = Regex::new(CHANNEL_REGEX).unwrap(); - if !re.is_match(channel_id) { + let Some((prefix, id)) = channel_id.split_once('-') else { + return Err(ContractError::InvalidChannelID { + channel_id: channel_id.to_string(), + }); + }; + + if prefix != CHANNEL_ID_PERFIX { + return Err(ContractError::InvalidChannelID { + channel_id: channel_id.to_string(), + }); + } + + if id.parse::().is_err() { return Err(ContractError::InvalidChannelID { channel_id: channel_id.to_string(), }); } + Ok(()) }